BPSOSRX5 ;ALB/SS - ECME REQUESTS ;10-JAN-08
 ;;1.0;E CLAIMS MGMT ENGINE;**7,8,10,11,20**;JUN 2004;Build 27
 ;;Per VA Directive 6402, this routine should not be modified.
 ;
 ;check if according the last response the payer IS going to PAY
 ;(Note: reversals can be done only on previously payable claims, if reversal failed then the claim stays PAYABLE)
PAYABLE(BPRESP) ;
 Q ",E PAYABLE,E DUPLICATE,E REVERSAL REJECTED,E REVERSAL OTHER,E REVERSAL UNSTRANDED,"[(","_BPRESP_",")
 ;
 ;Action type
ACTTYPE(BWHR) ;
 Q:",AREV,CRLR,CRLX,DC,DE,EREV,HLD,OREV,RS,"[(","_BWHR_",") "U"  ;UNCLAIM (reversal)
 Q:",CRLB,ED,ERES,P2S,"[(","_BWHR_",") "UC"  ;UNCLAIM (reversal) + CLAIM (resubmit)
 Q:",BB,CRRL,ERWV,ERNB,OF,PC,PE,PL,PP,RF,RN,RRL,RSNB,P2,"[(","_BWHR_",") "C"  ;CLAIM (the very first submit OR resubmit only)
 Q:BWHR="ELIG" "E"
 Q ""  ;unknown
 ;
 ;Check ECME availability at the site
 ;return :
 ; 1^CLMSTAT -off
 ; null -on
ECMESITE(SITE) ;
 I '$G(SITE) Q "1^No Site Information"
 I '$$ECMEON^BPSUTIL(SITE) Q "1^ECME switch is not on for the site"
 Q ""
 ;
 ; This is called by STATUS99^BPSOSU when the status of the current claim becomes 99%.
 ; The purpose is to decide what to with the new next request in the chain
 ;
 ; Example:
 ;  If this request (Request A) is the last one in the chain and we just received a new request
 ;   (Request B) for the same keys, then Request B needs to be activated after Request A has been completed.  Who will do this?
 ;  Situation 1:
 ;    If this code REQST99^BPSOSRX5 gets the lock first then it will not be able to activate Request B (because we
 ;    don't have it in the NEXT REQUEST field). So Request A will be completed and when the REQST^BPSOSRX code gets
 ;    the lock it will find Request A marked as completed and will not populate the NEXT REQUEST field of Request A.
 ;    Instead it will just activate Request B.
 ;  Situation 2:
 ;    If the REQST^BPSOSRX code gets the lock first then it will check the status of the Request A and since it is
 ;    still "IN PROCESS", then it will populate the NEXT REQUEST field of the Request 1 with ien of Request 2, and
 ;    then release the lock.  Then when the REQST99^BPSOSRX5 gets the lock it checks the NEXT REQUEST field and
 ;    activate the request 2
 ;
 ;Input:
 ;IEN59 - BPS TRANSACTION IEN
 ;BPCLMST - claim status
 ;     For Billing Requests (type= C):
 ;       E PAYABLE, E CAPTURED, E DUPLICATE, E REJECTED, E OTHER, and
 ;       E UNSTRANDED
 ;
 ;     For Reversals (type=U):
 ;       E REVERSAL ACCEPTED, E REVERSAL REJECTED, E REVERSAL OTHER, and
 ;       E REVERSAL UNSTRANDED
 ;
 ;     For Eligibility (type=E):
 ;       E ELIGIBILITY ACCEPTED, E ELIGIBILITY REJECTED, E ELIGIBILITY OTHER, and
 ;       E ELIGIBILITY UNSTRANDED
 ;
 ;Output:
 ; return 0 if there is no next request
 ; otherwise - return IEN of next BPS REQUEST
REQST99(IEN59,BPCLMST) ;
 N BP77,KEY1,KEY2,BPRETV,BPTYPE,RESAFTRV,BPPAYSEQ,BPTYPNXT,BPFLG
 N DOS,BWHERE,BILLNDC,REVREAS,DURREC,BPOVRIEN,BPSCLARF,BPSAUTH,BPSDELAY,BPCOBIND,BPDUR
 S RESAFTRV=0
 I '$G(IEN59) D LOG^BPSOSL(IEN59,$T(+0)_"-Transaction IEN not passed in") Q 0
 S BPCLMST=$G(BPCLMST)
 ;
 ; Get Keys to the request file
 S BP77=$$GETRQST^BPSUTIL2(IEN59)
 I 'BP77 D LOG^BPSOSL(IEN59,$T(+0)_"-BPS Request Pointer not found") Q 0
 S KEY1=$P($G(^BPS(9002313.77,BP77,0)),U,1)
 S KEY2=$P($G(^BPS(9002313.77,BP77,0)),U,2)
 I 'KEY1!(KEY2="") D LOG^BPSOSL(IEN59,$T(+0)_"-Request keys not found for "_BP77) Q 0
 ;
 ; Get lock
 D LOG^BPSOSL(IEN59,$T(+0)_"-Attempting to lock request with keys "_KEY1_", "_KEY2)
 S BPRETV=$$LOCKRF^BPSOSRX(KEY1,KEY2,10,IEN59,$T(+0))
 I 'BPRETV D LOG^BPSOSL(IEN59,$T(+0)_"-Cannot lock keys in REQST99") Q 0
 ;
 ; Mark this request as completed
 N BPNXT77
 S BPRETV=$$COMPLETD^BPSOSRX4(BP77) I +BPRETV=0 D  Q 0
 . D LOG^BPSOSL(IEN59,$T(+0)_"-Cannot change the PROCESS FLAG to COMPLETED: "_$P(BPRETV,U,2))
 . D UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$T(+0))
 D LOG^BPSOSL(IEN59,$T(+0)_"-The request "_BP77_" has been changed to COMPLETED ("_+$P($G(^BPS(9002313.77,BP77,0)),U,4)_")")
 ;
 ; Get the request type and get the next request in the list
 ; For eligibility, do not deleted duplicate request.
 ; For others, do delete duplicate request
 S BPTYPE=$P($G(^BPS(9002313.77,BP77,1)),U,4)
 S BPFLG=$S(BPTYPE="E":0,1:1)
 S BPNXT77=+$$GETNXREQ^BPSOSRX6(BP77,BPFLG,BPFLG,IEN59)
 ;
 ; If this was reversal (UNCLAIM), the next request is "CLAIM", 
 ;   and the RX action is = resubmit (ERES), then this is a submit after reversal
 I BPTYPE="U",$P($G(^BPS(9002313.77,+BPNXT77,1)),U,4)="C",$P($G(^BPS(9002313.77,+BPNXT77,1)),U,1)="ERES" S RESAFTRV=1
 I RESAFTRV=1 D LOG^BPSOSL(IEN59,$T(+0)_"-Reverse then Resubmit attempt")
 ;
 S BPPAYSEQ=$$COB59^BPSUTIL2(IEN59) ;payer sequence
 ;
 ; If not eligibility and the current request failed, then cancel and delete all subsequent requests and quit
 I BPTYPE'="E",$$SUCCESS^BPSOSRX7(BPTYPE,BPCLMST)=0 D  Q 0
 . ; If secondary claim was rejected with certain reject codes - send it to Pharmacy worklist
 . ; DMB-Not sure if this is valid.  Call from BPSOSQL to DURSYNC should have sent these already.
 . I BPTYPE="C",BPPAYSEQ=2 I $$SENDREJ^BPSWRKLS(KEY1,KEY2,IEN59,BPPAYSEQ)
 . D LOG^BPSOSL(IEN59,$T(+0)_"-Current request failed with "_BPCLMST_" - removing this and all sequential requests")
 . I RESAFTRV=1 D LOG^BPSOSL(IEN59,$T(+0)_"-Cannot do Reverse then Resubmit attempt - Reversal status: "_BPCLMST)
 . D DELALLRQ^BPSOSRX7(BP77,IEN59)
 . D UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$T(+0))
 ;
 ; If there is no "next request" for the RX/refill - delete the completed request and quit with 0
 I BPNXT77=0 D  Q 0
 . D LOG^BPSOSL(IEN59,$T(+0)_"-There is no NEXT REQUEST.  Deleting the current request")
 . D DELREQST^BPSOSRX4(BP77,IEN59)
 . D UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$T(+0))
 ;
 ; If there is a NEXT REQUEST
 D LOG^BPSOSL(IEN59,$T(+0)_"-The NEXT "_$P($G(^BPS(9002313.77,+BPNXT77,1)),U,4)_"-type REQUEST is "_BPNXT77)
 ;
 S BPTYPNXT=$P($G(^BPS(9002313.77,+BPNXT77,1)),U,4) ;action type of the next request
 ;
 ; If eligibility, activate the next request
 I BPTYPE="E" S BPRETV=$$ACTIVATE^BPSNCPD4(BPNXT77,"E") G END
 ;
 ; If secondary claim AND action type ="C", don't redo billing determination again, just activate
 I BPPAYSEQ>1,BPTYPNXT="C" S BPRETV=$$ACTIVATE^BPSNCPD4(BPNXT77,"C") G END
 ;
 I RESAFTRV=1 D LOG^BPSOSL(IEN59,$T(+0)_"-Now resubmit")
 S DOS=+$P($G(^BPS(9002313.77,BPNXT77,2)),U)
 S BWHERE=$P($G(^BPS(9002313.77,BPNXT77,1)),U)
 S BILLNDC=$P($G(^BPS(9002313.77,BPNXT77,2)),U,6) ;if we do not send it then BPSNCPDP will get the latest NDC
 S REVREAS=$P($G(^BPS(9002313.77,BPNXT77,2)),U,2)
 S DURREC=""
 S BPDUR=$O(^BPS(9002313.77,BPNXT77,3,"")) I BPDUR S DURREC=^BPS(9002313.77,BPNXT77,3,BPDUR,0)
 S BPOVRIEN=$P($G(^BPS(9002313.77,BPNXT77,2)),U,4)
 S BPSCLARF=$P($G(^BPS(9002313.77,BPNXT77,2)),U,5)
 S BPSAUTH=$P($G(^BPS(9002313.77,BPNXT77,2)),U,7) I BPSAUTH'="" S BPSAUTH=BPSAUTH_U_$P($G(^BPS(9002313.77,BPNXT77,2)),U,8)
 S BPCOBIND=+$P($G(^BPS(9002313.77,BPNXT77,0)),U,3)
 S BPSDELAY=$P($G(^BPS(9002313.77,BPNXT77,2)),U,10)
 ; Call ECME engine in "B" (background) mode to:
 ;   Perform checks if necessary,
 ;   Update billing info if this is a CLAIM
 ;   Activate the request
 S BPRETV=$$EN^BPSNCPDP(KEY1,KEY2,DOS,BWHERE,BILLNDC,REVREAS,DURREC,BPOVRIEN,BPSCLARF,BPSAUTH,BPCOBIND,"B",BPNXT77,"","","","",BPSDELAY)
 ; Code falls through to here but is also called above
END ;
 ; If unsuccessful, deactivate all subsequent request and quit
 I +BPRETV'=0 D  Q 0
 . D LOG^BPSOSL(IEN59,$T(+0)_"-Cannot activate the next request: "_$P(BPRETV,U,2))
 . D DELALLRQ^BPSOSRX7(BP77,IEN59)
 . D UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$T(+0))
 ; If was successful, do the next steps:
 ;   Log an entry
 ;   Delete the completed request
 ;   Run background process, if neeeded 
 D LOG^BPSOSL(IEN59,$T(+0)_"-The NEXT "_$P($G(^BPS(9002313.77,+BPNXT77,1)),U,4)_"-type REQUEST "_BPNXT77_" has been activated")
 D DELREQST^BPSOSRX4(BP77,IEN59)
 D UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$T(+0))
 ; Run background process to pick up the activated request for secondary claim (for primary only - it is done when we call EN^BPSNCPDP above)
 I BPTYPNXT="E"!(BPPAYSEQ>1&(BPTYPNXT="C")) D RUNNING^BPSOSRX()
 Q BPNXT77
 ;BPSOSRX5
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HBPSOSRX5   8364     printed  Sep 23, 2025@19:28:16                                                                                                                                                                                                    Page 2
BPSOSRX5  ;ALB/SS - ECME REQUESTS ;10-JAN-08
 +1       ;;1.0;E CLAIMS MGMT ENGINE;**7,8,10,11,20**;JUN 2004;Build 27
 +2       ;;Per VA Directive 6402, this routine should not be modified.
 +3       ;
 +4       ;check if according the last response the payer IS going to PAY
 +5       ;(Note: reversals can be done only on previously payable claims, if reversal failed then the claim stays PAYABLE)
PAYABLE(BPRESP) ;
 +1        QUIT ",E PAYABLE,E DUPLICATE,E REVERSAL REJECTED,E REVERSAL OTHER,E REVERSAL UNSTRANDED,"[(","_BPRESP_",")
 +2       ;
 +3       ;Action type
ACTTYPE(BWHR) ;
 +1       ;UNCLAIM (reversal)
           if ",AREV,CRLR,CRLX,DC,DE,EREV,HLD,OREV,RS,"[(","_BWHR_",")
               QUIT "U"
 +2       ;UNCLAIM (reversal) + CLAIM (resubmit)
           if ",CRLB,ED,ERES,P2S,"[(","_BWHR_",")
               QUIT "UC"
 +3       ;CLAIM (the very first submit OR resubmit only)
           if ",BB,CRRL,ERWV,ERNB,OF,PC,PE,PL,PP,RF,RN,RRL,RSNB,P2,"[(","_BWHR_",")
               QUIT "C"
 +4        if BWHR="ELIG"
               QUIT "E"
 +5       ;unknown
           QUIT ""
 +6       ;
 +7       ;Check ECME availability at the site
 +8       ;return :
 +9       ; 1^CLMSTAT -off
 +10      ; null -on
ECMESITE(SITE) ;
 +1        IF '$GET(SITE)
               QUIT "1^No Site Information"
 +2        IF '$$ECMEON^BPSUTIL(SITE)
               QUIT "1^ECME switch is not on for the site"
 +3        QUIT ""
 +4       ;
 +5       ; This is called by STATUS99^BPSOSU when the status of the current claim becomes 99%.
 +6       ; The purpose is to decide what to with the new next request in the chain
 +7       ;
 +8       ; Example:
 +9       ;  If this request (Request A) is the last one in the chain and we just received a new request
 +10      ;   (Request B) for the same keys, then Request B needs to be activated after Request A has been completed.  Who will do this?
 +11      ;  Situation 1:
 +12      ;    If this code REQST99^BPSOSRX5 gets the lock first then it will not be able to activate Request B (because we
 +13      ;    don't have it in the NEXT REQUEST field). So Request A will be completed and when the REQST^BPSOSRX code gets
 +14      ;    the lock it will find Request A marked as completed and will not populate the NEXT REQUEST field of Request A.
 +15      ;    Instead it will just activate Request B.
 +16      ;  Situation 2:
 +17      ;    If the REQST^BPSOSRX code gets the lock first then it will check the status of the Request A and since it is
 +18      ;    still "IN PROCESS", then it will populate the NEXT REQUEST field of the Request 1 with ien of Request 2, and
 +19      ;    then release the lock.  Then when the REQST99^BPSOSRX5 gets the lock it checks the NEXT REQUEST field and
 +20      ;    activate the request 2
 +21      ;
 +22      ;Input:
 +23      ;IEN59 - BPS TRANSACTION IEN
 +24      ;BPCLMST - claim status
 +25      ;     For Billing Requests (type= C):
 +26      ;       E PAYABLE, E CAPTURED, E DUPLICATE, E REJECTED, E OTHER, and
 +27      ;       E UNSTRANDED
 +28      ;
 +29      ;     For Reversals (type=U):
 +30      ;       E REVERSAL ACCEPTED, E REVERSAL REJECTED, E REVERSAL OTHER, and
 +31      ;       E REVERSAL UNSTRANDED
 +32      ;
 +33      ;     For Eligibility (type=E):
 +34      ;       E ELIGIBILITY ACCEPTED, E ELIGIBILITY REJECTED, E ELIGIBILITY OTHER, and
 +35      ;       E ELIGIBILITY UNSTRANDED
 +36      ;
 +37      ;Output:
 +38      ; return 0 if there is no next request
 +39      ; otherwise - return IEN of next BPS REQUEST
REQST99(IEN59,BPCLMST) ;
 +1        NEW BP77,KEY1,KEY2,BPRETV,BPTYPE,RESAFTRV,BPPAYSEQ,BPTYPNXT,BPFLG
 +2        NEW DOS,BWHERE,BILLNDC,REVREAS,DURREC,BPOVRIEN,BPSCLARF,BPSAUTH,BPSDELAY,BPCOBIND,BPDUR
 +3        SET RESAFTRV=0
 +4        IF '$GET(IEN59)
               DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Transaction IEN not passed in")
               QUIT 0
 +5        SET BPCLMST=$GET(BPCLMST)
 +6       ;
 +7       ; Get Keys to the request file
 +8        SET BP77=$$GETRQST^BPSUTIL2(IEN59)
 +9        IF 'BP77
               DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-BPS Request Pointer not found")
               QUIT 0
 +10       SET KEY1=$PIECE($GET(^BPS(9002313.77,BP77,0)),U,1)
 +11       SET KEY2=$PIECE($GET(^BPS(9002313.77,BP77,0)),U,2)
 +12       IF 'KEY1!(KEY2="")
               DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Request keys not found for "_BP77)
               QUIT 0
 +13      ;
 +14      ; Get lock
 +15       DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Attempting to lock request with keys "_KEY1_", "_KEY2)
 +16       SET BPRETV=$$LOCKRF^BPSOSRX(KEY1,KEY2,10,IEN59,$TEXT(+0))
 +17       IF 'BPRETV
               DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Cannot lock keys in REQST99")
               QUIT 0
 +18      ;
 +19      ; Mark this request as completed
 +20       NEW BPNXT77
 +21       SET BPRETV=$$COMPLETD^BPSOSRX4(BP77)
           IF +BPRETV=0
               Begin DoDot:1
 +22               DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Cannot change the PROCESS FLAG to COMPLETED: "_$PIECE(BPRETV,U,2))
 +23               DO UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$TEXT(+0))
               End DoDot:1
               QUIT 0
 +24       DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-The request "_BP77_" has been changed to COMPLETED ("_+$PIECE($GET(^BPS(9002313.77,BP77,0)),U,4)_")")
 +25      ;
 +26      ; Get the request type and get the next request in the list
 +27      ; For eligibility, do not deleted duplicate request.
 +28      ; For others, do delete duplicate request
 +29       SET BPTYPE=$PIECE($GET(^BPS(9002313.77,BP77,1)),U,4)
 +30       SET BPFLG=$SELECT(BPTYPE="E":0,1:1)
 +31       SET BPNXT77=+$$GETNXREQ^BPSOSRX6(BP77,BPFLG,BPFLG,IEN59)
 +32      ;
 +33      ; If this was reversal (UNCLAIM), the next request is "CLAIM", 
 +34      ;   and the RX action is = resubmit (ERES), then this is a submit after reversal
 +35       IF BPTYPE="U"
               IF $PIECE($GET(^BPS(9002313.77,+BPNXT77,1)),U,4)="C"
                   IF $PIECE($GET(^BPS(9002313.77,+BPNXT77,1)),U,1)="ERES"
                       SET RESAFTRV=1
 +36       IF RESAFTRV=1
               DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Reverse then Resubmit attempt")
 +37      ;
 +38      ;payer sequence
           SET BPPAYSEQ=$$COB59^BPSUTIL2(IEN59)
 +39      ;
 +40      ; If not eligibility and the current request failed, then cancel and delete all subsequent requests and quit
 +41       IF BPTYPE'="E"
               IF $$SUCCESS^BPSOSRX7(BPTYPE,BPCLMST)=0
                   Begin DoDot:1
 +42      ; If secondary claim was rejected with certain reject codes - send it to Pharmacy worklist
 +43      ; DMB-Not sure if this is valid.  Call from BPSOSQL to DURSYNC should have sent these already.
 +44                   IF BPTYPE="C"
                           IF BPPAYSEQ=2
                               IF $$SENDREJ^BPSWRKLS(KEY1,KEY2,IEN59,BPPAYSEQ)
 +45                   DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Current request failed with "_BPCLMST_" - removing this and all sequential requests")
 +46                   IF RESAFTRV=1
                           DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Cannot do Reverse then Resubmit attempt - Reversal status: "_BPCLMST)
 +47                   DO DELALLRQ^BPSOSRX7(BP77,IEN59)
 +48                   DO UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$TEXT(+0))
                   End DoDot:1
                   QUIT 0
 +49      ;
 +50      ; If there is no "next request" for the RX/refill - delete the completed request and quit with 0
 +51       IF BPNXT77=0
               Begin DoDot:1
 +52               DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-There is no NEXT REQUEST.  Deleting the current request")
 +53               DO DELREQST^BPSOSRX4(BP77,IEN59)
 +54               DO UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$TEXT(+0))
               End DoDot:1
               QUIT 0
 +55      ;
 +56      ; If there is a NEXT REQUEST
 +57       DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-The NEXT "_$PIECE($GET(^BPS(9002313.77,+BPNXT77,1)),U,4)_"-type REQUEST is "_BPNXT77)
 +58      ;
 +59      ;action type of the next request
           SET BPTYPNXT=$PIECE($GET(^BPS(9002313.77,+BPNXT77,1)),U,4)
 +60      ;
 +61      ; If eligibility, activate the next request
 +62       IF BPTYPE="E"
               SET BPRETV=$$ACTIVATE^BPSNCPD4(BPNXT77,"E")
               GOTO END
 +63      ;
 +64      ; If secondary claim AND action type ="C", don't redo billing determination again, just activate
 +65       IF BPPAYSEQ>1
               IF BPTYPNXT="C"
                   SET BPRETV=$$ACTIVATE^BPSNCPD4(BPNXT77,"C")
                   GOTO END
 +66      ;
 +67       IF RESAFTRV=1
               DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Now resubmit")
 +68       SET DOS=+$PIECE($GET(^BPS(9002313.77,BPNXT77,2)),U)
 +69       SET BWHERE=$PIECE($GET(^BPS(9002313.77,BPNXT77,1)),U)
 +70      ;if we do not send it then BPSNCPDP will get the latest NDC
           SET BILLNDC=$PIECE($GET(^BPS(9002313.77,BPNXT77,2)),U,6)
 +71       SET REVREAS=$PIECE($GET(^BPS(9002313.77,BPNXT77,2)),U,2)
 +72       SET DURREC=""
 +73       SET BPDUR=$ORDER(^BPS(9002313.77,BPNXT77,3,""))
           IF BPDUR
               SET DURREC=^BPS(9002313.77,BPNXT77,3,BPDUR,0)
 +74       SET BPOVRIEN=$PIECE($GET(^BPS(9002313.77,BPNXT77,2)),U,4)
 +75       SET BPSCLARF=$PIECE($GET(^BPS(9002313.77,BPNXT77,2)),U,5)
 +76       SET BPSAUTH=$PIECE($GET(^BPS(9002313.77,BPNXT77,2)),U,7)
           IF BPSAUTH'=""
               SET BPSAUTH=BPSAUTH_U_$PIECE($GET(^BPS(9002313.77,BPNXT77,2)),U,8)
 +77       SET BPCOBIND=+$PIECE($GET(^BPS(9002313.77,BPNXT77,0)),U,3)
 +78       SET BPSDELAY=$PIECE($GET(^BPS(9002313.77,BPNXT77,2)),U,10)
 +79      ; Call ECME engine in "B" (background) mode to:
 +80      ;   Perform checks if necessary,
 +81      ;   Update billing info if this is a CLAIM
 +82      ;   Activate the request
 +83       SET BPRETV=$$EN^BPSNCPDP(KEY1,KEY2,DOS,BWHERE,BILLNDC,REVREAS,DURREC,BPOVRIEN,BPSCLARF,BPSAUTH,BPCOBIND,"B",BPNXT77,"","","","",BPSDELAY)
 +84      ; Code falls through to here but is also called above
END       ;
 +1       ; If unsuccessful, deactivate all subsequent request and quit
 +2        IF +BPRETV'=0
               Begin DoDot:1
 +3                DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-Cannot activate the next request: "_$PIECE(BPRETV,U,2))
 +4                DO DELALLRQ^BPSOSRX7(BP77,IEN59)
 +5                DO UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$TEXT(+0))
               End DoDot:1
               QUIT 0
 +6       ; If was successful, do the next steps:
 +7       ;   Log an entry
 +8       ;   Delete the completed request
 +9       ;   Run background process, if neeeded 
 +10       DO LOG^BPSOSL(IEN59,$TEXT(+0)_"-The NEXT "_$PIECE($GET(^BPS(9002313.77,+BPNXT77,1)),U,4)_"-type REQUEST "_BPNXT77_" has been activated")
 +11       DO DELREQST^BPSOSRX4(BP77,IEN59)
 +12       DO UNLCKRF^BPSOSRX(KEY1,KEY2,IEN59,$TEXT(+0))
 +13      ; Run background process to pick up the activated request for secondary claim (for primary only - it is done when we call EN^BPSNCPDP above)
 +14       IF BPTYPNXT="E"!(BPPAYSEQ>1&(BPTYPNXT="C"))
               DO RUNNING^BPSOSRX()
 +15       QUIT BPNXT77
 +16      ;BPSOSRX5