PSOACR ;AITC/PD - Auto Close Reject Code ;11/12/2024
;;7.0;OUTPATIENT PHARMACY;**748**;DEC 1997;Build 14
;;
;
Q
;
EN(RX,RFL,REJ) ; Main entry point for PSO Auto Close Reject
;
; Input parameters:
; RX - IEN for Prescription File (#52)
; RFL - Refill
; REJ - IEN for BPS NCPDP Rejects File (#9002313.93)
;
; This routine will be called from CLOSE^PSOREJUT.
;
; CLOSE^PSOREJUT will only call this routine if the reason for closing the reject
; is IGNORED - NO RESUBMISSION and the Ignore Flag is set to 1.
;
; In ECME, the BPS SUPERVISOR can define reject codes as auto close reject codes.
; The auto close reject codes will be stored in file BPS Auto Reject Code (#9002313.94).
; From PSO Reject Notification Screen and PSO Reject Information Screen, if the pharmacist
; uses the IGNORE action, to ignore a reject, a call will be made to this routine
; to determine if the claim should be automatically closed.
;
; The logic will fall through a series of checks to verify if the claim should be closed. If
; all checks pass, the claim will be closed. If any of the checks fail, the claim will not
; be closed and will be placed onto the ECME User Screen worklist.
;
N BPSACRIEN,COB,DFN,DOS,DOSIB,PSOAMT,PSOCLST,PSOIEN02,PSOIEN03,PSOIEN59,PSOIENS
N PSORELCP,PSOSECOND,REJCOB,REJEXT,REJIEN,THRESHOLD,X,Y
;
; Check if the reject code being ignored is set up as an auto close reject.
; If not, quit.
;
S REJEXT=$$GET1^DIQ(52.25,REJ_","_RX,.01)
I '$D(^BPSACR("C",REJEXT)) Q
;
; Get COB indicator for the reject
S REJCOB=$$GET1^DIQ(52.25,REJ_","_RX,27,"I")
;
; Get IEN for BPS Transaction file (#9002313.93) and the BPS Claims file (#9002313.02).
; These will be needed for the following checks.
; Also get IEN for BPS Response file (#9002313.03).
;
S PSOIENS=$$CLAIM^BPSBUTL(RX,RFL,REJCOB)
S PSOIEN59=$P(PSOIENS,"^",1)
S PSOIEN02=$P(PSOIENS,"^",2)
S PSOIEN03=$$GET1^DIQ(9002313.59,PSOIEN59,4,"I")
;
; Get info needed to check for secondary insurance.
;
S DFN=$$GET1^DIQ(9002313.59,PSOIEN59,5,"I")
S DOS=$$GET1^DIQ(9002313.02,PSOIEN02,401,"I")
S X=DOS
D ^%DT
S DOSIB=Y
;
;
; At this time, auto close rejects only occurs for primary claims. If not COB=1, do not auto close.
I REJCOB'=1 D COMMENT(1) Q
;
; Do not close if patient has secondary insurance
;
I $$SECINSCK^BPSPRRX(DFN,DOSIB) D COMMENT(1) Q
;
; Get the IEN of the auto close reject code.
;
S REJIEN=$O(^BPSACR("C",REJEXT,""))
S BPSACRIEN=$O(^BPSACR("B",REJIEN,""))
;
; Auto close rejects have a dollar threshold defined. This amount is compared against the
; gross amount due. If the dollar threshold is 0, the gross amount due will not effect
; if the claim is closed or not. If the dollar threshold is greater than 0, the claim will
; be closed if the dollar threshold is less than the gross amount due.
;
; Get gross amount due
;
S PSOAMT=$$AMT^BPSBUTL(RX,RFL)
;
; Get dollar threshold from BPS Auto Close Reject file
;
S THRESHOLD=$$GET1^DIQ(9002313.94,BPSACRIEN,.03)
;
; If the threshold amount is not 0 and the threshold is equal to or greater than
; the gross amount due, quit and do not close the claim.
;
I +THRESHOLD'=0&(PSOAMT=THRESHOLD!(PSOAMT>THRESHOLD)) D COMMENT(4) Q
;
; Check the REJECT COUNT from BPS Responses If it is not exactly 1, quit.
;
I +$$GET1^DIQ(9002313.0301,"1,"_PSOIEN03,510)'=1 D COMMENT(3) Q
;
; Make sure the one and only reject code, from BPS Responses, matches the
; Auto Close reject currently being ignored. If not, quit.
;
I $$GET1^DIQ(9002313.03511,"1,1,"_PSOIEN03,.01,"I")'=REJEXT Q
;
; Get the claim status from the transaction file.
;
S PSOCLST=$$CLAIMST^BPSSCRU3(PSOIEN59)
;
; Check if Secondary claim.
;
S PSOSECOND=0
S COB=$$GET1^DIQ(9002313.93,PSOIEN59,18)
I COB=2 S PSOSECOND=1
;
; Can only be closed if E REJECTED or E REVERSAL ACCEPTED.
;
I PSOCLST'["E REJECTED",PSOCLST'["E REVERSAL ACCEPTED" D Q
. I PSOSECOND=1 D COMMENT(1)
;
; Cannot close if non-billable.
;
I $$NB^BPSSCR03(PSOIEN59) Q
;
; Cannot close if already closed.
;
I $$CLOSED02^BPSSCR03(PSOIEN02) Q
;
; Cannot close if secondary payable claim exists.
;
I COB<2,$$PAYABLE^BPSOSRX5($P(PSOCLST,"^")),$$PAYBLSEC^BPSUTIL2(PSOIEN59) D COMMENT(1) Q
;
; Default release of copay to 0 - do not release copay.
;
S PSORELCP=0
;
; If patient eligibilty is VETERAN, release copay.
;
I $$GET1^DIQ(9002313.59,PSOIEN59,901.04,"I")="V" S PSORELCP=1
;
; At this point, all checks have passed and the claim is okay to close.
;
D CLOSE
;
Q
;
CLOSE ; Close the claim
;
N BILLNUM,BPSAR,CLAIMID,DA,DIE,DR,PSOLOCK,RELDT
;
; Lock claim file
;
S PSOLOCK=0
L +^BPSC(PSOIEN02):0
I $T S PSOLOCK=1
E D COMMENT(2) Q
;
S BPSAR("FILL NUMBER")=+RFL
S BPSAR("DOS")=DOS-17000000
S BPSAR("FILLED BY")=$$GET1^DIQ(52,RX,16,"I")
S BPSAR("PRESCRIPTION")=RX
S BILLED=$$GET1^DIQ(9002313.0201,"1,"_PSOIEN02,426)
S BILLED=$P(BILLED,"DQ",2)
S BPSAR("BILLED")=$$DFF2EXT^BPSECFM(BILLED)
S CLAIMID=$$GET1^DIQ(9002313.0201,"1,"_PSOIEN02,402)
S BPSAR("CLAIMID")=$P(CLAIMID,"D2",2)
S BPSAR("PLAN")=$$GET1^DIQ(9002313.59902,"1,"_PSOIEN59,.01,"I")
S BPSAR("STATUS")="CLOSED"
S BPSAR("PAID")=0
I +RFL=0 S RELDT=$$GET1^DIQ(52,RX,31,"I")
E S RELDT=$$GET1^DIQ(52.1,+RFL_","_RX,17,"I")
S BPSAR("RELEASE DATE")=RELDT
S BPSAR("USER")=.5
S BPSAR("EPHARM")=$$GET1^DIQ(9002313.59,PSOIEN59,1.07,"I")
S BPSAR("RXCOB")=COB
S BPSAR("CLOSE REASON")=$$GET1^DIQ(9002313.94,BPSACRIEN,.02,"I")
S BPSAR("DROP TO PAPER")=0
S BPSAR("RELEASE COPAY")=+$G(PSORELCP)
S BPSAR("CLOSE COMMENT")="Auto Closed Claim"
;
; Call IB
;
S BILLNUM=$$STORESP^IBNCPDP(DFN,.BPSAR)
;
S DIE="^BPSC("
S DA=PSOIEN02
S DR="901///1"
S DR=DR_";902///"_$$NOW^XLFDT()
S DR=DR_";903////.5"
S DR=DR_";904///"_BPSAR("CLOSE REASON")
S DR=DR_";905////N"
D ^DIE
;
; Unlock claim file
;
I PSOLOCK L -^BPSC(PSOIEN02)
;
Q
;
;
; If the claim can not be automatically closed, it is possible to
; have the system add a comment. In the future, if other reasons
; are added, that require a comment, they can be added to COMREAS.
;
N %,DATA,LINE,NUM,PSODA,PSOFDA,PSONOW,PSOREC,REA,REASON
;
S REASON=""
F LINE=1:1 S DATA=$P($T(COMREAS+LINE),";;",2,99) Q:DATA="" D
. S NUM=$P(DATA,";")
. S REA=$P(DATA,";",2)
. I NUM=COM S REASON=REA
I REASON="" Q
;
D NOW^%DTC
S PSONOW=%
;
S PSOFDA(9002313.59111,"+1,"_PSOIEN59_",",.01)=PSONOW
D UPDATE^DIE("","PSOFDA","")
;
S PSOREC=$O(^BPST(PSOIEN59,11,"B",PSONOW,""))
S PSODA(9002313.59111,PSOREC_","_PSOIEN59_",",.02)=.5
S PSODA(9002313.59111,PSOREC_","_PSOIEN59_",",.03)=$G(REASON)
D FILE^DIE("","PSODA","")
;
Q
;
COMREAS ; Unable to close reason comments
;;1;IGNORED by Pharmacy - Not auto closed due to COB
;;2;IGNORED by Pharmacy - Not auto closed due to locked claim
;;3;IGNORED by Pharmacy - Not auto closed due to multiple rejects
;;4;IGNORED by Pharmacy - Not auto closed due to dollar threshold
;;
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSOACR 7214 printed Aug 26, 2025@22:39:58 Page 2
PSOACR ;AITC/PD - Auto Close Reject Code ;11/12/2024
+1 ;;7.0;OUTPATIENT PHARMACY;**748**;DEC 1997;Build 14
+2 ;;
+3 ;
+4 QUIT
+5 ;
EN(RX,RFL,REJ) ; Main entry point for PSO Auto Close Reject
+1 ;
+2 ; Input parameters:
+3 ; RX - IEN for Prescription File (#52)
+4 ; RFL - Refill
+5 ; REJ - IEN for BPS NCPDP Rejects File (#9002313.93)
+6 ;
+7 ; This routine will be called from CLOSE^PSOREJUT.
+8 ;
+9 ; CLOSE^PSOREJUT will only call this routine if the reason for closing the reject
+10 ; is IGNORED - NO RESUBMISSION and the Ignore Flag is set to 1.
+11 ;
+12 ; In ECME, the BPS SUPERVISOR can define reject codes as auto close reject codes.
+13 ; The auto close reject codes will be stored in file BPS Auto Reject Code (#9002313.94).
+14 ; From PSO Reject Notification Screen and PSO Reject Information Screen, if the pharmacist
+15 ; uses the IGNORE action, to ignore a reject, a call will be made to this routine
+16 ; to determine if the claim should be automatically closed.
+17 ;
+18 ; The logic will fall through a series of checks to verify if the claim should be closed. If
+19 ; all checks pass, the claim will be closed. If any of the checks fail, the claim will not
+20 ; be closed and will be placed onto the ECME User Screen worklist.
+21 ;
+22 NEW BPSACRIEN,COB,DFN,DOS,DOSIB,PSOAMT,PSOCLST,PSOIEN02,PSOIEN03,PSOIEN59,PSOIENS
+23 NEW PSORELCP,PSOSECOND,REJCOB,REJEXT,REJIEN,THRESHOLD,X,Y
+24 ;
+25 ; Check if the reject code being ignored is set up as an auto close reject.
+26 ; If not, quit.
+27 ;
+28 SET REJEXT=$$GET1^DIQ(52.25,REJ_","_RX,.01)
+29 IF '$DATA(^BPSACR("C",REJEXT))
QUIT
+30 ;
+31 ; Get COB indicator for the reject
+32 SET REJCOB=$$GET1^DIQ(52.25,REJ_","_RX,27,"I")
+33 ;
+34 ; Get IEN for BPS Transaction file (#9002313.93) and the BPS Claims file (#9002313.02).
+35 ; These will be needed for the following checks.
+36 ; Also get IEN for BPS Response file (#9002313.03).
+37 ;
+38 SET PSOIENS=$$CLAIM^BPSBUTL(RX,RFL,REJCOB)
+39 SET PSOIEN59=$PIECE(PSOIENS,"^",1)
+40 SET PSOIEN02=$PIECE(PSOIENS,"^",2)
+41 SET PSOIEN03=$$GET1^DIQ(9002313.59,PSOIEN59,4,"I")
+42 ;
+43 ; Get info needed to check for secondary insurance.
+44 ;
+45 SET DFN=$$GET1^DIQ(9002313.59,PSOIEN59,5,"I")
+46 SET DOS=$$GET1^DIQ(9002313.02,PSOIEN02,401,"I")
+47 SET X=DOS
+48 DO ^%DT
+49 SET DOSIB=Y
+50 ;
+51 ;
+52 ; At this time, auto close rejects only occurs for primary claims. If not COB=1, do not auto close.
+53 IF REJCOB'=1
DO COMMENT(1)
QUIT
+54 ;
+55 ; Do not close if patient has secondary insurance
+56 ;
+57 IF $$SECINSCK^BPSPRRX(DFN,DOSIB)
DO COMMENT(1)
QUIT
+58 ;
+59 ; Get the IEN of the auto close reject code.
+60 ;
+61 SET REJIEN=$ORDER(^BPSACR("C",REJEXT,""))
+62 SET BPSACRIEN=$ORDER(^BPSACR("B",REJIEN,""))
+63 ;
+64 ; Auto close rejects have a dollar threshold defined. This amount is compared against the
+65 ; gross amount due. If the dollar threshold is 0, the gross amount due will not effect
+66 ; if the claim is closed or not. If the dollar threshold is greater than 0, the claim will
+67 ; be closed if the dollar threshold is less than the gross amount due.
+68 ;
+69 ; Get gross amount due
+70 ;
+71 SET PSOAMT=$$AMT^BPSBUTL(RX,RFL)
+72 ;
+73 ; Get dollar threshold from BPS Auto Close Reject file
+74 ;
+75 SET THRESHOLD=$$GET1^DIQ(9002313.94,BPSACRIEN,.03)
+76 ;
+77 ; If the threshold amount is not 0 and the threshold is equal to or greater than
+78 ; the gross amount due, quit and do not close the claim.
+79 ;
+80 IF +THRESHOLD'=0&(PSOAMT=THRESHOLD!(PSOAMT>THRESHOLD))
DO COMMENT(4)
QUIT
+81 ;
+82 ; Check the REJECT COUNT from BPS Responses If it is not exactly 1, quit.
+83 ;
+84 IF +$$GET1^DIQ(9002313.0301,"1,"_PSOIEN03,510)'=1
DO COMMENT(3)
QUIT
+85 ;
+86 ; Make sure the one and only reject code, from BPS Responses, matches the
+87 ; Auto Close reject currently being ignored. If not, quit.
+88 ;
+89 IF $$GET1^DIQ(9002313.03511,"1,1,"_PSOIEN03,.01,"I")'=REJEXT
QUIT
+90 ;
+91 ; Get the claim status from the transaction file.
+92 ;
+93 SET PSOCLST=$$CLAIMST^BPSSCRU3(PSOIEN59)
+94 ;
+95 ; Check if Secondary claim.
+96 ;
+97 SET PSOSECOND=0
+98 SET COB=$$GET1^DIQ(9002313.93,PSOIEN59,18)
+99 IF COB=2
SET PSOSECOND=1
+100 ;
+101 ; Can only be closed if E REJECTED or E REVERSAL ACCEPTED.
+102 ;
+103 IF PSOCLST'["E REJECTED"
IF PSOCLST'["E REVERSAL ACCEPTED"
Begin DoDot:1
+104 IF PSOSECOND=1
DO COMMENT(1)
End DoDot:1
QUIT
+105 ;
+106 ; Cannot close if non-billable.
+107 ;
+108 IF $$NB^BPSSCR03(PSOIEN59)
QUIT
+109 ;
+110 ; Cannot close if already closed.
+111 ;
+112 IF $$CLOSED02^BPSSCR03(PSOIEN02)
QUIT
+113 ;
+114 ; Cannot close if secondary payable claim exists.
+115 ;
+116 IF COB<2
IF $$PAYABLE^BPSOSRX5($PIECE(PSOCLST,"^"))
IF $$PAYBLSEC^BPSUTIL2(PSOIEN59)
DO COMMENT(1)
QUIT
+117 ;
+118 ; Default release of copay to 0 - do not release copay.
+119 ;
+120 SET PSORELCP=0
+121 ;
+122 ; If patient eligibilty is VETERAN, release copay.
+123 ;
+124 IF $$GET1^DIQ(9002313.59,PSOIEN59,901.04,"I")="V"
SET PSORELCP=1
+125 ;
+126 ; At this point, all checks have passed and the claim is okay to close.
+127 ;
+128 DO CLOSE
+129 ;
+130 QUIT
+131 ;
CLOSE ; Close the claim
+1 ;
+2 NEW BILLNUM,BPSAR,CLAIMID,DA,DIE,DR,PSOLOCK,RELDT
+3 ;
+4 ; Lock claim file
+5 ;
+6 SET PSOLOCK=0
+7 LOCK +^BPSC(PSOIEN02):0
+8 IF $TEST
SET PSOLOCK=1
+9 IF '$TEST
DO COMMENT(2)
QUIT
+10 ;
+11 SET BPSAR("FILL NUMBER")=+RFL
+12 SET BPSAR("DOS")=DOS-17000000
+13 SET BPSAR("FILLED BY")=$$GET1^DIQ(52,RX,16,"I")
+14 SET BPSAR("PRESCRIPTION")=RX
+15 SET BILLED=$$GET1^DIQ(9002313.0201,"1,"_PSOIEN02,426)
+16 SET BILLED=$PIECE(BILLED,"DQ",2)
+17 SET BPSAR("BILLED")=$$DFF2EXT^BPSECFM(BILLED)
+18 SET CLAIMID=$$GET1^DIQ(9002313.0201,"1,"_PSOIEN02,402)
+19 SET BPSAR("CLAIMID")=$PIECE(CLAIMID,"D2",2)
+20 SET BPSAR("PLAN")=$$GET1^DIQ(9002313.59902,"1,"_PSOIEN59,.01,"I")
+21 SET BPSAR("STATUS")="CLOSED"
+22 SET BPSAR("PAID")=0
+23 IF +RFL=0
SET RELDT=$$GET1^DIQ(52,RX,31,"I")
+24 IF '$TEST
SET RELDT=$$GET1^DIQ(52.1,+RFL_","_RX,17,"I")
+25 SET BPSAR("RELEASE DATE")=RELDT
+26 SET BPSAR("USER")=.5
+27 SET BPSAR("EPHARM")=$$GET1^DIQ(9002313.59,PSOIEN59,1.07,"I")
+28 SET BPSAR("RXCOB")=COB
+29 SET BPSAR("CLOSE REASON")=$$GET1^DIQ(9002313.94,BPSACRIEN,.02,"I")
+30 SET BPSAR("DROP TO PAPER")=0
+31 SET BPSAR("RELEASE COPAY")=+$GET(PSORELCP)
+32 SET BPSAR("CLOSE COMMENT")="Auto Closed Claim"
+33 ;
+34 ; Call IB
+35 ;
+36 SET BILLNUM=$$STORESP^IBNCPDP(DFN,.BPSAR)
+37 ;
+38 SET DIE="^BPSC("
+39 SET DA=PSOIEN02
+40 SET DR="901///1"
+41 SET DR=DR_";902///"_$$NOW^XLFDT()
+42 SET DR=DR_";903////.5"
+43 SET DR=DR_";904///"_BPSAR("CLOSE REASON")
+44 SET DR=DR_";905////N"
+45 DO ^DIE
+46 ;
+47 ; Unlock claim file
+48 ;
+49 IF PSOLOCK
LOCK -^BPSC(PSOIEN02)
+50 ;
+51 QUIT
+52 ;
+1 ;
+2 ; If the claim can not be automatically closed, it is possible to
+3 ; have the system add a comment. In the future, if other reasons
+4 ; are added, that require a comment, they can be added to COMREAS.
+5 ;
+6 NEW %,DATA,LINE,NUM,PSODA,PSOFDA,PSONOW,PSOREC,REA,REASON
+7 ;
+8 SET REASON=""
+9 FOR LINE=1:1
SET DATA=$PIECE($TEXT(COMREAS+LINE),";;",2,99)
if DATA=""
QUIT
Begin DoDot:1
+10 SET NUM=$PIECE(DATA,";")
+11 SET REA=$PIECE(DATA,";",2)
+12 IF NUM=COM
SET REASON=REA
End DoDot:1
+13 IF REASON=""
QUIT
+14 ;
+15 DO NOW^%DTC
+16 SET PSONOW=%
+17 ;
+18 SET PSOFDA(9002313.59111,"+1,"_PSOIEN59_",",.01)=PSONOW
+19 DO UPDATE^DIE("","PSOFDA","")
+20 ;
+21 SET PSOREC=$ORDER(^BPST(PSOIEN59,11,"B",PSONOW,""))
+22 SET PSODA(9002313.59111,PSOREC_","_PSOIEN59_",",.02)=.5
+23 SET PSODA(9002313.59111,PSOREC_","_PSOIEN59_",",.03)=$GET(REASON)
+24 DO FILE^DIE("","PSODA","")
+25 ;
+26 QUIT
+27 ;
COMREAS ; Unable to close reason comments
+1 ;;1;IGNORED by Pharmacy - Not auto closed due to COB
+2 ;;2;IGNORED by Pharmacy - Not auto closed due to locked claim
+3 ;;3;IGNORED by Pharmacy - Not auto closed due to multiple rejects
+4 ;;4;IGNORED by Pharmacy - Not auto closed due to dollar threshold
+5 ;;
+6 ;