1 | CCRMEDS3 ; WV/CCDCCR/SMH - Meds: Non-VA/Outside Meds for Vista
|
---|
2 | ;;0.1;CCDCCR;;;
|
---|
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) ; Extract medications into provided xml template
|
---|
25 | ;
|
---|
26 | ; MINXML is the Input XML Template, passed by name
|
---|
27 | ; DFN is Patient IEN
|
---|
28 | ; OUTXML is the resultant XML.
|
---|
29 | ;
|
---|
30 | ; MEDS is return array from RPC.
|
---|
31 | ; MAP is a mapping variable map (store result) for each med
|
---|
32 | ; MED is holds each array element from MEDS, one medicine
|
---|
33 | ;
|
---|
34 | ; Non-VA meds don't have an API. They are stored in file 55, subfile 52.2
|
---|
35 | ; Discontinued meds are indicated by the presence of a value in fields
|
---|
36 | ; 5 or 6 (STATUS 1 or 2, and DISCONTINUED DATE)
|
---|
37 | ; Will use Fileman API GETS^DIQ
|
---|
38 | ;
|
---|
39 | N MEDS,MAP
|
---|
40 | K ^TMP($J),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 ZWR MEDS
|
---|
50 | N FDAIEN S FDAIEN=0 ; For use in $Order in the MEDS array.
|
---|
51 | S MEDMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP"))
|
---|
52 | N MEDCOUNT S MEDCOUNT=@MEDMAP@(0) ; We already have meds in the 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("GPLCCR",$J,"MEDMAP",MEDCOUNT))
|
---|
59 | . S @MEDMAP@(0)=@MEDMAP@(0)+1 ; INCREMENT TOTAL MEDS IN VAR ARRAY
|
---|
60 | . N RXIEN S RXIEN=$P(FDAIEN,",") ; First piece of FDAIEN is the number of the med for this patient
|
---|
61 | . I DEBUG W "RXIEN IS ",RXIEN,!
|
---|
62 | . I DEBUG W "MAP= ",MAP,!
|
---|
63 | . S @MAP@("MEDOBJECTID")="MED_OUTSIDE"_MEDCOUNT ; MEDCOUNT FOR ID
|
---|
64 | . S @MAP@("MEDISSUEDATETXT")="Documented Date"
|
---|
65 | . ; Field 6 is "Effective date", and we pull it in timson format w/ I
|
---|
66 | . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^CCRUTIL(MED(11,"I"),"DT")
|
---|
67 | . ; Med never filled; next 4 fields are not applicable.
|
---|
68 | . S @MAP@("MEDLASTFILLDATETXT")=""
|
---|
69 | . S @MAP@("MEDLASTFILLDATE")=""
|
---|
70 | . S @MAP@("MEDRXNOTXT")=""
|
---|
71 | . S @MAP@("MEDRXNO")=""
|
---|
72 | . S @MAP@("MEDTYPETEXT")="Medication"
|
---|
73 | . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
|
---|
74 | . S @MAP@("MEDSTATUSTEXT")="ACTIVE" ; nearest status for pending meds
|
---|
75 | . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_MED(12,"I")
|
---|
76 | . S @MAP@("MEDPRODUCTNAMETEXT")=MED(.01,"E")
|
---|
77 | . ; NDC is field 31 in the drug file.
|
---|
78 | . ; The actual drug entry in the drug file (MEDIEN) is not necessarily supplied.
|
---|
79 | . ; It' node 1, internal form.
|
---|
80 | . N MEDIEN S MEDIEN=MED(1,"I")
|
---|
81 | . I +MEDIEN D ; start of if/else block
|
---|
82 | . . ; 12/30/08: I will be using RxNorm for coding...
|
---|
83 | . . ; 176.001 is the file for Concepts; 176.003 is the file for
|
---|
84 | . . ; sources (i.e. for RxNorm Version)
|
---|
85 | . . ;
|
---|
86 | . . ; We need the VUID first for the National Drug File entry first
|
---|
87 | . . ; We get the VUID of the drug, by looking up the VA Product entry
|
---|
88 | . . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
|
---|
89 | . . ; Field 99.99 is the VUID.
|
---|
90 | . . ;
|
---|
91 | . . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
|
---|
92 | . . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
|
---|
93 | . . ; $$GET1^DIQ.
|
---|
94 | . . ;
|
---|
95 | . . ; I get the RxNorm name and version from the RxNorm Sources (file
|
---|
96 | . . ; 176.003), by searching for "RXNORM", then get the data.
|
---|
97 | . . D NDF^PSS50(MEDIEN,,,,,"NDF")
|
---|
98 | . . N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
|
---|
99 | . . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
|
---|
100 | . . N VAPROD S VAPROD=$P(NDFDATA(22),U)
|
---|
101 | . . ;
|
---|
102 | . . ; NDFIEN is not necessarily defined; it won't be if the drug
|
---|
103 | . . ; is not matched to the national drug file (e.g. if the drug is
|
---|
104 | . . ; new on the market, compounded, or is a fake drug [blue pill].
|
---|
105 | . . ; To protect against failure, I will put an if/else block
|
---|
106 | . . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
|
---|
107 | . . I NDFIEN,$D(^C0CRXN) D ; $Data is for Systems that don't have our RxNorm file yet.
|
---|
108 | . . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
|
---|
109 | . . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
|
---|
110 | . . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
|
---|
111 | . . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
|
---|
112 | . . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
|
---|
113 | . . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
|
---|
114 | . . ;
|
---|
115 | . . E S (RXNORM,RXNNAME,RXNVER)=""
|
---|
116 | . . ; End if/else block
|
---|
117 | . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
|
---|
118 | . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
|
---|
119 | . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
|
---|
120 | . . ;
|
---|
121 | . . S @MAP@("MEDBRANDNAMETEXT")=""
|
---|
122 | . . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
|
---|
123 | . . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
|
---|
124 | . . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
|
---|
125 | . . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
|
---|
126 | . . ; Units, concentration, etc, come from another call
|
---|
127 | . . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
|
---|
128 | . . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
|
---|
129 | . . ; NDF Entry IEN, and VA Product Name
|
---|
130 | . . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
|
---|
131 | . . ; Documented in the same manual; executed above.
|
---|
132 | . . ;
|
---|
133 | . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
|
---|
134 | . . ; and this will crash the call. So...
|
---|
135 | . . I NDFIEN="" S CONCDATA=""
|
---|
136 | . . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
|
---|
137 | . . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
|
---|
138 | . . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
|
---|
139 | . . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
|
---|
140 | . . S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
|
---|
141 | . . ; Oddly, there is no easy place to find the dispense unit.
|
---|
142 | . . ; It's not included in the original call, so we have to go to the drug file.
|
---|
143 | . . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
|
---|
144 | . . ; Node 14.5 is the Dispense Unit
|
---|
145 | . . D DATA^PSS50(MEDIEN,,,,,"QTY")
|
---|
146 | . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
|
---|
147 | . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
|
---|
148 | . E D
|
---|
149 | . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=""
|
---|
150 | . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
|
---|
151 | . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=""
|
---|
152 | . . S @MAP@("MEDBRANDNAMETEXT")=""
|
---|
153 | . . S @MAP@("MEDSTRENGTHVALUE")=""
|
---|
154 | . . S @MAP@("MEDSTRENGTHUNIT")=""
|
---|
155 | . . S @MAP@("MEDFORMTEXT")=""
|
---|
156 | . . S @MAP@("MEDCONCVALUE")=""
|
---|
157 | . . S @MAP@("MEDCONCUNIT")=""
|
---|
158 | . . S @MAP@("MEDSIZETEXT")=""
|
---|
159 | . . S @MAP@("MEDQUANTITYVALUE")=""
|
---|
160 | . . S @MAP@("MEDQUANTITYUNIT")=""
|
---|
161 | . ; End If/Else
|
---|
162 | . ; --- START OF DIRECTIONS ---
|
---|
163 | . ; Dosage is field 2, route is 3, schedule is 4
|
---|
164 | . ; These are all free text fields, and don't point to any files
|
---|
165 | . ; For that reason, I will use the field I never used before:
|
---|
166 | . ; MEDDIRECTIONDESCRIPTIONTEXT
|
---|
167 | . S DIRCNT=1 ; THERE IS ONLY ONE DIRECTION FOR OUTSIDE MEDS
|
---|
168 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
|
---|
169 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
|
---|
170 | . S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
|
---|
171 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
|
---|
172 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
|
---|
173 | . S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
|
---|
174 | . S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
|
---|
175 | . S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
|
---|
176 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
|
---|
177 | . S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
|
---|
178 | . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
|
---|
179 | . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
|
---|
180 | . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
|
---|
181 | . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
|
---|
182 | . S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
|
---|
183 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
|
---|
184 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
|
---|
185 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
|
---|
186 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
|
---|
187 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
|
---|
188 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
|
---|
189 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
|
---|
190 | . S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
|
---|
191 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
|
---|
192 | . S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
|
---|
193 | . ;
|
---|
194 | . ; --- END OF DIRECTIONS ---
|
---|
195 | . ;
|
---|
196 | . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
|
---|
197 | . I $D(MED(10,1)) D ;
|
---|
198 | . . S @MAP@("MEDPTINSTRUCTIONS")=MED(10,1) ; WP Field
|
---|
199 | . E S @MAP@("MEDPTINSTRUCTIONS")=""
|
---|
200 | . I $D(MED(14,1)) D ;
|
---|
201 | . . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
|
---|
202 | . E S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=""
|
---|
203 | . S @MAP@("MEDRFNO")=""
|
---|
204 | . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"MAPPED"))
|
---|
205 | . K @RESULT
|
---|
206 | . D MAP^GPLXPATH(MINXML,MAP,RESULT)
|
---|
207 | . ; D PARY^GPLXPATH(RESULT)
|
---|
208 | . ; MAPPING DIRECTIONS
|
---|
209 | . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
|
---|
210 | . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
|
---|
211 | . D QUERY^GPLXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
|
---|
212 | . D REPLACE^GPLXPATH(RESULT,"","//Medications/Medication/Directions")
|
---|
213 | . ; N MDZ1,MDZNA
|
---|
214 | . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
|
---|
215 | . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
|
---|
216 | . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
|
---|
217 | . . . D MAP^GPLXPATH(DIRXML1,MDZNA,DIRXML2)
|
---|
218 | . . . D INSERT^GPLXPATH(RESULT,DIRXML2,"//Medications/Medication")
|
---|
219 | . I MEDFIRST D ;
|
---|
220 | . . S MEDFIRST=0 ; RESET FIRST FLAG
|
---|
221 | . . D CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
|
---|
222 | . D:'MEDFIRST INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
|
---|
223 | N MEDTMP,MEDI
|
---|
224 | D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
|
---|
225 | I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
|
---|
226 | . W "MEDICATION MISSING ",!
|
---|
227 | . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
|
---|
228 | Q
|
---|
229 | ;
|
---|