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

Last change on this file since 688 was 685, checked in by Christopher Edwards, 15 years ago

added support for RPMS for Non-VA meds (Home meds)

File size: 11.7 KB
Line 
1C0CMED3 ; 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 ;
24EXTRACT(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 . . ;
108 . . ; NDFIEN is not necessarily defined; it won't be if the drug
109 . . ; is not matched to the national drug file (e.g. if the drug is
110 . . ; new on the market, compounded, or is a fake drug [blue pill].
111 . . ; To protect against failure, I will put an if/else block
112 . . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
113 . . I NDFIEN,$D(^C0CRXN) D ; $Data is for Systems that don't have our RxNorm file yet.
114 . . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
115 . . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
116 . . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
117 . . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
118 . . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
119 . . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
120 . . ;
121 . . E S (RXNORM,RXNNAME,RXNVER)=""
122 . . ; End if/else block
123 . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
124 . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
125 . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
126 . . ;
127 . . S @MAP@("MEDBRANDNAMETEXT")=""
128 . . ; DOSE^PSS50 ONLY ESISTS ON VISTA
129 . . I '$$RPMS^C0CUTIL() D
130 . . . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
131 . . . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
132 . . . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
133 . . . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
134 . . E S @MAP@("MEDSTRENGTHVALUE")="" S @MAP@("MEDSTRENGTHUNIT")=""
135 . . ; Units, concentration, etc, come from another call
136 . . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
137 . . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
138 . . ; NDF Entry IEN, and VA Product Name
139 . . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
140 . . ; Documented in the same manual; executed above.
141 . . ;
142 . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
143 . . ; and this will crash the call. So...
144 . . I NDFIEN="" S CONCDATA=""
145 . . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
146 . . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
147 . . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
148 . . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
149 . . S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
150 . . ; Oddly, there is no easy place to find the dispense unit.
151 . . ; It's not included in the original call, so we have to go to the drug file.
152 . . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
153 . . ; Node 14.5 is the Dispense Unit
154 . . ; PSS50 ONLY EXISTS ON VISTA
155 . . I '$$RPMS^C0CUTIL() D
156 . . . D DATA^PSS50(MEDIEN,,,,,"QTY")
157 . . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
158 . . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
159 . . E S @MAP@("MEDQUANTITYUNIT")=""
160 . E D
161 . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=""
162 . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
163 . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=""
164 . . S @MAP@("MEDBRANDNAMETEXT")=""
165 . . S @MAP@("MEDSTRENGTHVALUE")=""
166 . . S @MAP@("MEDSTRENGTHUNIT")=""
167 . . S @MAP@("MEDFORMTEXT")=""
168 . . S @MAP@("MEDCONCVALUE")=""
169 . . S @MAP@("MEDCONCUNIT")=""
170 . . S @MAP@("MEDSIZETEXT")=""
171 . . S @MAP@("MEDQUANTITYVALUE")=""
172 . . S @MAP@("MEDQUANTITYUNIT")=""
173 . ; End If/Else
174 . ; --- START OF DIRECTIONS ---
175 . ; Dosage is field 2, route is 3, schedule is 4
176 . ; These are all free text fields, and don't point to any files
177 . ; For that reason, I will use the field I never used before:
178 . ; MEDDIRECTIONDESCRIPTIONTEXT
179 . S DIRCNT=1 ; THERE IS ONLY ONE DIRECTION FOR OUTSIDE MEDS
180 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
181 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
182 . S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
183 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
184 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
185 . S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
186 . S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
187 . S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
188 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
189 . S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
190 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
191 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
192 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
193 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
194 . S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
195 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
196 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
197 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
198 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
199 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
200 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
201 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
202 . S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
203 . S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
204 . S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
205 . ;
206 . ; --- END OF DIRECTIONS ---
207 . ;
208 . S @MAP@("MEDRFNO")=""
209 . I $D(MED(14,1)) D ;
210 . . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
211 . E S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=""
212 . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
213 . K @RESULT
214 . D MAP^C0CXPATH(MINXML,MAP,RESULT)
215 . ; D PARY^C0CXPATH(RESULT)
216 . ; MAPPING DIRECTIONS
217 . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
218 . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
219 . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
220 . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
221 . N MDZ1,MDZNA
222 . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
223 . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
224 . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
225 . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
226 . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
227 . ;
228 . ; MAP PATIENT INSTRUCTIONS - HAVE TO DO THIS AFTER MAPPING DIRECTIONS DUE TO XML SCHEMA VALIDATION
229 . N MEDINT1,INTXML1 S INTXML1="MENINT1" ; VARIABLE AND NAME VARIABLE TEMPLATE
230 . N MEDINT2,INTXML2 S INTXML2="MEDINT2" ; VARIABLE AND NAME VARIABLE RESULT
231 . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/PatientInstructions",INTXML1)
232 . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/PatientInstructions")
233 . N MDI1
234 . S MDI1=$NA(@MAP@("I"))
235 . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
236 . I $D(MED(10,1)) D ;
237 . . S @MAP@("I","MEDPTINSTRUCTIONS")=$P(MED(10,1)," ",1) ; WP Field
238 . E S @MAP@("I","MEDPTINSTRUCTIONS")=""
239 . D MAP^C0CXPATH(INTXML1,MDI1,INTXML2)
240 . D INSERT^C0CXPATH(RESULT,INTXML2,"//Medications/Medication")
241 . ;
242 . ; FLAG HAS TO BE RESET OUTSIDE THE IF STATMENT.
243 . ;I MEDFIRST D ;
244 . ;. S MEDFIRST=0 ; RESET FIRST FLAG
245 . ;. D CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
246 . ;D:'MEDFIRST INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
247 . D:MEDFIRST CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
248 . D:'MEDFIRST INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
249 . I MEDFIRST S MEDFIRST=0
250 N MEDTMP,MEDI
251 D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
252 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
253 . W "MEDICATION MISSING ",!
254 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
255 Q
256 ;
Note: See TracBrowser for help on using the repository browser.