source: ccr/trunk/p/CCRMEDS2.m@ 298

Last change on this file since 298 was 295, checked in by Sam Habiel, 16 years ago

Corrected bugs in CCRMEDS3 and refactored CCRMEDS2

File size: 11.5 KB
Line 
1CCRMEDS2 ; WV/CCDCCR/SMH - CCR/CCD PROCESSING FOR MEDICATIONS - Pending Meds;08/24/08
2 ;;0.1;CCDCCR;;JUL 16,2008;
3 ; Copyright 2008 WorldVistA. Licensed under the terms of the GNU
4 ; General Public License See attached copy of the License.
5 ;
6 ; This program is free software; you can redistribute it and/or modify
7 ; it under the terms of the GNU General Public License as published by
8 ; the Free Software Foundation; either version 2 of the License, or
9 ; (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 General Public License for more details.
15 ;
16 ; You should have received a copy of the GNU General Public License along
17 ; with this program; if not, write to the Free Software Foundation, Inc.,
18 ; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20 W "NO ENTRY FROM TOP",!
21 Q
22 ;
23EXTRACT(MINXML,DFN,OUTXML) ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
24 ;
25 ; MINXML is the Input XML Template, passed by name
26 ; DFN is Patient IEN
27 ; OUTXML is the resultant XML.
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 ; PEN^PSO5241 is a Pharmacy Re-Enginnering (PRE) API to get Pending
34 ; meds data available.
35 ; http://www.va.gov/vdl/documents/Clinical/Pharm-Outpatient_Pharmacy/phar_1_api_r0807.pdf
36 ; Output of API is ^TMP($J,"SUBSCRIPT",DFN,RXIENS).
37 ; File for pending meds is 52.41
38 ; Unfortuantely, API does not supply us with any useful info beyond
39 ; the IEN in 52.41, and the Med Name, and route.
40 ; So, most of the info is going to get pulled from 52.41.
41 N MEDS,MAP
42 K ^TMP($J)
43 D PEN^PSO5241(DFN,"CCDCCR")
44 M MEDS=^TMP($J,"CCDCCR",DFN)
45 ; @(0) contains the number of meds or -1^NO DATA FOUND
46 ; If it is -1, we quit.
47 I $P(MEDS(0),U)=-1 S @OUTXML@(0)=0 QUIT
48 I DEBUG ZWR MEDS
49 N RXIEN S RXIEN=0
50 N MEDCOUNT S MEDCOUNT=0
51 N MEDFIRST S MEDFIRST=1 ; FLAG FOR FIRST MED IN THIS SECTION FOR MERGING
52 S MEDMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP")) ; THIS IS THE VARIABLE MAP
53 S MEDCOUNT=@MEDMAP@(0) ; ACCOUNT FOR MEDS ALREADY IN ARRAY
54 F S RXIEN=$O(MEDS(RXIEN)) Q:RXIEN="B" D ; FOR EACH MEDICATION IN THE LIST
55 . I $$GET1^DIQ(52.41,RXIEN,2,"I")="RF" QUIT ; Dont' want refill request as a "pending" order
56 . S MEDCOUNT=MEDCOUNT+1
57 . I DEBUG W "RXIEN IS ",RXIEN,!
58 . S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP",MEDCOUNT))
59 . ; K @MAP DON'T KILL MAP HERE, IT IS DONE IN CCRMEDS
60 . S @MEDMAP@(0)=@MEDMAP@(0)+1 ; INCREMENT TOTAL MEDS IN VAR ARRAY
61 . I DEBUG W "MAP= ",MAP,!
62 . N MED M MED=MEDS(RXIEN) ; PULL OUT MEDICATION FROM
63 . S @MAP@("MEDOBJECTID")="MED_PENDING"_MEDCOUNT ; MEDCOUNT FOR ID
64 . ; S @MAP@("MEDOBJECTID")="MED_PENDING"_MED(.01) ;Pending IEN
65 . S @MAP@("MEDISSUEDATETXT")="Issue Date"
66 . ; Field 6 is "Effective date", and we pull it in timson format w/ I
67 . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^CCRUTIL($$GET1^DIQ(52.41,RXIEN,6,"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")="On Hold" ; nearest status for pending meds
76 . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$$GET1^DIQ(52.41,RXIEN,5,"I")
77 . S @MAP@("MEDPRODUCTNAMETEXT")=$P(MED(11),U,2)
78 . ; NDC not supplied in API, but is rather trivial to obtain
79 . ; MED(11) piece 1 has the IEN of the drug (file 50)
80 . ; IEN is field 31 in the drug file.
81 . ;
82 . ; MEDIEN (node 11 in the returned output) might not necessarily be defined
83 . ; It is not defined when a dose in not chosen in CPRS. There is a long
84 . ; series of fields that depend on it. We will use If and Else to deal
85 . ; with that
86 . N MEDIEN S MEDIEN=$P(MED(11),U)
87 . I +MEDIEN>0 D
88 . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=$$GET1^DIQ(50,MEDIEN,31,"E")
89 . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")="NDC"
90 . . S @MAP@("MEDPRODUCTNAMECODEVERSION")="none"
91 . . S @MAP@("MEDBRANDNAMETEXT")=""
92 . . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
93 . . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
94 . . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
95 . . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
96 . . ; Units, concentration, etc, come from another call
97 . . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
98 . . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
99 . . ; NDF Entry IEN, and VA Product Name
100 . . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
101 . . ; Documented in the same manual.
102 . . D NDF^PSS50(MEDIEN,,,,,"CONC")
103 . . N NDFDATA M NDFDATA=^TMP($J,"CONC",MEDIEN)
104 . . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
105 . . N VAPROD S VAPROD=$P(NDFDATA(22),U)
106 . . N CONCDATA
107 . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
108 . . ; and this will crash the call. So...
109 . . I NDFIEN="" S CONCDATA=""
110 . . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
111 . . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
112 . . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
113 . . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
114 . . S @MAP@("MEDSIZETEXT")=$P(NDFDATA(23),U,2)_" "_$P(NDFDATA(24),U,2)
115 . . S @MAP@("MEDQUANTITYVALUE")=$$GET1^DIQ(52.41,RXIEN,12)
116 . . ; Oddly, there is no easy place to find the dispense unit.
117 . . ; It's not included in the original call, so we have to go to the drug file.
118 . . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
119 . . ; Node 14.5 is the Dispense Unit
120 . . D DATA^PSS50(MEDIEN,,,,,"QTY")
121 . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
122 . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
123 . E D
124 . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=""
125 . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
126 . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=""
127 . . S @MAP@("MEDBRANDNAMETEXT")=""
128 . . S @MAP@("MEDSTRENGTHVALUE")=""
129 . . S @MAP@("MEDSTRENGTHUNIT")=""
130 . . S @MAP@("MEDFORMTEXT")=""
131 . . S @MAP@("MEDCONCVALUE")=""
132 . . S @MAP@("MEDCONCUNIT")=""
133 . . S @MAP@("MEDSIZETEXT")=""
134 . . S @MAP@("MEDQUANTITYVALUE")=""
135 . . S @MAP@("MEDQUANTITYUNIT")=""
136 . ;
137 . ;
138 . ; --- START OF DIRECTIONS ---
139 . ; Sig data is not in any API. We obtain it using the IEN from
140 . ; the PEN API to file 52.41. It's in field 3, which is a multiple.
141 . ; I will be using FM call GETS^DIQ(FILE,IENS,FIELD,FLAGS,TARGET_ROOT)
142 . K FMSIG ; it's passed via the symbol table, so remove any leftovers from last call
143 . D GETS^DIQ(52.41,RXIEN,"3*",,"FMSIG")
144 . N FMSIGNUM S FMSIGNUM=0 ; Sigline number in fileman.
145 . ; FMSIGNUM gets outputted as "IEN,RXIEN,".
146 . ; DIRNUM will be first piece for IEN.
147 . ; DIRNUM is the proper Sigline numer.
148 . ; SIGDATA is the simplfied array. Subscripts are really field numbers
149 . ; in subfile 52.413.
150 . N DIRCNT S DIRCNT=0 ; COUNT OF DIRECTIONS
151 . F S FMSIGNUM=$O(FMSIG(52.413,FMSIGNUM)) Q:FMSIGNUM="" D
152 . . N DIRNUM S DIRNUM=$P(FMSIGNUM,",")
153 . . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
154 . . N SIGDATA M SIGDATA=FMSIG(52.413,FMSIGNUM)
155 . . ; If this is an order for a refill; it's not really a new order; move on to next
156 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")="" ; This is reserved for systems not able to generate the sig in components.
157 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1" ; means that we are specifying it. See E2369-05.
158 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=SIGDATA(13)
159 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=SIGDATA(8)
160 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
161 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")="" ; For inpatient
162 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")="" ; For inpatient
163 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")="" ; For inpatient
164 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=SIGDATA(10)
165 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=SIGDATA(1)
166 . . ; Invervals... again another call.
167 . . ; The schedule is a free text field
168 . . ; However, it gets translated by a call to the administration
169 . . ; schedule file to see if that schedule exists.
170 . . ; That's the same thing I am going to do.
171 . . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
172 . . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
173 . . ; I looked), PSSFT is the name,
174 . . ; and list is the ^TMP name to store the data in.
175 . . ; Also, freqency may have "PRN" in it, so strip that out
176 . . N FREQ S FREQ=SIGDATA(1)
177 . . I FREQ["PRN" S FREQ=$E(FREQ,1,$F(FREQ,"PRN")-5) ; 5 for $L("PRN") + 1 + sp
178 . . D AP^PSS51P1("PSJ",FREQ,,,"SCHEDULE")
179 . . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
180 . . N INTERVAL
181 . . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
182 . . E D
183 . . . N SUB S SUB=$O(SCHEDATA(0))
184 . . . S INTERVAL=SCHEDATA(SUB,2)
185 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
186 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
187 . . ; Duration comes as M2,H2,D2,W2,L2 for 2 minutes,hours,days,weeks,months
188 . . N DUR S DUR=SIGDATA(2)
189 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$E(DUR,2,$L(DUR))
190 . . N DURUNIT S DURUNIT=$E(DUR)
191 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=$S(DURUNIT="M":"Minutes",DURUNIT="H":"Hours",DURUNIT="D":"Days",DURUNIT="W":"Weeks",DURUNIT="L":"Months",1:"")
192 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=SIGDATA(1)["PRN"
193 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
194 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
195 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
196 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
197 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
198 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
199 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
200 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")="" ; Vista doesn't have that field
201 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
202 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=SIGDATA(6)
203 . ;
204 . ; --- END OF DIRECTIONS ---
205 . ;
206 . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
207 . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PI",1,0)) ;GPL
208 . ; W @MAP@("MEDPTINSTRUCTIONS"),!
209 . ; S @MAP@("MEDFULLFILLMENTINSTRUCTIONS","F")="52.41^9"
210 . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"SIG1",1,0)) ;GPL
211 . ; W @MAP@("MEDFULLFILLMENTINSTRUCTIONS"),!
212 . S @MAP@("MEDRFNO")=$$GET1^DIQ(52.41,RXIEN,13)
213 . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"MAPPED"))
214 . K @RESULT
215 . D MAP^GPLXPATH(MINXML,MAP,RESULT)
216 . ; D PARY^GPLXPATH(RESULT)
217 . ; MAPPING DIRECTIONS
218 . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
219 . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
220 . D QUERY^GPLXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
221 . D REPLACE^GPLXPATH(RESULT,"","//Medications/Medication/Directions")
222 . ; N MDZ1,MDZNA
223 . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
224 . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
225 . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
226 . . . D MAP^GPLXPATH(DIRXML1,MDZNA,DIRXML2)
227 . . . D INSERT^GPLXPATH(RESULT,DIRXML2,"//Medications/Medication")
228 . I MEDFIRST D ;
229 . . S MEDFIRST=0 ; RESET FIRST FLAG
230 . . D CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
231 . D:'MEDFIRST INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
232 N MEDTMP,MEDI
233 D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
234 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
235 . W "MEDICATION MISSING ",!
236 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
237 Q
238 ;
Note: See TracBrowser for help on using the repository browser.