source: WorldVistAEHR/trunk/r/OUTPATIENT_PHARMACY-PSO-APSP-HUIP/PSOSULBL.m@ 1464

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

initial load of WorldVistAEHR

File size: 8.8 KB
Line 
1PSOSULBL ;BHAM ISC/RTR,SAB-Print Suspended labels ;4/8/93
2 ;;7.0;OUTPATIENT PHARMACY;**139,173,174,148,200,260,264**;DEC 1997;Build 19
3 ;External reference ^PS(55 supported by DBIA 2228
4 ;Reference to SAVNDC^PSSNDCUT supported by IA 4707
5 ;Reference ^PSDRUG( supported by DBIA 221
6 K PDUZ,REPRINT G ^PSOSULB1
7BEG ;
8 K PSORUNIN,PSORETRY N BPSCNT
9 S PSORUNIN="PSOSUSP"_($G(PSOSITE))
10 L +@PSORUNIN:10 I '$T D
11 . F PSORETRY=1:1:120 L +@PSORUNIN:60 I $T Q ;wait Max of 2 hrs before continue
12 . Q
13 K ^UTILITY($J,"PSOPRO"),^TMP("PSOSBAI",$J) S PSOSEQ=1 F DFN=0:0 S DFN=$O(^PS(52.5,"AC",DFN)) Q:'DFN D D:'PSRT PID^VADPT6 D CHKDEAD D:'DEAD&($G(PSOSFLAG)) PRT
14 .S PSOSFLAG=0 F ZZ=0:0 S ZZ=$O(^PS(52.5,"AC",DFN,ZZ)) Q:'ZZ!$G(PSOSFLAG) I ZZ'>PRTDT S PSOSFLAG=1
15 D PPL
16 D:$D(^UTILITY($J,"PSOPRO"))&($P(PSOPAR,"^",8)) PROF
17 G EXIT
18PRT F SDT=0:0 S SDT=$O(^PS(52.5,"AC",DFN,SDT)) D:SDT CHK Q:'SDT
19 Q
20EXIT ;
21 I $D(^TMP("PSOSBAI",$J)) D CHKMAIL
22 K ^TMP($J),^TMP("PSOSBAI",$J)
23 I $D(PSORUNIN) L -@PSORUNIN
24 D ^%ZISC
25 K %,%ZIS,CNT,COM,DA,DEAD,DFN,DIRUT,DTTM,G,HDPPL,JJ,JJJ,JJJJ,PDUZ,IOP,ORD,PFIOQ,PSLION,PSRT,POP,PRF,PRTDT,PSLIO,PSNP,PSODBQ,PSOSEQ,PSOSFLAG,PSOSU,PSOTIME,PSOOUT,PSOPRFLG,PSOSEQ,PSOSUSPR,PSSPND,PST,PTL,PPLHLD,PSFNIEN,ZTSK
26 K PSOBADDR,PSORUNIN,PSORETRY,PSRTONE,PSSRT,PSUSDEA,RF,RFCNT,RX,RXDFN,SDT,SFN,SREC,STOP,SUSPT,VADM,VAPA,X,X1,X2,XAK,XDATE,Y,Z,ZZ,WWW,PSDDDATE,SINRX,RXPR,RXPR1,GGGG,XXX,ZII,ZTDESC,ZTRTN,ZTSAVE,RRRR,RXRP,RXRP1,RXFL,SPR S:$D(ZTQUEUED) ZTREQ="@" Q
27CHK I SDT'>XDATE D TMP Q
28 Q
29TMP F SFN=0:0 S SFN=$O(^PS(52.5,"AC",DFN,SDT,SFN)) Q:'SFN D
30 . I '$D(^PS(52.5,SFN,0))!'$D(^DPT(+DFN,0)) Q
31 . N RXSITE,PRINTED,PSDFN,RXSTS,RXIEN,RXFILL,PARTIAL,RXEXPDT,RESP
32 . S RXIEN=+$$GET1^DIQ(52.5,SFN,.01,"I"),RXDFN=$$GET1^DIQ(52,RXIEN,2,"I")
33 . S RXSTS=$$GET1^DIQ(52,RXIEN,100,"I"),RXSITE=+$$GET1^DIQ(52.5,SFN,.06,"I"),PRINTED=+$$GET1^DIQ(52.5,SFN,2,"I")
34 . S PARTIAL=+$$GET1^DIQ(52.5,SFN,.05,"I"),RXEXPDT=$$GET1^DIQ(52,RXIEN,26,"I")
35 . S RXFILL=$$GET1^DIQ(52.5,SFN,9,"I") I RXFILL="" S RXFILL=$$LSTRFL^PSOBPSU1(RXIEN)
36 . I RXSITE=$G(PSOSITE),'PRINTED,RXDFN=DFN,RXSTS<9 D
37 . . I PARTIAL,'$D(^PSRX(RXIEN,"P",PARTIAL)) Q
38 . . I RXEXPDT<DT,RXSTS<11 D Q
39 . . . N RXREC S RXREC=RXIEN D EX^PSOSUTL
40 . . . K DIE,DA S DIE=52,DA=RXIEN,DR="100///11" D ^DIE K DIE,DA
41 . . . K DIK,DA S DA=SFN,DIK="^PS(52.5," D ^DIK K DIK,DA
42 . . S PSOBADDR=0 D CHKBAI I PSOBADDR Q
43 . . I PSRT="D" D
44 . . . S PSSRT=$S($G(PSRTONE)="I":VA("PID"),1:$P(^DPT(DFN,0),"^")_$P(^(0),"^",9))
45 . . . S PSUSDEA=$P($G(^PS(52.5,SFN,0)),"^",10)
46 . . . S SRT=$S(PSUSDEA["A"!(PSUSDEA["C"):"A-"_PSSRT,PSUSDEA["S":"S-"_PSSRT,1:"Z-"_PSSRT)
47 . . I PSRT'="D" D
48 . . . S SRT=$S(PSRT:$P(^DPT(DFN,0),"^")_$P(^(0),"^",9),1:VA("PID"))
49 . . ; - If not partial fill, sending Rx to ECME for 3rd Party billing
50 . . I 'PARTIAL,$$RETRX^PSOBPSUT(RXIEN,RXFILL),SDT>DT Q
51 . . I 'PARTIAL D I $$FIND^PSOREJUT(RXIEN,RXFILL) Q
52 . . . I $$FIND^PSOREJUT(RXIEN,RXFILL) Q
53 . . . I '$$RETRX^PSOBPSUT(RXIEN,RXFILL),$$STATUS^PSOBPSUT(RXIEN,RXFILL)'="" Q
54 . . . D ECMESND^PSOBPSU1(RXIEN,RXFILL,,"PL",,,,,,.RESP) I $D(RESP),'RESP S BPSCNT=$G(BPSCNT)+1
55 . . S ^TMP($J,SRT,SFN)=RXIEN
56 Q
57PPL ; Wait some time before printing so response from 3rd party payers can be received
58 I $G(BPSCNT)>0 H 60+$S((BPSCNT*15)>7200:7200,1:(BPSCNT*15))
59 K PPL,PPL1 S ORD="" F S ORD=$O(^TMP($J,ORD)) Q:ORD="" D PPL1
60 Q
61PPL1 ; Printing Labels
62 N PARTIAL,REPRINT,REFILL,Z,QUIT
63 S (PSOPRFLG,SUSPT)=1 S:$D(PSOPROP) PFIO=PSOPROP
64 S:'$D(PDUZ) PDUZ=DUZ K RXPR,RXPR1,PPL
65 F SFN=0:0 S SFN=$O(^TMP($J,ORD,SFN)) Q:'SFN D
66 .I '$D(^PS(52.5,SFN,0)) Q
67 .S Z=$G(^PS(52.5,SFN,0)),SINRX=+$P(Z,"^"),REFILL=+$P(Z,"^",13)
68 .S PARTIAL=$P(Z,"^",5),REPRINT=$P(Z,"^",12)
69 .; - Screening out OPEN/UNRESOLVED Rejects (3rd Party Payer)
70 .S QUIT=0
71 .I 'PARTIAL,'REPRINT D I QUIT Q
72 ..I $$FIND^PSOREJUT(SINRX,REFILL) S QUIT=1 Q
73 ..I $$STATUS^PSOBPSUT(SINRX,REFILL)="IN PROGRESS" S QUIT=1 Q
74 ..I $$STATUS^PSOBPSUT(SINRX,REFILL)="E PAYABLE" D
75 ...D SAVNDC^PSSNDCUT(+$$GET1^DIQ(52,SINRX,6,"I"),$$RXSITE^PSOBPSUT(SINRX,REFILL),$$GETNDC^PSONDCUT(SINRX,REFILL))
76 .;
77 .I $L($G(PPL))<240 D
78 ..S PPL=$P(^TMP($J,ORD,SFN),"^")_","_$G(PPL),RXPR(SINRX)=$P(^PS(52.5,SFN,0),"^",5)
79 ..S:$P(^PS(52.5,SFN,0),"^",12) RXRP(SINRX)=1
80 .E D
81 ..S PPL1=$P(^TMP($J,ORD,SFN),"^")_","_$G(PPL1),RXPR1(SINRX)=$P(^PS(52.5,SFN,0),"^",5)
82 ..S:$P(^PS(52.5,SFN,0),"^",12) RXRP1(SINRX)=1
83 .S DFN=$P(^PS(52.5,SFN,0),"^",3)
84 .I $P(PSOPAR,"^",8),'$D(^PSRX($P(^PS(52.5,SFN,0),"^"),1)),'$G(RXPR(SINRX)),'$G(RXPR1(SINRX)) S PSOPRFLG=0
85 S PSNP=$S($P(PSOPAR,"^",8):1,1:0)
86 I $G(PPL) D
87 .S PPLHLD=$G(PPL1),HDPPL=PPL K PPL1 S (PSODBQ,PSOSUSPR)=1
88 .F GGGG=0:0 S GGGG=$O(RXPR(GGGG)) Q:'GGGG K:'$G(RXPR(GGGG)) RXPR(GGGG)
89 I $G(PPL) D DQ^PSOLBL,SEQ D:'$G(PSOPRFLG)
90 .I $G(PSOPROP)'=$G(PSLION) S ^UTILITY($J,"PSOPRO",DFN)="" Q
91 .D DQ^PSOPRFSS
92 I $G(PPLHLD) K RXPR S (PPL,HDPPL)=PPLHLD,(PSODBQ,PSOSUSPR)=1,PSNP=0 S:'$D(PDUZ) PDUZ=DUZ F XXX=0:0 S XXX=$O(RXPR1(XXX)) Q:'XXX S:$G(RXPR1(XXX)) RXPR(XXX)=RXPR1(XXX)
93 I $G(PPLHLD) F RRRR=0:0 S RRRR=$O(RXRP1(RRRR)) Q:'RRRR S:$D(RXRP1(RRRR)) RXRP(RRRR)=1
94 I $G(PPLHLD) D DQ^PSOLBL,SEQ D:'$G(PSOPRFLG)
95 .I $G(PSOPROP)'=$G(PSLION) S ^UTILITY($J,"PSOPRO",DFN)="" Q
96 .D DQ^PSOPRFSS
97 K PPL,PPL1,PPLHLD,RXPR,RXPR1,RXFL Q
98SEQ ;
99 S SQCOUNT=0 F JJJ=1:1:$L(HDPPL) S:$E(HDPPL,JJJ)="," SQCOUNT=SQCOUNT+1
100 F JJJJ=1:1:SQCOUNT S PSFNIEN=$P(HDPPL,",",JJJJ) D:PSFNIEN
101 .S PSFNIEN=$O(^PS(52.5,"B",PSFNIEN,0)) I PSFNIEN D
102 ..S $P(^PS(52.5,PSFNIEN,0),"^",11)=PSOSEQ,PSOSEQ=PSOSEQ+1 S:$P(^PS(52.5,PSFNIEN,0),"^",8)&($P(^(0),"^",9))&($P(^(0),"^",6)) ^PS(52.5,"AS",$P(^PS(52.5,PSFNIEN,0),"^",8),$P(^(0),"^",9),$P(^(0),"^",6),$P(^(0),"^",11),PSFNIEN)=""
103 Q
104CHKDEAD D DEM^VADPT I VADM(1)="" S DEAD=0 Q
105 I VADM(6)="" S DEAD=0 Q
106 S PSDDDATE=$P(VADM(6),"^",2) F WWW=0:0 S WWW=$O(^PS(55,DFN,"P",WWW)) Q:'WWW I $D(^PS(55,DFN,"P",WWW,0)),$P($G(^(0)),"^") S (DA,RXREC)=$P(^(0),"^") S SFN=$O(^PS(52.5,"B",RXREC,0)) I SFN,$D(^PS(52.5,SFN,0)) S RX=$P(^(0),"^") D DEAD
107 Q
108DEAD S $P(^PSRX(RX,"STA"),"^")=12,COM="Died ("_$G(PSDDDATE)_")",DA(1)=RX
109 S DEAD=1 D ARECD^PSOSUTL S DIK="^PS(52.5,",DA=SFN D ^DIK K DIK
110 Q
111PROF ;
112 S ZTRTN="PRPROF^PSOSULBL",ZTDESC="PRINT PROFILES FROM SUSPENSE",ZTDTH=$H,ZTIO=PSOPROP
113 S ZTSAVE("^UTILITY($J,""PSOPRO"",")="",ZTSAVE("PSOPAR")="",ZTSAVE("PSODTCUT")="",ZTSAVE("PSOSITE")="",ZTSAVE("PSOPRPAS")="" D ^%ZTLOAD Q
114PRPROF ;
115 F LLL=0:0 S LLL=$O(^UTILITY($J,"PSOPRO",LLL)) Q:'LLL I $D(^DPT(LLL,0)) S DFN=LLL D DQ^PSOPRFSS
116 K PSOPAR,PSODTCUT,PSOSITE,PSOPRPAS,LLL,DFN,^UTILITY($J,"PSOPRO") D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
117 Q
118 ;
119CHKBAI ; IF BAD ADDRESS INDICATOR, NO ACTIVE TEMPORARY ADDRESS AND ROUTING OF MAIL, DO NOT SEND TO OPAI AND/OR DO NOT PRINT LABEL
120 N PSOBADR,ACTSEQ,XX,PSOFIRST,ACTTYPE
121 I '$G(RXFILL),$P(^PSRX(RXIEN,0),"^",11)="W" Q
122 I $P($G(^PSRX(RXIEN,1,RXFILL,0)),"^",2)="W" Q
123 S ACTTYPE="BAD ADDRESS INDICATOR"
124 S PSOBADR=$$CHKRX^PSOBAI(RXIEN)
125 ; GOOD PERMANENT OR TEMPORARY ADDRESS - CHECK FOR DO NOT MAIL
126 I PSOBADR,'$P(PSOBADR,"^",2) D SETTMP(ACTTYPE) Q
127 S NOMAIL=0 D NOMAIL I NOMAIL Q
128 D FOREIGN
129 Q
130 ;
131SETTMP(ACTTYPE) ;
132 N ACTSEQ,XX,PSOFIRST,ZZ
133 S PSOFIRST=1
134 S PSOBADDR=1
135 S ACTSEQ=0 F S ACTSEQ=$O(^PSRX(RXIEN,"A",ACTSEQ)) Q:ACTSEQ="" D
136 .S XX=$G(^PSRX(RXIEN,"A",ACTSEQ,0)) I $P(XX,"^",2)="S" S ZZ=$P(XX,"^",4),ZZ=$S(ZZ<6:ZZ,1:ZZ-1) I ZZ=RXFILL,$P(XX,"^",5)["due to "_ACTTYPE S PSOFIRST=0 Q
137 I PSOFIRST D
138 .S ^TMP("PSOSBAI",$J,RXIEN,+RXFILL)=ACTTYPE
139 .D ACT(ACTTYPE)
140 Q
141 ;
142NOMAIL ; SEE IF FILE 55 STATUS IS DO NOT MAIL
143 N ACTTYPE,DFN,MAILST,MAILEXP
144 S ACTTYPE="DO NOT MAIL"
145 S DFN=+$P($G(^PSRX(RXIEN,0)),"^",2),MAILST=$P($G(^PS(55,DFN,0)),"^",3) I MAILST'=2 Q
146 S MAILEXP=$P(^PS(55,DFN,0),"^",5)
147 I MAILEXP=""!(MAILEXP>DT) D SETTMP(ACTTYPE)
148 Q
149 ;
150FOREIGN ;
151 N ACTTYPE,DFN,PSOFORGN
152 D ADD^VADPT
153 S PSOFORGN=$P($G(VAPA(25)),"^",2) I PSOFORGN'="",PSOFORGN'["UNITED STATES" S PSOFORGN=1
154 S ACTTYPE="FOREIGN ADDRESS"
155 S DFN=+$P($G(^PSRX(RXIEN,0)),"^",2)
156 I PSOFORGN D SETTMP(ACTYPE)
157 Q
158 ;
159CHKMAIL ; SEE IF MAILMAN MESSAGE SHOULD BE SENT FOR BAI/MAIL ROUTING
160 N RXIEN,RXFILL,ACTSEQ,XX,DFN,SSN,NAME,ACTTYPE,ZZ
161 K ^TMP("PSOSM",$J)
162 S RXIEN=0 F S RXIEN=$O(^TMP("PSOSBAI",$J,RXIEN)) Q:'RXIEN D
163 .S RXFILL="" F S RXFILL=$O(^TMP("PSOSBAI",$J,RXIEN,RXFILL)) Q:RXFILL="" D
164 ..S ACTTYPE=^TMP("PSOSBAI",$J,RXIEN,RXFILL)
165 ..S ACTSEQ=0 F S ACTSEQ=$O(^PSRX(RXIEN,"A",ACTSEQ)) Q:ACTSEQ="" D
166 ...S XX=$G(^PSRX(RXIEN,"A",ACTSEQ,0)) I $P(XX,"^",2)="S" S ZZ=$P(XX,"^",4),ZZ=$S(ZZ<6:ZZ,1:ZZ-1) I ZZ=RXFILL,$P(XX,"^",5)["due to "_ACTTYPE Q
167 ...S DFN=$P(^PSRX(RXIEN,0),"^",2),NAME=$P(^DPT(DFN,0),"^"),SSN=$P(^(0),"^",9) I SSN="" S SSN=0
168 ...S ^TMP("PSOSM",$J,NAME,SSN,RXIEN,RXFILL)=ACTTYPE
169 I $D(^TMP("PSOSM",$J)) D BAIMAIL^PSOSULB1
170 K ^TMP("PSOSM",$J)
171 Q
172 ;
173ACT(ACTTYPE) ;adds activity info for rx not printed from suspense/not sent to OPAI
174 N NOW,IR,FDA
175 D NOW^%DTC S NOW=%
176 S IR=0 F FDA=0:0 S FDA=$O(^PSRX(RXIEN,"A",FDA)) Q:'FDA S IR=FDA
177 S IR=IR+1,^PSRX(RXIEN,"A",0)="^52.3DA^"_IR_"^"_IR
178 S ^PSRX(RXIEN,"A",IR,0)=NOW_"^"_"S"_"^"_DUZ_"^"_$S(+RXFILL>5:RXFILL+1,1:+RXFILL)_"^"_"RX not printed from suspense due to "_ACTTYPE
179 K PSUS,RXF,I,FDA,DIC,DIE,DR,Y,X,%,%I,%H,RSDT
180 Q
181 ;
Note: See TracBrowser for help on using the repository browser.