Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: PSOSULBL

PSOSULBL.m

Go to the documentation of this file.
PSOSULBL ;BHAM ISC/RTR,SAB - Print Suspended labels ;SEP 30, 2020@13:11
 ;;7.0;OUTPATIENT PHARMACY;**139,173,174,148,200,260,264,287,289,290,354,421,370,427,466,539,452,627**;DEC 1997;Build 2
 ;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="^XTMP(""PSOSUSP"")"     ; global lock fix by patch 290
 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
 . S (PSOSFLAG,DEAD)=0
 . F ZZ=0:0 S ZZ=$O(^PS(52.5,"AC",DFN,ZZ)) Q:'ZZ!$G(PSOSFLAG)  D
 . . I ZZ'>PRTDT S PSOSFLAG=1
 . D:'$G(PSRT) PID^VADPT6 D CHKDEAD I $G(DEAD) Q
 . I $G(PSOSFLAG) D PRT
 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,PSOOK,PSOSULST
 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)) K ^PS(52.5,"AC",DFN,SDT,SFN) Q
 . I $D(PSOSULST) N PSOOK D EN^PSOSUCAT Q:'PSOOK  ;RTW line added for NSR20151109
 . N RXSITE,PRINTED,PSDFN,RXSTS,RXIEN,RXFILL,PARTIAL,RXEXPDT,RESP,DSHLD,ESTATUS
 . 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
 . . ; If already printed and the REPRINT flag is not set, remove from queue and quit
 . . ; Line below commented out due to patient safety issue
 . . ; Refer to PSO*7.0*466
 . . ;I $$PRINTED(SFN,RXIEN,RXFILL)=1 D REMOVE(SFN,RXIEN,RXFILL,.5,"","") Q  
 . . I RXEXPDT<DT,RXSTS<11 D  Q
 . . . N RXREC S RXREC=RXIEN D EX^PSOSUTL
 . . . K DIE,DA S DIE=52,DA=RXIEN,DR="100///11" D ^DIE K DIE,DA
 . . . K DIK,DA S DA=SFN,DIK="^PS(52.5," D ^DIK K DIK,DA
 . . S PSOBADDR=0 D CHKBAI I PSOBADDR Q
 . . I PSRT="D" D
 . . . S PSSRT=$S($G(PSRTONE)="I":VA("PID"),1:$P(^DPT(DFN,0),"^")_$P(^(0),"^",9))
 . . . S PSUSDEA=$P($G(^PS(52.5,SFN,0)),"^",10)
 . . . S SRT=$S(PSUSDEA["A"!(PSUSDEA["C"):"A-"_PSSRT,PSUSDEA["S":"S-"_PSSRT,1:"Z-"_PSSRT)
 . . I PSRT'="D" D
 . . . S SRT=$S(PSRT:$P(^DPT(DFN,0),"^")_$P(^(0),"^",9),1:VA("PID"))
 . . ; - If not partial fill, sending Rx to ECME for 3rd Party billing
 . . I 'PARTIAL,$$RETRX^PSOBPSUT(RXIEN,RXFILL),SDT>DT Q
 . . S ESTATUS=$$STATUS^PSOBPSUT(RXIEN,RXFILL)
 . . I 'PARTIAL,ESTATUS'="",ESTATUS'["PAYABLE",'$$ECMESTAT^PSOBPSU2(RXIEN,RXFILL) Q  ;check for existing epharmacy reject codes
 . . I 'PARTIAL,RXFILL>0,$$STATUS^PSOBPSUT(RXIEN,RXFILL-1)'="" S DSHLD=$$DSH^PSOSULB1(SFN) Q:'DSHLD  ;epharmacy-3/4 days supply (refill)
 . . I 'PARTIAL,RXFILL=0 S DSHLD=$$DSH^PSOSULB1(SFN) Q:'DSHLD  ;epharmacy-3/4 days supply (original fill)
 . . I 'PARTIAL,$$FIND^PSOREJUT(RXIEN,RXFILL,,"79,88",,1) Q  ;check for DUR/RTS/RRR (again as it is done in ECMESTAT above)
 . . I 'PARTIAL,($$RETRX^PSOBPSUT(RXIEN,RXFILL)!$$ECMEST2^PSOBPSU2(RXIEN,RXFILL)) D  Q:$$TRISTA^PSOREJU3(RXIEN,RXFILL,.RESP,"PL")
 . . . 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,RXFL,Z,QUIT,ESTAT
 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
 .;PSO*7.0*627 - add RXFL(SINRX) for downstream outpatient dispensing robots
 . ;             such as Optifill or ScriptPro
 .S Z=$G(^PS(52.5,SFN,0)),SINRX=+$P(Z,"^"),(REFILL,RXFL(SINRX))=+$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,,"79,88",,1) S QUIT=1 Q
 ..S ESTAT=$$STATUS^PSOBPSUT(SINRX,REFILL)
 ..I ESTAT'="E PAYABLE",'$$ECMESTAT^PSOBPSU2(SINRX,REFILL) S QUIT=1 Q  ;host reject
 ..I ESTAT="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,SFN,0),"^"),1)),'$G(RXPR(SINRX)),'$G(RXPR1(SINRX)) S PSOPRFLG=0
 S PSNP=$S($P(PSOPAR,"^",8):1,1:0)
 I $G(PPL) D
 .S PPLHLD=$G(PPL1),HDPPL=PPL K PPL1 S (PSODBQ,PSOSUSPR)=1
 .F GGGG=0:0 S GGGG=$O(RXPR(GGGG)) Q:'GGGG  K:'$G(RXPR(GGGG)) RXPR(GGGG)
 I $G(PPL) S ZTIO=$G(PSLION) D DQ^PSOLBL,SEQ D:'$G(PSOPRFLG) 
 .I $G(PSOPROP)'=$G(PSLION) S ^UTILITY($J,"PSOPRO",DFN)="" Q
 .D DQ^PSOPRFSS
 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)
 I $G(PPLHLD) F RRRR=0:0 S RRRR=$O(RXRP1(RRRR)) Q:'RRRR  S:$D(RXRP1(RRRR)) RXRP(RRRR)=1
 I $G(PPLHLD) S ZTIO=$G(PSLION) D DQ^PSOLBL,SEQ D:'$G(PSOPRFLG)
 .I $G(PSOPROP)'=$G(PSLION) S ^UTILITY($J,"PSOPRO",DFN)="" Q
 .D DQ^PSOPRFSS
 K PPL,PPL1,PPLHLD,RXPR,RXPR1,RXFL Q
SEQ ;
 S SQCOUNT=0 F JJJ=1:1:$L(HDPPL) S:$E(HDPPL,JJJ)="," SQCOUNT=SQCOUNT+1
 F JJJJ=1:1:SQCOUNT S PSFNIEN=$P(HDPPL,",",JJJJ) D:PSFNIEN
 .S PSFNIEN=$O(^PS(52.5,"B",PSFNIEN,0)) I PSFNIEN D
 ..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)=""
 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 DFN,PSOFORGN
 S DFN=$$GET1^DIQ(52,RXIEN,2,"I")  ;*370
 D ADD^VADPT
 S PSOFORGN=$P($G(VAPA(25)),"^",2) I PSOFORGN'="" D  ; *370
 . N PSON,PSOFOREN S PSOFOREN=1
 . S PSON=$$GET1^DIQ(59,PSOSITE,.01)
 . I PSON'["MANILA",PSOFORGN["UNITED STATES" S PSOFOREN=0
 . I PSON["MANILA",PSOFORGN["PHILIPPINES" S PSOFOREN=0
 . S PSOFORGN=PSOFOREN
 I PSOFORGN D SETTMP("FOREIGN ADDRESS")
 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
 ;
PRINTED(SFN,RX,RFL) ;
 ; Check if a label log indicates that a label has already been printed
 ; Input Parameters
 ;    SFN - IEN of RX Suspense file (#52.5)
 ;    RX  - IEN of Prescription file (#50)
 ;    RFL - Refill number
 ; Output
 ;     0 - Label not printed
 ;     1 - Label already printed
 ;     2 - Label already printed and reprint flag is set
 ;
 ; Check parameters
 I '$G(SFN) Q 0
 I '$G(RX) Q 0
 I $G(RFL)="" S RFL=$$LSTRFL^PSOBPSU1(RX)
 ;
 N LBL,PTLBL
 ; Check label log
 S LBL=0,PTLBL=0
 F  S LBL=$O(^PSRX(RX,"L",LBL)) Q:'LBL  D  Q:PTLBL
 . I +$$GET1^DIQ(52.032,LBL_","_RX,1,"I")'=RFL Q
 . I $$GET1^DIQ(52.032,LBL_","_RX,4,"I") Q    ; Warning Label printed
 . I $$GET1^DIQ(52.032,LBL_","_RX,2)["INTERACTION" Q  ; Comment contains "Interaction"
 . S PTLBL=1
 ; If the label log indicates a label was printed and the REPRINT flag is set, change the output to 2
 I PTLBL=1,$$GET1^DIQ(52.5,SFN_",",8,"I") S PTLBL=2
 ; 
 Q PTLBL
 ;
REMOVE(SFN,RX,RFL,USR,DSP,PRTFLG) ;
 ; Remove the RX from the RX Suspense queue (#52.5)
 ; Input Parameters
 ;    SFN - IEN of RX Suspense file (#52.5)
 ;    RX  - IEN of Prescription file (#52)
 ;    RFL - Refill number
 ;    USR - User to enter into the Activity Log
 ;    DSP - Display message
 ;    PRTFLG - 1:Printed,2:Printed and Reprint Flag
 ;
 ; If Reprint flag and display flags are on, display message and quit
 I $G(PRTFLG)=2,$G(DSP)  W !,"Reprint Flag is on.  Prescription left on suspense." H 1 Q
 ;
 ; Check parameters
 I '$G(SFN) Q
 I '$D(^PS(52.5,SFN,0)) Q
 I '$G(RX) Q
 I '$D(^PSRX(RX,0)) Q
 I $G(RFL)="" S RFL=$$LSTRFL^PSOBPSU1(RX)
 ;
 N DIK,DA,DIE,DR,DTOUT
 ;
 ; Remove from the suspense queue
 S DIK="^PS(52.5,",DA=SFN D ^DIK
 ;
 ; Update status in the PRESCRIPTION file
 K DIE,DA
 S DIE=52,DA=RX,DR="100///0" D ^DIE
 ; 
 ; Update the Activity Log
 I '$D(USR) S USR=DUZ
 I '$D(^VA(200,+USR,0)) S USR=DUZ
 N X,DIC,DA,DD,DO,DR,DINUM,Y,DLAYGO
 S DA(1)=RX,DIC="^PSRX("_RX_",""A"",",DLAYGO=52.3,DIC(0)="L",X=$$NOW^XLFDT()
 S DIC("DR")=".02///S;.03////"_USR_";.04///"_$S(RFL>5:RFL+1,1:RFL)_";.05///Rx removed from suspense due to previous label print"
 D FILE^DICN
 I $G(DSP) W !,"Prescription has been removed from suspense." H 1
 Q