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

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

Merged Routines in OHUM branch back in main tree

  • 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.2 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;C0C;;May 11, 2012;Build 47
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 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 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^C0CUTIL($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($L(MEDIEN):$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@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
108 . ; Oddly, there is no easy place to find the dispense unit.
109 . ; It's not included in the original call, so we have to go to the drug file.
110 . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
111 . ; Node 14.5 is the Dispense Unit
112 . I $L(MEDIEN) D
113 . . D DATA^PSS50(MEDIEN,,,,,"QTY")
114 . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
115 . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
116 E S @MAP@("MEDQUANTITYUNIT")=""
117 . ;
118 . ; --- START OF DIRECTIONS ---
119 . ; Dosage is field 2, route is 3, schedule is 4
120 . ; These are all free text fields, and don't point to any files
121 . ; For that reason, I will use the field I never used before:
122 . ; MEDDIRECTIONDESCRIPTIONTEXT
123 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
124 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
125 . S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
126 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
127 . S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
128 . S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
129 . S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
130 . S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
131 . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
132 . S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
133 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
134 . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
135 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
136 . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
137 . S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
138 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
139 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
140 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
141 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
142 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
143 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
144 . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
145 . S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
146 . S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
147 . S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
148 . ;
149 . ; --- END OF DIRECTIONS ---
150 . ;
151 . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
152 . S @MAP@("MEDPTINSTRUCTIONS")=MED(10,1) ; WP Field
153 . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
154 . S @MAP@("MEDRFNO")=""
155 . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"MAPPED"))
156 . K @RESULT
157 . D MAP^GPLXPATH(MINXML,MAP,RESULT)
158 . ; D PARY^GPLXPATH(RESULT)
159 . ; MAPPING DIRECTIONS
160 . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
161 . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
162 . D QUERY^GPLXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
163 . D REPLACE^GPLXPATH(RESULT,"","//Medications/Medication/Directions")
164 . ; N MDZ1,MDZNA
165 . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
166 . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
167 . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
168 . . . D MAP^GPLXPATH(DIRXML1,MDZNA,DIRXML2)
169 . . . D INSERT^GPLXPATH(RESULT,DIRXML2,"//Medications/Medication")
170 . D:MEDCOUNT=1 CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
171 . D:MEDCOUNT>1 INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
172 N MEDTMP,MEDI
173 D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
174 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
175 . W "MEDICATION MISSING ",!
176 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
177 Q
178 ;
Note: See TracBrowser for help on using the repository browser.