source: ccr/trunk/p/C0CNMED4.m@ 1204

Last change on this file since 1204 was 1204, checked in by George Lilly, 13 years ago

updates for MU Certification

File size: 10.1 KB
Line 
1C0CMED4 ; WV/CCDCCR/SMH/gpl - CCR/CCD PROCESSING FOR MEDICATIONS - Inpatient Meds/Unit Dose ;10/13/08
2 ;;0.1;CCDCCR;;;
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,MEDCOUNT) ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
24 ;
25 ; this routine has be adapted to retrieve meds from GET^NHINV by gpl 6/2011
26 ;
27 ; MINXML is the Input XML Template, passed by name
28 ; DFN is Patient IEN
29 ; OUTXML is the resultant XML.
30 ;
31 ; MEDS is return array from API.
32 ; MED is holds each array element from MEDS, one medicine
33 ; MAP is a mapping variable map (store result) for each med
34 ;
35 ; Inpatient Meds will be extracted using this routine and and the one following.
36 ; Inpatient Meds Unit Dose is going to be C0CMED4
37 ; Inpatient Meds IVs is going to be C0CMED5
38 ;
39 ; We will use two Pharmacy ReEnginnering API's:
40 ; PSS431^PSS55(DFN,PO,PSDATE,PEDATE,LIST) - provides most info
41 ; PSS432^PSS55(DFN,PO,LIST) - provides schedule info
42 ; For more information, see the PRE documentation at:
43 ; http://www.va.gov/vdl/documents/Clinical/Pharm-Inpatient_Med/phar_1_api_r0807.pdf
44 ;
45 ; Med data is stored in Unit Dose multiple of file 55, pharmacy patient
46 ;
47 N MEDS,MAP
48 ;K ^TMP($J)
49 ;D PSS431^PSS55(DFN,,,,"UD") ; Output is in ^TMP($J,"UD",*)
50 ;I ^TMP($J,"UD",0)'>0 S @OUTXML@(0)=0 QUIT ; No Meds - Quit
51 ;; Otherwise, we go on...
52 D EN^C0CNHIN(.MEDS,DFN,"MED;") ; gpl get the NHIN Array of meds
53 I '$D(MEDS) Q ; no meds
54 N ZI S ZI=""
55 N ZCOUNT S ZCOUNT=0
56 F S ZI=$O(MEDS("med",ZI)) Q:ZI="" D ; for each returned med
57 . I $G(MEDS("med",ZI,"vaType@value"))="I" S ZCOUNT=ZCOUNT+1
58 IF ZCOUNT=0 Q ; no inpatient meds
59 ;M MEDS=^TMP($J,"UD")
60 I DEBUG ZWR MEDS
61 S MEDMAP=$NA(^TMP("C0CCCR",$J,"MEDMAP"))
62 ;N MEDCOUNT S MEDCOUNT=@MEDMAP@(0) ; We already have meds in the array
63 N I S I=0
64 F S I=$O(MEDS("med",I)) Q:'I D ; For each medication
65 . N MED M MED=MEDS("med",I)
66 . I $G(MED("vaType@value"))'="I" Q ; not inpatient
67 . S MEDCOUNT=MEDCOUNT+1
68 . S @MEDMAP@(0)=MEDCOUNT ; Update MedMap array counter
69 . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
70 . ;N RXIEN S RXIEN=MED(.01) ; Order Number
71 . N RXIEN S RXIEN=$G(MED("orderID@value")) ; ien of the med
72 . I DEBUG W "RXIEN IS ",RXIEN,!
73 . I DEBUG W "MAP= ",MAP,!
74 . S @MAP@("MEDOBJECTID")="MED_INPATIENT_UD"_RXIEN
75 . S @MAP@("MEDISSUEDATETXT")="Order Date"
76 . ;S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($P(MED(27),U),"DT")
77 . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($G(MED("start@value")),"DT")
78 . S @MAP@("MEDLASTFILLDATETXT")="" ; For Outpatient
79 . S @MAP@("MEDLASTFILLDATE")="" ; For Outpatient
80 . S @MAP@("MEDRXNOTXT")="" ; For Outpatient
81 . S @MAP@("MEDRXNO")="" ; For Outpatient
82 . S @MAP@("MEDTYPETEXT")="Medication"
83 . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
84 . ;S @MAP@("MEDSTATUSTEXT")="ACTIVE"
85 . S @MAP@("MEDSTATUSTEXT")=$G(MED("vaStatus@value")) ; need to filter status
86 . ;S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$P(MED(1),U)
87 . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$G(MED("orderingProvider@code"))
88 . ;S @MAP@("MEDPRODUCTNAMETEXT")=MED("DDRUG",1,.01)
89 . S @MAP@("MEDPRODUCTNAMETEXT")=$G(MED("name@value"))
90 . ; NDC is field 31 in the drug file.
91 . ; The actual drug entry in the drug file is not necessarily supplied.
92 . ; It' node 1, internal form.
93 . ;N MEDIEN S MEDIEN=MED(1,"I")
94 . ;S @MAP@("MEDPRODUCTNAMECODEVALUE")=$S($L(MEDIEN):$$GET1^DIQ(50,MEDIEN,31,"E"),1:"")
95 . N ZVUID S ZVUID=$G(MED("products.product.vaProduct@vuid")) ; VUID
96 . N ZC,ZCD,ZCDS,ZCDSV ; CODE,CODE SYSTEM,CODE VERSION
97 . D ;
98 . . S ZC=$$CODE^C0CUTIL(ZVUID)
99 . . S ZCD=$P(ZC,"^",1) ; CODE TO USE
100 . . S ZCDS=$P(ZC,"^",2) ; CODING SYSTEM - RXNORM OR VUID
101 . . S ZCDSV=$P(ZC,"^",3) ; CODING SYSTEM VERSION
102 . ;N ZRXNORM S ZRXNORM=""
103 . ;S ZRXNORM=$$RXNCUI3^C0PLKUP(ZVUID)
104 . S @MAP@("MEDPRODUCTNAMECODEVALUE")=ZCD
105 . ;S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=$S($L(MEDIEN):"NDC",1:"")
106 . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=ZCDS
107 . ;S @MAP@("MEDPRODUCTNAMECODEVERSION")=$S($L(MEDIEN):"none",1:"")
108 . S @MAP@("MEDPRODUCTNAMECODEVERSION")=ZCDSV
109 . S @MAP@("MEDBRANDNAMETEXT")=""
110 . S @MAP@("MEDPRODUCTNAMETEXT")=$G(MED("name@value"))_" "_ZCDS_": "_ZCD
111 . ;I $L(MEDIEN) D DOSE^PSS50(MEDIEN,,,,,"DOSE")
112 . ;I $L(MEDIEN) N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
113 . ;S @MAP@("MEDSTRENGTHVALUE")=$S($L(MEDIEN):DOSEDATA(901),1:"")
114 . S @MAP@("MEDSTRENGTHVALUE")=$G(MED("dose.dose@dose"))
115 . ;S @MAP@("MEDSTRENGTHUNIT")=$S($P(DOSEDATA(902),U,2),1:"")
116 . S @MAP@("MEDSTRENGTHUNIT")=$G(MED("dose.dose@units"))
117 . ; Units, concentration, etc, come from another call
118 . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
119 . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
120 . ; NDF Entry IEN, and VA Product Name
121 . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
122 . ; Documented in the same manual.
123 . ;N NDFDATA,CONCDATA
124 . ;I $L(MEDIEN) D
125 . ;. D NDF^PSS50(MEDIEN,,,,,"CONC")
126 . ;. M NDFDATA=^TMP($J,"CONC",MEDIEN)
127 . ;. N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
128 . ;. N VAPROD S VAPROD=$P(NDFDATA(22),U)
129 . ;. ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
130 . ;. ; and this will crash the call. So...
131 . ;. I NDFIEN="" S CONCDATA=""
132 . ;. E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
133 . ;E S (NDFDATA,CONCDATA)="" ; This line is defensive programming to prevent undef errors.
134 . ;S @MAP@("MEDFORMTEXT")=$S($L(MEDIEN):$P(CONCDATA,U,1),1:"")
135 . S @MAP@("MEDFORMTEXT")=$G(MED("form@value"))
136 . ;S @MAP@("MEDCONCVALUE")=$S($L(MEDIEN):$P(CONCDATA,U,3),1:"")
137 . S @MAP@("MEDCONCVALUE")=$G(MED("dose.dose@dose"))
138 . ;S @MAP@("MEDCONCUNIT")=$S($L(MEDIEN):$P(CONCDATA,U,4),1:"")
139 . S @MAP@("MEDCONCUNIT")=$G(MED("dose.does@units"))
140 . ;S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
141 . S @MAP@("MEDQUANTITYVALUE")=""
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 . ;I $L(MEDIEN) D
147 . ;. D DATA^PSS50(MEDIEN,,,,,"QTY")
148 . ;. N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
149 . ;. S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
150 . ;E S @MAP@("MEDQUANTITYUNIT")=""
151 . S @MAP@("MEDQUANTITYUNIT")=$G(MED("dose.dose@unitsPerDose"))
152 . ;
153 . ; --- START OF DIRECTIONS ---
154 . ; Dosage is field 2, route is 3, schedule is 4
155 . ; These are all free text fields, and don't point to any files
156 . ; For that reason, I will use the field I never used before:
157 . ; MEDDIRECTIONDESCRIPTIONTEXT
158 . ;S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
159 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=$G(MED("sig"))
160 . ; $G(MED("products.product.vaProduct@name"))
161 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
162 . S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
163 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
164 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
165 . S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
166 . S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
167 . S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
168 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
169 . S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
170 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
171 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
172 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
173 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
174 . S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
175 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
176 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
177 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
178 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
179 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
180 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
181 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
182 . S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
183 . S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
184 . S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
185 . ;
186 . ; --- END OF DIRECTIONS ---
187 . ;
188 . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
189 . ;S @MAP@("MEDPTINSTRUCTIONS")=MED(10,1) ; WP Field
190 . S @MAP@("MEDPTINSTRUCTIONS")=""
191 . ;S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
192 . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=""
193 . S @MAP@("MEDRFNO")=""
194 . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
195 . K @RESULT
196 . D MAP^C0CXPATH(MINXML,MAP,RESULT)
197 . ; D PARY^C0CXPATH(RESULT)
198 . ; MAPPING DIRECTIONS
199 . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
200 . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
201 . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
202 . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
203 . ; N MDZ1,MDZNA
204 . N DIRCNT S DIRCNT=1 ; THERE ARE ALWAYS DIRECTIONS
205 . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
206 . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
207 . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
208 . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
209 . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
210 . D:MEDCOUNT=1 CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
211 . D:MEDCOUNT>1 INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
212 N MEDTMP,MEDI
213 D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
214 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
215 . W "MEDICATION MISSING ",!
216 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
217 Q
218 ;
Note: See TracBrowser for help on using the repository browser.