source: ccr/trunk/p/CCRMEDS.m@ 409

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

Changed CCRUTIL to C0CUTIL

File size: 9.4 KB
Line 
1CCRMEDS ; CCDCCR/GPL - CCR/CCD PROCESSING FOR MEDICATIONS ;07/23/08 14:33
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(MEDXML,DFN,MEDOUTXML) ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
24 ;
25 ; MEDXML AND OUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
26 ; IMEDXML WILL CONTAIN ONLY THE MEDICATIONS SECTION OF THE OVERALL TEMPLATE
27 ;
28 N HASOP S HASOP=0 ; FLAG FOR HAS OUTPATIENT MEDS
29 N MEDCNT S MEDCNT=0 ; COUNT FOR MEDS ALREADY PROCESSED
30 ; OUTPATIENT ACTIVE MEDS ARE PROCESSED IN EXTRACT^CCRMEDS1
31 ; OUTPATIENT PENDING MEDS IN EXTRACT^CCRMEDS2
32 ; NON-VA MEDS IN EXTRACT^CCRMEDS3
33 ; INPATIENT MEDS IN EXTRACT^CCRMEDS4
34 ; ALL OTHERS HERE
35 S MEDTVMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP"))
36 K @MEDTVMAP ; CLEAR VARIABLE ARRAY
37 S @MEDTVMAP@(0)=0 ; INITIALIZE NUMBER OF MEDS PROCESSED
38 S MEDTARYTMP=$NA(^TMP("GPLCCR",$J,"MEDARYTMP"))
39 K @MEDTARYTMP ; KILL XML ARRAY
40 I $G(DUZ("AG"))="I" D Q ;
41 . ; I '$D(C0CTESTMEDS) G USERPC ; DELETE THIS LINE AFTER TESTING IS DONE
42 . D EXTRACT^CCRMEDS6(MEDXML,DFN,MEDOUTXML)
43 . ; I @MEDOUTXML@(0)=0 D USERPC ; FOR RPMS, USE THE RPC FOR MEDS
44 D EXTRACT^CCRMEDS1(MEDXML,DFN,MEDOUTXML) ; FIRST EXTRACT OUTPATIENT MEDS
45 I @MEDOUTXML@(0)>0 D ; CCRMEDS FOUND ACTIVE OP MEDS
46 . S HASOP=1 ; SET FLAG TO KNOW HOW TO ADD XML
47 . S MEDCNT=MEDCNT+@MEDTVMAP@(0) ; SAVE COUNT TO KNOW HOW TO ADD TO MAP
48 . W MEDCNT,!
49 . W "HAS ACTIVE OP MEDS",!
50 N PENDINGXML,MEDPENDING
51 S PENDINGXML="MEDPENDING" ;NAME FOR ARRAY
52 D EXTRACT^CCRMEDS2(MEDXML,DFN,PENDINGXML) ; FIRST EXTRACT OUTPATIENT MEDS
53 I @PENDINGXML@(0)>0 D ; CCRMEDS FOUND PENDING OP MEDS
54 . S HASOP=1 ; SET FLAG TO KNOW HOW TO ADD XML
55 . I @MEDOUTXML@(0)>0 D ; IF WE NEED TO COMBINE MEDS
56 . . D INSINNER^GPLXPATH(MEDOUTXML,PENDINGXML) ;ADD PENDING TO ACTIVE
57 . E D CP^GPLXPATH(PENDINGXML,MEDOUTXML) ; NO ACTIVE MEDS, JUST COPY
58 . S MEDCNT=MEDCNT+@MEDTVMAP@(0) ; SAVE COUNT TO KNOW HOW TO ADD TO MAP
59 . ; W MEDCNT,!
60 . W "HAS OP PENDING MEDS",!
61 N PENDINGXML,MEDPENDING
62 S PENDINGXML="MEDPENDING" ;NAME FOR ARRAY
63 D EXTRACT^CCRMEDS3(MEDXML,DFN,PENDINGXML) ; FIRST EXTRACT OUTPATIENT MEDS
64 I @PENDINGXML@(0)>0 D ; CCRMEDS FOUND PENDING OP MEDS
65 . ; S HASOP=1 ; SET FLAG TO KNOW HOW TO ADD XML
66 . I @MEDOUTXML@(0)>0 D ; IF WE NEED TO COMBINE MEDS
67 . . D INSINNER^GPLXPATH(MEDOUTXML,PENDINGXML) ;ADD NON-VA TO MEDS
68 . E D CP^GPLXPATH(PENDINGXML,MEDOUTXML) ; NO PREVIOUS MEDS, JUST COPY
69 . S MEDCNT=MEDCNT+@MEDTVMAP@(0) ; SAVE COUNT TO KNOW HOW TO ADD TO MAP
70 . ; W MEDCNT,!
71 . W "HAS NON-VA MEDS",!
72THEND ;
73 Q ; SKIPPING ALL THE REST OF THIS LOGIC.. IT IS NOT GOING TO BE NEEDED
74 ; ONCE NON-VA AND IP MEDS WORK (CCRMEDS3 AND CCRMEDS4)
75USERPC ; ENTRY POINT FOR RPMS
76 N MEDRSLT,I,J,K,MEDPTMP,X,MEDVMAP,TBUF
77 D ACTIVE^ORWPS(.MEDRSLT,DFN)
78 I '$D(MEDRSLT(1)) D ; NO MEDS FOR THIS PATIENT, EXIT
79 . I DEBUG W "MEDICATIONS RPC RETURNED NULL",!
80 . S @MEDOUTXML@(0)=0
81 . Q
82 ; I DEBUG ZWR MEDRSLT
83 M GPLMEDS=MEDRSLT
84 S MEDTVMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP"))
85 S MEDTARYTMP=$NA(^TMP("GPLCCR",$J,"MEDARYTMP"))
86 ; I 'HASOP K @MEDTVMAP,@MEDTARYTMP KILL MOVED TO TOP OF ROUTINE
87 ; FIRST GO THROUGH MEDRSLT ARRAY AND COUNT MEDS AND LINES IN MEDS
88 ; ZA(0) IS TOTAL NUMBER OF MEDS ZA(ZI) IS LINES IN MED ZI
89 N ZA,ZI,ZJ,ZK,ZN S (ZI,ZJ,ZK,ZN)=0 ; ZI IS MED NUMBER, ZJ IS LINE IN MED
90 ; ZK IS THE NUMBER OF LINES IN A MED AND ZN IS COUNTER THROUGH LINES
91 S ZA(0)=0 ; ZA IS ARRAY OF MED LINE COUNTS
92 F ZJ=1:1 Q:'$D(MEDRSLT(ZJ)) D ; COUNT THE MEDS AND LINES
93 . I MEDRSLT(ZJ)?1"~".E D ; FOUND NEW MED
94 . . S ZI=ZI+1 ; INCREMENT MED COUNT
95 . . S ZA(0)=ZI ; NEW TOTAL FOR MEDS
96 . . S ZA(ZI)=ZJ_U_1 ; EACH ZA(X) IS Y^Z WHERE Y IS START LINE AND Z IS COUNT
97 . E D ; FOR EVERY LINE NOT A FIRST LINE IN MED
98 . . S ZK=$P(ZA(ZI),U,2)+1 ; INCREMENT LINE COUNT FOR CURRENT MED
99 . . S $P(ZA(ZI),U,2)=ZK ; AND STORE IT IN ARRAY
100 ;ZWR ZA
101 ; S @MEDTVMAP@(0)=ZA(0) ; SAVE NUMBER OF MEDS
102 F ZI=1:1:ZA(0) D ; FOR EACH MED
103 . I DEBUG W "ZI IS ",ZI,!
104 . ; W ZI," ",MEDCNT,!
105 . S ZJ=$P(ZA(ZI),U,1) ; INDEX OF FIRST LINE OF MED IN MEDRSLT
106 . S MEDPTMP=MEDRSLT(ZJ) ; PULL OUT FIRST LINE OF MED
107 . ;I $P(MEDPTMP,U,1)?1"~OP" Q ; SKIP OP ACTIVE AND PENDING
108 . S MEDCNT=MEDCNT+1 ; WE ARE GOING TO ADD A MED
109 . S MEDVMAP=$NA(@MEDTVMAP@(MEDCNT)) ; START PAST OP ACTIVE MEDS
110 . S @MEDTVMAP@(0)=@MEDTVMAP@(0)+1 ; ADDING A MED HERE
111 . S @MEDVMAP@("MEDOBJECTID")="MED"_(MEDCNT) ; UNIQUE OBJID FOR MEDS
112 . I $P(MEDPTMP,"^",11)="" S @MEDVMAP@("MEDISSUEDATETXT")=""
113 . E S @MEDVMAP@("MEDISSUEDATETXT")=$$FMDTOUTC^C0CUTIL($P(MEDPTMP,"^",11),"DT") ; GETS LAST FILL DATE
114 . S @MEDVMAP@("MEDISSUEDATE")=""
115 . S @MEDVMAP@("MEDLASTFILLDATETXT")=""
116 . S @MEDVMAP@("MEDLASTFILLDATE")=""
117 . S @MEDVMAP@("MEDRXNOTXT")=""
118 . S @MEDVMAP@("MEDRXNO")=""
119 . S @MEDVMAP@("MEDDETAILUNADORNED")=""
120 . S @MEDVMAP@("MEDCONCVALUE")=""
121 . S @MEDVMAP@("MEDCONCUNIT")=""
122 . S @MEDVMAP@("MEDDOSEINDICATOR")=""
123 . S @MEDVMAP@("MEDDELIVERYMETHOD")=""
124 . S @MEDVMAP@("MEDRATEVALUE")=""
125 . S @MEDVMAP@("MEDRATEUNIT")=""
126 . S @MEDVMAP@("MEDVEHICLETEXT")=""
127 . S @MEDVMAP@("MEDFREQUENCYUNIT")=""
128 . S @MEDVMAP@("MEDINTERVALVALUE")=""
129 . S @MEDVMAP@("MEDINTERVALUNIT")=""
130 . S @MEDVMAP@("MEDPRNFLAG")=""
131 . S @MEDVMAP@("MEDPROBLEMOBJECTID")=""
132 . S @MEDVMAP@("MEDPROBLEMTYPETXT")=""
133 . S @MEDVMAP@("MEDPROBLEMDESCRIPTION")=""
134 . S @MEDVMAP@("MEDPROBLEMCODEVALUE")=""
135 . S @MEDVMAP@("MEDPROBLEMCODINGSYSTEM")=""
136 . S @MEDVMAP@("MEDPROBLEMCODINGVERSION")=""
137 . S @MEDVMAP@("MEDPROBLEMSOURCEACTORID")=""
138 . S @MEDVMAP@("MEDSTOPINDICATOR")=""
139 . S @MEDVMAP@("MEDDIRSEQ")=""
140 . S @MEDVMAP@("MEDMULDIRMOD")=""
141 . S @MEDVMAP@("MEDPTINSTRUCTIONS")=""
142 . S @MEDVMAP@("MEDFULLFILLMENTINSTRUCTIONS")=""
143 . S @MEDVMAP@("MEDDATETIMEAGE")=""
144 . S @MEDVMAP@("MEDDATETIMEAGEUNITS")=""
145 . S @MEDVMAP@("MEDTYPETEXT")="Medication"
146 . S @MEDVMAP@("MEDSTATUSTEXT")=$P(MEDPTMP,"^",10) ; STATUS FROM RPC
147 . S @MEDVMAP@("MEDSOURCEACTORID")="ACTORSYSTEM_1"
148 . S @MEDVMAP@("MEDPRODUCTNAMETEXT")=$P(MEDPTMP,"^",3)
149 . S @MEDVMAP@("MEDPRODUCTNAMECODEVALUE")="" ; DEFAULT VALUE
150 . S @MEDVMAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
151 . S @MEDVMAP@("MEDPRODUCTNAMECODEVERSION")=""
152 . I $P(MEDPTMP,U,1)?1"~OP" D ; IS OUTPATIENT, MIGHT HAVE CODE
153 . . I $P(MEDPTMP,"^",10)="ACTIVE" D ; ONLY ACTIVE MEDS HAVE CODES
154 . . . N RXIEN ; IEN TO RX, EXAMPLE "~OP^13R;O^IBUPROFEN 400MG^" 13 IS IT
155 . . . S RXIEN=$$DIGITS($P($P(MEDPTMP,U,2),";",1)) ; GET JUST LEADING DIGITS
156 . . . I DEBUG W "RXIEN=",RXIEN,! ;
157 . . . ;D RX^PSO52API(DFN,"MEDCODE",RXIEN) ; EXTRACT THE RX RECORD TO ^TMP
158 . . . I $D(^TMP($J,"MEDCODE",DFN,RXIEN,27)) D ; IF SUCCESS
159 . . . . S @MEDVMAP@("MEDPRODUCTNAMECODEVALUE")=^TMP($J,"MEDCODE",DFN,RXIEN,27)
160 . . . . S @MEDVMAP@("MEDPRODUCTNAMECODINGINGSYSTEM")="NDC"
161 . S @MEDVMAP@("MEDBRANDNAMETEXT")=""
162 . S @MEDVMAP@("MEDBRANDNAMECODEVALUE")=""
163 . S @MEDVMAP@("MEDBRANDNAMECODINGSYSTEM")=""
164 . S @MEDVMAP@("MEDBRANDNAMECODEVERSION")=""
165 . S @MEDVMAP@("MEDSTRENGTHVALUE")=""
166 . S @MEDVMAP@("MEDSTRENGTHUNIT")=""
167 . S @MEDVMAP@("MEDFORMTEXT")=""
168 . S @MEDVMAP@("MEDQUANTITYVALUE")=""
169 . S @MEDVMAP@("MEDQUANTITYUNIT")=""
170 . S @MEDVMAP@("MEDRFNO")=""
171 . S ZK=$P(ZA(ZI),U,2) ; NUMBER OF LINES IN MED
172 . I ZK>1 D ; MORE THAN ONE LINE IN MED
173 . . S @MEDVMAP@("MEDDESCRIPTIONTEXT")=$P(MEDRSLT(ZJ+1)," *",2)
174 . I ZK>2 D ; THIRD THROUGH 2+N LINES OF MED ARE INSTRUCTIONS
175 . . N TMPTXT S TMPTXT="" ; BUILD UP INSTRUCTION LINE
176 . . F ZN=2:1:ZK-1 D ; REMAINING LINES IN EACH MED
177 . . . I MEDRSLT(ZJ+ZN)]"\ Sig: " D ; REMOVE THIS MARKUP
178 . . . . S TMPTXT=TMPTXT_$P(MEDRSLT(ZJ+ZN),"\ Sig: ",2)_" " ; APPEND 2 TMPTXT
179 . . . E S TMPTXT=TMPTXT_MEDRSLT(ZJ+ZN)_" " ; SEPARATE LINES WITH SPACE
180 . . S @MEDVMAP@("MEDDIRECTIONDESCRIPTIONTEXT")=TMPTXT ; CP TO MAP VAR
181 . S @MEDVMAP@("MEDDOSEVALUE")=""
182 . S @MEDVMAP@("MEDDOSEUNIT")=""
183 . S @MEDVMAP@("MEDFREQUENCYVALUE")=""
184 . S @MEDVMAP@("MEDDURATIONVALUE")=""
185 . S @MEDVMAP@("MEDDURATIONUNIT")=""
186 . S @MEDVMAP@("MEDDIRECTIONROUTETEXT")=""
187 . S @MEDVMAP@("MEDDIRECTIONFREQUENCYVALUE")=""
188 . S MEDARYTMP=$NA(@MEDTARYTMP@(ZI))
189 . K @MEDARYTMP
190 . D MAP^GPLXPATH(MEDXML,MEDVMAP,MEDARYTMP)
191 . I ZI=1&('HASOP) D ; FIRST ONE IS JUST A COPY MAKE SURE OP IS NOT THERE
192 . . ; W "FIRST ONE",!
193 . . D CP^GPLXPATH(MEDARYTMP,MEDOUTXML)
194 . E D ; AFTER THE FIRST OR IF THERE ARE OP, INSERT INNER XML
195 . . D INSINNER^GPLXPATH(MEDOUTXML,MEDARYTMP)
196 N MEDTMP,MEDI
197 D MISSING^GPLXPATH(MEDOUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
198 I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
199 . W "MEDICATION MISSING ",!
200 . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
201 Q
202 ;
203DIGITS(INSTR) ; RETURN JUST THE LEADING DIGITS OF THE STRING
204 ; EXAMPLE: $$DIGITS("13R") RETURNS 13
205 N ALPHA ; CONTANT TO HOLD ALL ALPHA CHARACTERS
206 S ALPHA="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ; ALPHAS
207 Q $TR(INSTR,ALPHA) ; LEAVE ONLY THE DIGITS
208 ;
Note: See TracBrowser for help on using the repository browser.