source: ccr/trunk/p/CCRMEDS3.m@ 356

Last change on this file since 356 was 347, checked in by George Lilly, 16 years ago

update to support parameters .. XPATGPLCCR(1,"LABSTART:T^LABLIMIT:T-5000")

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