1 | C0CMED3 ; WV/CCDCCR/SMH - Meds: Non-VA/Outside Meds for Vista
|
---|
2 | ;;1.0;C0C;;May 19, 2009;
|
---|
3 | ;;Last Modified: Sun Jan 11 05:45:03 UTC 2009
|
---|
4 | ; Copyright 2009 WorldVistA. Licensed under the terms of the GNU
|
---|
5 | ; General Public License See attached copy of the License.
|
---|
6 | ;
|
---|
7 | ; This program is free software; you can redistribute it and/or modify
|
---|
8 | ; it under the terms of the GNU General Public License as published by
|
---|
9 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
10 | ; (at your option) any later version.
|
---|
11 | ;
|
---|
12 | ; This program is distributed in the hope that it will be useful,
|
---|
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | ; GNU General Public License for more details.
|
---|
16 | ;
|
---|
17 | ; You should have received a copy of the GNU General Public License along
|
---|
18 | ; with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
19 | ; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
---|
20 | ;
|
---|
21 | W "NO ENTRY FROM TOP",!
|
---|
22 | Q
|
---|
23 | ;
|
---|
24 | EXTRACT(MINXML,DFN,OUTXML,MEDCOUNT) ; Extract medications into provided xml template
|
---|
25 | ;
|
---|
26 | ; MINXML is the Input XML Template, (passed by name)
|
---|
27 | ; DFN is Patient IEN (passed by value)
|
---|
28 | ; OUTXML is the resultant XML (passed by name)
|
---|
29 | ; MEDCOUNT is the number of Meds extracted so far (passed by reference)
|
---|
30 | ;
|
---|
31 | ; MEDS is return array from RPC.
|
---|
32 | ; MAP is a mapping variable map (store result) for each med
|
---|
33 | ; MED is holds each array element from MEDS, one medicine
|
---|
34 | ;
|
---|
35 | ; Non-VA meds don't have an API. They are stored in file 55, subfile 52.2
|
---|
36 | ; Discontinued meds are indicated by the presence of a value in fields
|
---|
37 | ; 5 or 6 (STATUS 1 or 2, and DISCONTINUED DATE)
|
---|
38 | ; Will use Fileman API GETS^DIQ
|
---|
39 | ;
|
---|
40 | N MEDS,MAP
|
---|
41 | K ^TMP($J,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
|
---|
42 | N NVA
|
---|
43 | D GETS^DIQ(55,DFN,"52.2*","IE","NVA") ; Output in NVA in FDA array format.
|
---|
44 | ; If NVA does not exist, then patient has no non-VA meds
|
---|
45 | I $D(NVA)=0 S @OUTXML@(0)=0 QUIT
|
---|
46 | ; Otherwise, we go on...
|
---|
47 | M MEDS=NVA(55.05)
|
---|
48 | ; We are done with NVA
|
---|
49 | K NVA
|
---|
50 | ;
|
---|
51 | I DEBUG ZWRITE MEDS
|
---|
52 | N FDAIEN S FDAIEN=0 ; For use in $Order in the MEDS array.
|
---|
53 | N MEDFIRST S MEDFIRST=1 ; FLAG FOR FIRST MED PROCESSED HERE
|
---|
54 | F S FDAIEN=$O(MEDS(FDAIEN)) Q:FDAIEN="" D ; FOR EACH MEDICATION IN THE LIST
|
---|
55 | . N MED M MED=MEDS(FDAIEN)
|
---|
56 | . I MED(5,"I")!MED(6,"I") QUIT ; If disconinued, we don't want to pull it.
|
---|
57 | . S MEDCOUNT=MEDCOUNT+1
|
---|
58 | . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
|
---|
59 | . N RXIEN S RXIEN=$P(FDAIEN,",") ; First piece of FDAIEN is the number of the med for this patient
|
---|
60 | . I DEBUG W "RXIEN IS ",RXIEN,!
|
---|
61 | . I DEBUG W "MAP= ",MAP,!
|
---|
62 | . S @MAP@("MEDOBJECTID")="MED_OUTSIDE"_MEDCOUNT ; MEDCOUNT FOR ID
|
---|
63 | . S @MAP@("MEDISSUEDATETXT")="Documented Date"
|
---|
64 | . ; Field 6 is "Effective date", and we pull it in timson format w/ I
|
---|
65 | . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL(MED(11,"I"),"DT")
|
---|
66 | . ; Med never filled; next 4 fields are not applicable.
|
---|
67 | . S @MAP@("MEDLASTFILLDATETXT")=""
|
---|
68 | . S @MAP@("MEDLASTFILLDATE")=""
|
---|
69 | . S @MAP@("MEDRXNOTXT")=""
|
---|
70 | . S @MAP@("MEDRXNO")=""
|
---|
71 | . S @MAP@("MEDTYPETEXT")="Medication"
|
---|
72 | . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
|
---|
73 | . S @MAP@("MEDSTATUSTEXT")="ACTIVE" ; nearest status for pending meds
|
---|
74 | . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_MED(12,"I")
|
---|
75 | . S @MAP@("MEDPRODUCTNAMETEXT")=MED(.01,"E")
|
---|
76 | . ; NDC is field 31 in the drug file.
|
---|
77 | . ; The actual drug entry in the drug file (MEDIEN) is not necessarily supplied.
|
---|
78 | . ; It' node 1, internal form.
|
---|
79 | . N MEDIEN S MEDIEN=MED(1,"I")
|
---|
80 | . I +MEDIEN D ; start of if/else block
|
---|
81 | . . ; 12/30/08: I will be using RxNorm for coding...
|
---|
82 | . . ; 176.001 is the file for Concepts; 176.003 is the file for
|
---|
83 | . . ; sources (i.e. for RxNorm Version)
|
---|
84 | . . ;
|
---|
85 | . . ; We need the VUID first for the National Drug File entry first
|
---|
86 | . . ; We get the VUID of the drug, by looking up the VA Product entry
|
---|
87 | . . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
|
---|
88 | . . ; Field 99.99 is the VUID.
|
---|
89 | . . ;
|
---|
90 | . . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
|
---|
91 | . . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
|
---|
92 | . . ; $$GET1^DIQ.
|
---|
93 | . . ;
|
---|
94 | . . ; I get the RxNorm name and version from the RxNorm Sources (file
|
---|
95 | . . ; 176.003), by searching for "RXNORM", then get the data.
|
---|
96 | . . ; NDF^PSS50 ONLY EXISTS ON VISTA
|
---|
97 | . . N NDFDATA,NDFIEN,VAPROD
|
---|
98 | . . S NDFIEN=""
|
---|
99 | . . I '$$RPMS^C0CUTIL() D
|
---|
100 | . . . D NDF^PSS50(MEDIEN,,,,,"NDF")
|
---|
101 | . . . ;N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
|
---|
102 | . . . ;N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
|
---|
103 | . . . ;N VAPROD S VAPROD=$P(NDFDATA(22),U)
|
---|
104 | . . . M NDFDATA=^TMP($J,"NDF",MEDIEN)
|
---|
105 | . . . S NDFIEN=$P(NDFDATA(20),U)
|
---|
106 | . . . S VAPROD=$P(NDFDATA(22),U)
|
---|
107 | . . . S @MAP@("MEDPRODUCTNAMETEXT")=$$GET1^DIQ(50.68,VAPROD,.01) ;
|
---|
108 | . . ; GPL - RESET THE NAME TO THE REAL NAME OF THE DRUG NOW THAT WE
|
---|
109 | . . ; HAVE IT.
|
---|
110 | . . ;
|
---|
111 | . . ; NDFIEN is not necessarily defined; it won't be if the drug
|
---|
112 | . . ; is not matched to the national drug file (e.g. if the drug is
|
---|
113 | . . ; new on the market, compounded, or is a fake drug [blue pill].
|
---|
114 | . . ; To protect against failure, I will put an if/else block
|
---|
115 | . . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
|
---|
116 | . . I NDFIEN,$D(^C0CRXN) D ; $Data is for Systems that don't have our RxNorm file yet.
|
---|
117 | . . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
|
---|
118 | . . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
|
---|
119 | . . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
|
---|
120 | . . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
|
---|
121 | . . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
|
---|
122 | . . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
|
---|
123 | . . ;
|
---|
124 | . . E S (RXNORM,RXNNAME,RXNVER)=""
|
---|
125 | . . ; End if/else block
|
---|
126 | . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
|
---|
127 | . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
|
---|
128 | . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
|
---|
129 | . . ;
|
---|
130 | . . S @MAP@("MEDBRANDNAMETEXT")=""
|
---|
131 | . . ; DOSE^PSS50 ONLY ESISTS ON VISTA
|
---|
132 | . . I '$$RPMS^C0CUTIL() D
|
---|
133 | . . . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
|
---|
134 | . . . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
|
---|
135 | . . . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
|
---|
136 | . . . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
|
---|
137 | . . E S @MAP@("MEDSTRENGTHVALUE")="" S @MAP@("MEDSTRENGTHUNIT")=""
|
---|
138 | . . ; Units, concentration, etc, come from another call
|
---|
139 | . . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
|
---|
140 | . . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
|
---|
141 | . . ; NDF Entry IEN, and VA Product Name
|
---|
142 | . . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
|
---|
143 | . . ; Documented in the same manual; executed above.
|
---|
144 | . . ;
|
---|
145 | . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
|
---|
146 | . . ; and this will crash the call. So...
|
---|
147 | . . I NDFIEN="" S CONCDATA=""
|
---|
148 | . . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
|
---|
149 | . . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
|
---|
150 | . . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
|
---|
151 | . . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
|
---|
152 | . . S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
|
---|
153 | . . ; Oddly, there is no easy place to find the dispense unit.
|
---|
154 | . . ; It's not included in the original call, so we have to go to the drug file.
|
---|
155 | . . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
|
---|
156 | . . ; Node 14.5 is the Dispense Unit
|
---|
157 | . . ; PSS50 ONLY EXISTS ON VISTA
|
---|
158 | . . I '$$RPMS^C0CUTIL() D
|
---|
159 | . . . D DATA^PSS50(MEDIEN,,,,,"QTY")
|
---|
160 | . . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
|
---|
161 | . . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
|
---|
162 | . . E S @MAP@("MEDQUANTITYUNIT")=""
|
---|
163 | . E D
|
---|
164 | . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=""
|
---|
165 | . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
|
---|
166 | . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=""
|
---|
167 | . . S @MAP@("MEDBRANDNAMETEXT")=""
|
---|
168 | . . S @MAP@("MEDSTRENGTHVALUE")=""
|
---|
169 | . . S @MAP@("MEDSTRENGTHUNIT")=""
|
---|
170 | . . S @MAP@("MEDFORMTEXT")=""
|
---|
171 | . . S @MAP@("MEDCONCVALUE")=""
|
---|
172 | . . S @MAP@("MEDCONCUNIT")=""
|
---|
173 | . . S @MAP@("MEDSIZETEXT")=""
|
---|
174 | . . S @MAP@("MEDQUANTITYVALUE")=""
|
---|
175 | . . S @MAP@("MEDQUANTITYUNIT")=""
|
---|
176 | . ; End If/Else
|
---|
177 | . ; --- START OF DIRECTIONS ---
|
---|
178 | . ; Dosage is field 2, route is 3, schedule is 4
|
---|
179 | . ; These are all free text fields, and don't point to any files
|
---|
180 | . ; For that reason, I will use the field I never used before:
|
---|
181 | . ; MEDDIRECTIONDESCRIPTIONTEXT
|
---|
182 | . S DIRCNT=1 ; THERE IS ONLY ONE DIRECTION FOR OUTSIDE MEDS
|
---|
183 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
|
---|
184 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
|
---|
185 | . S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
|
---|
186 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
|
---|
187 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
|
---|
188 | . S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
|
---|
189 | . S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
|
---|
190 | . S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
|
---|
191 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
|
---|
192 | . S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
|
---|
193 | . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
|
---|
194 | . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
|
---|
195 | . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
|
---|
196 | . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
|
---|
197 | . S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
|
---|
198 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
|
---|
199 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
|
---|
200 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
|
---|
201 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
|
---|
202 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
|
---|
203 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
|
---|
204 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
|
---|
205 | . S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
|
---|
206 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
|
---|
207 | . S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
|
---|
208 | . ;
|
---|
209 | . ; --- END OF DIRECTIONS ---
|
---|
210 | . ;
|
---|
211 | . S @MAP@("MEDRFNO")=""
|
---|
212 | . I $D(MED(14,1)) D ;
|
---|
213 | . . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
|
---|
214 | . E S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=""
|
---|
215 | . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
|
---|
216 | . K @RESULT
|
---|
217 | . D MAP^C0CXPATH(MINXML,MAP,RESULT)
|
---|
218 | . ; D PARY^C0CXPATH(RESULT)
|
---|
219 | . ; MAPPING DIRECTIONS
|
---|
220 | . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
|
---|
221 | . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
|
---|
222 | . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
|
---|
223 | . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
|
---|
224 | . N MDZ1,MDZNA
|
---|
225 | . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
|
---|
226 | . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
|
---|
227 | . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
|
---|
228 | . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
|
---|
229 | . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
|
---|
230 | . ;
|
---|
231 | . ; MAP PATIENT INSTRUCTIONS - HAVE TO DO THIS AFTER MAPPING DIRECTIONS DUE TO XML SCHEMA VALIDATION
|
---|
232 | . N MEDINT1,INTXML1 S INTXML1="MENINT1" ; VARIABLE AND NAME VARIABLE TEMPLATE
|
---|
233 | . N MEDINT2,INTXML2 S INTXML2="MEDINT2" ; VARIABLE AND NAME VARIABLE RESULT
|
---|
234 | . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/PatientInstructions",INTXML1)
|
---|
235 | . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/PatientInstructions")
|
---|
236 | . ;N MDI1 ; removing the "I" which is not in the protocol gpl 1/2010
|
---|
237 | . ;S MDI1=$NA(@MAP@("I"))
|
---|
238 | . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
|
---|
239 | . I $D(MED(10,1)) D ;
|
---|
240 | . . ;S @MAP@("I","MEDPTINSTRUCTIONS")=$P(MED(10,1)," ",1) ; WP Field
|
---|
241 | . . S @MAP@("MEDPTINSTRUCTIONS")=$P(MED(10,1)," ",1) ; WP Field
|
---|
242 | . E S @MAP@("MEDPTINSTRUCTIONS")=""
|
---|
243 | . ;E S @MAP@("I","MEDPTINSTRUCTIONS")=""
|
---|
244 | . ;D MAP^C0CXPATH(INTXML1,MDI1,INTXML2)
|
---|
245 | . D MAP^C0CXPATH(INTXML1,MAP,INTXML2) ; JUST MAP WORKS.. GPL
|
---|
246 | . D INSERT^C0CXPATH(RESULT,INTXML2,"//Medications/Medication")
|
---|
247 | . ;
|
---|
248 | . ; FLAG HAS TO BE RESET OUTSIDE THE IF STATMENT.
|
---|
249 | . ;I MEDFIRST D ;
|
---|
250 | . ;. S MEDFIRST=0 ; RESET FIRST FLAG
|
---|
251 | . ;. D CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
|
---|
252 | . ;D:'MEDFIRST INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
|
---|
253 | . D:MEDFIRST CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
|
---|
254 | . D:'MEDFIRST INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
|
---|
255 | . I MEDFIRST S MEDFIRST=0
|
---|
256 | N MEDTMP,MEDI
|
---|
257 | D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
|
---|
258 | I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
|
---|
259 | . W "MEDICATION MISSING ",!
|
---|
260 | . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
|
---|
261 | Q
|
---|
262 | ;
|
---|