source: ccr/trunk/p/GPLMEDS.m@ 159

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

enhancements to GPLRIMA to locate patients

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