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

RCDPEAP1.m

Go to the documentation of this file.
  1. RCDPEAP1 ;ALB/KML - AUTO POST MATCHING EFT ERA PAIR - CONT. ;Jun 06, 2014@19:11:19
  1. ;;4.5;Accounts Receivable;**298,304,318,321,326,345,349,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. ;-------------------------------
  1. ;RCDPEM0 and RCDPEAP SUBROUTINES
  1. ;-------------------------------
  1. AUTOCHK(RCERA) ;Verify if ERA can be auto-posted - PRE-CHECK USED IN RCDPEM0
  1. ; Input: RCERA - IEN for file 344.4
  1. ; Returns: 1 - Auto-Post candidate, 0 - Not an Auto-Post candidate
  1. ; Many checks done by this are also done AUTOCHK2 below so if these are changed,
  1. ; may also need to be changed
  1. N NOTOK,RCDSUB,RCD0,RCMATCH,RCSCR,RCZERO
  1. K ^TMP($J,"RCDPEWLA")
  1. ;
  1. ; Check for exceptions
  1. S RCDSUB=0,NOTOK=0
  1. F S RCDSUB=$O(^RCY(344.4,RCERA,1,RCDSUB)) Q:'RCDSUB D Q:NOTOK
  1. . ;
  1. . ; Exception exists if INVALID BILL NUMBER field is populated in #344.41
  1. . S RCD0=$G(^RCY(344.4,RCERA,1,RCDSUB,0)) S:($P(RCD0,U,5)]"") NOTOK=1
  1. ;
  1. ; Cannot auto-post if exceptions exist
  1. Q:NOTOK 0
  1. ;
  1. ; Ignore ERA if ERA level Adjustments exist
  1. I $O(^RCY(344.4,RCERA,2,0)) Q 0
  1. ;
  1. ; Ignore non-ACH type ERA to prevent CHK type ERA from automatically auto-posting in nightly job - PRCA*4.5*321
  1. ;I $$GET1^DIQ(344.4,RCERA_",",.15)'="ACH" Q 0 ; extended - PRCA*4.5*326
  1. ; Ignore non-valid auto-post ERA types
  1. I "^ACH^CHK^BOP^NON^"'[(U_$$GET1^DIQ(344.4,RCERA_",",.15)_U) Q 0
  1. ;
  1. ; PRCA*4.5*424 - allow auto-post of zero dollar ERA
  1. ; ERA must be matched to an EFT to be eligible for mark for autopost
  1. S RCMATCH=$$MATCHED(RCERA)
  1. S RCZERO=$$ISZERO(RCERA)
  1. I RCZERO I $$ISTYPE^RCDPEU1(344.4,RCERA,"C") Q 0 ; PRCA*4.5*432 Zero balance ERA with CHAMPVA payer is not an auto-post candidate
  1. I 'RCZERO,'RCMATCH Q 0 ; ERAs much be matched unless they are zero balance
  1. ;
  1. ; If this is a zero balance ERA and the site parameter for posting zero balance
  1. ; ERAs is turned off, don't auto-post it
  1. I RCZERO,'$$GET1^DIQ(344.61,"1,",1.11,"I") Q 0
  1. ; PRCA*4.5*424 - end modified code block
  1. ;
  1. ; Create scratchpad
  1. ;I 'RCZERO S RCSCR=$$SCRPAD^RCDPEAP(RCERA) Q:'RCSCR 0 ;PRCA*4.5*424 added I 'RCZERO
  1. S RCSCR=$$SCRPAD^RCDPEAP(RCERA,RCZERO) Q:'RCSCR 0 ;PRCA*4.5*424 added ,RCZERO
  1. ;
  1. ; Ignore ERA if claim level adjustments without payment exist
  1. ; This will only get set if the scratchpad is created, not if it already exists.
  1. ; Looking at the code, it will mainly set if there are ERA level adjustments and
  1. ; may get set for unbalanced pairs, which is found by the ZEROBAL function. So,
  1. ; I think this does not have a real purpose but was not 100% sure.
  1. I $D(^TMP($J,"RCDPEWLA","ERA LEVEL ADJUSTMENT EXISTS")) D CLEAR^RCDPEAP(RCSCR) Q 0
  1. ;
  1. ; PRCA*4.5*424 added line
  1. I RCZERO Q 1
  1. ;
  1. ; ERA needs to drop to standard worklist if adjustment between matching
  1. ; positive/negative does not create a zero balance
  1. I '$$ZEROBAL(RCSCR) D CLEAR^RCDPEAP(RCSCR) Q 0
  1. ;
  1. ; Clear scratchpad
  1. D CLEAR^RCDPEAP(RCSCR)
  1. ;
  1. ; This is valid auto-post - return to MATCH^RCPDEM0
  1. Q 1
  1. ;
  1. AUTOCHK2(RCERA,RCTYP) ; RCTYP added PRCA*4.5*321
  1. ; Check if this entry is an auto-post candidate
  1. ; This has the same/similar checks as MATCH^RCDPEM0 and AUTOCHK above. If those procedures are
  1. ; changed, this may need to updated as well.
  1. ; ; Input: RCERA - IEN for file 344.4
  1. ; RCTYP - 0 - Called from Worklist/Mark for autopost
  1. ; 1 - Called from Manual match
  1. ; Returns: 1 - Auto-Post candidate
  1. ; 0^Reason - Not an auto-post candidate and reason
  1. ; Validate Parameter
  1. I '$G(RCERA) Q "0^Invalid Parameter"
  1. I $G(RCTYP)="" Q "0^Invalid Parameter" ; PRCA*4.5*321
  1. I (RCTYP>1)!(RCTYP<0) Q "0^Invalid Parameter" ; PRCA*4.5*321
  1. ;
  1. ; PRCA*4.5*345 - Added PNAM,PTIN,XX
  1. N NOTOK,PNAM,PTIN,RCCREATE,RCDSUB,RCERATYP,RCMATCH,RCSCR,RCXCLDE,RC0,RCZERO,STATUS,XX
  1. K ^TMP($J,"RCDPEWLA")
  1. ;
  1. ; Check if record exists
  1. I '$D(^RCY(344.4,RCERA,0)) Q "0^Invalid ERA record"
  1. ;
  1. ; Check current status
  1. S STATUS=$$GET1^DIQ(344.4,RCERA_",",4.02,"I")
  1. I STATUS=0 Q "0^Already marked for Auto-Posting"
  1. I STATUS=1 Q "0^Already partially Auto-Posted"
  1. I STATUS=2 Q "0^Already completely Auto-Posted"
  1. ;
  1. ; PRCA*4.5*424 - allow auto-post of zero dollar ERA
  1. ; ERA must be matched to an EFT to be eligible for mark for autopost
  1. S RC0=$G(^RCY(344.4,RCERA,0))
  1. S RCMATCH=$$MATCHED(RCERA)
  1. S RCZERO=$$ISZERO(RCERA)
  1. I RCZERO I $$ISTYPE^RCDPEU1(344.4,RCERA,"C") Q "0^CHAMPVA 0 balance ERA" ; PRCA*4.5*432 Zero balance ERA with CHAMPVA payer is not an auto-post candidate
  1. I 'RCZERO,'RCMATCH Q "0^ERA not matched" ; ERAs much be matched unless they are zero balance
  1. ; Only Auto-post zero pay ERA if parameter is enabled
  1. I RCZERO,'$$GET1^DIQ(344.61,"1,",1.11,"I") Q "0^Auto-post 0 balance disabled"
  1. ; PRCA*4.5*424 - end modified code block
  1. ;
  1. ; Determine if ERA should be excluded using the site parameters
  1. S PNAM=$$GET1^DIQ(344.4,RCERA_",",.06,"E") ; PRCA*4.5*345 - Added line - Payer Name
  1. S PTIN=$$GET1^DIQ(344.4,RCERA_",",.03,"E") ; PRCA*4.5*345 - Added line - Payer TIN
  1. S XX=$$GETPAY^RCDPEU1(PNAM,PTIN) ; PRCA*4.5*345 - Get the IEN from 344.6
  1. I $$CHKTYPE^RCDPEU1(XX,"T") S RCERATYP=2 ; PRCA*4.5*349 - Check if this is TRICARE ERA
  1. E S RCERATYP=$$PHARM^RCDPEAP1(RCERA) ; Else it must be a Medical or Rx ERA
  1. ;
  1. ; Check if medical claim and auto-posting is turned off
  1. S XX=$$GET1^DIQ(344.61,"1,",.02,"I") ; PRCA*4.5*345 - Added line - Med Auto-Posting on/off
  1. I RCERATYP=0,'XX Q "0^Medical auto-posting off" ; PRCA*4.5*345 - Changed 'RCERATYP to RCEARTYP=0
  1. ;
  1. ; Check if pharmacy claim and auto-posting is turned off
  1. S XX=$$GET1^DIQ(344.61,"1,",1.01,"I") ; PRCA*4.5*345 - Added line - Rx Auto-Posting on/off
  1. I RCERATYP=1,'XX Q "0^Pharmacy auto-posting off" ; PRCA*4.5*345 - Changed RCERATYP to RCEARTYP=1
  1. ;
  1. ; Check if TRICARE claim and auto-posting is turned off
  1. S XX=$$GET1^DIQ(344.61,"1,",1.05,"I") ; PRCA*4.5*349 - Added line - TRICARE Auto-Posting on/off
  1. I RCERATYP=2,'XX Q "0^TRICARE auto-posting off" ; PRCA*4.5*349 - Added line
  1. ;
  1. ; Check if ERA payer is excluded from autopost
  1. S RCXCLDE=0
  1. S:RCERATYP=0 RCXCLDE=$$EXCLUDE(RCERA) ; PRCA*4.5*345 - Changed to =0 from 'RCERATYP
  1. S:RCERATYP=1 RCXCLDE=$$EXCLDRX(RCERA) ; PRCA*4.5*345 - Changed to =1 from RCERATYP
  1. S:RCERATYP=2 RCXCLDE=$$EXCLDTR(RCERA) ; PRCA*4.5*349 - Added Line
  1. I RCXCLDE Q "0^"_$S(RCERATYP=1:"Pharmacy",RCERATYP=2:"TRICARE",1:"Medical")_" payer excluded" ; PRCA*4.5*349
  1. ;
  1. ; Check for invalid bill number exception
  1. S RCDSUB=0,NOTOK=0
  1. F S RCDSUB=$O(^RCY(344.4,RCERA,1,RCDSUB)) Q:'RCDSUB D Q:NOTOK
  1. . S RCD0=$G(^RCY(344.4,RCERA,1,RCDSUB,0))
  1. . I $P(RCD0,U,5)]"" S NOTOK=1
  1. I NOTOK Q "0^Invalid Bill Number Exception(s)"
  1. ;
  1. ; Check for ERA level Adjustments
  1. I $O(^RCY(344.4,RCERA,2,0)) Q "0^ERA level Adjustment(s)"
  1. ;
  1. ; Check if receipt already created
  1. I +$P(RC0,U,8) Q "0^ERA has a receipt"
  1. ;
  1. ; BEGIN PRCA*4.5*326
  1. ; Check payment type of ERA - CHK type is allowed for a manual match
  1. ;I "^ACH^CHK^"'[(U_$P(RC0,U,15)_U) Q "0^Payment Type is not ACH or CHK" ; PRCA*4.5*321
  1. ; Check payment type of ERA - now also includes CHK, NON and BOP type from manual match
  1. I "^ACH^CHK^BOP^NON^"'[(U_$P(RC0,U,15)_U) Q "0^Payment Type is not ACH, CHK, BOP or NON"
  1. ;
  1. ; CHK type ERA must be matched to an EFT to be eligible for mark for autopost
  1. ;I $P(RC0,U,15)="CHK",'$O(^RCY(344.31,"AERA",RCERA,"")) Q "0^ERA is not matched to an EFT" ; PRCA*4.5*321
  1. ; CHK, NON and BOP type ERA must be matched to an EFT to be eligible for mark for autopost
  1. ;PRCA*4.5*424 Added 'RCZERO
  1. I 'RCZERO,"^CHK^BOP^NON^"'[(U_$P(RC0,U,15)_U),'$O(^RCY(344.31,"AERA",RCERA,"")) Q "0^ERA is not matched to an EFT" ;
  1. ; END PRCA*4.5*326
  1. ;
  1. ; Create scratchpad if needed
  1. S RCCREATE=0
  1. S RCSCR=+$O(^RCY(344.49,"B",RCERA,0))
  1. I 'RCSCR S RCSCR=$$SCRPAD^RCDPEAP(RCERA,RCZERO) S RCCREATE=1 ;PRCA*4.5*424 Added ,RCZERO
  1. I 'RCSCR,'RCZERO Q "0^Unable to create scratchpad" ;PRCA*4.5*424 added 'RCZERO
  1. ;
  1. ; Check if claim level adjustments without payment exist
  1. ; Note that PRCA*298 sets this temp global only if the scratchpad is created by the call above ($$SCRPAD^RCDPEAP). If the
  1. ; scratchpad already exists, the TMP global will never get set. Looking at the code, it will mainly set if there
  1. ; are ERA level adjustments and may get set for unbalanced pairs, which is found by the ZEROBAL function. So, I think
  1. ; this does not have a real purpose but was not 100% sure and wanted to mimic what AUTOCHK does.
  1. I $D(^TMP($J,"RCDPEWLA","ERA LEVEL ADJUSTMENT EXISTS")) D:RCCREATE CLEAR^RCDPEAP(RCSCR) Q "0^Claim Level Adjustments w/o payment"
  1. ;
  1. ; Check if adjustment between matching positive/negative does not create a zero balance
  1. I '$$ZEROBAL(RCSCR) D:RCCREATE CLEAR^RCDPEAP(RCSCR) Q "0^+/- pairs do not balance"
  1. ;
  1. ; Clear scratchpad if it was created by this function
  1. D:RCCREATE CLEAR^RCDPEAP(RCSCR)
  1. ;
  1. ;If we got this far, this is an autopost candidate so quit with 1
  1. Q 1
  1. ;
  1. EXCLUDE(RCERA) ; Verify if auto-posting is allowed for this Payer - PRECHECK USED IN RCDPEM0
  1. ; Not allowed if medical auto-posting is switched off
  1. ; Input: RCERA - IEN for file 344.4
  1. ; Returns: 1 - Exclude ERA becaus Payer is in exclusion table, 0 otherwise
  1. ; PRCA*4.5*345 - changed to $$GET1^DIQ calls below
  1. Q:'$$GET1^DIQ(344.61,"1,",.02,"I") 1 ; Medical Auto-Posting is turned OFF
  1. ;
  1. ; Check if Payer Name and Payer ID from ERA are in auto-posting payer table
  1. N RCPID,RCPNM,RCPXDA
  1. S RCPNM=$$GET1^DIQ(344.4,RCERA_",",.06,"E")
  1. Q:RCPNM="" 1 ; No Payer Name
  1. S RCPID=$$GET1^DIQ(344.4,RCERA_",",.03,"E")
  1. Q:RCPID="" 1 ; No Payer TIN
  1. ;
  1. ; Auto-post is allowed if this is a new payer (not in table)
  1. S RCPXDA=$O(^RCY(344.6,"CPID",RCPNM,RCPID,""))
  1. Q:RCPXDA="" 0
  1. ;
  1. ; If payer table entry found check if payer is excluded from medical auto-post
  1. Q:$$GET1^DIQ(344.6,RCPXDA_",",.06,"I")=1 1
  1. ;
  1. ; Otherwise it is OK to auto-post
  1. Q 0
  1. ;
  1. PHARM(RCERA) ;Check if ERA is for Pharmacy only (ECME number on first line) - CALLED FROM RCDPEM0
  1. N SUB S SUB=$O(^RCY(344.4,RCERA,1,0)) Q:'SUB 0
  1. Q:$P($G(^RCY(344.4,RCERA,1,SUB,4)),U,2)]"" 1
  1. Q 0
  1. ;
  1. ERADET(RCERA,RCRCPTDA,RCLINES) ; called on subsequent attempts of auto-post for a given ERA (DAY 2, DAY 3, ex.)
  1. ; update ERA with receipt or if not posted then update the AUTO-POST REJECTION REASON (#5)
  1. ;
  1. ; RCERA = ien of entry in file 344.4
  1. ; RCRCPTDA = ien of receipt number (344, .01) - optional
  1. ; RCLINES = array of ERA line references
  1. ;
  1. I '$G(RCERA) Q
  1. S RCRCPTDA=$G(RCRCPTDA)
  1. ;
  1. N DA,DIC,DIE,DLAYGO,DO,DR,X
  1. ; Update receipt. If this is the first receipt, put it in the RECEIPT (#08) field. If not, put in OTHER RECEIPTS multiple (#344.48)
  1. I RCRCPTDA D
  1. . I $P($G(^RCY(344.4,RCERA,0)),U,8)]"" S DA(1)=RCERA,DIC="^RCY(344.4,"_DA(1)_",8,",DIC(0)="L",X=RCRCPTDA D FILE^DICN I 1
  1. . E S DIE="^RCY(344.4,",DR=".14////1;.08////"_RCRCPTDA,DA=RCERA D ^DIE
  1. ;
  1. ; Update ERA detail line with Receipt or reject reason as appropriate
  1. ; PRCA*4.5*318 begins
  1. N RCLIN,REJECT
  1. S RCLIN=0
  1. F S RCLIN=$O(RCLINES(RCLIN)) Q:'RCLIN D
  1. . ; Set REJECT to true if the line was rejected during validation
  1. . S REJECT=0 I '$P(RCLINES(RCLIN),U) S REJECT=1
  1. . ;If not posted then update the AUTO-POST REJECTION REASON (#5)
  1. . ;Otherwise update line with receipt number and autopost date
  1. . S DA(1)=RCERA,DA=RCLIN,DIE="^RCY(344.4,"_DA(1)_",1,"
  1. . I 'REJECT,'RCRCPTDA Q
  1. . I REJECT S DR="5///"_$P(RCLINES(RCLIN),U,3)
  1. . E S DR=".25///"_RCRCPTDA_";9///"_DT
  1. . D ^DIE
  1. ; PRCA*4.5*318 ends
  1. Q
  1. ;
  1. ZEROBAL(RCSCR) ;
  1. ; per requirements, only positive/negative payment pairs where payment
  1. ; calculates to zero are allowed for auto-post
  1. ; if payment ends up less than zero or greater than zero then ERA cannot
  1. ; be autoposted.
  1. ; ERA gets sent to the standard worklist for manual receipt processing
  1. ; note: a payment pair represents 2 EEOB sequences with the same claim
  1. ; RCSCR - 344.49 ien
  1. ; X - returns 1 or 0
  1. ;
  1. N SUB,SUB1,WLINE,X,ERALINE
  1. S SUB=0,X=1,ERALINE=""
  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))
  1. . ;If integer sequence, get ERA line reference then quit for this sequence and go on to the non-integer sequence to finish validation
  1. . I $P(WLINE,U)?1N.N S ERALINE=$P(WLINE,U,9) Q
  1. . ; there are multiple EEOB sequences for the specific bill number so an adjustment took place;
  1. . ; if payment adjustment doesn't generate a zero payment balance at 344.491,.06 then this ERA needs to drop to standard worklist
  1. . I ERALINE[",",+$P(WLINE,U,6)'=0 S X=0 Q
  1. . ;do not autopost ERA if one of payments is negative amount
  1. . I $P(WLINE,U,6)<0 S X=0
  1. Q X
  1. ;
  1. EXCLDRX(RCERA) ; Verify if auto-posting is allowed for Pharmacy claims
  1. ; and for the Payer - PRECHECK USED IN RCDPEM0. Not allowed if pharmacy
  1. ; auto-posting is switched off
  1. ; Input: RCERA - IEN for file 344.4
  1. ; Returns: 1 - ERA is excluded from Auto-Posting, 0 otherwise
  1. Q:'$$GET1^DIQ(344.61,"1,",1.01,"I") 1 ; Rx Auto-Posting is turned OFF
  1. N RCPID,RCPNM,RCPXDA
  1. ;
  1. ; Check if Payer Name and Payer ID from ERA are in auto-posting payer table
  1. S RCPNM=$$GET1^DIQ(344.4,RCERA_",",.06,"E")
  1. Q:RCPNM="" 1 ; No Payer Name
  1. S RCPID=$$GET1^DIQ(344.4,RCERA_",",.03,"E")
  1. Q:RCPID="" 1 ; No Payer TIN
  1. ;
  1. ; Auto-post is allowed if this is a new payer (not in table)
  1. S RCPXDA=$O(^RCY(344.6,"CPID",RCPNM,RCPID,"")) Q:RCPXDA="" 0
  1. ;
  1. ; If payer table entry found check if payer is excluded from pharmacy auto-post
  1. Q:$$GET1^DIQ(344.6,RCPXDA_",",.08,"I")=1 1
  1. ;
  1. ; Otherwise it is OK to auto-post
  1. Q 0
  1. ;
  1. EXCLDTR(RCERA) ; Verify if auto-posting is allowed for TRICARE claims
  1. ; and for the Payer - PRECHECK USED IN RCDPEM0. Not allowed if TRICARE
  1. ; auto-posting is switched off
  1. ; PRCA*4.5*349 - Added function
  1. ; Input: RCERA - IEN for file 344.4
  1. ; Returns: 1 - ERA is excluded from Auto-Posting, 0 otherwise
  1. Q:'$$GET1^DIQ(344.61,"1,",1.05,"I") 1 ; TRICARE Auto-Posting is turned OFF
  1. N RCPID,RCPNM,RCPXDA
  1. ;
  1. ; Check if Payer Name and Payer ID from ERA are in auto-posting payer table
  1. S RCPNM=$$GET1^DIQ(344.4,RCERA_",",.06,"E")
  1. Q:RCPNM="" 1 ; No Payer Name
  1. S RCPID=$$GET1^DIQ(344.4,RCERA_",",.03,"E")
  1. Q:RCPID="" 1 ; No Payer TIN
  1. ;
  1. ; Auto-post is allowed if this is a new payer (not in table)
  1. S RCPXDA=$O(^RCY(344.6,"CPID",RCPNM,RCPID,"")) Q:RCPXDA="" 0
  1. ;
  1. ; If payer table entry found check if payer is excluded from TRICARE auto-post
  1. Q:$$GET1^DIQ(344.6,RCPXDA_",",.13,"I")=1 1
  1. ;
  1. ; Otherwise it is OK to auto-post
  1. Q 0
  1. ;
  1. VALID(RCERA,RCLINES) ;
  1. ;Verify which scratchpad lines are able to auto-post - called by EN2^RCDPEAP
  1. ;
  1. ; RCERA - Electronic Remittance Advice (#344.4) IEN
  1. ; RCLINES - Array of ERA line references (passed in by reference)
  1. ; RCLINES(ERALINE)=1 - ERA line(s) are postable. Also RCLINES counter is incremented.
  1. ; RCLINES(ERALINE)=0^^Reject Reason Code - ERA line(s) are not postable
  1. ; NOTE: ORIGINAL ERA SEQUENCES (#.09) can have multiple ERA line references separated by commas (e.g.,"3,4")
  1. ;
  1. ;Check for ScratchPad entry. If missing (should not happen), quit
  1. N RCSCR
  1. S RCSCR=$O(^RCY(344.49,"B",+$G(RCERA),""))
  1. I RCSCR="" S RCLINES=0 Q
  1. ;Loop through scratchpad for this ERA
  1. N SUB,SUB1,WLINE,ERALINE,PIECE,SEQ,CLAIM,STATUS,CLARRAY,AUTOPOST
  1. S SUB=0 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,""))
  1. . I 'SUB1 Q
  1. . S WLINE=$G(^RCY(344.49,RCSCR,1,SUB1,0))
  1. . ;If integer sequence, get ERA line reference and check for auto-post flag
  1. . I $P(WLINE,U)?1N.N D Q
  1. .. S ERALINE=$P(WLINE,U,9)
  1. .. ; If ERA reference is missing (should not happen), skip ahead to next integer sequence
  1. .. I ERALINE="" S SUB=SUB\1_".999" Q
  1. .. ; Check for receipt - PRCA*4.5*318
  1. .. I $$GET1^DIQ(344.41,ERALINE_","_RCERA_",",.25)]"" S SUB=SUB\1_".999" Q ; PRCA*4.5*318
  1. .. S AUTOPOST=1
  1. .. F PIECE=1:1 S SEQ=$P(ERALINE,",",PIECE) Q:'SEQ I '$P($G(^RCY(344.4,RCERA,1,SEQ,5)),U,2) S AUTOPOST=0 Q
  1. .. ; Unless all of the associated ERA detail lines are set for auto-post, skip ahead to next integer sequence
  1. .. I 'AUTOPOST S SUB=SUB\1_".999" Q
  1. . ;If no claim number (suspense), set to autopost but check the rest of the lines for the ERA reference
  1. . S CLAIM=$P(WLINE,U,7)
  1. . I 'CLAIM S RCLINES(ERALINE)=1 Q
  1. . ;Quit with error if claim is not OPEN or ACTIVE
  1. . S STATUS=$P($G(^PRCA(430,CLAIM,0)),"^",8)
  1. . I STATUS'=42,STATUS'=16 S RCLINES(ERALINE)="0^^5",SUB=SUB\1_".999" Q
  1. . ;Quit with error if referred to general council
  1. . I $P($G(^PRCA(430,CLAIM,6)),U,4)]"" S RCLINES(ERALINE)="0^^7",SUB=SUB\1_".999" Q
  1. . ;Check for negative payment amount
  1. . I $P(WLINE,U,6)<0 S RCLINES(ERALINE)="0^^6",SUB=SUB\1_".999" Q
  1. . ;Increment claim balance. If payment exceeds claim balance and no pending payments (at the time of auto posting), quit
  1. . ; with error. Also deduct the amount from the balance so subsequent, smaller amounts may get posted
  1. . S CLARRAY(CLAIM)=+$G(CLARRAY(CLAIM))+$P(WLINE,U,3)
  1. . I '$$CHECKPAY^RCDPEAP(.CLARRAY,CLAIM) S RCLINES(ERALINE)="0^^3",SUB=SUB\1_".999",CLARRAY(CLAIM)=+$G(CLARRAY(CLAIM))-$P(WLINE,U,3) Q
  1. . ;Line is potentially postable - update flag
  1. . S RCLINES(ERALINE)=1
  1. ;
  1. ;Reset the MARK FOR AUTOPOST flag on ERA lines and return count of auto-postable lines - PRCA*4.5*318
  1. N DA,DIE,DR,RCLIN,RCI
  1. S RCLIN=0,RCLINES=0 F S RCLIN=$O(RCLINES(RCLIN)) Q:'RCLIN D
  1. . I +RCLINES(RCLIN) S RCLINES=RCLINES+1
  1. . ;Set MARK FOR AUTO-POST (#6) to NO for every line
  1. . S DA(1)=RCERA,DA=RCLIN,DIE="^RCY(344.4,"_DA(1)_",1,"
  1. . S DR="6///0"
  1. . D ^DIE
  1. Q
  1. ;
  1. UNBAL(RCERA) ; PRCA*4.5*318 added method
  1. ; Determine if the ERA total matches the EFT total for the selected ERA
  1. ; Input: RCERA - Internal IEN of the selected ERA
  1. ; Returns: 1 - ERA is unbalanced, 0 otherwise
  1. N RCLTOT,RCSUB,RCTOT
  1. ;ERA total balance - on matched ERAs the ERA total balance is the same as the EFT total
  1. S RCTOT=+$$GET1^DIQ(344.4,RCERA_",",.05)
  1. ;Sum of ERA claim line payments
  1. S RCSUB=0,RCLTOT=0
  1. F S RCSUB=$O(^RCY(344.4,RCERA,1,RCSUB)) Q:'RCSUB D
  1. . S RCLTOT=RCLTOT+$$GET1^DIQ(344.41,RCSUB_","_RCERA_",",.03)
  1. ;Plus sum of ERA adjustment lines
  1. S RCSUB=0
  1. F S RCSUB=$O(^RCY(344.4,RCERA,2,RCSUB)) Q:'RCSUB D
  1. . S RCLTOT=RCLTOT+$$GET1^DIQ(344.42,RCSUB_","_RCERA_",",.03)
  1. ;Return 1 if total of ERA lines does not match EFT
  1. Q $S(RCTOT=RCLTOT:0,1:1)
  1. ;
  1. ; PRCA*4.5*424 New subroutines MATCHED and is ZERO added
  1. MATCHED(IEN) ; Check if ERA is matched
  1. ; Input IEN - Internal entry number of ERA #344.4
  1. ; Returns 1 if ERA is matched, otherwise 0
  1. I $O(^RCY(344.31,"AERA",RCERA,"")) Q 1
  1. Q 0
  1. ISZERO(IEN) ; Check is ERA is zero balance (EP)
  1. ; Input IEN - Internal entry number of ERA #344.4
  1. ; Returns 1 if ERA is zero balance, otherwise 0
  1. I +$P($G(^RCY(344.4,IEN,0)),U,5)=0 Q 1
  1. Q 0