1 | CCRMEDS3 ; WV/CCDCCR/SMH - CCR/CCD PROCESSING FOR MEDICATIONS - Outside_non-VA Meds;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 | ;
|
---|
23 | EXTRACT(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 RPC.
|
---|
30 | ; MAP is a mapping variable map (store result) for each med
|
---|
31 | ; MED is holds each array element from MEDS, one medicine
|
---|
32 | ;
|
---|
33 | ; Non-VA meds don't have an API. They are stored in file 55, subfile 52.2
|
---|
34 | ; Discontinued meds are indicated by the presence of a value in fields
|
---|
35 | ; 5 or 6 (STATUS 1 or 2, and DISCONTINUED DATE)
|
---|
36 | ; Will use Fileman API GETS^DIQ
|
---|
37 | ;
|
---|
38 | N MEDS,MAP
|
---|
39 | K ^TMP($J),NVA
|
---|
40 | D GETS^DIQ(55,DFN,"52.2*","IE","NVA") ; Output in NVA in FDA array format.
|
---|
41 | ; If NVA does not exist, then patient has no non-VA meds
|
---|
42 | I $D(NVA)=0 S @OUTXML@(0)=0 QUIT
|
---|
43 | ; Otherwise, we go on...
|
---|
44 | M MEDS=NVA(55.05)
|
---|
45 | ; We are done with NVA
|
---|
46 | K NVA
|
---|
47 | ;
|
---|
48 | I DEBUG ZWR MEDS
|
---|
49 | N FDAIEN S FDAIEN=0 ; For use in $Order in the MEDS array.
|
---|
50 | S MEDMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP"))
|
---|
51 | N MEDCOUNT S MEDCOUNT=@MEDMAP@(0) ; We already have meds in the array
|
---|
52 | N MEDFIRST S MEDFIRST=1 ; FLAG FOR FIRST MED PROCESSED HERE
|
---|
53 | F S FDAIEN=$O(MEDS(FDAIEN)) Q:FDAIEN="" D ; FOR EACH MEDICATION IN THE LIST
|
---|
54 | . N MED M MED=MEDS(FDAIEN)
|
---|
55 | . I MED(5,"I")!MED(6,"I") QUIT ; If disconinued, we don't want to pull it.
|
---|
56 | . S MEDCOUNT=MEDCOUNT+1
|
---|
57 | . S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP",MEDCOUNT))
|
---|
58 | . S @MEDMAP@(0)=@MEDMAP@(0)+1 ; INCREMENT TOTAL MEDS IN VAR ARRAY
|
---|
59 | . N RXIEN S RXIEN=$P(FDAIEN,",") ; First piece of FDAIEN is the number of the med for this patient
|
---|
60 | . I DEBUG W "RXIEN IS ",RXIEN,!
|
---|
61 | . I DEBUG W "MAP= ",MAP,!
|
---|
62 | . S @MAP@("MEDOBJECTID")="MED_OUTSIDE"_MEDCOUNT ; MEDCOUNT FOR ID
|
---|
63 | . S @MAP@("MEDISSUEDATETXT")="Documented Date"
|
---|
64 | . ; Field 6 is "Effective date", and we pull it in timson format w/ I
|
---|
65 | . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^CCRUTIL(MED(11,"I"),"DT")
|
---|
66 | . ; Med never filled; next 4 fields are not applicable.
|
---|
67 | . S @MAP@("MEDLASTFILLDATETXT")=""
|
---|
68 | . S @MAP@("MEDLASTFILLDATE")=""
|
---|
69 | . S @MAP@("MEDRXNOTXT")=""
|
---|
70 | . S @MAP@("MEDRXNO")=""
|
---|
71 | . S @MAP@("MEDTYPETEXT")="Medication"
|
---|
72 | . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
|
---|
73 | . S @MAP@("MEDSTATUSTEXT")="ACTIVE" ; nearest status for pending meds
|
---|
74 | . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_MED(12,"I")
|
---|
75 | . S @MAP@("MEDPRODUCTNAMETEXT")=MED(.01,"E")
|
---|
76 | . ; NDC is field 31 in the drug file.
|
---|
77 | . ; The actual drug entry in the drug file is not necessarily supplied.
|
---|
78 | . ; It' node 1, internal form.
|
---|
79 | . N MEDIEN S MEDIEN=MED(1,"I")
|
---|
80 | . S @MAP@("MEDPRODUCTNAMECODEVALUE")=$S($L(MEDIEN):$$GET1^DIQ(50,MEDIEN,31,"E"),1:"")
|
---|
81 | . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=$S($L(MEDIEN):"NDC",1:"")
|
---|
82 | . S @MAP@("MEDPRODUCTNAMECODEVERSION")=$S($L(MEDIEN):"none",1:"")
|
---|
83 | . S @MAP@("MEDBRANDNAMETEXT")=""
|
---|
84 | . I $L(MEDIEN) D DOSE^PSS50(MEDIEN,,,,,"DOSE")
|
---|
85 | . I $L(MEDIEN) N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
|
---|
86 | . S @MAP@("MEDSTRENGTHVALUE")=$S($L(MEDIEN):DOSEDATA(901),1:"")
|
---|
87 | . S @MAP@("MEDSTRENGTHUNIT")=$S($L(DOSEDATA(902))>0:$P(DOSEDATA(902),U,2),1:"") ; SAM PLEASE CHECK
|
---|
88 | . ; Units, concentration, etc, come from another call
|
---|
89 | . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
|
---|
90 | . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
|
---|
91 | . ; NDF Entry IEN, and VA Product Name
|
---|
92 | . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
|
---|
93 | . ; Documented in the same manual.
|
---|
94 | . N NDFDATA,CONCDATA
|
---|
95 | . I $L(MEDIEN) D
|
---|
96 | . . D NDF^PSS50(MEDIEN,,,,,"CONC")
|
---|
97 | . . M NDFDATA=^TMP($J,"CONC",MEDIEN)
|
---|
98 | . . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
|
---|
99 | . . N VAPROD S VAPROD=$P(NDFDATA(22),U)
|
---|
100 | . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
|
---|
101 | . . ; and this will crash the call. So...
|
---|
102 | . . I NDFIEN="" S CONCDATA=""
|
---|
103 | . . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
|
---|
104 | . E S (NDFDATA,CONCDATA)="" ; This line is defensive programming to prevent undef errors.
|
---|
105 | . S @MAP@("MEDFORMTEXT")=$S($L(MEDIEN):$P(CONCDATA,U,1),1:"")
|
---|
106 | . S @MAP@("MEDCONCVALUE")=$S($L(MEDIEN):$P(CONCDATA,U,3),1:"")
|
---|
107 | . S @MAP@("MEDCONCUNIT")=$S($L(MEDIEN):$P(CONCDATA,U,4),1:"")
|
---|
108 | . S @MAP@("MEDSIZETEXT")=$S($L(MEDIEN):$P(NDFDATA(23),U,2)_" "_$P(NDFDATA(24),U,2),1:"")
|
---|
109 | . S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
|
---|
110 | . ; Oddly, there is no easy place to find the dispense unit.
|
---|
111 | . ; It's not included in the original call, so we have to go to the drug file.
|
---|
112 | . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
|
---|
113 | . ; Node 14.5 is the Dispense Unit
|
---|
114 | . I $L(MEDIEN) D
|
---|
115 | . . D DATA^PSS50(MEDIEN,,,,,"QTY")
|
---|
116 | . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
|
---|
117 | . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
|
---|
118 | . E S @MAP@("MEDQUANTITYUNIT")=""
|
---|
119 | . ;
|
---|
120 | . ; --- START OF DIRECTIONS ---
|
---|
121 | . ; Dosage is field 2, route is 3, schedule is 4
|
---|
122 | . ; These are all free text fields, and don't point to any files
|
---|
123 | . ; For that reason, I will use the field I never used before:
|
---|
124 | . ; MEDDIRECTIONDESCRIPTIONTEXT
|
---|
125 | . S DIRCNT=1 ; THERE IS ONLY ONE DIRECTION FOR OUTSIDE MEDS
|
---|
126 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
|
---|
127 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
|
---|
128 | . S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
|
---|
129 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
|
---|
130 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
|
---|
131 | . S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
|
---|
132 | . S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
|
---|
133 | . S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
|
---|
134 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
|
---|
135 | . S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
|
---|
136 | . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
|
---|
137 | . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
|
---|
138 | . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
|
---|
139 | . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
|
---|
140 | . S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
|
---|
141 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
|
---|
142 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
|
---|
143 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
|
---|
144 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
|
---|
145 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
|
---|
146 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
|
---|
147 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
|
---|
148 | . S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
|
---|
149 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
|
---|
150 | . S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
|
---|
151 | . ;
|
---|
152 | . ; --- END OF DIRECTIONS ---
|
---|
153 | . ;
|
---|
154 | . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
|
---|
155 | . I $D(MED(10,1)) D ;
|
---|
156 | . . S @MAP@("MEDPTINSTRUCTIONS")=MED(10,1) ; WP Field
|
---|
157 | . E S @MAP@("MEDPTINSTRUCTIONS")=""
|
---|
158 | . I $D(MED(14,1)) D ;
|
---|
159 | . . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
|
---|
160 | . E S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=""
|
---|
161 | . S @MAP@("MEDRFNO")=""
|
---|
162 | . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"MAPPED"))
|
---|
163 | . K @RESULT
|
---|
164 | . D MAP^GPLXPATH(MINXML,MAP,RESULT)
|
---|
165 | . ; D PARY^GPLXPATH(RESULT)
|
---|
166 | . ; MAPPING DIRECTIONS
|
---|
167 | . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
|
---|
168 | . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
|
---|
169 | . D QUERY^GPLXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
|
---|
170 | . D REPLACE^GPLXPATH(RESULT,"","//Medications/Medication/Directions")
|
---|
171 | . ; N MDZ1,MDZNA
|
---|
172 | . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
|
---|
173 | . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
|
---|
174 | . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
|
---|
175 | . . . D MAP^GPLXPATH(DIRXML1,MDZNA,DIRXML2)
|
---|
176 | . . . D INSERT^GPLXPATH(RESULT,DIRXML2,"//Medications/Medication")
|
---|
177 | . I MEDFIRST D ;
|
---|
178 | . . S MEDFIRST=0 ; RESET FIRST FLAG
|
---|
179 | . . D CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
|
---|
180 | . D:'MEDFIRST INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
|
---|
181 | N MEDTMP,MEDI
|
---|
182 | D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
|
---|
183 | I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
|
---|
184 | . W "MEDICATION MISSING ",!
|
---|
185 | . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
|
---|
186 | Q
|
---|
187 | ;
|
---|