PSOSULBL ;BHAM ISC/RTR,SAB-Print Suspended labels ;4/8/93
;;7.0;OUTPATIENT PHARMACY;**139,173,174,148,200,260,264**;DEC 1997;Build 19
;External reference ^PS(55 supported by DBIA 2228
;Reference to SAVNDC^PSSNDCUT supported by IA 4707
;Reference ^PSDRUG( supported by DBIA 221
K PDUZ,REPRINT G ^PSOSULB1
BEG ;
K PSORUNIN,PSORETRY N BPSCNT
S PSORUNIN="PSOSUSP"_($G(PSOSITE))
L +@PSORUNIN:10 I '$T D
. F PSORETRY=1:1:120 L +@PSORUNIN:60 I $T Q ;wait Max of 2 hrs before continue
. Q
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
.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
D PPL
D:$D(^UTILITY($J,"PSOPRO"))&($P(PSOPAR,"^",8)) PROF
G EXIT
PRT F SDT=0:0 S SDT=$O(^PS(52.5,"AC",DFN,SDT)) D:SDT CHK Q:'SDT
Q
EXIT ;
I $D(^TMP("PSOSBAI",$J)) D CHKMAIL
K ^TMP($J),^TMP("PSOSBAI",$J)
I $D(PSORUNIN) L -@PSORUNIN
D ^%ZISC
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
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
CHK I SDT'>XDATE D TMP Q
Q
TMP F SFN=0:0 S SFN=$O(^PS(52.5,"AC",DFN,SDT,SFN)) Q:'SFN D
. I '$D(^PS(52.5,SFN,0))!'$D(^DPT(+DFN,0)) Q
. N RXSITE,PRINTED,PSDFN,RXSTS,RXIEN,RXFILL,PARTIAL,RXEXPDT,RESP
. S RXIEN=+$$GET1^DIQ(52.5,SFN,.01,"I"),RXDFN=$$GET1^DIQ(52,RXIEN,2,"I")
. S RXSTS=$$GET1^DIQ(52,RXIEN,100,"I"),RXSITE=+$$GET1^DIQ(52.5,SFN,.06,"I"),PRINTED=+$$GET1^DIQ(52.5,SFN,2,"I")
. S PARTIAL=+$$GET1^DIQ(52.5,SFN,.05,"I"),RXEXPDT=$$GET1^DIQ(52,RXIEN,26,"I")
. S RXFILL=$$GET1^DIQ(52.5,SFN,9,"I") I RXFILL="" S RXFILL=$$LSTRFL^PSOBPSU1(RXIEN)
. I RXSITE=$G(PSOSITE),'PRINTED,RXDFN=DFN,RXSTS<9 D
. . I PARTIAL,'$D(^PSRX(RXIEN,"P",PARTIAL)) Q
. . I RXEXPDT
DT Q
. . I 'PARTIAL D I $$FIND^PSOREJUT(RXIEN,RXFILL) Q
. . . I $$FIND^PSOREJUT(RXIEN,RXFILL) Q
. . . I '$$RETRX^PSOBPSUT(RXIEN,RXFILL),$$STATUS^PSOBPSUT(RXIEN,RXFILL)'="" Q
. . . D ECMESND^PSOBPSU1(RXIEN,RXFILL,,"PL",,,,,,.RESP) I $D(RESP),'RESP S BPSCNT=$G(BPSCNT)+1
. . S ^TMP($J,SRT,SFN)=RXIEN
Q
PPL ; Wait some time before printing so response from 3rd party payers can be received
I $G(BPSCNT)>0 H 60+$S((BPSCNT*15)>7200:7200,1:(BPSCNT*15))
K PPL,PPL1 S ORD="" F S ORD=$O(^TMP($J,ORD)) Q:ORD="" D PPL1
Q
PPL1 ; Printing Labels
N PARTIAL,REPRINT,REFILL,Z,QUIT
S (PSOPRFLG,SUSPT)=1 S:$D(PSOPROP) PFIO=PSOPROP
S:'$D(PDUZ) PDUZ=DUZ K RXPR,RXPR1,PPL
F SFN=0:0 S SFN=$O(^TMP($J,ORD,SFN)) Q:'SFN D
.I '$D(^PS(52.5,SFN,0)) Q
.S Z=$G(^PS(52.5,SFN,0)),SINRX=+$P(Z,"^"),REFILL=+$P(Z,"^",13)
.S PARTIAL=$P(Z,"^",5),REPRINT=$P(Z,"^",12)
.; - Screening out OPEN/UNRESOLVED Rejects (3rd Party Payer)
.S QUIT=0
.I 'PARTIAL,'REPRINT D I QUIT Q
..I $$FIND^PSOREJUT(SINRX,REFILL) S QUIT=1 Q
..I $$STATUS^PSOBPSUT(SINRX,REFILL)="IN PROGRESS" S QUIT=1 Q
..I $$STATUS^PSOBPSUT(SINRX,REFILL)="E PAYABLE" D
...D SAVNDC^PSSNDCUT(+$$GET1^DIQ(52,SINRX,6,"I"),$$RXSITE^PSOBPSUT(SINRX,REFILL),$$GETNDC^PSONDCUT(SINRX,REFILL))
.;
.I $L($G(PPL))<240 D
..S PPL=$P(^TMP($J,ORD,SFN),"^")_","_$G(PPL),RXPR(SINRX)=$P(^PS(52.5,SFN,0),"^",5)
..S:$P(^PS(52.5,SFN,0),"^",12) RXRP(SINRX)=1
.E D
..S PPL1=$P(^TMP($J,ORD,SFN),"^")_","_$G(PPL1),RXPR1(SINRX)=$P(^PS(52.5,SFN,0),"^",5)
..S:$P(^PS(52.5,SFN,0),"^",12) RXRP1(SINRX)=1
.S DFN=$P(^PS(52.5,SFN,0),"^",3)
.I $P(PSOPAR,"^",8),'$D(^PSRX($P(^PS(52.5,SF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(0),"^",9),$P(^(0),"^",6),$P(^(0),"^",11),PSFNIEN)=""
Q
CHKDEAD D DEM^VADPT I VADM(1)="" S DEAD=0 Q
I VADM(6)="" S DEAD=0 Q
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
Q
DEAD S $P(^PSRX(RX,"STA"),"^")=12,COM="Died ("_$G(PSDDDATE)_")",DA(1)=RX
S DEAD=1 D ARECD^PSOSUTL S DIK="^PS(52.5,",DA=SFN D ^DIK K DIK
Q
PROF ;
S ZTRTN="PRPROF^PSOSULBL",ZTDESC="PRINT PROFILES FROM SUSPENSE",ZTDTH=$H,ZTIO=PSOPROP
S ZTSAVE("^UTILITY($J,""PSOPRO"",")="",ZTSAVE("PSOPAR")="",ZTSAVE("PSODTCUT")="",ZTSAVE("PSOSITE")="",ZTSAVE("PSOPRPAS")="" D ^%ZTLOAD Q
PRPROF ;
F LLL=0:0 S LLL=$O(^UTILITY($J,"PSOPRO",LLL)) Q:'LLL I $D(^DPT(LLL,0)) S DFN=LLL D DQ^PSOPRFSS
K PSOPAR,PSODTCUT,PSOSITE,PSOPRPAS,LLL,DFN,^UTILITY($J,"PSOPRO") D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
Q
;
CHKBAI ; IF BAD ADDRESS INDICATOR, NO ACTIVE TEMPORARY ADDRESS AND ROUTING OF MAIL, DO NOT SEND TO OPAI AND/OR DO NOT PRINT LABEL
N PSOBADR,ACTSEQ,XX,PSOFIRST,ACTTYPE
I '$G(RXFILL),$P(^PSRX(RXIEN,0),"^",11)="W" Q
I $P($G(^PSRX(RXIEN,1,RXFILL,0)),"^",2)="W" Q
S ACTTYPE="BAD ADDRESS INDICATOR"
S PSOBADR=$$CHKRX^PSOBAI(RXIEN)
; GOOD PERMANENT OR TEMPORARY ADDRESS - CHECK FOR DO NOT MAIL
I PSOBADR,'$P(PSOBADR,"^",2) D SETTMP(ACTTYPE) Q
S NOMAIL=0 D NOMAIL I NOMAIL Q
D FOREIGN
Q
;
SETTMP(ACTTYPE) ;
N ACTSEQ,XX,PSOFIRST,ZZ
S PSOFIRST=1
S PSOBADDR=1
S ACTSEQ=0 F S ACTSEQ=$O(^PSRX(RXIEN,"A",ACTSEQ)) Q:ACTSEQ="" D
.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
I PSOFIRST D
.S ^TMP("PSOSBAI",$J,RXIEN,+RXFILL)=ACTTYPE
.D ACT(ACTTYPE)
Q
;
NOMAIL ; SEE IF FILE 55 STATUS IS DO NOT MAIL
N ACTTYPE,DFN,MAILST,MAILEXP
S ACTTYPE="DO NOT MAIL"
S DFN=+$P($G(^PSRX(RXIEN,0)),"^",2),MAILST=$P($G(^PS(55,DFN,0)),"^",3) I MAILST'=2 Q
S MAILEXP=$P(^PS(55,DFN,0),"^",5)
I MAILEXP=""!(MAILEXP>DT) D SETTMP(ACTTYPE)
Q
;
FOREIGN ;
N ACTTYPE,DFN,PSOFORGN
D ADD^VADPT
S PSOFORGN=$P($G(VAPA(25)),"^",2) I PSOFORGN'="",PSOFORGN'["UNITED STATES" S PSOFORGN=1
S ACTTYPE="FOREIGN ADDRESS"
S DFN=+$P($G(^PSRX(RXIEN,0)),"^",2)
I PSOFORGN D SETTMP(ACTYPE)
Q
;
CHKMAIL ; SEE IF MAILMAN MESSAGE SHOULD BE SENT FOR BAI/MAIL ROUTING
N RXIEN,RXFILL,ACTSEQ,XX,DFN,SSN,NAME,ACTTYPE,ZZ
K ^TMP("PSOSM",$J)
S RXIEN=0 F S RXIEN=$O(^TMP("PSOSBAI",$J,RXIEN)) Q:'RXIEN D
.S RXFILL="" F S RXFILL=$O(^TMP("PSOSBAI",$J,RXIEN,RXFILL)) Q:RXFILL="" D
..S ACTTYPE=^TMP("PSOSBAI",$J,RXIEN,RXFILL)
..S ACTSEQ=0 F S ACTSEQ=$O(^PSRX(RXIEN,"A",ACTSEQ)) Q:ACTSEQ="" D
...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
...S DFN=$P(^PSRX(RXIEN,0),"^",2),NAME=$P(^DPT(DFN,0),"^"),SSN=$P(^(0),"^",9) I SSN="" S SSN=0
...S ^TMP("PSOSM",$J,NAME,SSN,RXIEN,RXFILL)=ACTTYPE
I $D(^TMP("PSOSM",$J)) D BAIMAIL^PSOSULB1
K ^TMP("PSOSM",$J)
Q
;
ACT(ACTTYPE) ;adds activity info for rx not printed from suspense/not sent to OPAI
N NOW,IR,FDA
D NOW^%DTC S NOW=%
S IR=0 F FDA=0:0 S FDA=$O(^PSRX(RXIEN,"A",FDA)) Q:'FDA S IR=FDA
S IR=IR+1,^PSRX(RXIEN,"A",0)="^52.3DA^"_IR_"^"_IR
S ^PSRX(RXIEN,"A",IR,0)=NOW_"^"_"S"_"^"_DUZ_"^"_$S(+RXFILL>5:RXFILL+1,1:+RXFILL)_"^"_"RX not printed from suspense due to "_ACTTYPE
K PSUS,RXF,I,FDA,DIC,DIE,DR,Y,X,%,%I,%H,RSDT
Q
;