source: WorldVistAEHR/trunk/r/OUTPATIENT_PHARMACY-PSO-APSP-HUIP/PSOVDF1.m@ 1166

Last change on this file since 1166 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 9.5 KB
Line 
1PSOVDF1 ;BPOIFO/EL-OUTPATIENT PHARMACY (PRES, PREF, PPAR) HL7 MESSAGE ;10/04/04
2 ;;7.0;OUTPATIENT PHARMACY;**190,205,220,235,261**;DEC 1997;Build 9
3 ;
4VALID ;;VDEF HL7 MESSAGE BUILDER
5 ;
6 ; DBIA #4248 - $$XCN200^VDEFEL (or <MultipleTag>^VDEFEL)
7 ; DBIA #3552 - $$PARAM^HLCS2
8 ; DBIA #3630 - BLDPID^VAFCQRY
9 ; DBIA #10040 - 0-NODE of ^SC
10 ; DBIA 4571 - ERR^VDEFREQ
11 ;
12 ; This routine is called at tag EN as a Function by VDEFREQ1
13 ;
14 Q
15 ;
16EN(EVIEN,KEY,VFLAG,OUT,MSHP) ;
17 ; This routine creates one of three Outpatient Pharmacy HL7 messages:
18 ; RDE^O11^PRES, RDS^O13^PREF, or RDS^O13^PPAR
19 ;
20 ; Input Parameters:
21 ; EVIEN - IEN of message in file 577
22 ; KEY - IEN to File #52 ^PSRX
23 ; VFLAG - "V" for VistA HL7 destination (default)
24 ; OUT - Target array. Must be passed by reference
25 ; MSHP - 4th piece is SUBTYPE (PRES, PREF, PPAR)
26 ;
27 ; Returns:
28 ; Two piece string with separator '^':
29 ; Piece 1 - "LM" - LOCAL ARRAY
30 ; Piece 2 - MSH segment, is not set
31 ; OUT - OUTPUT array includes HL7 message for every segment except MSH
32 ;
33 ; Message Body "MSH,PID,ORC1,RXE1,RXR1,FT1,OBX1,NTE1,ORC2,ORC3"
34 ; The Pharmacy Original Fill message will be generated by pgm:PSOVDF2 - (ORC1. . NTE1)
35 ;
36 ;
37 N CTR,PSOVDFD0,PSOVDFD1,DFN,DRCODE,PSOVDRUG,ERR,FILE,FIELD,GIVECODE,GL,GLOB,GLOBAL,HLINST,PSOVDDIV,PSOVD59,PSOVERR
38 N I,L,MSG,NTE,P,RES,SEPC,SEPE,SEPF,SEPR,SEPS,SRC,SUBTYPE,TARGET,PSOVDFES,PSOVESC,PSOVDFIN
39 N HL7DEL,REPSEPC,REPSEPE,REPSEPF,REPSEPR,REPSEPS,TEMP,TP,UNIT,VAL,WR,X,Y,Z,VCMP,VFT7
40 ;
41 S (ERR,TARGET)=""
42 D INIT
43 I $G(ERR)'="" D ERR^VDEFREQ(ERR) S ZTSTOP=1 G QUIT
44 D MSHPID
45 I $G(ERR)'="" D ERR^VDEFREQ(ERR) S ZTSTOP=1 G QUIT
46 D PROCESS^PSOVDF2
47 D ORC2
48QUIT Q TARGET
49 ;
50INIT ;
51 K GL,OUT,TEMP,TP
52 S (PSOVDFD0,PSOVDFES,DFN,DRCODE,PSOVDRUG,FILE,GIVECODE,GLOB,SEPC,SEPE,SEPF,SEPR,SEPS,SRC,SUBTYPE,UNIT,VAL)=""
53 S (HL7DEL,REPSEPC,REPSEPE,REPSEPF,REPSEPR,REPSEPS)=""
54 S OUT("HLS")=0
55 S PSOVDFD0=KEY
56 I $G(U)'="^" S U="^"
57 S FILE=52
58 S SUBTYPE=$P($G(MSHP),"~",4)
59 S VAL=$G(HL("ECH")) I VAL="" S VAL="~|\&",HL("ECH")=VAL
60 S SEPE=$E(VAL,3),REPSEPE=SEPE_"E"_SEPE
61 S SEPC=$E(VAL,1),REPSEPC=SEPE_"S"_SEPE
62 S SEPR=$E(VAL,2),REPSEPR=SEPE_"R"_SEPE
63 S SEPS=$E(VAL,4),REPSEPS=SEPE_"T"_SEPE
64 S VAL=$G(HL("FS")) I VAL="" S VAL="^",HL("FS")=VAL
65 S SEPF=$E(VAL,1),REPSEPF=SEPE_"F"_SEPE
66 S HL7DEL=$G(HL("ECH"))_$G(HL("FS"))
67 S GLOB=$$ROOT^DILFD(FILE)_PSOVDFD0_")"
68 M GL=@GLOB
69 S DFN=$P($G(GL(0)),U,2)
70 I $G(DFN)="" S ERR="MISSING DFN IN FILE-52 AT IEN="_PSOVDFD0 Q
71 I $G(^DPT(DFN,0))="" S ERR="MISSING DFN IN FILE-2 AT FILE-52/IEN="_PSOVDFD0 Q
72 S PSOVDFES=$$REPL(PSOVDFD0)
73 S PSOVDFIN=$$SITE^VASITE,PSOVDFIN=$P($G(PSOVDFIN),"^",2),PSOVDFIN=$$REPL(PSOVDFIN)
74 Q
75 ;
76PUT(P) ; Put in MSG
77 I $G(VAL)="" Q
78 S $P(MSG,SEPF,P)=VAL
79 Q
80 ;
81REPL(L) ; REPLACE HL7 DELIMITER CHAR
82 I $G(L)="" Q ""
83 I $TR(L,$G(HL7DEL))=L Q L
84 N X,Y,Z,RES
85 S RES=L
86 I $F(L,SEPE) S X=RES D
87 . S Z=$P(X,SEPE,2,9999),Y=$P(X,SEPE)_REPSEPE_Z,RES=Y,X=Z I '$F(Z,SEPE) Q
88 . F I=2:1 S Z=$P(X,SEPE,2,9999),Y=$P(RES,REPSEPE,1,I-1)_REPSEPE_$P(X,SEPE)_REPSEPE_Z,RES=Y,X=Z I '$F(Z,SEPE) Q
89 I $F(RES,SEPC) F I=1:1 S Y=$P(RES,SEPC)_REPSEPC_$P(RES,SEPC,2,9999),RES=Y I '$F(RES,SEPC) Q
90 I $F(RES,SEPR) F I=1:1 S Y=$P(RES,SEPR)_REPSEPR_$P(RES,SEPR,2,9999),RES=Y I '$F(RES,SEPR) Q
91 I $F(RES,SEPS) F I=1:1 S Y=$P(RES,SEPS)_REPSEPS_$P(RES,SEPS,2,9999),RES=Y I '$F(RES,SEPS) Q
92 I $F(RES,SEPF) F I=1:1 S Y=$P(RES,SEPF)_REPSEPF_$P(RES,SEPF,2,9999),RES=Y I '$F(RES,SEPF) Q
93 Q RES
94 ;
95OUT D OUT^PSOVDF2 Q
96OUT20 D OUT20^PSOVDF2 Q
97 ;
98MSHPID ;
99MSH ; MSH
100 S (HLINST,MSG,SRC)=""
101 I '$D(SITEPARM) S SITEPARM=$$PARAM^HLCS2
102 S HLINST=$P(SITEPARM,U,6),HLINST=$$REPL(HLINST),SRC=HLINST_"_"_FILE
103 S TARGET="LM"_SEPF_MSG
104 ;
105PID ; PID
106 K WR
107 S (MSG)=""
108 D BLDPID^VAFCQRY(DFN,1,"",.WR,.HL,.ERR)
109 I $G(WR(1))="" S ERR="MISSING PID AT DFN="_DFN_" IN FILE-52 AT IEN="_PSOVDFD0 Q
110 I $P(WR(1),U,3)="V" S $P(WR(1),U,3)=""
111 D OUT20
112 K WR
113 Q
114 ;
115ORC2 ; RF
116 I '$D(GL(1)) G ORC3
117 K TEMP M TEMP=GL(1)
118 S PSOVDFD1=0
119ORC2A S PSOVDFD1=$O(TEMP(PSOVDFD1)) G ORC3:'PSOVDFD1
120 S MSG=""
121 S TP=$G(TEMP(PSOVDFD1,0)) I TP="" G ORC2A
122 S PSOVESC=$$REPL(PSOVDFD1),VAL=PSOVESC D PUT(3)
123 ; (7~4-10.1)
124 S (VAL,WR)="",WR=$P(TP,U,19) I $G(WR)'="" D
125 .S WR=$$HLDATE^HLFNC(WR,"TS") I WR>0 S WR=$$REPL(WR),$P(VAL,SEPC,4)=WR,$P(VAL,SEPC,7)="DISPENSED"
126 ; (7~5-13)
127 S WR=$P(TP,U,15) I $G(WR)'="" D
128 .S WR=$$HLDATE^HLFNC(WR,"TS") I WR>0 S WR=$$REPL(WR),$P(VAL,SEPC,5)=WR,$P(VAL,SEPC,7)=$P(VAL,SEPC,7)_"/EXPIRATION"
129 D PUT(7)
130 S VAL="",$P(VAL,SEPC,2)=PSOVDFES D PUT(8)
131 ; (9-7)
132 S VAL=$P(TP,U,8) I $G(VAL)'="" S VAL=$$HLDATE^HLFNC(VAL,"TS") I VAL>0 S VAL=$$REPL(VAL) D PUT(9)
133 ; (12-15)
134 S VAL=$P(TP,U,17) I $G(VAL)'="" S VAL=$$XCN200^VDEFEL(VAL) D PUT(12)
135 S VAL="REFILL" D PUT(16)
136 S VAL=$P(TP,U,9) S:$G(VAL)="" VAL=$P($G(^PSRX(PSOVDFD0,2)),"^",9) I $G(VAL)'="" D
137 .S PSOVD59=VAL I $D(PSOVDDIV(VAL)) S VAL=$G(PSOVDDIV(VAL)) S $P(VAL,SEPC,3)=$P($P(VAL,SEPC,3),"_")_"_52.1_8" D PUT(17) Q
138 .N PSONCRF,PSONCRFP,PSOSTNUM
139 .S X=$G(^PS(59,VAL,0)),PSONCRFP=$P($G(^("SAND")),"^",3)
140 .S VAL=$P(X,U),(VAL,PSONCRF)=$$REPL(VAL) Q:VAL=""
141 .S PSOSTNUM=$P(X,U,6),PSOSTNUM=$$REPL(PSOSTNUM)
142 .S VAL=PSOSTNUM_SEPC_VAL_SEPC_HLINST_"_52.1_8"
143 .I PSONCRFP'="" S PSONCRFP=$$REPL(PSONCRFP),VAL=VAL_SEPC_PSONCRFP_SEPC_PSONCRF_SEPC_"NCPDP"
144 .S PSOVDDIV(PSOVD59)=$G(VAL)
145 .D PUT(17)
146 S VAL=$G(PSOVDFIN) D PUT(21)
147 I $D(VCMP(PSOVDFD1)) S VAL=SEPC_SEPC_SEPC_VCMP(PSOVDFD1) D PUT(25)
148 I $G(MSG)="" G ORC2Q
149 S $P(MSG,U)="RF"
150 S MSG="ORC"_SEPF_MSG D OUT
151ORC2Q ; Q
152 ;
153RXE2 ; RF
154 S MSG=""
155 ; (1~4-.01)
156 S (VAL,WR)="",WR=$P(TP,U,1) I $G(WR)'="" D
157 .S WR=$$HLDATE^HLFNC(WR,"TS") I WR>0 S WR=$$REPL(WR),$P(VAL,SEPC,4)=WR,$P(VAL,SEPC,7)="REFILL" D PUT(1)
158 ; (2~1..~3-6, 2~4-API , 2~6-NDC)
159 S VAL=""
160 I $T(NDC^PSOHDR)]"" D
161 .S VAL=$$NDC^PSOHDR(PSOVDFD0,PSOVDFD1,"R")
162 E S VAL=$P($G(TEMP(PSOVDFD1,1)),U,3) D
163 .I $G(VAL)="",$G(PSOVDRUG)'="" S VAL=$P($G(^PSDRUG(PSOVDRUG,2)),"^",4)
164 I $G(VAL)'="" D
165 .S VAL=$$REPL(VAL)
166 .S X="",X=GIVECODE,$P(X,SEPC,4)=VAL,$P(X,SEPC,6)="NDC",VAL=X D PUT(2)
167 E S VAL=GIVECODE D PUT(2)
168 S VAL=0 D PUT(3)
169 ; (5-DEF="UNK" or API)
170 S VAL=UNIT D PUT(5)
171 ; (8~6-2)
172 S (VAL,WR)=""
173 S WR=$$GET1^DIQ(52.1,PSOVDFD1_","_PSOVDFD0_",",2,"","","PSOVERR") K PSOVERR I $G(WR)'="" S WR=$$REPL(WR),$P(VAL,SEPC,6)=WR D PUT(8)
174 ; (10-1)
175 S VAL=$P(TP,U,4),VAL=$$REPL(VAL) D PUT(10)
176 ; (14|1-4)
177 S VAL=$P(TP,U,5) I $G(VAL)="" G RXE2A
178 S VAL=$$XCN200^VDEFEL(VAL,"PHARMACIST") D PUT(14)
179 ; (18-17)
180RXE2A S VAL=$P(TP,U,18) I $G(VAL)'="" S VAL=$$HLDATE^HLFNC(VAL,"TS") I VAL>0 S VAL=$$REPL(VAL) D PUT(18)
181 ; (22-1.1)
182 S VAL=$P(TP,U,10) I $G(VAL)'="" S VAL="D"_VAL,VAL=$$REPL(VAL) D PUT(22)
183 D RXE31A^PSOVDF3
184 D PUT(31)
185 I $G(MSG)="" G RXE2Q
186 S MSG="RXE"_SEPF_MSG D OUT
187RXE2Q ; Q
188 ;
189NTE2 ; RF
190 S MSG=""
191 ; (3-52.1_3)
192 S WR=$P(TP,U,3) I $G(WR)="" G NTE2Q
193 S VAL=PSOVDFD1 D PUT(1)
194 S VAL=$$REPL(WR)
195 D PUT(3),RREM^PSOVDF3,PUT(4)
196 S MSG="NTE"_SEPF_MSG D OUT
197NTE2Q ; Q
198 ;
199FT12 ; RF
200 ; patch 261 - FT1
201 D FT1R^PSOVDF3
202FT12Q ; Q
203 G ORC2A
204 ;
205ORC3 ; PAR
206 I '$D(GL("P")) Q
207 K TEMP M TEMP=GL("P")
208 S PSOVDFD1=0
209ORC3A S PSOVDFD1=$O(TEMP(PSOVDFD1)) Q:'PSOVDFD1
210 S MSG=""
211 S TP=$G(TEMP(PSOVDFD1,0)) I TP="" G ORC3A
212 S PSOVESC=$$REPL(PSOVDFD1),VAL=PSOVESC D PUT(3)
213 ; (7~4-7.5)
214 S WR=$P(TP,U,13) I $G(WR)'="" D
215 .S WR=$$HLDATE^HLFNC(WR,"TS") I WR>0 S WR=$$REPL(WR),VAL="",$P(VAL,SEPC,4)=WR,$P(VAL,SEPC,7)="DISPENSED" D PUT(7)
216 S VAL="",$P(VAL,SEPC,2)=PSOVDFES D PUT(8)
217 ; (9-.08)
218 S VAL=$P(TP,U,8) I $G(VAL)'="" S VAL=$$HLDATE^HLFNC(VAL,"TS") I VAL>0 S VAL=$$REPL(VAL) D PUT(9)
219 ; (12-6)
220 S VAL=$P(TP,U,17) I $G(VAL)'="" S VAL=$$XCN200^VDEFEL(VAL) D PUT(12)
221 S VAL="PARTIAL" D PUT(16)
222 S VAL=$P(TP,U,9) S:$G(VAL)="" VAL=$P($G(^PSRX(PSOVDFD0,2)),"^",9) I $G(VAL)'="" D
223 .S PSOVD59=VAL I $D(PSOVDDIV(VAL)) S VAL=$G(PSOVDDIV(VAL)) S $P(VAL,SEPC,3)=$P($P(VAL,SEPC,3),"_")_"_52.2_.09" D PUT(17) Q
224 .N PSONCPR,PSONCPRP,PSOSPNUM
225 .S X=$G(^PS(59,VAL,0)),PSONCPRP=$P($G(^("SAND")),"^",3)
226 .S VAL=$P(X,U),(VAL,PSONCPR)=$$REPL(VAL) Q:VAL=""
227 .S PSOSPNUM=$P(X,U,6),PSOSPNUM=$$REPL(PSOSPNUM)
228 .S VAL=PSOSPNUM_SEPC_VAL_SEPC_HLINST_"_52.2_.09"
229 .I PSONCPRP'="" S PSONCPRP=$$REPL(PSONCPRP),VAL=VAL_SEPC_PSONCPRP_SEPC_PSONCPR_SEPC_"NCPDP"
230 .S PSOVDDIV(PSOVD59)=$G(VAL)
231 .D PUT(17)
232 S VAL=$G(PSOVDFIN) D PUT(21)
233 I $G(MSG)="" G ORC3Q
234 S $P(MSG,U)="RF"
235 S MSG="ORC"_SEPF_MSG D OUT
236ORC3Q ; Q
237 ;
238RXE3 ; PAR
239 S MSG=""
240 ; (1~4-.01)
241 S WR=$P(TP,U,1) I $G(WR)'="" D
242 .S WR=$$HLDATE^HLFNC(WR,"TS") I WR>0 S WR=$$REPL(WR),VAL="",$P(VAL,SEPC,4)=WR,$P(VAL,SEPC,7)="PARTIAL" D PUT(1)
243 ; (2~1..~3-6, 2~4-API, 2~6-NDC)
244 S VAL=""
245 I $T(NDC^PSOHDR)]"" D
246 .S VAL=$$NDC^PSOHDR(PSOVDFD0,PSOVDFD1,"P")
247 E S VAL=$P($G(TEMP(PSOVDFD1,0)),U,12) D
248 .I $G(VAL)="",$G(PSOVDRUG)'="" S VAL=$P($G(^PSDRUG(PSOVDRUG,2)),"^",4)
249 I $G(VAL)'="" D
250 .S VAL=$$REPL(VAL)
251 .S X="",X=GIVECODE,$P(X,SEPC,4)=VAL,$P(X,SEPC,6)="NDC",VAL=X D PUT(2)
252 E S VAL=GIVECODE D PUT(2)
253 S VAL=0 D PUT(3)
254 ; (5-DEF="UNK" or API)
255 S VAL=UNIT D PUT(5)
256 ; (8~6-.02)
257 S (VAL,WR)=""
258 S WR=$$GET1^DIQ(52.2,PSOVDFD1_","_PSOVDFD0_",",.02,"","","PSOVERR") K PSOVERR I $G(WR)'="" S WR=$$REPL(WR),$P(VAL,SEPC,6)=WR D PUT(8)
259 ; (10-.04)
260 S VAL=$P(TP,U,4),VAL=$$REPL(VAL) D PUT(10)
261 ; (14|1-.05)
262 S VAL=$P(TP,U,5) I $G(VAL)="" G RXE3B
263 S VAL=$$XCN200^VDEFEL(VAL,"PHARMACIST") D PUT(14)
264 ; (18-8)
265RXE3B S VAL=$P(TP,U,19) I $G(VAL)'="" S VAL=$$HLDATE^HLFNC(VAL,"TS") I VAL>0 S VAL=$$REPL(VAL) D PUT(18)
266 S VAL=$P(TP,U,10) I $G(VAL)'="" S VAL="D"_VAL,VAL=$$REPL(VAL) D PUT(22)
267 D RXE31^PSOVDF3
268 D PUT(31)
269 ;
270 I $G(MSG)="" G RXE3Q
271 S MSG="RXE"_SEPF_MSG D OUT
272RXE3Q ; Q
273 ;
274NTE3 ; PAR
275 S MSG=""
276 ; (3-.03)
277 S WR=$P(TP,U,3) I $G(WR)="" G NTE3Q
278 S VAL=PSOVDFD1 D PUT(1)
279 S VAL=$$REPL(WR)
280 D PUT(3),PREM^PSOVDF3,PUT(4)
281 S MSG="NTE"_SEPF_MSG D OUT
282NTE3Q ; Q
283FT13 ; patch 261
284 D FT1R^PSOVDF3
285 G ORC3A
286 ;
287 Q
Note: See TracBrowser for help on using the repository browser.