source: WorldVistAEHR/trunk/r/OUTPATIENT_PHARMACY-PSO-APSP-HUIP/PSOHLDS1.m@ 1742

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

initial load of WorldVistAEHR

File size: 7.9 KB
Line 
1PSOHLDS1 ;BIR/LC,PWC-Build HL7 Segments for Automated Interface ;11/22/06 3:24pm
2 ;;7.0;OUTPATIENT PHARMACY;**156,232,255,200**;DEC 1997;Build 7
3 ;HLFNC supp. by DBIA 10106
4 ;PSNAPIS supp. by DBIA 2531
5 ;VASITE supp. by DBIA 10112
6 ;VADPT supp. by DBIA 10061
7 ;EN^DIQ1 supp. by DBIA 100
8 ;EN^VAFHLZTA supp. by DBIA 758
9 ;PSDRUG supp. by DBIA 221
10 ;PS(50.607 supp. by DBIA 2221
11 ;PS(55 supp. by DBIA 2228
12 ;DPT supp. by DBIA 3097
13 ;SC supp. by DBIA 10040
14 ;VA(200 supp. by DBIA 10060
15 ;SCMSVUT5 supp. by DBIA 4347
16 ;BLDPID^VAFCQRY supp. by DBIA 3630
17 ;MAKEIT^VAFHLU supp. by DBIA 4346
18 ;
19 ;*232 allow for Do Not Mail
20 ;*255 move NTEPMI to PSOHLDS4. fix "MP" node test to '=""
21 ;
22START ;
23 D GETDATA
24 D PID(.PSI),PV1(.PSI),PV2(.PSI),IAM^PSOHLDS4(.PSI),ORC^PSOHLDS4(.PSI)
25 D NTE^PSOHLDS2,RXE^PSOHLDS2(.PSI),RXD^PSOHLDS2(.PSI)
26 D NTEPMI^PSOHLDS4(.PSI),RXR^PSOHLDS2(.PSI) ;*255
27 ; clean up data set by GETDATA
28 K EBY,EBY1,EFDT,EXDT,FDT,PVDR,PVDR1,CSINER,CSINER1,SITE,SITADD,SITPHN
29 K VPHARMID,VPHARM,DEAID,MW,QTY,DASPLY,OLAN,OTHLAN,PRIORDT,RFRM,NFLD,WARN
30 K PSOXN,PSOXN2,PSND1,PSND2,PRODUCT,PSOPROD,UNIT,VANAME,DISPDT,PSONDC
31 K DRUG
32 Q
33GETDATA ; this is the place to set all data needed for several segments
34 I $G(FP)="F"&('$G(FPN)) D ;original
35 . S FDT=$P(^PSRX(IRXN,2),"^",2),VPHARMID=$P(^(2),"^",10),DISPDT=$P(^(2),"^",5),EXDT=$P(^(2),"^",6),PSONDC=$P(^(2),"^",7)
36 . S PVDR=$P(^PSRX(IRXN,0),"^",4),QTY=$P(^(0),"^",7),DASPLY=$P(^(0),"^",8),MW=$P(^(0),"^",11),EBY=$P(^(0),"^",16)
37 I $G(FP)="F"&($G(FPN)) D ;refill
38 . S FDT=$P(^PSRX(IRXN,1,FPN,0),"^"),MW=$P(^(0),"^",2),QTY=$P(^(0),"^",4),DASPLY=$P(^(0),"^",10),DISPDT=$P(^(0),"^",19),EXDT=$S($P(^(0),"^",15):$P(^(0),"^",15),1:$P(^PSRX(IRXN,2),"^",6))
39 . S VPHARMID=$S($P(^PSRX(IRXN,1,FPN,0),"^",5)'="":$P(^(0),"^",5),1:$P(^PSRX(IRXN,2),"^",10))
40 . S EBY=$S($P(^PSRX(IRXN,1,FPN,0),"^",5):$P(^(0),"^",5),1:$P(^(0),"^",7)),PVDR=$P(^(0),"^",17),PSONDC=$S($P($G(^PSRX(IRXN,1,FPN,1)),"^",3):$P(^(1),"^",3),1:$P(^PSRX(IRXN,2),"^",7))
41 I $G(FP)="P"&($G(FPN)) D ;partial
42 . S FDT=$P(^PSRX(IRXN,"P",FPN,0),"^"),MW=$P(^(0),"^",2),QTY=$P(^(0),"^",4),DASPLY=$P(^(0),"^",10),DISPDT=$P(^(0),"^",13),PVDR=$P(^(0),"^",17),EXDT=$P(^PSRX(IRXN,2),"^",6)
43 . S EBY=$S($P(^PSRX(IRXN,"P",FPN,0),"^",5):$P(^(0),"^",5),1:$P(^(0),"^",7)),VPHARMID=$S($P(^(0),"^",5)'="":$P(^(0),"^",5),1:$P(^PSRX(IRXN,2),"^",10)),PVDR=$P(^PSRX(IRXN,"P",FPN,0),"^",17)
44 . S PSONDC=$S($P(^PSRX(IRXN,"P",FPN,0),"^",12):$P(^(0),"^",12),1:$P(^PSRX(IRXN,2),"^",7))
45 S EFDT=$P(^PSRX(IRXN,2),"^",2) S:$G(EFDT) EFDT=$$HLDATE^HLFNC(EFDT,"DT")
46 S ISDT=$P(^PSRX(IRXN,0),"^",13) S:$G(ISDT) ISDT=$$HLDATE^HLFNC(ISDT,"DT")
47 S DEAID=$$GET1^DIQ(200,PVDR_",",53.2)
48 K DIC,X,Y S DIC="^VA(200,",DIC(0)="N,Z",X=VPHARMID D ^DIC
49 S VPHARM=$S(+Y:$$HLNAME^HLFNC($P(Y,"^",2)),1:"""""") K DIC,X,Y
50 K DIC,X,Y S DIC="^VA(200,",DIC(0)="N,Z",X=EBY D ^DIC
51 S EBY1=$S(+Y:$$HLNAME^HLFNC($P(Y,"^",2)),1:"""""") K DIC,X,Y
52 K DIC,X,Y S DIC="^VA(200,",DIC(0)="N,Z",X=PVDR D ^DIC
53 S PVDR1=$S(+Y:$$HLNAME^HLFNC($P(Y,"^",2)),1:"""""") K DIC,X,Y
54 S PRIORDT=$P(^PSRX(IRXN,3),"^",4),PRIORDT=$$HLDATE^HLFNC(PRIORDT,"DT")
55 S FDT=$$HLDATE^HLFNC(FDT,"DT")
56 S:$G(DISPDT) DISPDT=$$HLDATE^HLFNC(DISPDT,"DT")
57 S:$G(EXDT) EXDT=$$HLDATE^HLFNC(EXDT,"DT")
58 S FIN=$P(^PSRX(IRXN,"OR1"),"^",5)
59 K DIC,X,Y S DIC="^VA(200,",DIC(0)="N,Z",X=FIN D ^DIC
60 S FIN1=$S(+Y:$$HLNAME^HLFNC($P(Y,"^",2)),1:"""""") K DIC,X,Y
61 S SITE=$S($D(^PS(59,PSOSITE,0)):^(0),1:"")
62 S PSZIP=$P(SITE,"^",5) S PSOHZIP=$S(PSZIP["-":PSZIP,1:$E(PSZIP,1,5)_$S($E(PSZIP,6,9)]"":"-"_$E(PSZIP,6,9),1:""))
63 S CLN=+$P(^PSRX(IRXN,0),"^",5),CLN1=$S($D(^SC(CLN,0)):$P(^(0),"^",1),1:"UNKNOWN")
64 S CSINER=$P(^PSRX(IRXN,3),"^",3)
65 K DIC,X,Y S DIC="^VA(200,",DIC(0)="N,Z",X=CSINER D ^DIC
66 S CSINER1=$S(+Y:$$HLNAME^HLFNC($P(Y,"^",2)),1:"""""") K DIC,X,Y
67 D 6^VADPT
68 S X=$S($D(^PS(55,DFN,0)):^(0),1:""),CAP=$P(X,"^",2)
69 D MW(X,.MW,.MP) ;PSO*232
70 I (($P(^PSRX(IRXN,"STA"),"^")>0)&($P(^("STA"),"^")'=2)&('$G(PSODBQ)))!'$G(^PSRX(IRXN,"IB")) S COPAY="NO COPAY"
71 E S COPAY="COPAY"
72 S NURSE=$S($P($G(^DPT(DFN,"NHC")),"^")="Y":1,$P($G(^PS(55,DFN,40)),"^"):1,1:0)
73 S DATE=$$HLDATE^HLFNC(FDT) D NOW^%DTC S NOW=$$HLDATE^HLFNC(%,"TS")
74 S OLAN=$P($G(^PS(55,DFN,"LAN")),"^",2),OTLAN="N" I OLAN=2 S OTLAN="Y"
75 S CSUB1=$$GET1^DIQ(50,IDGN_",",3),CSUB="N" I $E(CSUB1,1)>1&($E(CSUB1,1)<6) S CSUB="Y"
76 S SCTALK=+$G(^PS(55,"ASTALK",$P(^PSRX(IRXN,0),"^",2)))
77 K DIC,DR,DIQ S DA=$P($$SITE^VASITE(),"^") I DA D
78 .K PSOINST S DIC=4,DIQ(0)="I",DR=99,DIQ="PSOINST" D EN^DIQ1
79 .S PSOINST=PSOINST(4,DA,99,"I") K DIC,DA,DR,DIQ,PSOINST(4)
80 S DRUG=$$ZZ^PSOSUTL(IRXN),DEA=$P(^PSDRUG(IDGN,0),"^",3),WARN=$P($G(^(0)),"^",8)
81 S PSND1=$P($G(^PSDRUG(IDGN,"ND")),"^"),PSND2=$P($G(^("ND")),"^",2),PSND3=$P($G(^("ND")),"^",3)
82 K PSOXN,PSOXN2,PSOPROD
83 I PSND1,PSND3 D
84 .S PSOPROD=$$PROD2^PSNAPIS(PSND1,PSND3),VANAME=$P($G(PSOPROD),"^",1)
85 .I $T(^PSNAPIS)]"" S PSOXN=$$DFSU^PSNAPIS(PSND1,PSND3),UNIT=$P($G(PSOXN),"^",6) S PSOXN=$P($G(PSOXN),"^",5) S PSOXN2=$$PROD2^PSNAPIS(PSND1,PSND3) Q
86 .S PSOXN2=$G(^PSNDF(PSND1,5,PSND3,2))
87 .S PRODUCT=$G(^PSNDF(PSND1,5,PSND3,0))
88 .I $G(PRODUCT)'="" S PSOXN=+$P($G(^PSNDF(PSND1,2,+$P(PRODUCT,"^",2),3,+$P(PRODUCT,"^",3),4,+$P(PRODUCT,"^",4),0)),"^"),UNIT=$P($G(^PS(50.607,PSOXN,0)),"^")
89 S NFLD=0,UU="" F S UU=$O(^PSRX(IRXN,1,UU)) Q:UU="" S:$D(^PSRX(IRXN,1,UU,0)) NFLD=NFLD+1
90 S NRFL=$P(^PSRX(IRXN,0),"^",9),RFRM=(NRFL-NFLD)
91 Q
92PID(PSI) ;patient ID segment
93 Q:'$D(DFN)!$D(PAS)
94 S HLFS=HL1("FS"),HLECH=HL1("ECH"),HLQ=HL1("Q"),HLVER=HL1("VER")
95 K PSPID,PSPID1
96 D BLDPID^VAFCQRY(DFN,"","3,5,7,8,11,13",.PSPID,.HL1,.ERR)
97 ; put PID in format needed for segment parser
98 S PSPID=PSPID(1) K PSPID(1)
99 S (X,Y)=1 F S X=+$O(PSPID(X)) Q:'X S PSPID(Y)=PSPID(X),Y=Y+1 K PSPID(X)
100 ;parse PID into individual fields
101 K PRSEPID D SEGPRSE^SCMSVUT5("PSPID","PRSEPID",HL1("FS"))
102 ; parse address into individual components
103 K ADDSEQ D SEQPRSE^SCMSVUT5($NA(PRSEPID(11)),"ADDSEQ",HL1("ECH"))
104 ; build ZTA (Temporary Address)
105 K X2 S X2=$$EN^VAFHLZTA(DFN,"1,2,3,4,5,6,7,",1)
106 ; parse X2 (ZTA) into individual fields if temp add. exists
107 D:'$$CHKTEMP^PSOBAI(DFN)
108 . N BADA S BADA=$$CHKRX^PSOBAI(IRXN)
109 . I $P(BADA,"^"),'$P(BADA,"^",2),ADDSEQ(1,7)'["VAB" S BADA=$$GET1^DIQ(2,DFN_",",.121,"I") S:BADA ADDSEQ(1,7)="VAB"_BADA
110 D:$$CHKTEMP^PSOBAI(DFN)
111 . K PRSEZTA D SEGPRSE^SCMSVUT5("X2","PRSEZTA",HL1("FS"))
112 . ; parse temporary address into individual components
113 . K TMPADD D SEQPRSE^SCMSVUT5($NA(PRSEZTA(5)),"TMPADD",HL1("ECH"))
114 . ; add temporary address as next repitition in PID segment
115 . S SPOT=1+$O(ADDSEQ(""),-1)
116 . M ADDSEQ(SPOT)=TMPADD(1)
117 . S ADDSEQ(SPOT,7)="C"
118 . S ADDSEQ(SPOT,9)=PRSEZTA(6)
119 . S ADDSEQ(SPOT,12,1)=PRSEZTA(3)
120 . S ADDSEQ(SPOT,12,2)=PRSEZTA(4)
121 . ;move address sequence back into parse PID segment
122 ; rebuild PID segment
123 K PRSEPID(11) M PRSEPID(11)=ADDSEQ
124 K PSPID1 D MAKEIT^VAFHLU("PID",.PRSEPID,.PSPID1,.PSPID1)
125 ;put rebuilt PID into format used by $$EN^VAFCQRY
126 K PSPID S PSPID(1)=PSPID1
127 S X=0,Y=2 F S X=+$O(PSPID1(X)) Q:'X S PSPID(Y)=PSPID1(X) S Y=Y+1
128 S CNT=0 F I=1:1 Q:'$D(PSPID(I)) D
129 . I I=1 S ^TMP("PSO",$J,PSI)=PSPID(I) Q
130 . S CNT=CNT+1 S ^TMP("PSO",$J,PSI,CNT)=PSPID(I)
131 S PSI=PSI+1
132 S PAS=1
133 K PSPID,PSPID1,PRSEPID,PRSEZTA,SPOT,TMPADD,ADDSEQ
134 Q
135PV1(PSI) ;patient visit segment
136 Q:'$D(DFN)!$D(PAS1)
137 N PV1 ;hardcoded to letter O for Outpatient (Patient class)
138 S PV1="PV1"_FS_FS_"O"_FS
139 S ^TMP("PSO",$J,PSI)=PV1
140 S PSI=PSI+1,PAS1=1
141 Q
142PV2(PSI) ;patient visit segment (additional information)
143 ;PATIENT STATUS AND COPAY
144 Q:'$D(DFN)!$D(PAS2)
145 N PV2 S PV2=""
146 S $P(PV2,"|",24)=$P($G(^PS(53,+$P($G(^PSRX(IRXN,0)),"^",3),0)),"^",2)_"~"_COPAY_FS
147 S ^TMP("PSO",$J,PSI)="PV2|"_PV2
148 S PSI=PSI+1,PAS2=1
149 Q
150 ;
151MW(PS55,MW,MP) ;Return Mail/Window and MP expanded text ;PSO*232
152 I MW="W"!(MW="") D ;*255
153 . S MP=$S($P($G(^PSRX(IRXN,"MP")),"^")'="":$P(^("MP"),"^"),1:"""""")
154 . S MW="WINDOW"
155 I MW="M" D
156 . S MP=""""""
157 . S PS55=$P(PS55,"^",3)
158 . S MW=$S(PS55=1:"CERTIFIED MAIL",PS55=2:"DO NOT MAIL",1:"REGULAR MAIL")
159 Q
Note: See TracBrowser for help on using the repository browser.