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

RCDPEAP.m

Go to the documentation of this file.
  1. RCDPEAP ;ALB/PJH - AUTO POST MATCHING EFT ERA PAIR ;Oct 15, 2014@12:36:51
  1. ;;4.5;Accounts Receivable;**298,304,318,321,326,424,432**;Mar 20, 1995;Build 16
  1. ;Per VA Directive 6402, this routine should not be modified.
  1. ;Read ^IBM(361.1) via Private IA 4051
  1. ;
  1. EN ;Auto-post ERA Receipts
  1. ;Process newly matched and matched but unprocessed ERAs
  1. D EN1
  1. ;Process previously processed ERA's
  1. D EN2
  1. Q
  1. ;
  1. EN1 ;Auto-post newly matched and matched but unprocessed ERA
  1. N RCRZ,RCEFTDA,RCZERO ; PRCA*4.5*424 Add RCZERO
  1. S RCRZ=0
  1. ;Scan ERA file for auto-post candidates with AUTO-POST STATUS = UNPOSTED
  1. F S RCRZ=$O(^RCY(344.4,"E",0,RCRZ)) Q:'RCRZ D
  1. .S RCZERO=$$ISZERO^RCDPEAP1(RCRZ) ; PRCA*4.5*424 Check for Zero balance ERA
  1. .I RCZERO I $$ISTYPE^RCDPEU1(344.4,RCRZ,"C") Q ; PRCA*4.5*432 Zero balance ERA with CHAMPVA payer is not an auto-post candidate
  1. .;Get EFT reference
  1. .;PRCA*4.5*424 next, line don't require matched EFT for zero balance ERAs
  1. .S RCEFTDA=$O(^RCY(344.31,"AERA",RCRZ,"")) I 'RCZERO Q:'RCEFTDA
  1. .;Check that EFT funds were posted to FMS and Accepted by FMS. If not, quit and go to next unposted ERA
  1. .N RCOK,RCDEPTDA,RCRECTDA
  1. .S RCOK=1
  1. .;PRCA*4.5*424 next, line don't check matched EFT for zero balance ERAs
  1. .I 'RCZERO,$P($G(^RCY(344.3,+$G(^RCY(344.31,+RCEFTDA,0)),0)),U,8),$P($G(^RCY(344.31,+RCEFTDA,0)),U,7) D Q:'RCOK
  1. ..S RCDEPTDA=+$P($G(^RCY(344.3,+$G(^RCY(344.31,+RCEFTDA,0)),0)),U,3),RCRECTDA=+$O(^RCY(344,"AD",+RCDEPTDA,0)) ; Get deposit ticket and EFT receipt (CR - 8NZZ)
  1. ..I RCRECTDA N Z S Z=$P($$FMSSTAT^RCDPUREC(RCRECTDA),U,2) Q:$E(Z)="A" Q:$E(Z)="O" ; EFT Accepted by FMS or ON-LINE ENTRY - PRCA*4.5*326
  1. ..S RCOK=0
  1. .;
  1. .;Auto-Post
  1. .D AUTOPOST(RCEFTDA,RCRZ,RCZERO) ; PRCA*4.5*424 add parameter
  1. Q
  1. ;
  1. ; Process ERA
  1. AUTOPOST(RCEFTDA,RCERA,RCZERO) ; PRCA*4.5*424 add parameter
  1. ; RCEFTDA = ien of file #344.31
  1. ; RCERA = ien of file #344.4
  1. ; RCZERO = 1 if this ERA is zero balance, otherwise 0 ; PRCA*4.5*424
  1. ;
  1. ;Lock ERA
  1. L +^RCY(344.4,RCERA):5 Q:'$T
  1. ;
  1. ;Build Scratchpad and Verify Lines
  1. N ALLOK,RCERR,RCLINES,RCRCPTDA,RCSCR,RCTRDA,ZEROBAL ; PRCA*4.5*318 Variables placed in alpha order
  1. K ^TMP($J,"RCDPEWLA")
  1. S RCSCR=$$SCRPAD(RCERA,RCZERO) ;**PRCA*4.5*424 Added ,RCZERO
  1. ; Re-set AUTO-POST STATUS if unable to create scratchpad
  1. I 'RCSCR,'RCZERO D Q ;PRCA*4.5*424 Added 'RCZERO
  1. . D SETSTA(RCERA,"@","Auto Posting: Removed from Auto Posting-Unable to create scratchpad")
  1. . D AUTOQ
  1. ;
  1. ; ERA cannot be autoposted
  1. ; remove any pre-existing value to the AUTO-POST STATUS so ERA can be processed manually in the Worklist
  1. I $D(^TMP($J,"RCDPEWLA","ERA LEVEL ADJUSTMENT EXISTS")) D Q
  1. . D SETSTA(RCERA,"@","Auto Posting: Removed from Auto Posting-ERA level Adjustment(s)")
  1. . D AUTOQ
  1. ;
  1. I $$UNBAL^RCDPEAP1(RCERA) D Q ; PRCA*4.5*318 Added line
  1. . D SETSTA(RCERA,"@","Auto Posting: Removed from Auto Posting-Unbalanced ERA") ; PRCA*4.5*321
  1. . D AUTOQ
  1. ;
  1. ; Check if all lines can be posted
  1. S ALLOK=$$ALLOK(RCERA,RCSCR,.ZEROBAL,.RCLINES)
  1. ;
  1. ; ; PRCA*4.5*424 Added line - post zero balance ERA
  1. I RCZERO D Q ;
  1. . I ZEROBAL D ;
  1. . . D POST0^RCDPEAP2(RCERA)
  1. . I 'ZEROBAL D ;
  1. . . D SETSTA(RCERA,"@","Auto Posting: Removed zero pay ERA has +/- Payments")
  1. . D AUTOQ
  1. ;
  1. ;If $$ALLOK post entire ERA and reset AUTO-POST STATUS = COMPLETE
  1. I ALLOK D POSTALL(RCERA)
  1. ;
  1. ;If 'ALLOK and some of the lines passed validation then post receipt to summary ERA and set AUTO-POST STATUS = PARTIAL
  1. ;Un-posted lines fall to APAR list for processing.
  1. I 'ALLOK D POSTERA(RCERA,.RCLINES)
  1. ;Unlock ERA
  1. AUTOQ D UNLOCKE
  1. Q
  1. ;
  1. EN2 ;Auto-Post Previously Processed ERA
  1. N AUTORCPT,CLAIM,COMPLETE,EOBIEN,RCDUZ,RCERA,RCIFN,RCRCPTDA,RCLINES
  1. S RCERA=0,AUTORCPT=1 ;Variable AUTORCPT suppresses #344 trigger update to ERA receipt field
  1. ;Scan ERA file for auto-post candidates with AUTO-POST STATUS = PARTIAL
  1. F S RCERA=$O(^RCY(344.4,"E",1,RCERA)) Q:'RCERA D
  1. . ;Ignore if it was just partially posted in POSTLNS so we do not process again
  1. . Q:$D(^TMP("RCDPEAP",$J,RCERA))
  1. . S RCDUZ=$$GET1^DIQ(344.4,RCERA_",",4.04,"I") ; PRCA*4.5*326
  1. . ;Set receipt variable to null for each ERA so that the receipt number from the previous ERA is not hanging around
  1. . S RCRCPTDA=""
  1. . ;Check if there are lines that are set for auto-posting and if they can be posted or have errors.
  1. . K RCLINES
  1. . S RCLINES=0
  1. . D VALID^RCDPEAP1(RCERA,.RCLINES)
  1. . ;If valid lines found create receipt for those lines (Variable RCLINES is only incremented for valid lines)
  1. . I RCLINES D
  1. . . N RCEFTDA,RCDEPTDA,RCRECTDA
  1. . . ;Get EFT reference
  1. . . S RCEFTDA=$O(^RCY(344.31,"AERA",RCERA,"")) Q:'RCEFTDA
  1. . . ;Get deposit ticket and EFT receipt
  1. . . S RCDEPTDA=+$P($G(^RCY(344.3,+$G(^RCY(344.31,+RCEFTDA,0)),0)),U,3),RCRECTDA=+$O(^RCY(344,"AD",+RCDEPTDA,0))
  1. . . ;ERA Receipt is created from scratchpad entry - type 14 is EDI Lockbox payment
  1. . . ; Creates basic receipt for ERA of payment type EDI LOCKBOX; 2nd parameter means an alpha suffix on receipt number
  1. . . S RCRCPTDA=$$BLDRCPT^RCDPEMA(RCERA,RCDUZ) ; PRCA*4.5*326 Add RCDUZ to call
  1. . . I 'RCRCPTDA Q ;PRCA*4.5*318 - Problem building receipt header
  1. . . K RCERR
  1. . . D RCPTDET^RCDPEMA(RCERA,RCRCPTDA,.RCLINES,.RCERR) ; Adds detail to a receipt based on file 344.49 and RCLINES array
  1. . . I $O(RCERR("")) Q ; PRCA*4.5*318 - Do not attempt to process partially filed receipt
  1. . . ;Lock ERA receipt and deposit ticket
  1. . . I '$$LOCKREC^RCDPRPLU(RCRCPTDA) Q
  1. . . I '$$LOCKDEP^RCDPDPLU(RCDEPTDA) D UNLOCKR Q
  1. . . ;Process Receipt to FMS
  1. . . D PROCESS^RCDPURE1(RCRCPTDA,2) I $D(^TMP("RCDPE-RECEIPT-ERROR",$J)) D UNLOCKR Q
  1. . . ; update 344, .18 ERA REFERENCE field
  1. . . D ERAREF(RCERA,RCRCPTDA)
  1. . . ;Unlock deposit ticket and receipt
  1. . . D UNLOCKR
  1. . ;Update ERA and ERA detail lines with receipt # or auto-post rejection reason
  1. . D ERADET^RCDPEAP1(RCERA,RCRCPTDA,.RCLINES)
  1. . ;Determine if posting complete for this ERA
  1. . S COMPLETE=$$COMPLETE(RCERA)
  1. . ;If complete update ERA detail post status to POSTED
  1. . I COMPLETE S DIE="^RCY(344.4,",DR=".14////1",DA=RCERA D ^DIE
  1. . ;Update the audit log
  1. . D AUDITLOG(RCERA,$S(COMPLETE:2,1:1),"Auto Posting: Previously processed ERA posting attempt")
  1. . ;Set ERA auto-post status and update latest auto-post date
  1. . S DIE="^RCY(344.4,",DR="4.01////"_DT_";4.02////"_$S(COMPLETE:2,1:1),DA=RCERA D ^DIE
  1. ;Unlock ERA
  1. D UNLOCKE
  1. Q
  1. ;
  1. ACTIVE(EOBIEN) ;Verify claim is active
  1. ; EOBIEN - IEN of file 361.1
  1. N RCIFN,RCBILL,RCSTATUS
  1. ;Get EOB number (implies this is 3rd Party claim)
  1. I 'EOBIEN Q 0
  1. ;Get #399 claim number from EOB
  1. S RCIFN=$P($G(^IBM(361.1,EOBIEN,0)),U) Q:'RCIFN 0
  1. S RCBILL=$P($G(^DGCR(399,RCIFN,0)),U) Q:RCBILL="" 0 ; IA 4051
  1. ;Check if bill is cancelled or closed
  1. S RCSTATUS=$P($G(^DGCR(399,RCIFN,0)),U,13)
  1. Q $S(RCSTATUS=0:0,RCSTATUS=7:0,1:1)
  1. ;
  1. ALLOK(RCERA,RCSCR,ZEROBAL,RCLINES) ;Verify which scratchpad lines are able to auto-post
  1. ; RCERA - 344.4 ien
  1. ; RCSCR - 344.49 ien
  1. ; ZEROBAL - flag that represents if ERA has zero payment balance after processing
  1. ; matched positive/negative pairs, passed by reference
  1. ; RCLINES - array of ERA line references (passed in by reference)
  1. ; NOTE: ORIGINAL ERA SEQUENCES (344.491, .09) can have multiple ERA line
  1. ; references separated by commas (e.g., 3,4)
  1. ; returns 0 or 1 (ALLOK)
  1. N ALLOK,AMT,ERALINE,STATUS,SUB,SUB1,CLAIM,WLINE,VERIFY
  1. K CLARRAY
  1. S (ZEROBAL,ALLOK)=1
  1. S (SUB,RCLINES)=0
  1. F S SUB=$O(^RCY(344.49,RCSCR,1,"B",SUB)) Q:SUB="" D
  1. . ;Get scratchpad line and data
  1. . S SUB1=$O(^RCY(344.49,RCSCR,1,"B",SUB,"")) Q:'SUB1 S WLINE=$G(^RCY(344.49,RCSCR,1,SUB1,0)),AMT=$P(WLINE,U,3)
  1. . ;If integer sequence, get ERA line reference and verify flag and then quit for this sequence and go on to the non-integer sequence to finish validation
  1. . I $P(WLINE,U)?1N.N S VERIFY=1 S ERALINE=$P(WLINE,U,9) S:'$P(WLINE,U,13) ALLOK=0,RCLINES(ERALINE)="0^^1",VERIFY=0 Q
  1. . ; ignore zero valued lines
  1. . Q:AMT=0 Q:AMT="0.00"
  1. . S ZEROBAL=0 ; PRCA*4.5*424 at least one line has non-zero balance
  1. . ;Get claim number from N.001 line - if not found treat as inactive
  1. . S CLAIM=$P(WLINE,U,7) I 'CLAIM S ALLOK=0,$P(RCLINES(ERALINE),U,3)=2 Q
  1. . ;Save claim number
  1. . S $P(RCLINES(ERALINE),U,2)=$P($G(^PRCA(430,CLAIM,0)),U) Q:'VERIFY
  1. . ;Claim must be OPEN or ACTIVE
  1. . S STATUS=$P($G(^PRCA(430,CLAIM,0)),"^",8) I STATUS'=42,STATUS'=16 S ALLOK=0,$P(RCLINES(ERALINE),U,3)=2 Q
  1. . ;Check that payment does not exceed balance and no pending payments (at the time of auto posting)
  1. . S CLARRAY(CLAIM)=+$G(CLARRAY(CLAIM))+$P(WLINE,U,3) I '$$CHECKPAY(.CLARRAY,CLAIM) S ALLOK=0,$P(RCLINES(ERALINE),U,3)=3 Q
  1. . ;Check if referred to general council
  1. . I $P($G(^PRCA(430,CLAIM,6)),U,4)]"" S ALLOK=0,$P(RCLINES(ERALINE),U,3)=4 Q
  1. . ;Line is potentially postable
  1. . S $P(RCLINES(ERALINE),U)=1,$P(RCLINES(ERALINE),U,3)=$P(WLINE,U,6),RCLINES=$G(RCLINES)+1
  1. Q ALLOK
  1. ;
  1. AUDITLOG(DA,RCNEWST,RCREASON) ;
  1. ; Update the Auto-post Audit Log
  1. I '$G(DA) Q
  1. I $G(RCREASON)="" Q
  1. ;
  1. N RCAUDIT,RCOLDST,DIE,DR,X,Y,DTOUT,DUOUT,DROUT,DIRUT
  1. ; Get the current status
  1. S RCOLDST=$$GET1^DIQ(344.4,DA_",",4.02,"I")
  1. ; If the new status is null, set to old status (no change)
  1. I $G(RCNEWST)="" S RCNEWST=RCOLDST
  1. ; File
  1. S RCAUDIT(344.72,"+1,",.01)=$$NOW^XLFDT ;Date/Time Stamp
  1. S RCAUDIT(344.72,"+1,",.02)=$S($G(RCDUZ):RCDUZ,1:DUZ) ;User PRCA*4.5*321 Use RCDUZ if defined
  1. S RCAUDIT(344.72,"+1,",.03)=DA ;ERA #
  1. S RCAUDIT(344.72,"+1,",.04)=RCOLDST ;Old Status
  1. I RCNEWST'="@" S RCAUDIT(344.72,"+1,",.05)=RCNEWST ;New status
  1. S RCAUDIT(344.72,"+1,",.06)=$E(RCREASON,1,80) ;Reason text
  1. D UPDATE^DIE(,"RCAUDIT")
  1. Q
  1. ;
  1. BUILD(RCSCR,ARRAY) ; EP from EN2^RCDPEAD - Build list of ERA lines
  1. ; RCSCR = ien of file 344.49
  1. ; ARRAY = the array that will hold the list of ERA lines, passed by reference
  1. N ERALINE,FOUND,SCRLINE,SUB,SUB1
  1. K ARRAY
  1. S SUB=0,ARRAY=0
  1. F S SUB=$O(^RCY(344.49,RCSCR,1,"B",SUB)) Q:SUB="" D:SUB'["."
  1. . ;Get actual scratchpad ^RCY(344.49,RCSCR,1) node
  1. . S SUB1=$O(^RCY(344.49,RCSCR,1,"B",SUB,"")) Q:'SUB1
  1. . ;;Ignore zero lines - removed PRCA*4.5*326
  1. . ;Q:'$P($G(^RCY(344.49,RCSCR,1,SUB1,0)),U,3)
  1. . ; Get ERA line
  1. . S ERALINE=$$GET1^DIQ(344.491,SUB1_","_RCSCR,.09) ; PRCA*4.5*326
  1. . ; Ignore reversals
  1. . Q:ERALINE["," ; PRCA*4.5*326
  1. . ;Index scratchpad line by ERA sequence
  1. . S ARRAY(ERALINE)=SUB1,ARRAY=$G(ARRAY)+1 ; PRCA*4.5*326
  1. Q
  1. ;
  1. CHECKPAY(ARRAY,CLAIM) ;Check balance versus payments
  1. ; ARRAY = array of claim numbers and respective payment amounts
  1. ; e.g. ARRAY(430 ien) = 123.04
  1. ; CLAIM = AR BILL (344.491, .07) - IEN of file 430
  1. Q:'CLAIM 0
  1. ; BEGIN PRCA*4.5*326
  1. N RCADMIN,RCBAL,RCCOURT,RCINT,RCMAR,RCPRIN
  1. S RCPRIN=$$GET1^DIQ(430,CLAIM_",",71) ; Principle Balance
  1. S RCINT=$$GET1^DIQ(430,CLAIM_",",72) ; Interest
  1. S RCADMIN=$$GET1^DIQ(430,CLAIM_",",73) ; Admin Cost
  1. S RCMAR=$$GET1^DIQ(430,CLAIM_",",74) ; Marshal Fee
  1. S RCCOURT=$$GET1^DIQ(430,CLAIM_",",75) ; Court Cost
  1. S RCBAL=RCPRIN+RCINT+RCADMIN+RCMAR+RCCOURT ; Total balance
  1. ; get the payment amount to be posted to the claim
  1. S AMT=ARRAY(CLAIM)
  1. ;Payment exceeds principle balance
  1. Q:AMT>RCBAL 0
  1. ; END PRCA*4.5*326
  1. ;Check pending payments for claim
  1. N PENDING S PENDING=$$PENDPAY^RCDPURET(CLAIM) K ^TMP($J,"RCDPUREC","PP")
  1. ;Pending payments is > billed
  1. I PENDING>AMT Q 0
  1. ;otherwise OK to post payment
  1. Q 1
  1. ;
  1. CLEAR(DA) ;Clear scratchpad
  1. N DIK S DIK="^RCY(344.49," D ^DIK
  1. Q
  1. ;
  1. COMPLETE(RCSCR) ;Check for non-zero lines without a receipt
  1. ; RCSCR = ien of file 344.49
  1. ; Returns status of check (1 or 0)
  1. N RCSUB,SCRSUB,COMPLETE,SCRLINE,RCERA
  1. ;Default to complete
  1. S SCRSUB=0,COMPLETE=1,RCERA=RCSCR
  1. ;Scan scratchpad
  1. F S SCRSUB=$O(^RCY(344.49,RCSCR,1,SCRSUB)) Q:'SCRSUB D Q:'COMPLETE
  1. . ;Ignore zero and split lines (splitting line should not change balance)
  1. . S SCRLINE=$G(^RCY(344.49,RCSCR,1,SCRSUB,0)) Q:$P(SCRLINE,U)'?1N.N Q:$P(SCRLINE,U,3)=0 Q:$P(SCRLINE,U,3)="0.00"
  1. . ;Check if non-zero line has receipt on ERA, DETAIL line
  1. . S RCSUB=$P(SCRLINE,U,9) I RCSUB,$P($G(^RCY(344.4,RCERA,1,RCSUB,4)),U,3)]"" Q
  1. . ;Otherwise more AUTO-posting to do
  1. . S COMPLETE=0
  1. Q COMPLETE
  1. ;
  1. ERAREF(RCSCR,RCRCPTDA) ; update ERA reference and EFT record IEN in file 344
  1. ; RCSCR - IEN of record in file 344.49
  1. ; RCRCPTDA - ien of record in file 344 (receipt ien)
  1. N Z,DR,DIE,DA
  1. S Z=+$O(^RCY(344.31,"AERA",RCSCR,0))
  1. S DIE="^RCY(344,",DA=RCRCPTDA,DR=".18////"_RCSCR_$S(Z:";.17////"_Z,1:"") D ^DIE
  1. Q
  1. ;
  1. NOTOK(RCSCR) ;Verify all scratchpad lines passed auto verify (V)
  1. ; RCSCR = ien of file 344.49
  1. ; Returns status of check (1 or 0)
  1. N NOTOK,SUB
  1. S SUB=0,NOTOK=0
  1. F S SUB=$O(^RCY(344.49,RCSCR,1,SUB)) Q:'SUB D Q:NOTOK
  1. . ;Set NOTOK if any single line is unverified
  1. . S:$P($G(^RCY(344.49,RCSCR,1,SUB,0)),U,13)'=1 NOTOK=1
  1. Q NOTOK
  1. ;
  1. POSTALL(RCERA) ; all lines in ERA get posted on first attempt of auto-post
  1. ; RCERA = ien of 344.4
  1. ;ERA Receipt is created from scratchpad entry - type 14 is EDI Lockbox payment
  1. ; PRCA*4.5*326 begin modified code block
  1. N RCDUZ
  1. S RCDUZ=$$GET1^DIQ(344.4,RCERA_",",4.04,"I")
  1. S RCRCPTDA=$$BLDRCPT^RCDPUREC(DT,"",+$O(^RC(341.1,"AC",14,0)),RCDUZ) ; Creates basic receipt for ERA of payment type EDI LOCKBOX; 2nd parameter means no alpha suffix on receipt number
  1. D RCPTDET^RCDPEM(RCSCR,RCRCPTDA,.RCERR,RCDUZ) ; Adds detail to a receipt based on file 344.49
  1. ; PRCA*4.5*326 end modified code block
  1. ;
  1. ;Unable to create receipt - clear scratchpad, reset AUTO-POST STATUS = NULL
  1. I $O(RCERR("")) D CLEAR(RCSCR),SETSTA(RCERA,"@","Auto Posting: Removed from Auto Posting-Unable to create receipt") Q
  1. ;
  1. ;Lock ERA receipt and deposit ticket
  1. I '$$LOCKREC^RCDPRPLU(RCRCPTDA) Q
  1. I '$$LOCKDEP^RCDPDPLU(RCDEPTDA) D UNLOCKR Q
  1. ;
  1. ;Process Receipt to FMS
  1. D PROCESS^RCDPURE1(RCRCPTDA,2)
  1. I $D(^TMP("RCDPE-RECEIPT-ERROR",$J)) D CLEAR(RCSCR),SETSTA(RCERA,"@","Auto Posting: Removed from Auto Posting-Error in receipt processing"),UNLOCKR Q
  1. ;
  1. ; update 344, .18 ERA REFERENCE field
  1. D ERAREF(RCSCR,RCRCPTDA)
  1. ;
  1. ;Unlock deposit ticket and receipt
  1. D UNLOCKR
  1. ;
  1. ;Update the audit log
  1. D AUDITLOG(RCERA,2,"Auto Posting: ERA posted successfully")
  1. ;Update ERA receipt and detail post status
  1. S DIE="^RCY(344.4,",DR=".14////1;.08////"_RCRCPTDA,DA=RCERA D ^DIE
  1. ;Set ERA auto-post status to 'complete' and update latest auto-post date
  1. S DIE="^RCY(344.4,"
  1. S DR="4.01////"_DT_";4.02////2"
  1. S DA=RCERA
  1. D ^DIE
  1. ;Update auto-post date for each claim line
  1. N RCLINE,RCSCSUB,RCSCD0
  1. S RCSCSUB=0
  1. F S RCSCSUB=$O(^RCY(344.49,RCERA,1,RCSCSUB)) Q:'RCSCSUB D
  1. . S RCSCD0=$G(^RCY(344.49,RCERA,1,RCSCSUB,0))
  1. . ;Ignore if zero value (line not on receipt) otherwise get original ERA line sequence
  1. . Q:'+$P(RCSCD0,U,3) S RCLINE=$P(RCSCD0,U,9) Q:'RCLINE
  1. . ;Update ERA line with receipt number and auto-post date
  1. . N DA,DIE,DR S DA(1)=RCERA,DA=RCLINE,DIE="^RCY(344.4,"_DA(1)_",1,",DR=".25////"_RCRCPTDA_";9////"_DT D ^DIE
  1. Q
  1. ;
  1. POSTERA(RCERA,RCLINES) ; only some of the EEOB lines passed validation on first attempt (DAY 1) of auto-post
  1. ; therefore assign the receipt number and 'partial' post status to ERA summary
  1. ; RCERA = ien of 344.4
  1. ; RCLINES = array of ERA line references
  1. ; no lines passed validation; at lease 1 EEOB line needs to pass validation before assigning a receipt to the ERA
  1. I RCLINES=0 S RCRCPTDA="" G POSTERAQ
  1. ;ERA Receipt is created from scratchpad entry - type 14 is EDI Lockbox payment
  1. S RCRCPTDA=$$BLDRCPT^RCDPEMA(RCERA) ; Creates basic receipt for ERA of payment type EDI LOCKBOXA
  1. D RCPTDET^RCDPEMA(RCSCR,RCRCPTDA,.RCLINES,.RCERR) ; Adds detail to a receipt based on file 344.49 and RCLINES array
  1. ;
  1. ;Unable to create receipt - clear scratchpad, reset AUTO-POST STATUS = NULL
  1. I $O(RCERR("")) D CLEAR(RCSCR),SETSTA(RCERA,"@","Auto Posting: Removed from Auto Posting-Unable to create receipt") Q
  1. ;
  1. ;Lock ERA receipt and deposit ticket
  1. I '$$LOCKREC^RCDPRPLU(RCRCPTDA) Q
  1. I '$$LOCKDEP^RCDPDPLU(RCDEPTDA) D UNLOCKR Q
  1. ;
  1. ;Process Receipt to FMS
  1. D PROCESS^RCDPURE1(RCRCPTDA,2)
  1. I $D(^TMP("RCDPE-RECEIPT-ERROR",$J)) D CLEAR(RCSCR),SETSTA(RCERA,"@","Auto Posting: Removed from Auto Posting-Error in receipt processing"),UNLOCKR Q
  1. ;
  1. ; update 344, .18 ERA REFERENCE field
  1. D ERAREF(RCSCR,RCRCPTDA)
  1. ;
  1. ;Unlock deposit ticket and receipt
  1. D UNLOCKR
  1. ;Update ERA receipt and detail post status
  1. S DIE="^RCY(344.4,",DR=".14////5;.08////"_RCRCPTDA,DA=RCERA D ^DIE
  1. POSTERAQ ;
  1. D POSTLNS(RCERA,RCRCPTDA,.RCLINES)
  1. Q
  1. ;
  1. POSTLNS(RCERA,RCRCPTDA,RCLINES) ; this subroutine should only be called when some of the EEOB lines
  1. ; passed validation on FIRST attempt (DAY 1) of auto-post
  1. ; RCERA = ien of ERA entry in 344.4
  1. ; RCRCPTDA = ien of receipt entry in 344 or undefined if receipt not created since none of the lines passed validation
  1. ; RCLINES = array of ERA line references
  1. ;Mark ERA as processed to prevent reprocessing in EN2^RCDPEAP which runs next
  1. S ^TMP("RCDPEAP",$J,RCERA)=""
  1. S RCRCPTDA=$G(RCRCPTDA)
  1. ;Update individual claim lines on ERA
  1. N RCLIN,DA,DIE,DR,LNUM,RCI,REJECT
  1. S RCLIN=0 F S RCLIN=$O(RCLINES(RCLIN)) Q:'RCLIN D
  1. . ; flag the line if it was rejected during validation
  1. . S REJECT=0 I '$P(RCLINES(RCLIN),U) S REJECT=1
  1. . ;get all ERA line references (e.g. RCLINES(RCLIN) could have multiple line # references)
  1. . ;Need to parse out each line reference so that the necessary fields can be updated for the specific line
  1. . F RCI=1:1 S LNUM=$P(RCLIN,",",RCI) Q:LNUM="" D
  1. . . S DA(1)=RCERA,DA=LNUM,DIE="^RCY(344.4,"_DA(1)_",1,"
  1. . . ;If not posted then the AUTO-POST REJECTION REASON (344.41,5) needs to be updated ;otherwise update line with receipt number and auto-post date
  1. . . I REJECT S DR="5////"_$P(RCLINES(RCLIN),U,3)
  1. . . E S DR=".25////"_RCRCPTDA_";9////"_DT
  1. . . D ^DIE
  1. ;Update the Audit Log
  1. D AUDITLOG(RCERA,1,"Auto Posting: Some of the ERA lines went to APAR")
  1. ;Set ERA AUTO-POST STATUS = PARTIAL and update auto-post date
  1. S DIE="^RCY(344.4,",DR="4.01////"_DT_";4.02////1",DA=RCERA D ^DIE
  1. Q
  1. ;
  1. SCRPAD(RCERA,RCZERO) ;Build Scratchpad entry in #344.49 for the ERA
  1. ; Input - RCERA - IEN for #344.4
  1. ; RCZERO - Optional, if passed, 1 if zero balance ERA. 0 otherwise
  1. ; Output - RCSCR = Scratchpad IEN (Success) or 0 (Fail)
  1. N RC0,RC5,RCSCR,RCDAT,X
  1. S RC0=$G(^RCY(344.4,RCERA,0)),RC5=$G(^RCY(344.4,RCERA,5))
  1. ;Ignore is this ERA already has a receipt
  1. I +$P(RC0,U,8) Q 0
  1. ;Ignore if this is zero ERA
  1. I '$G(RCZERO),+$P(RC0,U,5)=0 Q 0 ;PRCA*4.5*424 Added '$G(RCZERO),
  1. ; BEGIN PRCA*4.5*326
  1. ;Ignore if this is not a valid auto-post ERA type
  1. ;I "^ACH^CHK^"'[(U_$P(RC0,U,15)_U) Q 0 ; added CHK - PRCA*4.5*321
  1. I "^ACH^CHK^NON^BOP^"'[(U_$P(RC0,U,15)_U) Q 0
  1. ;ERA must be matched to an EFT to be eligible for mark for autopost
  1. I '$G(RCZERO),'$O(^RCY(344.31,"AERA",RCERA,"")) Q 0 ;PRCA*4.5*424 Added '$G(RCZERO),
  1. ; END PRCA*4.5*326
  1. ;Scratchpad already exists
  1. S RCSCR=+$O(^RCY(344.49,"B",RCERA,0)) I RCSCR G SCRPADX
  1. ;Create new Scratchpad
  1. S RCSCR=+$$ADDREC^RCDPEWL(RCERA,.RCDAT) I 'RCSCR Q 0
  1. ;Add all the ERA lines to the Scratchpad entry
  1. D ADDLINES^RCDPEWLA(RCSCR)
  1. SCRPADX ;Return Scratchpad IEN
  1. Q RCSCR
  1. ;
  1. SETSTA(DA,STATUS,RCREASON) ;Set ERA auto-post status
  1. ; Log status change
  1. I '$G(DA) Q
  1. I $G(STATUS)="" Q
  1. D AUDITLOG(DA,STATUS,$G(RCREASON))
  1. ; Update status
  1. N DIE,DR
  1. S DIE="^RCY(344.4,"
  1. S DR="4.02////"_STATUS
  1. S DR=DR_";4.04///"_$S(STATUS=0&(DUZ'=.5):DUZ,1:"@")
  1. D ^DIE
  1. Q
  1. ;
  1. UNLOCKR ;Unlock ERA receipt and deposit ticket
  1. L -^RCY(344,RCRCPTDA)
  1. L -^RCY(344.1,RCDEPTDA)
  1. Q
  1. ;
  1. UNLOCKE ;Unlock ERA
  1. L -^RCY(344.4,RCERA)
  1. Q