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

Last change on this file since 1682 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/C0CNMED4.m1290
    /ccr/branches/ohum/p/C0CNMED4.m1291-1543
    /ccr/branches/ohum/p/p/C0CNMED4.m1287-1289
File size: 10.6 KB
Line 
1C0CNMED4 ; WV/CCDCCR/SMH/gpl - CCR/CCD PROCESSING FOR MEDICATIONS - Inpatient Meds/Unit Dose ;10/13/08 ; 5/10/12 2:54pm
2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
3 ; Copyright 2008 WorldVistA.
4 ;
5 ; This program is free software: you can redistribute it and/or modify
6 ; it under the terms of the GNU Affero General Public License as
7 ; published by the Free Software Foundation, either version 3 of the
8 ; License, or (at your option) any later version.
9 ;
10 ; This program is distributed in the hope that it will be useful,
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ; GNU Affero General Public License for more details.
14 ;
15 ; You should have received a copy of the GNU Affero General Public License
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
17 ;
18 W "NO ENTRY FROM TOP",!
19 Q
20 ;
21EXTRACT(MINXML,DFN,OUTXML,MEDCOUNT) ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
22 ;
23 ; this routine has be adapted to retrieve meds from GET^NHINV by gpl 6/2011
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 API.
30 ; MED is holds each array element from MEDS, one medicine
31 ; MAP is a mapping variable map (store result) for each med
32 ;
33 ; Inpatient Meds will be extracted using this routine and and the one following.
34 ; Inpatient Meds Unit Dose is going to be C0CMED4
35 ; Inpatient Meds IVs is going to be C0CMED5
36 ;
37 ; We will use two Pharmacy ReEnginnering API's:
38 ; PSS431^PSS55(DFN,PO,PSDATE,PEDATE,LIST) - provides most info
39 ; PSS432^PSS55(DFN,PO,LIST) - provides schedule info
40 ; For more information, see the PRE documentation at:
41 ; http://www.va.gov/vdl/documents/Clinical/Pharm-Inpatient_Med/phar_1_api_r0807.pdf
42 ;
43 ; Med data is stored in Unit Dose multiple of file 55, pharmacy patient
44 ;
45 N MEDS,MAP
46 ;K ^TMP($J)
47 ;D PSS431^PSS55(DFN,,,,"UD") ; Output is in ^TMP($J,"UD",*)
48 ;I ^TMP($J,"UD",0)'>0 S @OUTXML@(0)=0 QUIT ; No Meds - Quit
49 ;; Otherwise, we go on...
50 D EN^C0CNHIN(.MEDS,DFN,"MED;") ; gpl get the NHIN Array of meds
51 I '$D(MEDS) Q ; no meds
52 N ZI S ZI=""
53 N ZCOUNT S ZCOUNT=0
54 F S ZI=$O(MEDS("med",ZI)) Q:ZI="" D ; for each returned med
55 . I $G(MEDS("med",ZI,"vaType@value"))="I" S ZCOUNT=ZCOUNT+1
56 IF ZCOUNT=0 Q ; no inpatient meds
57 ;M MEDS=^TMP($J,"UD")
58 ;I DEBUG ZWR MEDS
59 S MEDMAP=$NA(^TMP("C0CCCR",$J,"MEDMAP"))
60 ;N MEDCOUNT S MEDCOUNT=@MEDMAP@(0) ; We already have meds in the array
61 S C0CMFLAG=$$GET^C0CPARMS("MEDALL")_"^"_$$GET^C0CPARMS("MEDLIMIT")_"^"_$$GET^C0CPARMS("MEDACTIVE")_"^"_$$GET^C0CPARMS("MEDPENDING") ;SETTING FLAG
62 N I S I=0
63 F S I=$O(MEDS("med",I)) Q:'I D ; For each medication
64 . ;OHUM/RUT 3120507 ;STATUS VALIDATION FOR INPATIENT
65 . I ($P(C0CMFLAG,"^",1)'=1) D
66 . . I ($P(C0CMFLAG,"^",3)=1)&(MEDS("med",I,"vaStatus@value")'="ACTIVE") D
67 . . . K MEDS("med",I) Q
68 . . I ($P(C0CMFLAG,"^",4)=1)&(MEDS("med",I,"vaStatus@value")'="PENDING") D
69 . . . K MEDS("med",I) Q
70 . ;OHUM/RUT
71 . N MED M MED=MEDS("med",I)
72 . I $G(MED("vaType@value"))'="I" Q ; not inpatient
73 . S MEDCOUNT=MEDCOUNT+1
74 . S @MEDMAP@(0)=MEDCOUNT ; Update MedMap array counter
75 . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
76 . ;N RXIEN S RXIEN=MED(.01) ; Order Number
77 . N RXIEN S RXIEN=$G(MED("orderID@value")) ; ien of the med
78 . I DEBUG W "RXIEN IS ",RXIEN,!
79 . I DEBUG W "MAP= ",MAP,!
80 . S @MAP@("MEDOBJECTID")="MED_INPATIENT_UD"_RXIEN
81 . S @MAP@("MEDISSUEDATETXT")="Order Date"
82 . ;S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($P(MED(27),U),"DT")
83 . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($G(MED("start@value")),"DT")
84 . S @MAP@("MEDLASTFILLDATETXT")="" ; For Outpatient
85 . S @MAP@("MEDLASTFILLDATE")="" ; For Outpatient
86 . S @MAP@("MEDRXNOTXT")="" ; For Outpatient
87 . S @MAP@("MEDRXNO")="" ; For Outpatient
88 . S @MAP@("MEDTYPETEXT")="Medication"
89 . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
90 . ;S @MAP@("MEDSTATUSTEXT")="ACTIVE"
91 . N C0CMST S C0CMST=$G(MED("vaStatus@value")) ; need to filter status
92 . I C0CMST="EXPIRED" S C0CMST="Prior History No Longer Active"
93 . I C0CMST="ACTIVE" S C0CMST="Active" ;
94 . S @MAP@("MEDSTATUSTEXT")=C0CMST
95 . ;S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$P(MED(1),U)
96 . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$G(MED("orderingProvider@code"))
97 . ;S @MAP@("MEDPRODUCTNAMETEXT")=MED("DDRUG",1,.01)
98 . S @MAP@("MEDPRODUCTNAMETEXT")=$G(MED("name@value"))
99 . ; NDC is field 31 in the drug file.
100 . ; The actual drug entry in the drug file is not necessarily supplied.
101 . ; It' node 1, internal form.
102 . ;N MEDIEN S MEDIEN=MED(1,"I")
103 . ;S @MAP@("MEDPRODUCTNAMECODEVALUE")=$S($L(MEDIEN):$$GET1^DIQ(50,MEDIEN,31,"E"),1:"")
104 . N ZVUID S ZVUID=$G(MED("products.product.vaProduct@vuid")) ; VUID
105 . N ZC,ZCD,ZCDS,ZCDSV ; CODE,CODE SYSTEM,CODE VERSION
106 . D ;
107 . . S ZC=$$CODE^C0CUTIL(ZVUID)
108 . . S ZCD=$P(ZC,"^",1) ; CODE TO USE
109 . . S ZCDS=$P(ZC,"^",2) ; CODING SYSTEM - RXNORM OR VUID
110 . . S ZCDSV=$P(ZC,"^",3) ; CODING SYSTEM VERSION
111 . ;N ZRXNORM S ZRXNORM=""
112 . ;S ZRXNORM=$$RXNCUI3^C0PLKUP(ZVUID)
113 . S @MAP@("MEDPRODUCTNAMECODEVALUE")=ZCD
114 . ;S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=$S($L(MEDIEN):"NDC",1:"")
115 . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=ZCDS
116 . ;S @MAP@("MEDPRODUCTNAMECODEVERSION")=$S($L(MEDIEN):"none",1:"")
117 . S @MAP@("MEDPRODUCTNAMECODEVERSION")=ZCDSV
118 . S @MAP@("MEDBRANDNAMETEXT")=""
119 . S @MAP@("MEDPRODUCTNAMETEXT")=$G(MED("name@value"))_" "_ZCDS_": "_ZCD
120 . ;I $L(MEDIEN) D DOSE^PSS50(MEDIEN,,,,,"DOSE")
121 . ;I $L(MEDIEN) N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
122 . ;S @MAP@("MEDSTRENGTHVALUE")=$S($L(MEDIEN):DOSEDATA(901),1:"")
123 . S @MAP@("MEDSTRENGTHVALUE")=$G(MED("doses.dose@dose"))
124 . ;S @MAP@("MEDSTRENGTHUNIT")=$S($P(DOSEDATA(902),U,2),1:"")
125 . S @MAP@("MEDSTRENGTHUNIT")=$G(MED("doses.dose@units"))
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.
132 . ;N NDFDATA,CONCDATA
133 . ;I $L(MEDIEN) D
134 . ;. D NDF^PSS50(MEDIEN,,,,,"CONC")
135 . ;. M NDFDATA=^TMP($J,"CONC",MEDIEN)
136 . ;. N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
137 . ;. N VAPROD S VAPROD=$P(NDFDATA(22),U)
138 . ;. ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
139 . ;. ; and this will crash the call. So...
140 . ;. I NDFIEN="" S CONCDATA=""
141 . ;. E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
142 . ;E S (NDFDATA,CONCDATA)="" ; This line is defensive programming to prevent undef errors.
143 . ;S @MAP@("MEDFORMTEXT")=$S($L(MEDIEN):$P(CONCDATA,U,1),1:"")
144 . S @MAP@("MEDFORMTEXT")=$G(MED("form@value"))
145 . ;S @MAP@("MEDCONCVALUE")=$S($L(MEDIEN):$P(CONCDATA,U,3),1:"")
146 . S @MAP@("MEDCONCVALUE")=$G(MED("doses.dose@dose"))
147 . ;S @MAP@("MEDCONCUNIT")=$S($L(MEDIEN):$P(CONCDATA,U,4),1:"")
148 . S @MAP@("MEDCONCUNIT")=$G(MED("doses.does@units"))
149 . ;S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
150 . S @MAP@("MEDQUANTITYVALUE")=$G(MED("doses.dose@unitsPerDose")) ;
151 . ; Oddly, there is no easy place to find the dispense unit.
152 . ; It's not included in the original call, so we have to go to the drug file.
153 . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
154 . ; Node 14.5 is the Dispense Unit
155 . ;I $L(MEDIEN) D
156 . ;. D DATA^PSS50(MEDIEN,,,,,"QTY")
157 . ;. N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
158 . ;. S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
159 . ;E S @MAP@("MEDQUANTITYUNIT")=""
160 . S @MAP@("MEDQUANTITYUNIT")=$G(MED("dose.dose@unitsPerDose"))
161 . ;
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 @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
168 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=$G(MED("sig"))
169 . ; $G(MED("products.product.vaProduct@name"))
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 . ;S @MAP@("MEDPTINSTRUCTIONS")=MED(10,1) ; WP Field
199 . S @MAP@("MEDPTINSTRUCTIONS")=""
200 . ;S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
201 . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=""
202 . S @MAP@("MEDRFNO")=""
203 . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
204 . K @RESULT
205 . D MAP^C0CXPATH(MINXML,MAP,RESULT)
206 . ; D PARY^C0CXPATH(RESULT)
207 . ; MAPPING DIRECTIONS
208 . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
209 . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
210 . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
211 . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
212 . ; N MDZ1,MDZNA
213 . N DIRCNT S DIRCNT=1 ; THERE ARE ALWAYS DIRECTIONS
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^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
218 . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
219 . D:MEDCOUNT=1 CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
220 . D:MEDCOUNT>1 INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
221 N MEDTMP,MEDI
222 D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
223 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
224 . W "MEDICATION MISSING ",!
225 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
226 Q
227 ;
Note: See TracBrowser for help on using the repository browser.