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

BPSNCPDP.m

Go to the documentation of this file.
  1. BPSNCPDP ;BHAM ISC/LJE/SS - API to submit a claim to ECME ;11/7/07 16:58
  1. ;;1.0;E CLAIMS MGMT ENGINE;**1,3,4,2,5,6,7,8,10,11,19,20,22**;JUN 2004;Build 28
  1. ;;Per VA Directive 6402, this routine should not be modified.
  1. ;
  1. ; Reference to $$PROD^XUPROD supported by DBIA 4440
  1. ; Reference to $$GETNDC^PSONDCUT supported by DBIA 4705
  1. ; Reference to Patient file (#2) supported by DBIA 10035
  1. ;
  1. ; For comments regarding this API, see routine BPSNCPD3.
  1. ;
  1. EN(BRXIEN,BFILL,DOS,BWHERE,BILLNDC,REVREAS,DURREC,BPOVRIEN,BPSCLARF,BPSAUTH,BPCOBIND,BPJOBFLG,BPREQIEN,BPSCLOSE,BPSPLAN,BPSPRDAT,BPSRTYPE,BPSDELAY) ;
  1. N BPRETV,CLMSTAT,BRX,RESPONSE,BPSCOB,IEN59,DFN,PNAME,WFLG,BPLCK,BPACTTYP,BPRET,BPSQUIT,SITE
  1. N BPNEWCLM,OLDRESP,BPPAYABL,BPSTART,BPRESLT,BPSELIG,BP77NEW,TODAY,BPPREVRQ,BPSSTAT
  1. ; test not ecme active
  1. I '$$PROD^XUPROD,'$P($G(^BPS(9002313.99,1,0)),"^",3) Q "1^ECME switch is not on for the site"
  1. ;== Set default values and other required vars
  1. ; default is foreground ("F")
  1. S BPJOBFLG=$S($G(BPJOBFLG)="":"F",1:$G(BPJOBFLG))
  1. S RESPONSE="",CLMSTAT="",BP77NEW=0
  1. S BPLCK=0 ;0 - default for "B" jobs
  1. S REVREAS=$G(REVREAS),DURREC=$G(DURREC),BPSCLARF=$G(BPSCLARF),BPSAUTH=$G(BPSAUTH),BPOVRIEN=$G(BPOVRIEN),BPSDELAY=$G(BPSDELAY)
  1. ; BPCOBIND will be used as a flag to indicate the following
  1. ; If BPCOBIND>0 then the API is called for the particular COB claim
  1. ; if BPCOBIND=0 then the API is called for a whole RX/RF - Outpatient Pharmacy doesn't care about COB
  1. ; when the pharmacy user enters, deletes or edits RX/refills
  1. S BPCOBIND=+$G(BPCOBIND)
  1. ;
  1. ; BPSCOB variable will be used to store COB value (default is PRIMARY) in this function only
  1. S BPSCOB=$S(BPCOBIND>0:BPCOBIND,1:1)
  1. ;
  1. ; Remove semi-colons from reversal reason BPS*1*20
  1. S REVREAS=$TR(REVREAS,";","-")
  1. ;
  1. ; Default is original fill
  1. S BRXIEN=$G(BRXIEN)
  1. I '$G(BFILL) S BFILL=0
  1. ;
  1. ; Get prescription number
  1. S BRX=$$RXAPI1^BPSUTIL1(BRXIEN,.01,"I")
  1. ;
  1. ; Make sure fill date is not in the future or empty
  1. S TODAY=$$DT^XLFDT
  1. I '$G(DOS)!($G(DOS)>TODAY) S DOS=$$DOSDATE^BPSSCRRS(BRXIEN,BFILL)
  1. ;
  1. ; Get the NDC if it was not passed in
  1. I $G(BILLNDC)="" S BILLNDC=$$GETNDC^PSONDCUT(BRXIEN,BFILL)
  1. ;
  1. ; Patient Info
  1. S DFN=$$RXAPI1^BPSUTIL1(BRXIEN,2,"I"),PNAME=$$GET1^DIQ(2,DFN,.01)
  1. ;
  1. ; Check parameters and vars
  1. S BPRETV=$$CHCKPAR^BPSOSRX8(BRXIEN,BRX,$G(BWHERE),DFN,PNAME) I +BPRETV=0 S CLMSTAT=$P(BPRETV,U,2),RESPONSE=5 G END
  1. ;
  1. ; Calculate IEN59
  1. S IEN59=$$IEN59^BPSOSRX(BRXIEN,BFILL,BPSCOB) I IEN59="" S CLMSTAT="BPS Transaction IEN could not be calculated",RESPONSE=1 G END
  1. ;
  1. ;populate COB fields from BPS TRANSACTION to resubmit secondary claims from the User Screen
  1. ;if $G(BPSPRDAT("NEW COB DATA"))=1 then the resubmit requested from the BPS COB PROCESS SECOND TRICARE and the user can change the data
  1. I BPSCOB=2,$$ACTTYPE^BPSOSRX5(BWHERE)="UC",'$G(BPSPRDAT("NEW COB DATA")) N:$D(BPSRTYPE)=0 BPSRTYPE N:$D(BPSPLAN)=0 BPSPLAN N:$D(BPSPRDAT)=0 BPSPRDAT I $$SECDATA^BPSPRRX6(BRXIEN,BFILL,.BPSPLAN,.BPSPRDAT,.BPSRTYPE)=0 D G END
  1. . S CLMSTAT="Insufficient data to resubmit the secondary claim, use Process Secondary/TRICARE Rx to ECME option.",RESPONSE=5
  1. ;
  1. ; Initialize log
  1. D LOG^BPSOSL(IEN59,$T(+0)_"-Start of claim","DT")
  1. D LOG^BPSOSL(IEN59,$T(+0)_"-BWHERE = "_BWHERE)
  1. D LOG^BPSOSL(IEN59,$T(+0)_"-Job flag = "_BPJOBFLG_$S(BPJOBFLG="B":" BPS REQUEST ien = "_$G(BPREQIEN),1:""))
  1. ;
  1. ; Check if we need to print the messages to the screen (WFLG=1 : YES)
  1. S WFLG=0
  1. S:BPJOBFLG="F" WFLG=$$PRINTSCR^BPSOSRX8(BWHERE)
  1. ;
  1. ; Lock the Rx and Fill while putting it on the queue to prevent two jobs from being
  1. ; activated at the same time. This is only for foreground jobs.
  1. ; Background jobs are called from REQST99^BPSOSRX5 and the RX/RF should be already locked by this point.
  1. I BPJOBFLG="F" D I 'BPLCK G END
  1. . S BPLCK=$$LOCKRF^BPSOSRX(BRXIEN,BFILL,10,$G(IEN59),$T(+0))
  1. . I 'BPLCK S RESPONSE=4,CLMSTAT="Unable to acquire the lock needed to put the RX and fill on the queue"
  1. ;
  1. ; Determine the action type
  1. ; If foreground job then can be C,U and UC actions types
  1. S BPACTTYP=""
  1. I BPJOBFLG="F" S BPACTTYP=$$ACTTYPE^BPSOSRX5(BWHERE)
  1. ;if background/unqueueing job then only two action types are allowed - C and U
  1. I BPJOBFLG="B" D I RESPONSE=5 G END
  1. . S BPACTTYP=$P($G(^BPS(9002313.77,+$G(BPREQIEN),1)),U,4)
  1. . I BPACTTYP="" S RESPONSE=5,CLMSTAT="Unknown Action type in BPS REQUEST ien="_BPREQIEN
  1. ;
  1. ;code to handle "general" submit/reversal as opposed to processing a claim for a specific payer sequence (primary, secondary)
  1. ;ECME and IB always know the payer sequence and always should set the proper BPCOBIND parameter
  1. ;thus if BPCOBIND=0 then the API is called by Pharmacy. If so then the CLAIM action (not reversal) should be done for primary only.
  1. S BPSQUIT=0
  1. I BPCOBIND=0 D I BPSQUIT=1 S CLMSTAT="The secondary claim needs to be reversed first.",RESPONSE=5 G END
  1. . I BPACTTYP=""!(BPACTTYP="C") S BPCOBIND=1 Q
  1. . ;code to handle "general" reversal
  1. . N BPSECLM
  1. . ;check if there is the secondary e-claim
  1. . S BPSECLM=$$FINDECLM^BPSPRRX5(BRXIEN,BFILL,2)
  1. . ;quit if we have secondary claim and it is payable or in progress - it needs to be reversed first
  1. . I BPSECLM=1!(BPSECLM=3) S BPSQUIT=1
  1. . S BPCOBIND=1
  1. ;
  1. ;== IF BPJOBFLG="F" THEN determine if there are any scheduled/active/in process requests for the RX/RF
  1. ;CHKREQST^BPSOSRX7 returns
  1. ; negative number^message : cannot be accepted for some reason
  1. ; 0 : can be accepted because there are NO requests for this RX/RF,
  1. ; we will create a new record in BPS REQUEST for it and ACTIVATE it.
  1. ; 1 : there are ACTIVATED/IN PROCESS requests already for this RX/RF
  1. S BPPREVRQ="-10^Background queuing." ;default
  1. I BPJOBFLG="F" D I BPPREVRQ'=0 G STATUS:RESPONSE=0,END:RESPONSE>0
  1. . S BPPREVRQ=$$CHKREQST^BPSOSRX7(BRXIEN,BFILL,.BPRESLT)
  1. . D LOG^BPSOSL(IEN59,$T(+0)_"-CHKREQ^BPSOSRX7 result: "_BPPREVRQ)
  1. . ;if error
  1. . I BPPREVRQ<0 S RESPONSE=4,CLMSTAT=$P(BPPREVRQ,U,2) D LOG^BPSOSL(IEN59,$T(+0)_"- - Cannot be accepted because of issues with already scheduled requests")
  1. . ;if there are prior requests for the RX/RF in the queue already then schedule additional request(s)
  1. . ;for the future and quit since we do not know the result of prior requests
  1. . I BPPREVRQ>0 D
  1. . . D LOG^BPSOSL(IEN59,$T(+0)_"-There are requests in the queue, do not process - schedule additional request(s)")
  1. . . I BPACTTYP="U" S BPRET=$$SCHREQ^BPSNCPD5(.BP77NEW,BRXIEN,BFILL,DOS,BWHERE,$G(BILLNDC),REVREAS,DURREC,BPOVRIEN,BPSCLARF,BPSAUTH,BPSDELAY,IEN59,BPCOBIND,BPPREVRQ,"U",.BPSCLOSE,$G(BPSRTYPE),$G(BPSPLAN),.BPSPRDAT)
  1. . . I BPACTTYP="UC" D
  1. . . . S BPRET=$$SCHREQ^BPSNCPD5(.BP77NEW,BRXIEN,BFILL,DOS,BWHERE,$G(BILLNDC),REVREAS,DURREC,BPOVRIEN,BPSCLARF,BPSAUTH,BPSDELAY,IEN59,BPCOBIND,BPPREVRQ,"U",.BPSCLOSE,$G(BPSRTYPE),$G(BPSPLAN),.BPSPRDAT)
  1. . . . I +BPRET=0 S BPRET=$$SCHREQ^BPSNCPD5(.BP77NEW,BRXIEN,BFILL,DOS,BWHERE,$G(BILLNDC),REVREAS,DURREC,BPOVRIEN,BPSCLARF,BPSAUTH,BPSDELAY,IEN59,BPCOBIND,BP77NEW,"C",.BPSCLOSE,$G(BPSRTYPE),$G(BPSPLAN),.BPSPRDAT)
  1. . . I BPACTTYP="C" S BPRET=$$SCHREQ^BPSNCPD5(.BP77NEW,BRXIEN,BFILL,DOS,BWHERE,$G(BILLNDC),REVREAS,DURREC,BPOVRIEN,BPSCLARF,BPSAUTH,BPSDELAY,IEN59,BPCOBIND,BPPREVRQ,"C",.BPSCLOSE,$G(BPSRTYPE),$G(BPSPLAN),.BPSPRDAT)
  1. . . I +BPRET=0 S RESPONSE=0,CLMSTAT=$P(BPRET,U,2) D LOG^BPSOSL(IEN59,$T(+0)_"-The new request(s) scheduled. The last one for the RX/RF now is: "_(BP77NEW)) Q
  1. . . I +BPRET>0 S RESPONSE=+BPRET,CLMSTAT=$P(BPRET,U,2) D LOG^BPSOSL(IEN59,$T(+0)_"-Cannot create request(s)")
  1. ;
  1. ;== So we can continue only if either
  1. ; BPJOBFLG="B"
  1. ; or
  1. ; BPJOBFLG="F" and BPPREVRQ=0
  1. ;
  1. ; If a new RX/RF - i.e. RX/RF was never processed thru ECME - process and quit
  1. S BPNEWCLM=$S(+$G(^BPST(IEN59,0)):0,1:1)
  1. ; get pre-existing RX/RFs status
  1. S OLDRESP=$P($$STATUS^BPSOSRX(BRXIEN,BFILL,0,,BPSCOB),U,1)
  1. ; check if the payer IS going to PAY according the last response
  1. S BPPAYABL=$$PAYABLE^BPSOSRX5(OLDRESP)
  1. ; set starttime
  1. S BPSTART=$$STTM^BPSNCPD4()
  1. ;
  1. ; if this is a new RX/RF
  1. I BPNEWCLM D NEWCLAIM^BPSNCPD6 G STATUS:RESPONSE=0,END:RESPONSE>0
  1. ;
  1. ; if we do not have a status for the previous claim AND this is not a reversal request - treat it as a new claim
  1. ; this will be the case when resubmitting a non-billable entry (bps*1*20)
  1. I (OLDRESP=""),(BPACTTYP'="U") D NEWCLAIM^BPSNCPD6 G STATUS:RESPONSE=0,END:RESPONSE>0
  1. ;
  1. ; if we do not have a status for the pre-existing claim AND this is a reversal request - DO NOT reverse
  1. I (OLDRESP=""),(BPACTTYP="U") D RVNEW^BPSNCPD6 G END
  1. ;
  1. ;== Further below - all claims with some response (i.e. OLDRESP]""=1)
  1. ;
  1. ; if Back Billing - impossible
  1. I BWHERE="BB" D BB^BPSNCPD6 G END
  1. ;
  1. ; If returning to stock or deleting and the previous claim was not paid, then no reversal is needed
  1. ; so close the prescription and quit
  1. ; Note: this is inherited "fuzzy logic" -
  1. ; it checks only two statuses to determine that the claim "was not paid"
  1. I OLDRESP'["E PAYABLE",OLDRESP'["E REVERSAL REJECTED",(",RS,DE,"[(","_BWHERE_",")) D G END
  1. . D CLOSE2^BPSBUTL(BRXIEN,BFILL,BWHERE)
  1. . S RESPONSE=3
  1. . S CLMSTAT="Claim was not payable so it has been closed. No ECME claim created."
  1. . D DISPL^BPSNCPD4(WFLG,RESPONSE_U_CLMSTAT_"^D^2",$G(BPSELIG))
  1. . D LOG^BPSOSL(IEN59,$T(+0)_"-"_CLMSTAT)
  1. ;
  1. ; Reversals for Payable claims
  1. ; (Note: BPSCLOSE can be used in this case only)
  1. I BPPAYABL,BPACTTYP="U" D RVPAID^BPSNCPD6 G STATUS:RESPONSE=0,END:RESPONSE>0
  1. ;
  1. ; Resubmits without doing a Reversal - special hidden action on ECME User Screen (BPS*1*20)
  1. I BWHERE="ERWV" D RVRSNPD^BPSNCPD6 G STATUS:RESPONSE=0,END:RESPONSE>0
  1. ;
  1. ; Reversals+Resubmits for Payable claims
  1. I BPPAYABL,BPACTTYP="UC" D RVRSPAID^BPSNCPD6 G STATUS:((RESPONSE=0)!(RESPONSE=10)),END:RESPONSE>0
  1. ;
  1. ; Resubmits for Payable claims - DO NOT resubmit
  1. I BPPAYABL,BPACTTYP="C" D RSPAID^BPSNCPD6 G END
  1. ;
  1. ; Reversals for Non-Payable claims - DO NOT reverse
  1. I 'BPPAYABL,BPACTTYP="U" D RVNPAID^BPSNCPD6 G END
  1. ;
  1. ; Resubmits AND Reversals+Resubmits for Non-Payable claims
  1. I 'BPPAYABL,((BPACTTYP="C")!(BPACTTYP="UC")) D RVRSNPD^BPSNCPD6 G STATUS:RESPONSE=0,END:RESPONSE>0
  1. ;
  1. S RESPONSE=5,CLMSTAT="Unknown error"
  1. G END
  1. ;
  1. ;== Display status
  1. STATUS ;
  1. ;if successful scheduling or/and activation of the request then make sure the background job is running
  1. I BPJOBFLG="F",BPLCK D UNLCKRF^BPSOSRX(BRXIEN,BFILL,$G(IEN59),$T(+0)) S BPLCK=0 ;to prevent unlocking in END
  1. I (RESPONSE=0)!(RESPONSE=10) D LOG^BPSOSL(IEN59,$T(+0)_"-Call RUNNING^BPSOSRX") D RUNNING^BPSOSRX()
  1. I WFLG W !!,"Processing ",$S(BPSCOB=1:"Primary claim...",BPSCOB=2:"Secondary claim...",1:"claim with Unknown Payer Sequence...")
  1. I BPJOBFLG="F" D
  1. . ; If the Write Flag is off and this is TRICARE/CHAMPVA, set Write Flag to 2
  1. . ; STATUS^BPSNCPD1 will not display messages but will wait the same amount of time as if it were writing messages
  1. . ; This needs to be done so that TRICARE/CHAMPVA claims get a chance to complete before continuing
  1. . ; Otherwise, the claim will be IN PROGRESS, which will create the bulletin (code below) and OP/CMOP will
  1. . ; not process correctly (keep on suspense queue, etc)
  1. . I 'WFLG,$G(BPSELIG)="T"!($G(BPSELIG)="C") S WFLG=2
  1. . I 'WFLG H 1
  1. . E D STATUS^BPSNCPD1(BRXIEN,BFILL,+$G(BPPAYABL),$S(BPACTTYP="U":1,1:0),BPSTART,BWHERE,$G(BP77NEW),BPSCOB,$G(BPSELIG),IEN59,WFLG)
  1. ;
  1. ;== Clean up and quit
  1. END ;
  1. ; BPSELIG and other variables are established by inference in BPSNCPD6.
  1. I BPJOBFLG="F",BPLCK D UNLCKRF^BPSOSRX(BRXIEN,BFILL,$G(IEN59),$T(+0)) S BPLCK=0
  1. ; Get Site in case we send a Bulletin
  1. S SITE=$$GETSITE^BPSOSRX8(BRXIEN,BFILL)
  1. ;if foreground AND we can't schedule request for any reason AND this is not OP - send bulletin
  1. I BPJOBFLG="F",RESPONSE=4,",AREV,BB,ERES,ERWV,ERNB,EREV,P2,P2S,"'[(","_BWHERE_",") D BULL^BPSNCPD1(BRXIEN,BFILL,$G(SITE),$G(DFN),$G(PNAME),"",$G(CLMSTAT),$G(RESPONSE),$G(BPSCOB))
  1. I $G(BPSELIG)="" S BPSELIG=""
  1. ; Send Bulletin if TRICARE or CHAMPVA is IN PROGRESS and this is not a release process
  1. S BPSSTAT=$S($G(BRXIEN):$P($$STATUS^BPSOSRX(BRXIEN,BFILL,,,BPSCOB),U),1:"")
  1. ;
  1. I $G(IEN59) D
  1. . D LOG^BPSOSL(IEN59,$T(+0)_"-Nearing end of first process, BPSELIG="_BPSELIG_", BPSSTAT="_BPSSTAT)
  1. . I BPSELIG="T"!(BPSELIG="C"),BPSSTAT="IN PROGRESS",$G(REVREAS)'="RX RELEASE-NDC CHANGE",BWHERE="PC" D LOG^BPSOSL(IEN59,$T(+0)_"-Would have sent bulletin")
  1. ;
  1. I BPSELIG="T"!(BPSELIG="C"),BPSSTAT="IN PROGRESS",$G(REVREAS)'="RX RELEASE-NDC CHANGE",",CRLB,CRLR,CRLX,CRRL,PC,RRL,"'[(","_BWHERE_",") D BULL^BPSNCPD1(BRXIEN,BFILL,SITE,$G(DFN),$G(PNAME),BPSELIG,"","",$G(BPSCOB))
  1. ;
  1. S:'$D(RESPONSE) RESPONSE=1
  1. K MOREDATA
  1. I $G(IEN59) D
  1. . N MSG
  1. . S MSG="First Process Complete-RESPONSE="_$G(RESPONSE)
  1. . I $G(RESPONSE)'=0 S MSG=MSG_", CLMSTAT="_$G(CLMSTAT)
  1. . D LOG^BPSOSL(IEN59,$T(+0)_"-"_MSG)
  1. ;
  1. ; The function $$ECMESND returns the following:
  1. ; Response ^ Message ^ Eligibility ^ Claim Status ^ COB ^
  1. ; RxCOB ^ Insurance
  1. ; Response =
  1. ; 0 Submitted through ECME
  1. ; 1 No submission through ECME
  1. ; 2 IB not billable
  1. ; 3 Claim was closed, not submitted (RTS/Deletes)
  1. ; 4 Unable to queue claim
  1. ; 5 Incorrect information supplied to ECME
  1. ; 6 Inactive ECME - Primarily used for TRICARE/CHAMPVA to
  1. ; say ok to process Rx
  1. ; 10 Reversal but no resubmit
  1. ; Message = Message indicating whether the claim was submitted
  1. ; Eligibility = V, Veteran; T, TRICARE; C, CHAMPVA
  1. ; Claim Status = IN PROGRESS if incomplete; final status (e.g.
  1. ; E PAYABLE or E REJECTED) if complete; null if non-billable
  1. ; COB = COB indicator as stored in the INSURANCE TYPE sub-file
  1. ; of the PATIENT file
  1. ; RxCOB = COB indicator sent to the payer and stored in the
  1. ; BPS TRANSACTIONS file
  1. ; Insurance = Name of the insurance company that was billed as
  1. ; a result of this call
  1. ;
  1. Q RESPONSE_U_$G(CLMSTAT)_U_BPSELIG_U_BPSSTAT_U_$$CLMINFO^BPSUTIL2(+$G(IEN59))
  1. ;
  1. ;BPSNCPDP