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

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

handles cases with both OP and UV meds

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