1 | CCRMEDS6 ; WV/CCDCCR/SMH - Meds from RPMS;01/10/09
|
---|
2 | ;;0.1;CCDCCR;;JUL 16,2008;
|
---|
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 and OUTXML are passed by name so globals can be used
|
---|
26 | ; MINXML will contain only the medications skeleton of the overall template
|
---|
27 | ;
|
---|
28 | ; MEDS is return array from RPC.
|
---|
29 | ; MAP is a mapping variable map (store result) for each med
|
---|
30 | ; MED is holds each array element from MEDS(J), one medicine
|
---|
31 | ; J is a counter.
|
---|
32 | ;
|
---|
33 | ; GETRXS^BEHORXFN(ARRAYNAME,DFN,DAYS) will be the the API used.
|
---|
34 | ; This API has been developed by Medsphere for IHS for getting
|
---|
35 | ; Medications from RPMS. It has most of what we need.
|
---|
36 | ; -- ARRAYNAME is passed by name (required)
|
---|
37 | ; -- DFN is passed by value (required)
|
---|
38 | ; -- DAYS is passed by value (optional; if not passed defaults to 365)
|
---|
39 | ;
|
---|
40 | ; Return:
|
---|
41 | ; ~Type^PharmID^Drug^InfRate^StopDt^RefRem^TotDose^UnitDose^OrderID
|
---|
42 | ; ^Status^LastFill^Chronic^Issued^Rx #^Provider^
|
---|
43 | ; Status Reason^DEA Handling
|
---|
44 | ;
|
---|
45 | N MEDS,MEDS1,MAP
|
---|
46 | D GETRXS^BEHORXFN("MEDS1",DFN,365) ; Days hard set to 365
|
---|
47 | ; If MEDS1 is not defined, then no meds
|
---|
48 | I '$D(MEDS1) S @OUTXML@(0)=0 QUIT
|
---|
49 | I DEBUG ZWR MEDS1
|
---|
50 | N MEDCNT S MEDCNT=0 ; Med Count
|
---|
51 | ; The next line is a super line. It goes through the array return
|
---|
52 | ; and if the first character is a ~, it grabs the line.
|
---|
53 | ; That line has the metadata about the med that I need.
|
---|
54 | ; The next lines, however many, are the med and the sig.
|
---|
55 | ; I won't be using those because I have to get the sig parsed exactly.
|
---|
56 | N J S J="" F S J=$O(MEDS1(J)) Q:J="" I $E(MEDS1(J))="~" S MEDCNT=MEDCNT+1 S MED(MEDCNT)=MEDS1(J)
|
---|
57 | S MEDMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP")) ; this is the variable map
|
---|
58 | S @MEDMAP@(0)=0 ; Initial count of meds
|
---|
59 | F S MEDCNT=$O(MEDS(MEDCNT)) Q:MEDCNT="" D ; for each medication in the list
|
---|
60 | . I DEBUG W "MEDCNT IS ",MEDCNT,!
|
---|
61 | . S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP",MEDCNT))
|
---|
62 | . ; K @MAP DO NOT KILL HERE, WAS CLEARED IN CCRMEDS
|
---|
63 | . S @MEDMAP@(0)=@MEDMAP@(0)+1 ; increment total meds in var array
|
---|
64 | . I DEBUG W "MAP= ",MAP,!
|
---|
65 | . S @MAP@("MEDOBJECTID")="MED"_MEDCNT ; MEDCNT FOR ID
|
---|
66 | . S @MAP@("MEDISSUEDATETXT")="Issue Date"
|
---|
67 | . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^CCRUTIL($P(MEDS(MEDCNT),U,13))
|
---|
68 | . S @MAP@("MEDLASTFILLDATETXT")="Last Fill Date"
|
---|
69 | . S @MAP@("MEDLASTFILLDATE")=$$FMDTOUTC^CCRUTIL($P(MEDS(MEDCNT),U,11))
|
---|
70 | . S @MAP@("MEDRXNOTXT")="Prescription Number"
|
---|
71 | . S @MAP@("MEDRXNO")=$P(MEDS(MEDCNT),U,14)
|
---|
72 | . S @MAP@("MEDTYPETEXT")="Medication"
|
---|
73 | . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
|
---|
74 | . S @MAP@("MEDSTATUSTEXT")=$P(MEDS(MEDCNT),U,10)
|
---|
75 | . ; Provider only provided in API as text, not DUZ.
|
---|
76 | . ; We need to get DUZ from filman file 52 (Prescription)
|
---|
77 | . ; Field 4;; IEN is Piece 1 of Meds stripped of trailing characters.
|
---|
78 | . N RXIEN S RXIEN=+$P(MEDS(MEDCNT),U)
|
---|
79 | . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$$GET1^DIQ(52,RXIEN,4,"I")
|
---|
80 | . S @MAP@("MEDPRODUCTNAMETEXT")=$P(MEDS(MEDCNT),U,3)
|
---|
81 | . ; --- RxNorm Stuff
|
---|
82 | . ; 176.001 is the file for Concepts; 176.003 is the file for
|
---|
83 | . ; sources (i.e. for RxNorm Version)
|
---|
84 | . ;
|
---|
85 | . ; I use 176.001 for the Vista version of this routine (files 1-3)
|
---|
86 | . ; Since IHS does not have VUID's, I will be getting RxNorm codes
|
---|
87 | . ; using NDCs. My specially crafted index (sounds evil) named "NDC"
|
---|
88 | . ; is in file 176.002. The file is called RxNorm NDC to VUID.
|
---|
89 | . ; Except that I don't need the VUID, but it's there if I need it.
|
---|
90 | . ;
|
---|
91 | . ; We obviously need the NDC. That is easily obtained from the prescription.
|
---|
92 | . ; Field 27 in file 52
|
---|
93 | . ; N NDC S NDC=$$GET1^DIQ(52,RXIEN,27,"I")
|
---|
94 | . ; S NDC=$TR(NDC,"-") ; Remove dashes
|
---|
95 | . ; NDC="0"_NDC ; Add an extra zero to front; don't ask, that's how RxNorm has it
|
---|
96 | . N NDC S NDC=0 ; TODO:Remove this line after I fix the RxNorm 176.002 file.
|
---|
97 | . N RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
|
---|
98 | . I +NDC,$D(^C0CRXN) D ; $Data is for Systems that don't have our RxNorm file yet.
|
---|
99 | . . S RXNIEN=$$FIND1^DIC(176.002,,,NDC,"NDC")
|
---|
100 | . . S RXNORM=$$GET1^DIQ(176.002,RXNIEN,.01)
|
---|
101 | . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
|
---|
102 | . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
|
---|
103 | . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
|
---|
104 | . ;
|
---|
105 | . E S (RXNORM,RXNNAME,RXNVER)=""
|
---|
106 | . ; End if/else block
|
---|
107 | . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
|
---|
108 | . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
|
---|
109 | . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
|
---|
110 | . ; --- End RxNorm section
|
---|
111 | . ;
|
---|
112 | . ; Brand name is 52 field 6.5
|
---|
113 | . S @MAP@("MEDBRANDNAMETEXT")=$$GET1^DIQ(52,RXIEN,6.5,"I")
|
---|
114 | . ;
|
---|
115 | . ; Next I need Med Form (tab, cap etc), strength (250mg)
|
---|
116 | . ; concentration for liquids (250mg/mL)
|
---|
117 | . ; Since IHS does not have any of the new calls that
|
---|
118 | . ; Vista has, I will be doing a crosswalk:
|
---|
119 | . ; File 52, field 6 is Drug IEN in file 50
|
---|
120 | . ; File 50, field 22 is VA Product IEN in file 50.68
|
---|
121 | . ; In file 50.68, I will get the following:
|
---|
122 | . ; -- 1: Dosage Form
|
---|
123 | . ; -- 2: Strength
|
---|
124 | . ; -- 3: Units
|
---|
125 | . ; -- 8: Dispense Units
|
---|
126 | . ; -- Conc is 2 concatenated with 3
|
---|
127 | . ;
|
---|
128 | . N MEDIEN S MEDIEN=$P(MED(6),U)
|
---|
129 | . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
|
---|
130 | . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
|
---|
131 | . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
|
---|
132 | . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
|
---|
133 | . ; Units, concentration, etc, come from another call
|
---|
134 | . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
|
---|
135 | . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
|
---|
136 | . ; NDF Entry IEN, and VA Product Name
|
---|
137 | . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
|
---|
138 | . ; Documented in the same manual.
|
---|
139 | . D NDF^PSS50(MEDIEN,,,,,"CONC")
|
---|
140 | . N NDFDATA M NDFDATA=^TMP($J,"CONC",MEDIEN)
|
---|
141 | . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
|
---|
142 | . N VAPROD S VAPROD=$P(NDFDATA(22),U)
|
---|
143 | . N CONCDATA
|
---|
144 | . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
|
---|
145 | . ; and this will crash the call. So...
|
---|
146 | . I NDFIEN="" S CONCDATA=""
|
---|
147 | . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
|
---|
148 | . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
|
---|
149 | . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
|
---|
150 | . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
|
---|
151 | . S @MAP@("MEDQUANTITYVALUE")=MED(7)
|
---|
152 | . ; Oddly, there is no easy place to find the dispense unit.
|
---|
153 | . ; It's not included in the original call, so we have to go to the drug file.
|
---|
154 | . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
|
---|
155 | . ; Node 14.5 is the Dispense Unit
|
---|
156 | . D DATA^PSS50(MEDIEN,,,,,"QTY")
|
---|
157 | . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
|
---|
158 | . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
|
---|
159 | . ;
|
---|
160 | . ; --- START OF DIRECTIONS ---
|
---|
161 | . ; Sig data not in any API :-( Oh yes, you can get the whole thing, but...
|
---|
162 | . ; we want the compoenents.
|
---|
163 | . ; It's in node 6 of ^PSRX(IEN)
|
---|
164 | . ; So, here we go again
|
---|
165 | . ; ^PSRX(D0,6,D1,0)= (#.01) DOSAGE ORDERED [1F] ^ (#1) DISPENSE UNITS PER DOSE
|
---|
166 | . ; ==>[2N] ^ (#2) UNITS [3P:50.607] ^ (#3) NOUN [4F] ^ (#4)
|
---|
167 | . ; ==>DURATION [5F] ^ (#5) CONJUNCTION [6S] ^ (#6) ROUTE
|
---|
168 | . ; ==>[7P:51.2] ^ (#7) SCHEDULE [8F] ^ (#8) VERB [9F] ^
|
---|
169 | . ;
|
---|
170 | . N DIRNUM S DIRNUM=0 ; Sigline number
|
---|
171 | . S DIRCNT=0 ; COUNT OF MULTIPLE DIRECTIONS
|
---|
172 | . F S DIRNUM=$O(^PSRX(RXIEN,6,DIRNUM)) Q:DIRNUM="" D
|
---|
173 | . . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
|
---|
174 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")="" ; This is reserved for systems not able to generate the sig in components.
|
---|
175 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1" ; means that we are specifying it. See E2369-05.
|
---|
176 | . . N SIGDATA S SIGDATA=^PSRX(RXIEN,6,DIRNUM,0)
|
---|
177 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=$P(SIGDATA,U,9)
|
---|
178 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=$P(SIGDATA,U,1)
|
---|
179 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
|
---|
180 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")="" ; For inpatient
|
---|
181 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")="" ; For inpatient
|
---|
182 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")="" ; For inpatient
|
---|
183 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=$$GET1^DIQ(51.2,$P(SIGDATA,U,7),.01)
|
---|
184 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=$P(SIGDATA,U,8)
|
---|
185 | . . ; Invervals... again another call.
|
---|
186 | . . ; In the wisdom of the original programmers, the schedule is a free text field
|
---|
187 | . . ; However, it gets translated by a call to the administration schedule file
|
---|
188 | . . ; to see if that schedule exists.
|
---|
189 | . . ; That's the same thing I am going to do.
|
---|
190 | . . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
|
---|
191 | . . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
|
---|
192 | . . ; I looked), PSSFT is the name, and list is the ^TMP name to store the data in.
|
---|
193 | . . ; So...
|
---|
194 | . . D AP^PSS51P1("PSJ",$P(SIGDATA,U,8),,,"SCHEDULE")
|
---|
195 | . . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
|
---|
196 | . . N INTERVAL
|
---|
197 | . . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
|
---|
198 | . . E D
|
---|
199 | . . . N SUB S SUB=$O(SCHEDATA(0))
|
---|
200 | . . . S INTERVAL=SCHEDATA(SUB,2)
|
---|
201 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
|
---|
202 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
|
---|
203 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$P(SIGDATA,U,5)
|
---|
204 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=""
|
---|
205 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=$P(SIGDATA,U,8)["PRN"
|
---|
206 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
|
---|
207 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
|
---|
208 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
|
---|
209 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
|
---|
210 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
|
---|
211 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
|
---|
212 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
|
---|
213 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")=""
|
---|
214 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
|
---|
215 | . . N DIRMOD S DIRMOD=$P(SIGDATA,U,6)
|
---|
216 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=$S(DIRMOD="T":"THEN",DIRMOD="A":"AND",DIRMOD="X":"EXCEPT",1:"")
|
---|
217 | . ;
|
---|
218 | . ; --- END OF DIRECTIONS ---
|
---|
219 | . ;
|
---|
220 | . ; ^PSRX(22,"INS1",1,0)="FOR BLOOD PRESSURE"
|
---|
221 | . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"INS1",1,0))
|
---|
222 | . ; ^PSRX(22,"PRC",1,0)="Pharmacist: you must obey my command"
|
---|
223 | . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PRC",1,0))
|
---|
224 | . S @MAP@("MEDRFNO")=MED(9)
|
---|
225 | . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"MAPPED"))
|
---|
226 | . K @RESULT
|
---|
227 | . D MAP^GPLXPATH(MINXML,MAP,RESULT)
|
---|
228 | . ; D PARY^GPLXPATH(RESULT)
|
---|
229 | . ; MAPPING DIRECTIONS
|
---|
230 | . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
|
---|
231 | . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
|
---|
232 | . D QUERY^GPLXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
|
---|
233 | . D REPLACE^GPLXPATH(RESULT,"","//Medications/Medication/Directions")
|
---|
234 | . ; N MDZ1,MDZNA
|
---|
235 | . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
|
---|
236 | . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
|
---|
237 | . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
|
---|
238 | . . . D MAP^GPLXPATH(DIRXML1,MDZNA,DIRXML2)
|
---|
239 | . . . D INSERT^GPLXPATH(RESULT,DIRXML2,"//Medications/Medication")
|
---|
240 | . D:RXIEN=1 CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
|
---|
241 | . D:RXIEN>1 INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
|
---|
242 | N MEDTMP,MEDI
|
---|
243 | D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
|
---|
244 | I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
|
---|
245 | . W "MEDICATION MISSING ",!
|
---|
246 | . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
|
---|
247 | Q
|
---|
248 | ;
|
---|