source: ccr/trunk/p/CCRMEDS1.m@ 212

Last change on this file since 212 was 204, checked in by George Lilly, 16 years ago

fixing the SIG

File size: 9.4 KB
Line 
1CCRMEDS ; WV/CCDCCR/SMH - CCR/CCD PROCESSING FOR MEDICATIONS ;08/24/08
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 ;
23EXTRACT(MINXML,DFN,OUTXML) ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
24 ;
25 ; INXML AND OUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
26 ; INXML WILL CONTAIN ONLY THE MEDICATIONS SECTION 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 ; RX^PSO52API is a Pharmacy Re-Enginnering (PRE) API to get all
34 ; med data available.
35 ; http://www.va.gov/vdl/documents/Clinical/Pharm-Outpatient_Pharmacy/phar_1_api_r0807.pdf
36 ; Output of API is ^TMP($J,"SUBSCRIPT",DFN,RXIENS).
37 ; D PARY^GPLXPATH(MINXML)
38 N MEDS,MAP
39 K ^TMP($J)
40 D RX^PSO52API(DFN,"CCDCCR")
41 M MEDS=^TMP($J,"CCDCCR",DFN)
42 ; @(0) contains the number of meds or -1^NO DATA FOUND
43 ; If it is -1, we quit.
44 I $P(MEDS(0),U)=-1 S @OUTXML@(0)=0 QUIT
45 I DEBUG ZWR MEDS
46 N RXIEN S RXIEN=0
47 N MEDCOUNT S MEDCOUNT=0
48 S MEDMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP")) ; THIS IS THE VARIABLE MAP
49 S MEDCOUNT=@MEDMAP@(0) ; ACCOUNT FOR MEDS ALREADY IN ARRAY
50 F S RXIEN=$O(MEDS(RXIEN)) Q:RXIEN="" D ; FOR EACH MEDICATION IN THE LIST
51 . S MEDCOUNT=MEDCOUNT+1
52 . I DEBUG W "RXIEN IS ",RXIEN,!
53 . S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP",MEDCOUNT))
54 . ; K @MAP DO NOT KILL HERE, WAS CLEARED IN CCRMEDS
55 . S @MEDMAP@(0)=@MEDMAP@(0)+1 ; INCREMENT TOTAL MEDS IN VAR ARRAY
56 . I DEBUG W "MAP= ",MAP,!
57 . N MED M MED=MEDS(RXIEN) ; PULL OUT MEDICATION FROM
58 . S @MAP@("MEDOBJECTID")="MED"_MEDCOUNT ; MEDCOUNT FOR ID
59 . ; S @MAP@("MEDOBJECTID")="MED"_MED(.01) ;Rx Number
60 . S @MAP@("MEDISSUEDATETXT")="Issue Date"
61 . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^CCRUTIL($P(MED(1),U))
62 . S @MAP@("MEDLASTFILLDATETXT")="Last Fill Date"
63 . S @MAP@("MEDLASTFILLDATE")=$$FMDTOUTC^CCRUTIL($P(MED(101),U))
64 . S @MAP@("MEDRXNOTXT")="Prescription Number"
65 . S @MAP@("MEDRXNO")=MED(.01)
66 . S @MAP@("MEDTYPETEXT")="Medication"
67 . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
68 . S @MAP@("MEDSTATUSTEXT")=$P(MED(100),U,2)
69 . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$P(MED(4),U)
70 . S @MAP@("MEDPRODUCTNAMETEXT")=$P(MED(6),U,2)
71 . S @MAP@("MEDPRODUCTNAMECODEVALUE")=MED(27)
72 . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")="NDC"
73 . S @MAP@("MEDPRODUCTNAMECODEVERSION")="none"
74 . S @MAP@("MEDBRANDNAMETEXT")=MED(6.5)
75 . N MEDIEN S MEDIEN=$P(MED(6),U)
76 . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
77 . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
78 . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
79 . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
80 . ; Units, concentration, etc, come from another call
81 . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
82 . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
83 . ; NDF Entry IEN, and VA Product Name
84 . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
85 . ; Documented in the same manual.
86 . D NDF^PSS50(MEDIEN,,,,,"CONC")
87 . N NDFDATA M NDFDATA=^TMP($J,"CONC",MEDIEN)
88 . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
89 . N VAPROD S VAPROD=$P(NDFDATA(22),U)
90 . N CONCDATA
91 . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
92 . ; and this will crash the call. So...
93 . I NDFIEN="" S CONCDATA=""
94 . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
95 . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
96 . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
97 . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
98 . S @MAP@("MEDSIZETEXT")=$P(NDFDATA(23),U,2)_" "_$P(NDFDATA(24),U,2)
99 . S @MAP@("MEDQUANTITYVALUE")=MED(7)
100 . ; Oddly, there is no easy place to find the dispense unit.
101 . ; It's not included in the original call, so we have to go to the drug file.
102 . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
103 . ; Node 14.5 is the Dispense Unit
104 . D DATA^PSS50(MEDIEN,,,,,"QTY")
105 . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
106 . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
107 . ;
108 . ; --- START OF DIRECTIONS ---
109 . ; Sig data not in any API :-( Oh yes, you can get the whole thing, but...
110 . ; we want the compoenents.
111 . ; It's in node 6 of ^PSRX(IEN)
112 . ; So, here we go again
113 . ; ^PSRX(D0,6,D1,0)= (#.01) DOSAGE ORDERED [1F] ^ (#1) DISPENSE UNITS PER DOSE
114 . ; ==>[2N] ^ (#2) UNITS [3P:50.607] ^ (#3) NOUN [4F] ^ (#4)
115 . ; ==>DURATION [5F] ^ (#5) CONJUNCTION [6S] ^ (#6) ROUTE
116 . ; ==>[7P:51.2] ^ (#7) SCHEDULE [8F] ^ (#8) VERB [9F] ^
117 . ;
118 . N DIRNUM S DIRNUM=0 ; Sigline number
119 . S DIRCNT=0 ; COUNT OF MULTIPLE DIRECTIONS
120 . F S DIRNUM=$O(^PSRX(RXIEN,6,DIRNUM)) Q:DIRNUM="" D
121 . . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
122 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")="" ; This is reserved for systems not able to generate the sig in components.
123 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1" ; means that we are specifying it. See E2369-05.
124 . . N SIGDATA S SIGDATA=^PSRX(RXIEN,6,DIRNUM,0)
125 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=$P(SIGDATA,U,9)
126 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=$P(SIGDATA,U,1)
127 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
128 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")="" ; For inpatient
129 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")="" ; For inpatient
130 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")="" ; For inpatient
131 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=$$GET1^DIQ(51.2,$P(SIGDATA,U,7),.01)
132 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=$P(SIGDATA,U,8)
133 . . ; Invervals... again another call.
134 . . ; In the wisdom of the original programmers, the schedule is a free text field
135 . . ; However, it gets translated by a call to the administration schedule file
136 . . ; to see if that schedule exists.
137 . . ; That's the same thing I am going to do.
138 . . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
139 . . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
140 . . ; I looked), PSSFT is the name, and list is the ^TMP name to store the data in.
141 . . ; So...
142 . . D AP^PSS51P1("PSJ",$P(SIGDATA,U,8),,,"SCHEDULE")
143 . . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
144 . . N INTERVAL
145 . . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
146 . . E D
147 . . . N SUB S SUB=$O(SCHEDATA(0))
148 . . . S INTERVAL=SCHEDATA(SUB,2)
149 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
150 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
151 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$P(SIGDATA,U,5)
152 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=""
153 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=$P(SIGDATA,U,8)["PRN"
154 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
155 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
156 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
157 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
158 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
159 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
160 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
161 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")=""
162 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
163 . . N DIRMOD S DIRMOD=$P(SIGDATA,U,6)
164 . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=$S(DIRMOD="T":"THEN",DIRMOD="A":"AND",DIRMOD="X":"EXCEPT",1:"")
165 . ;
166 . ; --- END OF DIRECTIONS ---
167 . ;
168 . ; ^PSRX(22,"INS1",1,0)="FOR BLOOD PRESSURE"
169 . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"INS1",1,0))
170 . ; ^PSRX(22,"PRC",1,0)="Pharmacist: you must obey my command"
171 . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PRC",1,0))
172 . S @MAP@("MEDRFNO")=MED(9)
173 . N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"MAPPED"))
174 . K @RESULT
175 . D MAP^GPLXPATH(MINXML,MAP,RESULT)
176 . ; D PARY^GPLXPATH(RESULT)
177 . ; MAPPING DIRECTIONS
178 . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
179 . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
180 . D QUERY^GPLXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
181 . D REPLACE^GPLXPATH(RESULT,"","//Medications/Medication/Directions")
182 . ; N MDZ1,MDZNA
183 . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
184 . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
185 . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
186 . . . D MAP^GPLXPATH(DIRXML1,MDZNA,DIRXML2)
187 . . . D INSERT^GPLXPATH(RESULT,DIRXML2,"//Medications/Medication")
188 . D:MEDCOUNT=1 CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
189 . D:MEDCOUNT>1 INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
190 N MEDTMP,MEDI
191 D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
192 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
193 . W "MEDICATION MISSING ",!
194 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
195 Q
196 ;
Note: See TracBrowser for help on using the repository browser.