source: ccr/trunk/p/C0CMED4.m@ 1751

Last change on this file since 1751 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

  • Property svn:executable set to *
  • Property svn:mergeinfo set to (toggle deleted branches)
    /ccr/branches/ohum/o-old/p/C0CMED4.m1290
    /ccr/branches/ohum/p/C0CMED4.m1291-1543
    /ccr/branches/ohum/p/p/C0CMED4.m1287-1289
File size: 8.1 KB
Line 
1C0CMED4 ; WV/CCDCCR/SMH - CCR/CCD PROCESSING FOR MEDICATIONS - Inpatient Meds/Unit Dose ;10/13/08 ; 5/10/12 2:38pm
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) ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
22 ;
23 ; MINXML is the Input XML Template, passed by name
24 ; DFN is Patient IEN
25 ; OUTXML is the resultant XML.
26 ;
27 ; MEDS is return array from API.
28 ; MED is holds each array element from MEDS, one medicine
29 ; MAP is a mapping variable map (store result) for each med
30 ;
31 ; Inpatient Meds will be extracted using this routine and and the one following.
32 ; Inpatient Meds Unit Dose is going to be C0CMED4
33 ; Inpatient Meds IVs is going to be C0CMED5
34 ;
35 ; We will use two Pharmacy ReEnginnering API's:
36 ; PSS431^PSS55(DFN,PO,PSDATE,PEDATE,LIST) - provides most info
37 ; PSS432^PSS55(DFN,PO,LIST) - provides schedule info
38 ; For more information, see the PRE documentation at:
39 ; http://www.va.gov/vdl/documents/Clinical/Pharm-Inpatient_Med/phar_1_api_r0807.pdf
40 ;
41 ; Med data is stored in Unit Dose multiple of file 55, pharmacy patient
42 ;
43 N MEDS,MAP
44 K ^TMP($J)
45 D PSS431^PSS55(DFN,,,,"UD") ; Output is in ^TMP($J,"UD",*)
46 I ^TMP($J,"UD",0)'>0 S @OUTXML@(0)=0 QUIT ; No Meds - Quit
47 ; Otherwise, we go on...
48 M MEDS=^TMP($J,"UD")
49 ; I DEBUG ZWR MEDS
50 S MEDMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP"))
51 N MEDCOUNT S MEDCOUNT=@MEDMAP@(0) ; We already have meds in the array
52 N I S I=0
53 F S I=$O(MEDS("B",I)) Q:'I D ; For each medication in B index
54 . N MED M MED=MEDS(I)
55 . S MEDCOUNT=MEDCOUNT+1
56 . S @MEDMAP@(0)=MEDCOUNT ; Update MedMap array counter
57 . S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP",MEDCOUNT))
58 . N RXIEN S RXIEN=MED(.01) ; Order Number
59 . I DEBUG W "RXIEN IS ",RXIEN,!
60 . I DEBUG W "MAP= ",MAP,!
61 . S @MAP@("MEDOBJECTID")="MED_INPATIENT_UD"_RXIEN
62 . S @MAP@("MEDISSUEDATETXT")="Order Date"
63 . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($P(MED(27),U),"DT")
64 . S @MAP@("MEDLASTFILLDATETXT")="" ; For Outpatient
65 . S @MAP@("MEDLASTFILLDATE")="" ; For Outpatient
66 . S @MAP@("MEDRXNOTXT")="" ; For Outpatient
67 . S @MAP@("MEDRXNO")="" ; For Outpatient
68 . S @MAP@("MEDTYPETEXT")="Medication"
69 . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
70 . S @MAP@("MEDSTATUSTEXT")="ACTIVE"
71 . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$P(MED(1),U)
72 . S @MAP@("MEDPRODUCTNAMETEXT")=MED("DDRUG",1,.01)
73 . ; NDC is field 31 in the drug file.
74 . ; The actual drug entry in the drug file is not necessarily supplied.
75 . ; It' node 1, internal form.
76 . N MEDIEN S MEDIEN=MED(1,"I")
77 . S @MAP@("MEDPRODUCTNAMECODEVALUE")=$S($L(MEDIEN):$$GET1^DIQ(50,MEDIEN,31,"E"),1:"")
78 . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=$S($L(MEDIEN):"NDC",1:"")
79 . S @MAP@("MEDPRODUCTNAMECODEVERSION")=$S($L(MEDIEN):"none",1:"")
80 . S @MAP@("MEDBRANDNAMETEXT")=""
81 . I $L(MEDIEN) D DOSE^PSS50(MEDIEN,,,,,"DOSE")
82 . I $L(MEDIEN) N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
83 . S @MAP@("MEDSTRENGTHVALUE")=$S($L(MEDIEN):DOSEDATA(901),1:"")
84 . S @MAP@("MEDSTRENGTHUNIT")=$S($L(MEDIEN):$P(DOSEDATA(902),U,2),1:"")
85 . ; Units, concentration, etc, come from another call
86 . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
87 . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
88 . ; NDF Entry IEN, and VA Product Name
89 . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
90 . ; Documented in the same manual.
91 . N NDFDATA,CONCDATA
92 . I $L(MEDIEN) D
93 . . D NDF^PSS50(MEDIEN,,,,,"CONC")
94 . . M NDFDATA=^TMP($J,"CONC",MEDIEN)
95 . . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
96 . . N VAPROD S VAPROD=$P(NDFDATA(22),U)
97 . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
98 . . ; and this will crash the call. So...
99 . . I NDFIEN="" S CONCDATA=""
100 . . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
101 . E S (NDFDATA,CONCDATA)="" ; This line is defensive programming to prevent undef errors.
102 . S @MAP@("MEDFORMTEXT")=$S($L(MEDIEN):$P(CONCDATA,U,1),1:"")
103 . S @MAP@("MEDCONCVALUE")=$S($L(MEDIEN):$P(CONCDATA,U,3),1:"")
104 . S @MAP@("MEDCONCUNIT")=$S($L(MEDIEN):$P(CONCDATA,U,4),1:"")
105 . S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
106 . ; Oddly, there is no easy place to find the dispense unit.
107 . ; It's not included in the original call, so we have to go to the drug file.
108 . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
109 . ; Node 14.5 is the Dispense Unit
110 . I $L(MEDIEN) D
111 . . D DATA^PSS50(MEDIEN,,,,,"QTY")
112 . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
113 . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
114 . E S @MAP@("MEDQUANTITYUNIT")=""
115 . ;
116 . ; --- START OF DIRECTIONS ---
117 . ; Dosage is field 2, route is 3, schedule is 4
118 . ; These are all free text fields, and don't point to any files
119 . ; For that reason, I will use the field I never used before:
120 . ; MEDDIRECTIONDESCRIPTIONTEXT
121 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
122 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
123 . S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
124 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
125 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
126 . S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
127 . S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
128 . S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
129 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
130 . S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
131 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
132 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
133 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
134 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
135 . S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
136 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
137 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
138 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
139 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
140 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
141 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
142 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
143 . S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
144 . S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
145 . S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
146 . ;
147 . ; --- END OF DIRECTIONS ---
148 . ;
149 . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
150 . S @MAP@("MEDPTINSTRUCTIONS")=MED(10,1) ; WP Field
151 . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
152 . S @MAP@("MEDRFNO")=""
153 . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"MAPPED"))
154 . K @RESULT
155 . D MAP^GPLXPATH(MINXML,MAP,RESULT)
156 . ; D PARY^GPLXPATH(RESULT)
157 . ; MAPPING DIRECTIONS
158 . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
159 . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
160 . D QUERY^GPLXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
161 . D REPLACE^GPLXPATH(RESULT,"","//Medications/Medication/Directions")
162 . ; N MDZ1,MDZNA
163 . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
164 . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
165 . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
166 . . . D MAP^GPLXPATH(DIRXML1,MDZNA,DIRXML2)
167 . . . D INSERT^GPLXPATH(RESULT,DIRXML2,"//Medications/Medication")
168 . D:MEDCOUNT=1 CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
169 . D:MEDCOUNT>1 INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
170 N MEDTMP,MEDI
171 D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
172 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
173 . W "MEDICATION MISSING ",!
174 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
175 Q
176 ;
Note: See TracBrowser for help on using the repository browser.