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

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

namespacing

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