source: ccr/trunk/p/C0CMED3.m@ 1678

Last change on this file since 1678 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

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