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

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

Removed Size from XML and all references in Med files -- I changed my mind and think now that it is a useless field.

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