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

BPSOSU.m

Go to the documentation of this file.
  1. BPSOSU ;BHAM ISC/FCS/DRS/FLS - Common utilities ;06/01/2004
  1. ;;1.0;E CLAIMS MGMT ENGINE;**1,2,5,7,10,20,27,31**;JUN 2004;Build 16
  1. ;;Per VA Directive 6402, this routine should not be modified.
  1. Q
  1. ; Common utilities called a lot.
  1. ;
  1. ; SETSTAT - set status field for ^BPST(IEN59,
  1. ; Input:
  1. ; IEN59 - BPS Transaction
  1. ; STATUS - Value to set into BPS Transaction
  1. SETSTAT(IEN59,STATUS) ; EP - from many places
  1. ;
  1. ; Lock the record - something is very wrong if you can't get the lock
  1. F L +^BPST(IEN59):300 Q:$T Q:'$$IMPOSS^BPSOSUE("L","RTI","LOCK +^BPST",,"SETSTAT",$T(+0))
  1. N DIE,DA,DR,X
  1. S DIE=9002313.59,DA=IEN59,DR="1///"_STATUS_";7///NOW" ; Status and Last Update
  1. I STATUS=0 S DR=DR_";15///NOW" ; If Status is 0, init START TIME
  1. D ^DIE
  1. ;
  1. ; Verify that there no other statuses in the X-ref
  1. S X=""
  1. F S X=$O(^BPST("AD",X)) Q:X="" D
  1. . I X'=STATUS K ^BPST("AD",X,IEN59)
  1. I STATUS=99 D STATUS99(IEN59)
  1. L -^BPST(IEN59)
  1. Q
  1. ;
  1. ; STATUS99 - Special activity when a claim reaches status 99
  1. ; Input:
  1. ; IEN59 - BPS Transaction IEN
  1. STATUS99(IEN59) ;
  1. N IEN77,BPS57,CLMSTAT,BPNXTREQ,BPSCLNOD,BPTYPE
  1. ;
  1. ; check and process non-billable entries - BPS*1*20
  1. I $P($G(^BPST(IEN59,0)),U,15)="N" D Q
  1. . D LOG^BPSOSL(IEN59,$T(+0)_"-BPS Transaction non-billable entry has reached a status of 99%")
  1. . S BPS57=$$NEW57(IEN59) ; copy it over into BPS Log of Transaction file
  1. . D LOG^BPSOSL(IEN59,$T(+0)_"-Created BPS Log of Transaction record for non-billable entry: "_BPS57)
  1. . D LOG^BPSOSL(IEN59,$T(+0)_"-BPS Transaction Non-Billable Entry Complete")
  1. . Q
  1. ;
  1. ; Get the current request
  1. S IEN77=+$$GETRQST^BPSUTIL2(IEN59)
  1. D LOG^BPSOSL(IEN59,$T(+0)_"-Claim of the request "_IEN77_" has reached 99%")
  1. ;
  1. ; Create a copy in the BPS Log of Transaction
  1. S BPS57=$$NEW57(IEN59)
  1. D LOG^BPSOSL(IEN59,$T(+0)_"-Created BPS Log of Transaction record "_BPS57)
  1. ;
  1. ; This data is needed when closing the claim later but needs to be
  1. ; read now since $$REQST99^BPSOSRX5 will delete the request as part
  1. ; of its processing
  1. S BPSCLNOD=$G(^BPS(9002313.77,IEN77,7))
  1. S BPTYPE=$P($G(^BPS(9002313.77,IEN77,1)),U,4)
  1. ;
  1. ; Get status of the claim
  1. S CLMSTAT=$$CATEG^BPSOSUC(IEN59)
  1. S BPNXTREQ=$$REQST99^BPSOSRX5(IEN59,CLMSTAT)
  1. ;
  1. ; Check if the BPS Claim should be closed
  1. I +BPSCLNOD=1,$P(BPSCLNOD,U,2)>0 D
  1. . N BPSCLA,BPLCK,BPDROP,ERROR,DA,DR,DIE
  1. . I $$SUCCESS^BPSOSRX7(BPTYPE,CLMSTAT)=0 Q
  1. . I BPNXTREQ>0 D LOG^BPSOSL(IEN59,$T(+0)_"-Cannot close after reversal due to sequential requests in the queue") Q
  1. . D LOG^BPSOSL(IEN59,$T(+0)_"-Closing the claim after accepted reversal")
  1. . S BPSCLA=$$GET1^DIQ(9002313.59,IEN59,3,"I"),BPLCK=0,BPDROP="N"
  1. . L +^BPSC(BPSCLA):0 I '$T D Q
  1. . . D LOG^BPSOSL(IEN59,$T(+0)_"-Unable to close claim. Could not lock BPS CLAIMS file.") Q
  1. . D CLOSE^BPSBUTL(BPSCLA,IEN59,$P(^IBE(356.8,$P(BPSCLNOD,U,2),0),U),0,1,$P(BPSCLNOD,U,3),.ERROR)
  1. . I $D(ERROR) D Q
  1. . . D LOG^BPSOSL(IEN59,$T(+0)_"Unable to close Bill in IB. "_ERROR)
  1. . . L -^BPSC(BPSCLA)
  1. . S DIE="^BPSC("
  1. . S DA=BPSCLA
  1. . S DR="901///1"
  1. . S DR=DR_";902///"_$$NOW^XLFDT()
  1. . S DR=DR_";903////"_$$GET1^DIQ(9002313.59,IEN59,13,"I")
  1. . S DR=DR_";904///"_$P(BPSCLNOD,U,2)
  1. . S DR=DR_";905////"_BPDROP
  1. . D ^DIE
  1. . L -^BPSC(BPSCLA)
  1. . Q
  1. ;
  1. ;
  1. ; If claims completed normally, log its completion.
  1. ; Do not log error'ed or stranded claims as we don't want to show these in the
  1. ; turn-around stats
  1. ; Needed for Turn-Around Stats - Do NOT delete/alter!!
  1. I CLMSTAT'["E OTHER",CLMSTAT'["E UNSTRANDED",CLMSTAT'["E REVERSAL UNSTRANDED" D LOG^BPSOSL(IEN59,$T(+0)_"-Claim Complete")
  1. Q
  1. ;
  1. ; NEW57 - Copy the BPS Transaction into BPS Log of Transaction
  1. ; Input
  1. ; IEN59 - BPS Transaction
  1. ; Returns
  1. ; BPS Log of Transaction IEN
  1. NEW57(IEN59) ;
  1. F L +^BPSTL:300 Q:$T Q:'$$IMPOSS^BPSOSUE("L","RTI","LOCK ^BPSTL",,"NEW57",$T(+0))
  1. ;
  1. ; Get next record number in BPS Log of Transactions
  1. NEW57A N N,C
  1. S N=$P(^BPSTL(0),U,3)+1
  1. S C=$P(^BPSTL(0),U,4)+1
  1. S $P(^BPSTL(0),U,3,4)=N_U_C
  1. I $D(^BPSTL(N)) G NEW57A ; should never happen
  1. L -^BPSTL
  1. ;
  1. ; Merge BPS Transaction into Log of Transactions
  1. M ^BPSTL(N)=^BPST(IEN59)
  1. ;
  1. ; Set MCCF EDI TAS PROGRESS flag to 1
  1. ; Only if Transaction Type is not Non-Billable
  1. I $$GET1^DIQ(9002313.59,IEN59,19,"I")'="N" D
  1. . N BPSA,BPSFN,BPSREC
  1. . S BPSFN=9002313.57
  1. . S BPSREC=N_","
  1. . S BPSA(BPSFN,BPSREC,20)=1
  1. . D FILE^DIE("","BPSA","")
  1. ;
  1. ; Build fileman indices
  1. D
  1. . N DIK,DA S DIK="^BPSTL(",DA=N N N D IX1^DIK
  1. ;
  1. ; Quit with the new record number
  1. Q N
  1. ;
  1. ; ISREVES - Is this a reversal claim
  1. ; Input
  1. ; CLAIMIEN - Pointer to BPS Claims
  1. ;
  1. ; Return Value
  1. ; 1 - Reversal claim
  1. ; 0 - Not a reversal claim
  1. ISREVERS(CLAIM) ;
  1. Q $P($G(^BPSC(CLAIM,100)),"^",3)="B2"
  1. ;
  1. ; SETCSTAT - Set the status for every transaction associated with
  1. ; this claim
  1. SETCSTAT(CLAIM,STATUS) ;
  1. N IEN59,INDEX
  1. ;
  1. ; Determine correct index
  1. I $$ISREVERS(CLAIM) S INDEX="AER"
  1. E S INDEX="AE"
  1. ;
  1. ; Loop through the transactions and set the status
  1. S IEN59=""
  1. F S IEN59=$O(^BPST(INDEX,CLAIM,IEN59)) Q:IEN59="" D SETSTAT(IEN59,STATUS)
  1. Q
  1. ;
  1. ; ERROR - Handle any errors
  1. ; Log them into BPS Transactions
  1. ; Change status to 99
  1. ; Update the LOG
  1. ; Increment the statistics
  1. ; We should be okay for the resubmit flag since the STATUS
  1. ; will be E OTHER instead of E REVERSAL ACCEPTED
  1. ; Input
  1. ; RTN - Routine reporting the error
  1. ; IEN59 - BPS Transaction
  1. ; ERROR - Error Number (goes in RESULT CODE)
  1. ; ERRTEXT - Error Text (goes in RESULT TEXT)
  1. ;
  1. ; To prevent conflicts, set the error number to the first digit of
  1. ; Status and a unique number for the status.
  1. ERROR(RTN,IEN59,ERROR,ERRTEXT) ;
  1. ;
  1. ; Check parameters
  1. I '$G(IEN59) Q
  1. I '$G(ERROR) S ERROR=0
  1. I $G(ERRTEXT)="" S ERRTEXT="ERROR - see LOG"
  1. ;
  1. ; Set Error and Error Text in BPS Transaction
  1. D SETRESU(IEN59,ERROR,ERRTEXT)
  1. ;
  1. ; Log Message
  1. D LOG^BPSOSL(IEN59,RTN_" returned error - "_ERRTEXT)
  1. ;
  1. ; Update unbillable count in stats
  1. D INCSTAT^BPSOSUD("R",1)
  1. ;
  1. ; Update Status to complete
  1. D SETSTAT(IEN59,99)
  1. Q
  1. ;
  1. ; SETRESU - Set Result into ^BPST(IEN59,2)
  1. ; Input
  1. ; IEN59 - BPS Transaction IEN
  1. ; RESULT - Result Code
  1. ; TEXT - Result Text. Semi-colons (";") should not in the text data as
  1. ; this is used as a separator between current and previous text
  1. ; messages. If there is a semi-colon, it is converted to a dash.
  1. SETRESU(IEN59,RESULT,TEXT) ;
  1. ;
  1. ; First, store the Result Code
  1. S $P(^BPST(IEN59,2),U)=$G(RESULT)
  1. ;
  1. ; Second, store the Result Text
  1. ; Considerations:
  1. ; Convert any semi-colons to dashes
  1. ; Add semi-colon delimiter if needed
  1. ; Truncate data if needed
  1. I $G(TEXT)]"" D
  1. . N X
  1. . S TEXT=$TR(TEXT,";","-")
  1. . S X=$P(^BPST(IEN59,2),U,2,99)
  1. . I X]"",$E(X)'=";" S X=";"_X
  1. . S X=$E(TEXT_X,1,255-$L(RESULT)-1)
  1. . S $P(^BPST(IEN59,2),U,2)=X
  1. Q
  1. ;
  1. ; SETCRESU - set the result code for every transaction assoc'd with
  1. ; this claim. Note that this will only work for billing requests (B1)
  1. ; Input
  1. ; CLAIMIEN - BPS Claim IEN
  1. ; RESULT - Result Code
  1. ; TEXT - Result Text
  1. SETCRESU(CLAIM,RESULT,TEXT) ;
  1. N IEN59
  1. S IEN59=""
  1. F S IEN59=$O(^BPST("AE",CLAIM,IEN59)) Q:IEN59="" D SETRESU(IEN59,RESULT,$G(TEXT))
  1. Q
  1. ;
  1. ; STATI(X) gives a text version of what status code X means.
  1. ; For effeciency, put more common ones at the top.
  1. ; Also note that you should check the display on the stats screen if you
  1. ; modify any of these.
  1. STATI(X) ;
  1. I X=99 Q "Done"
  1. I X=60 Q "Transmitting"
  1. I X=0 Q "Waiting to start"
  1. I X=40 Q "Building the HL7 packet"
  1. I X=70 Q "Parsing response"
  1. I X=30 Q "Building the claim"
  1. I X=10 Q "Building the transaction"
  1. I X=90 Q "Processing response"
  1. I X=98 Q "Resubmitting" ; Used only by STATUS^BPSOSRX (Not stored in BPS Transactions)
  1. I X=50 Q "Preparing for transmit"
  1. I X=31 Q "Wait for retry (insurer asleep)"
  1. I X=80 Q "Waiting to process response"
  1. I X=-99 Q "Waiting for activation (scheduled)" ; Used only by STATUS^BPSOSRX (Not stored in BPS Transactions)
  1. I X=-98 Q "Cancelled" ; Used only by STATUS^BPSOSRX (Not stored in BPS Transactions)
  1. I X=-97 Q "Inactive" ; Used only by STATUS^BPSOSRX (Not stored in BPS Transactions)
  1. I X=-96 Q "Processing request" ; Used only by STATUS^BPSOSRX (Not stored in BPS Transactions)
  1. Q "?"_X_"?"