source: ccr/trunk/p/C0CMED2.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/C0CMED2.m1290
    /ccr/branches/ohum/p/C0CMED2.m1291-1543
    /ccr/branches/ohum/p/p/C0CMED2.m1287-1289
File size: 12.8 KB
Line 
1C0CMED2 ; WV/CCDCCR/SMH - CCR/CCD Meds - Pending for Vista
2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
3 ;;Last Modified Sat Jan 10 21:41:14 PST 2009
4 ; Copyright 2008 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 (by Value)
26 ; OUTXML is the resultant XML (by Name)
27 ; MEDCOUNT is the current count of extracted meds, 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 ; 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,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
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 ; ZWRITE:$G(DEBUG) MEDS
49 N RXIEN S RXIEN=0
50 N MEDFIRST S MEDFIRST=1 ; FLAG FOR FIRST MED IN THIS SECTION FOR MERGING
51 F S RXIEN=$O(MEDS(RXIEN)) Q:RXIEN="B" D ; FOR EACH MEDICATION IN THE LIST
52 . I $$GET1^DIQ(52.41,RXIEN,2,"I")="RF" QUIT ; Dont' want refill request as a "pending" order
53 . S MEDCOUNT=MEDCOUNT+1
54 . I DEBUG W "RXIEN IS ",RXIEN,!
55 . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
56 . ; K @MAP DON'T KILL MAP HERE, IT IS DONE IN C0CMED
57 . I DEBUG W "MAP= ",MAP,!
58 . N MED M MED=MEDS(RXIEN) ; PULL OUT MEDICATION FROM
59 . S @MAP@("MEDOBJECTID")="MED_PENDING"_MEDCOUNT ; MEDCOUNT FOR ID
60 . ; S @MAP@("MEDOBJECTID")="MED_PENDING"_MED(.01) ;Pending IEN
61 . S @MAP@("MEDISSUEDATETXT")="Issue Date"
62 . ; Field 6 is "Effective date", and we pull it in timson format w/ I
63 . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($$GET1^DIQ(52.41,RXIEN,6,"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")="On Hold" ; nearest status for pending meds
72 . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$$GET1^DIQ(52.41,RXIEN,5,"I")
73 . S @MAP@("MEDPRODUCTNAMETEXT")=$P(MED(11),U,2)
74 . ; NDC not supplied in API, but is rather trivial to obtain
75 . ; MED(11) piece 1 has the IEN of the drug (file 50)
76 . ; IEN is field 31 in the drug file.
77 . ;
78 . ; MEDIEN (node 11 in the returned output) might not necessarily be defined
79 . ; It is not defined when a dose in not chosen in CPRS. There is a long
80 . ; series of fields that depend on it. We will use If and Else to deal
81 . ; with that
82 . N MEDIEN S MEDIEN=$P(MED(11),U)
83 . I +MEDIEN>0 D ; start of if/else block
84 . . ; 12/30/08: I will be using RxNorm for coding...
85 . . ; 176.001 is the file for Concepts; 176.003 is the file for
86 . . ; sources (i.e. for RxNorm Version)
87 . . ;
88 . . ; We need the VUID first for the National Drug File entry first
89 . . ; We get the VUID of the drug, by looking up the VA Product entry
90 . . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
91 . . ; Field 99.99 is the VUID.
92 . . ;
93 . . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
94 . . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
95 . . ; $$GET1^DIQ.
96 . . ;
97 . . ; I get the RxNorm name and version from the RxNorm Sources (file
98 . . ; 176.003), by searching for "RXNORM", then get the data.
99 . . D NDF^PSS50(MEDIEN,,,,,"NDF")
100 . . N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
101 . . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
102 . . N VAPROD S VAPROD=$P(NDFDATA(22),U)
103 . . ;
104 . . ; NDFIEN is not necessarily defined; it won't be if the drug
105 . . ; is not matched to the national drug file (e.g. if the drug is
106 . . ; new on the market, compounded, or is a fake drug [blue pill].
107 . . ; To protect against failure, I will put an if/else block
108 . . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
109 . . I NDFIEN,$D(^C0CRXN) D ; $Data is for Systems that don't have our RxNorm file yet.
110 . . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
111 . . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
112 . . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
113 . . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
114 . . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
115 . . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
116 . . ;
117 . . E S (RXNORM,RXNNAME,RXNVER)=""
118 . . ; End if/else block
119 . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
120 . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
121 . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
122 . . ;
123 . . S @MAP@("MEDBRANDNAMETEXT")=""
124 . . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
125 . . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
126 . . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
127 . . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
128 . . ; Units, concentration, etc, come from another call
129 . . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
130 . . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
131 . . ; NDF Entry IEN, and VA Product Name
132 . . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
133 . . ; Documented in the same manual; executed above.
134 . . N CONCDATA
135 . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
136 . . ; and this will crash the call. So...
137 . . I NDFIEN="" S CONCDATA=""
138 . . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
139 . . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
140 . . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
141 . . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
142 . . S @MAP@("MEDQUANTITYVALUE")=$$GET1^DIQ(52.41,RXIEN,12)
143 . . ; Oddly, there is no easy place to find the dispense unit.
144 . . ; It's not included in the original call, so we have to go to the drug file.
145 . . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
146 . . ; Node 14.5 is the Dispense Unit
147 . . D DATA^PSS50(MEDIEN,,,,,"QTY")
148 . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
149 . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
150 . E D
151 . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=""
152 . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
153 . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=""
154 . . S @MAP@("MEDBRANDNAMETEXT")=""
155 . . S @MAP@("MEDSTRENGTHVALUE")=""
156 . . S @MAP@("MEDSTRENGTHUNIT")=""
157 . . S @MAP@("MEDFORMTEXT")=""
158 . . S @MAP@("MEDCONCVALUE")=""
159 . . S @MAP@("MEDCONCUNIT")=""
160 . . S @MAP@("MEDSIZETEXT")=""
161 . . S @MAP@("MEDQUANTITYVALUE")=""
162 . . S @MAP@("MEDQUANTITYUNIT")=""
163 . ; end of if/else block
164 . ;
165 . ; --- START OF DIRECTIONS ---
166 . ; Sig data is not in any API. We obtain it using the IEN from
167 . ; the PEN API to file 52.41. It's in field 3, which is a multiple.
168 . ; I will be using FM call GETS^DIQ(FILE,IENS,FIELD,FLAGS,TARGET_ROOT)
169 . K FMSIG ; it's passed via the symbol table, so remove any leftovers from last call
170 . D GETS^DIQ(52.41,RXIEN,"3*",,"FMSIG")
171 . N FMSIGNUM S FMSIGNUM=0 ; Sigline number in fileman.
172 . ; FMSIGNUM gets outputted as "IEN,RXIEN,".
173 . ; DIRNUM will be first piece for IEN.
174 . ; DIRNUM is the proper Sigline numer.
175 . ; SIGDATA is the simplfied array. Subscripts are really field numbers
176 . ; in subfile 52.413.
177 . N DIRCNT S DIRCNT=0 ; COUNT OF DIRECTIONS
178 . F S FMSIGNUM=$O(FMSIG(52.413,FMSIGNUM)) Q:FMSIGNUM="" D
179 . . N DIRNUM S DIRNUM=$P(FMSIGNUM,",")
180 . . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
181 . . N SIGDATA M SIGDATA=FMSIG(52.413,FMSIGNUM)
182 . . ; If this is an order for a refill; it's not really a new order; move on to next
183 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")="" ; This is reserved for systems not able to generate the sig in components.
184 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1" ; means that we are specifying it. See E2369-05.
185 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=SIGDATA(13)
186 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=SIGDATA(8)
187 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
188 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")="" ; For inpatient
189 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")="" ; For inpatient
190 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")="" ; For inpatient
191 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=SIGDATA(10)
192 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=SIGDATA(1)
193 . . ; Invervals... again another call.
194 . . ; The schedule is a free text field
195 . . ; However, it gets translated by a call to the administration
196 . . ; schedule file to see if that schedule exists.
197 . . ; That's the same thing I am going to do.
198 . . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
199 . . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
200 . . ; I looked), PSSFT is the name,
201 . . ; and list is the ^TMP name to store the data in.
202 . . ; Also, freqency may have "PRN" in it, so strip that out
203 . . N FREQ S FREQ=SIGDATA(1)
204 . . I FREQ["PRN" S FREQ=$E(FREQ,1,$F(FREQ,"PRN")-5) ; 5 for $L("PRN") + 1 + sp
205 . . D AP^PSS51P1("PSJ",FREQ,,,"SCHEDULE")
206 . . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
207 . . N INTERVAL
208 . . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
209 . . E D
210 . . . N SUB S SUB=$O(SCHEDATA(0))
211 . . . S INTERVAL=SCHEDATA(SUB,2)
212 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
213 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
214 . . ; Duration comes as M2,H2,D2,W2,L2 for 2 minutes,hours,days,weeks,months
215 . . N DUR S DUR=SIGDATA(2)
216 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$E(DUR,2,$L(DUR))
217 . . N DURUNIT S DURUNIT=$E(DUR)
218 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=$S(DURUNIT="M":"Minutes",DURUNIT="H":"Hours",DURUNIT="D":"Days",DURUNIT="W":"Weeks",DURUNIT="L":"Months",1:"")
219 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=SIGDATA(1)["PRN"
220 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
221 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
222 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
223 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
224 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
225 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
226 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
227 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")="" ; Vista doesn't have that field
228 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
229 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=SIGDATA(6)
230 . ;
231 . ; --- END OF DIRECTIONS ---
232 . ;
233 . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
234 . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PI",1,0)) ;GPL
235 . ; W @MAP@("MEDPTINSTRUCTIONS"),!
236 . ; S @MAP@("MEDFULLFILLMENTINSTRUCTIONS","F")="52.41^9"
237 . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"SIG1",1,0)) ;GPL
238 . ; W @MAP@("MEDFULLFILLMENTINSTRUCTIONS"),!
239 . S @MAP@("MEDRFNO")=$$GET1^DIQ(52.41,RXIEN,13)
240 . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
241 . K @RESULT
242 . D MAP^C0CXPATH(MINXML,MAP,RESULT)
243 . ; D PARY^C0CXPATH(RESULT)
244 . ; MAPPING DIRECTIONS
245 . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
246 . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
247 . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
248 . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
249 . ; N MDZ1,MDZNA
250 . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
251 . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
252 . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
253 . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
254 . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
255 . I MEDFIRST D ;
256 . . ;S MEDFIRST=0 ; RESET FIRST FLAG ;OHUM/RUT COMMENTED (1ST PENDING MEDICATION WAS GETTING DUPLICATED)
257 . . D CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
258 . D:'MEDFIRST INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER
259 . I MEDFIRST S MEDFIRST=0 ;OHUM/RUT ADDED
260 N MEDTMP,MEDI
261 D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
262 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
263 . W "Pending Medication MISSING ",!
264 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
265 Q
266 ;
Note: See TracBrowser for help on using the repository browser.