source: ccr/trunk/p/CCRMEDS4.m@ 272

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

Added CCRMEDS4 for inpatient UD, and tiny fixes for the FMDTOUTCCCRUTIL call for CCRMEDS1 and 2

  • Property svn:executable set to *
File size: 8.3 KB
RevLine 
[227]1CCRMEDS4 ; WV/CCDCCR/SMH - 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) ; 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 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 CCRMEDS4
35 ; Inpatient Meds IVs is going to be CCRMEDS5
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 M MEDS=^TMP($J,"UD")
51 I DEBUG ZWR MEDS
52 S MEDMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP"))
53 N MEDCOUNT S MEDCOUNT=@MEDMAP@(0) ; We already have meds in the array
54 N I S I=0
55 F S I=$O(MEDS("B",I)) Q:'I D ; For each medication in B index
56 . N MED M MED=MEDS(I)
57 . S MEDCOUNT=MEDCOUNT+1
58 . S @MEDMAP@(0)=MEDCOUNT ; Update MedMap array counter
59 . S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP",MEDCOUNT))
60 . N RXIEN S RXIEN=MED(.01) ; Order Number
61 . I DEBUG W "RXIEN IS ",RXIEN,!
62 . I DEBUG W "MAP= ",MAP,!
63 . S @MAP@("MEDOBJECTID")="MED_INPATIENT_UD"_RXIEN
64 . S @MAP@("MEDISSUEDATETXT")="Order Date"
65 . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^CCRUTIL($P(MED(27),U),"DT")
66 . S @MAP@("MEDLASTFILLDATETXT")="" ; For Outpatient
67 . S @MAP@("MEDLASTFILLDATE")="" ; For Outpatient
68 . S @MAP@("MEDRXNOTXT")="" ; For Outpatient
69 . S @MAP@("MEDRXNO")="" ; For Outpatient
70 . S @MAP@("MEDTYPETEXT")="Medication"
71 . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
72 . S @MAP@("MEDSTATUSTEXT")="ACTIVE"
73 . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$P(MED(1),U)
74 . S @MAP@("MEDPRODUCTNAMETEXT")=MED("DDRUG",1,.01)
75 . ; NDC is field 31 in the drug file.
76 . ; The actual drug entry in the drug file is not necessarily supplied.
77 . ; It' node 1, internal form.
78 . N MEDIEN S MEDIEN=MED(1,"I")
79 . S @MAP@("MEDPRODUCTNAMECODEVALUE")=$S($L(MEDIEN):$$GET1^DIQ(50,MEDIEN,31,"E"),1:"")
80 . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=$S($L(MEDIEN):"NDC",1:"")
81 . S @MAP@("MEDPRODUCTNAMECODEVERSION")=$S($L(MEDIEN):"none",1:"")
82 . S @MAP@("MEDBRANDNAMETEXT")=""
83 . I $L(MEDIEN) D DOSE^PSS50(MEDIEN,,,,,"DOSE")
84 . I $L(MEDIEN) N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
85 . S @MAP@("MEDSTRENGTHVALUE")=$S($L(MEDIEN):DOSEDATA(901),1:"")
86 . S @MAP@("MEDSTRENGTHUNIT")=$S($P(DOSEDATA(902),U,2),1:"")
87 . ; Units, concentration, etc, come from another call
88 . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
89 . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
90 . ; NDF Entry IEN, and VA Product Name
91 . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
92 . ; Documented in the same manual.
93 . N NDFDATA,CONCDATA
94 . I $L(MEDIEN) D
95 . . D NDF^PSS50(MEDIEN,,,,,"CONC")
96 . . M NDFDATA=^TMP($J,"CONC",MEDIEN)
97 . . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
98 . . N VAPROD S VAPROD=$P(NDFDATA(22),U)
99 . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
100 . . ; and this will crash the call. So...
101 . . I NDFIEN="" S CONCDATA=""
102 . . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
103 . E S (NDFDATA,CONCDATA)="" ; This line is defensive programming to prevent undef errors.
104 . S @MAP@("MEDFORMTEXT")=$S($L(MEDIEN):$P(CONCDATA,U,1),1:"")
105 . S @MAP@("MEDCONCVALUE")=$S($L(MEDIEN):$P(CONCDATA,U,3),1:"")
106 . S @MAP@("MEDCONCUNIT")=$S($L(MEDIEN):$P(CONCDATA,U,4),1:"")
107 . S @MAP@("MEDSIZETEXT")=$S($L(MEDIEN):$P(NDFDATA(23),U,2)_" "_$P(NDFDATA(24),U,2),1:"")
108 . S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
109 . ; Oddly, there is no easy place to find the dispense unit.
110 . ; It's not included in the original call, so we have to go to the drug file.
111 . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
112 . ; Node 14.5 is the Dispense Unit
113 . I $L(MEDIEN) D
114 . . D DATA^PSS50(MEDIEN,,,,,"QTY")
115 . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
116 . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
117 E S @MAP@("MEDQUANTITYUNIT")=""
118 . ;
119 . ; --- START OF DIRECTIONS ---
120 . ; Dosage is field 2, route is 3, schedule is 4
121 . ; These are all free text fields, and don't point to any files
122 . ; For that reason, I will use the field I never used before:
123 . ; MEDDIRECTIONDESCRIPTIONTEXT
124 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
125 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
126 . S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
127 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
128 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
129 . S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
130 . S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
131 . S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
132 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
133 . S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
134 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
135 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
136 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
137 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
138 . S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
139 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
140 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
141 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
142 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
143 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
144 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
145 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
146 . S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
147 . S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
148 . S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
149 . ;
150 . ; --- END OF DIRECTIONS ---
151 . ;
152 . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
153 . S @MAP@("MEDPTINSTRUCTIONS")=MED(10,1) ; WP Field
154 . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
155 . S @MAP@("MEDRFNO")=""
156 . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"MAPPED"))
157 . K @RESULT
158 . D MAP^GPLXPATH(MINXML,MAP,RESULT)
159 . ; D PARY^GPLXPATH(RESULT)
160 . ; MAPPING DIRECTIONS
161 . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
162 . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
163 . D QUERY^GPLXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
164 . D REPLACE^GPLXPATH(RESULT,"","//Medications/Medication/Directions")
165 . ; N MDZ1,MDZNA
166 . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
167 . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
168 . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
169 . . . D MAP^GPLXPATH(DIRXML1,MDZNA,DIRXML2)
170 . . . D INSERT^GPLXPATH(RESULT,DIRXML2,"//Medications/Medication")
171 . D:MEDCOUNT=1 CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
172 . D:MEDCOUNT>1 INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
173 N MEDTMP,MEDI
174 D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
175 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
176 . W "MEDICATION MISSING ",!
177 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
178 Q
179 ;
Note: See TracBrowser for help on using the repository browser.