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

BAREDEP.m

Go to the documentation of this file.
BAREDEP ; IHS/SD/TPF - AR ERA PAYMENT CHECKER ; 01/30/2009
 ;;1.8;IHS ACCOUNTS RECEIVABLE;**5,6,10,20,23,24**;OCT 26,2005;Build 69
 ;BAR*1.8*6 IHS/SD/TPF MOVE REVERSAL CHECK TO A FULL CLMDA LOOP
 ;IHS/SD/POT HEAT#82698 NOV 2012  ACCEPT LEADING ZEROES IN CHKECK # (POS)- BAR 1.8*23
 ;IHS/SD/POT HEAT148388 1/10/2014 ACCEPT REVERSALS FOR TYPE= 1 IF NEG PAYMENT- BAR 1.8*24
 ;IHS/SD/POT HEAT147572 ALLOW TRIBAL SITES ERA POSTING OF NEG BAL & CANCELLED BILLS- BAR 1.8*24
 Q
REVLOOP(IMPDA) ;EP - REVERSAL LOOP
 N CLMDA,MATCHES,ERRORS
 S CLMDA=0
 I $G(BARDBG) W !!,"BEGIN REVERSAL/PAYMENT MATCHING PROCESS"
 F  S CLMDA=$O(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA)) Q:'CLMDA  D
 . Q:$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,2)="P"  ;DON'T CHECK REVERSALS ALREADY POSTED
 . ;Q:$D(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,4,"B",44))  ;DON'T PROCESS USER STATUS OVERRIDE BAR*1.8*6 SCR120
 . Q:$$OVERIDE^BAREDEP1(CLMDA)                         ;MRS:BAR*1.8*10 D159-1 AND 2
 . ;;;S REVERSAL=+$$GET1^DIQ(90056.0205,CLMDA_","_IMPDA_",",.11)=22 old code HEAT148388 - BAR 1.8*24
 . S REVERSAL=$$ISREV(CLMDA,IMPDA) ; 1/10/2014 P.OTT HEAT148388 - BAR 1.8*24
 . ;ONLY REVERSALS WITH A NEGATIVE AMOUNT WILL BE PROCESSED FOR A MATCHING PAYMENT - PER ADRIAN
 . I REVERSAL D
 ..I $G(BARDBG) W !,"SHOULD WE CHECK FOR A MATCHING PAYMENT?  ",$$GET1^DIQ(90056.0205,CLMDA_","_IMPDA_",",.01)
 ..I $G(BARDBG) W !,"ONLY IF E-PAYMENT IS < 0 ",$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,4)
 . ;old code I REVERSAL,$$IHS^BARUFUT(DUZ(2)),(+$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,4)<0) D REVCHECK(IMPDA,CLMDA)  ;CHECK FOR PAYMENT AND REVERSALS W/IN ERA FILE
 . I REVERSAL,$$IHSNEGB^BARUFUT(DUZ(2)),(+$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,4)<0) D REVCHECK(IMPDA,CLMDA) ;HEAT147572 - BAR 1.8*24
 Q
REVCHECK(IMPDA,REVDA) ;EP - REVERSAL AND PAYMENT CHECKS
 I $G(BARDBG) W !!,"LOOKING FOR MATCHING PAYMENT FOR REVERSAL ",$P($G(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,0)),U)
 I $P($G(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,0)),U,2)="P" W:$G(BARDBG) !,"CLAIM ",$P($G(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,0)),U)," ALREADY POSTED"
 I $P($G(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,5)),U)=139 W:$G(BARDBG) !,"CLAIM ",$P($G(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,0)),U)," ALREADY CREDIT FROM"
 I $P($G(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,5)),U)=138 W:$G(BARDBG) !,"CLAIM ",$P($G(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,0)),U)," ALREADY CREDIT TO"
 I $P($G(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,1)),U)="" W:$G(BARDBG) !,"CLAIM ",$P($G(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,0)),U)," NO A-CLAIM"
 ;N MATCHES,ERRORS BAR*1.8*6 MOVE UP TO REVLOOP
 S (MATCHES,NOMATCH)=0
 D INBILL(IMPDA,REVDA,.MATCHES,.NOMATCH)
 Q:$G(MATCHES)=1
 S (MATCHES,NOMATCH)=0
 D INERA(IMPDA,REVDA,.MATCHES,.NOMATCH)   ;NOW CHECK INSIDE ERA FILE FOR MATHES
 Q:$G(MATCHES)=1    ; IF MATCH FOUND IN ERA FILE THEN YOU'RE DONE
 S (MATCHES,NOMATCH)=0
 D INRPMS(IMPDA,REVDA,.MATCHES,.NOMATCH)
 I $G(MATCHES)=0 D
 .I $G(BARDBG) W !!,"MATCHING PAYMENT NOT FOUND FOR REVERSAL!"
 .S ERRORS("PT NF E")=""
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 .K ERRORS
 Q
INBILL(IMPDA,REVDA,MATCHES,NOMATCH) ;EP - SEARCH FOR MATCHES WITHIN BILL
 N CLIENS,CLBILL,CLPAYMNT,CLSTATUS,CLCHECK,PAYMENTS,REVICN,CLMICN,CNT
 N CLMDA  ;BAR*1.8*6
 S REVCHECK=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",201,"E")   ;CHECK/EFT TRACE
 S REVBILL=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",.01,"E")   ;E-CLAIM (AR BILL
 S REVAMT=-$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",.04,"E")   ;E-PAYMENT
 ;S REVAMT=-$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",.05,"E")   ;E-BILLED
 S REVICN=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",302,"E")   ;PAYER CLAIM CONTROL # (ICN)
 ;IF REVICN CONTAINS AN 'R' THIS IS A MEDICARE REVERSAL
 I $G(BARDBG) W !!,"LOOKING FOR MATCHING PAYMENT FOR ",-REVAMT," WITHIN BILL ",REVBILL
 S PAYMENTS=0
 S CLMDA=""
 F CNT=1:1 S CLMDA=$O(^BAREDI("I",DUZ(2),IMPDA,30,"B",REVBILL,CLMDA)) Q:CLMDA=""  D
 .W:'(CNT#1000) "."
 .Q:$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,2)="P"  ;DON'T CHECK POSTED CLAIMS
 .Q:REVDA=CLMDA  ;DO NOT PROCESS REVERSAL CLAIM WE FOUND IN BAREDP04
 .S CLIENS=CLMDA_","_IMPDA_","
 .;Q:$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,1)),U)=""  ;IF NOT MATCHED DON'T COMPARE  ;bar*1.8*20 REQ4
 .S CLSTATUS=$P($$GET1^DIQ(90056.0205,CLIENS,.11,"E")," ")  ;E-CLAIM STATUS CODE (CLP02)
 .I CLSTATUS="" S CLSTATUS=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,2)),U,4)  ;MRS:BAR*1.8*10 H2555
 .I CLSTATUS=22 Q  ;DON'T LOOK AT OTHER REVERSALS
 .Q:(U_"1"_U_"2"_U_"3"_U_"19"_U_"20"_U_"21"_U)'[(U_CLSTATUS_U)  ;PRIMARY,SECONDARY,TERTIARY AS WELL AS THOSE 19,20,21 FORWARDED TO ADDITIONAL PAYER
 .S POSTAS=$$GET1^DIQ(90056.0205,CLIENS,501,"I")   ;POST THIS CLAIM AS TYPE
 .Q:POSTAS=138!(POSTAS=139)  ;DON'T TRY TO MATCH A REVERSAL TO A PAYMENT ALREADY MATCHED
 .S CLMICN=$$GET1^DIQ(90056.0205,CLIENS,302,"E")   ;PAYER CLAIM CONTROL # (ICN)
 .S PAYMENTS=PAYMENTS+1
 .S CLPAYMNT=$$GET1^DIQ(90056.0205,CLIENS,.04,"E")  ;E-PAYMENT
 .I REVICN["R" D  Q
 ..I (CLPAYMNT=REVAMT) D
 ...S MATCHES=MATCHES+1
 ...S MATCHES(IMPDA,CLMDA,REVDA)=""
 ..E  S NOMATCH=NOMATCH+1 S NOMATCH(IMPDA,CLMDA,REVDA)=""
 .I REVAMT=CLPAYMNT D
 ..S MATCHES=MATCHES+1
 ..S MATCHES(IMPDA,CLMDA,REVDA)=""
 .E  S NOMATCH=NOMATCH+1 S NOMATCH(IMPDA,CLMDA,REVDA)=""
 Q:'PAYMENTS!'MATCHES
 I REVICN["R" D MCRERRS(.MATCHES,.NOMATCH,PAYMENTS,"INBILL") I 1
 E  D REGERRS(.MATCHES,.NOMATCH,PAYMENTS,"INBILL")
 K ERRORS
 Q
INERA(IMPDA,REVDA,MATCHES,NOMATCH) ;EP - FIND PAYMENTS AND REVERSAL W/IN ERA FILE
 N CLIENS,CLBILL,CLPAYMNT,CLSTATUS,CLCHECK,PAYMENTS,REVICN,CLMICN,CNT
 N CLMDA  ;BAR*1.8*6
 S REVCHECK=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",201,"E")  ;CHECK/EFT TRACE
 S REVBILL=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",.01,"E")   ;E-CLAIM (AR BILL
 S REVAMT=-$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",.04,"E")   ;E-PAYMENT
 S REVICN=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",302,"E")   ;PAYER CLAIM CONTROL # (ICN)
 S ERAFILE=$$GET1^DIQ(90056.02,IMPDA_",",.01,"E")  ;CHECK/EFT TRACE
 ;IF REVICN CONTAINS AN 'R' THIS IS A MEDICARE REVERSAL
 I $G(BARDBG) W !!,"LOOKING FOR MATCHING PAYMENT FOR ",-REVAMT," IN ERA FILE ",ERAFILE
 S PAYMENTS=0
 S NOMATCH=0
 S CLMDA=0
 F CNT=1:1 S CLMDA=$O(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA)) Q:'CLMDA!(MATCHES)  D
 .W:'(CNT#1000) "."
 .Q:$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,2)="P"  ;DON'T CHECK POSTED CLAIMS
 .S CLCHECK=$$GET1^DIQ(90056.0205,CLMDA_","_IMPDA_",",201,"E")  ;CHECK/EFT TRACE
 .Q:CLCHECK'=REVCHECK
 .Q:REVDA=CLMDA  ;DO NOT PROCESS REVERSAL CLAIM WE FOUND
 .S CLIENS=CLMDA_","_IMPDA_","
 .Q:$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,1)),U)=""  ;IF NOT MATCHED DON'T COMPARE
 .S CLSTATUS=$P($$GET1^DIQ(90056.0205,CLIENS,.11,"E")," ")  ;E-CLAIM STATUS CODE (CLP02)
 .I CLSTATUS="" S CLSTATUS=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,2)),U,4)  ;MRS:BAR*1.8*10 H2555
 .I CLSTATUS=22 Q  ;DON'T LOOK AT OTHER REVERSALS,SHOULD WE SKIP ANY OTHERS?
 .Q:(U_"1"_U_"2"_U_"3"_U_"19"_U_"20"_U_"21"_U)'[(U_CLSTATUS_U)  ;PRIMARY,SECONDARY,TERTIARY AS WELL AS THOSE 19,20,21 FORWARDED TO ADDITIONAL PAYER
 .S POSTAS=$$GET1^DIQ(90056.0205,CLIENS,501,"I")   ;POST THIS CLAIM AS TYPE
 .Q:POSTAS=138!(POSTAS=139)  ;DON'T TRY TO MATCH A REVERSAL TO A PAYMENT ALREADY MATCHED
 .S PAYMENTS=PAYMENTS+1
 .I $G(BARDBG) W !?15,"SEARCHING FOR PAYMENT TO MATCH REV OF ",REVAMT
 .S CLBILL=$$GET1^DIQ(90056.0205,CLIENS,.01,"E")  ;E-CLAIM (AR BILL
 .Q:CLBILL=REVBILL  ;ALREADY CHECKED WITHIN THE BILL FOR MATCHES, NOW CHECK OTHER BILLS IN ERA FILE
 .I $G(BARDBG) W !?20,"REV BILL ",REVBILL,!?20,"CL BILL ",CLBILL
 .S CLMICN=$$GET1^DIQ(90056.0205,CLIENS,302,"E")   ;PAYER CLAIM CONMTROL # (ICN)
 .S CLPAYMNT=$$GET1^DIQ(90056.0205,CLIENS,.04,"E")  ;E-PAYMENT
 .;S CLPAYMNT=$$GET1^DIQ(90056.0205,CLIENS,.05,"E")  ;E-BILL
 .;MEDICARE MATCH?
 .I REVICN["R" D  Q
 ..I CLMICN=$TR(REVICN,"R") D
 ...S MATCHES=MATCHES+1
 ...S MATCHES(IMPDA,CLMDA,REVDA)=""
 ..E  S NOMATCH=NOMATCH+1 S NOMATCH(IMPDA,CLMDA,REVDA)=""
 .;REGULAR MATCH?
 .I CLPAYMNT=REVAMT D  Q
 ..S MATCHES=MATCHES+1
 ..S MATCHES(IMPDA,CLMDA,REVDA)=""
 .E  S NOMATCH=NOMATCH+1 S NOMATCH(IMPDA,CLMDA,REVDA)=""
 Q:'MATCHES!'PAYMENTS
 I REVICN["R" D MCRERRS(.MCRMATCH,.MCRNOMAT,PAYMENTS,"INERA") I 1
 E  D REGERRS(.MATCHES,.NOMATCH,PAYMENTS,"INERA")
 K ERRORS
 Q
INRPMS(IMPDA,REVDA,MATCHES,NOMATCH) ;EP - LOOK FOR MATCHING PAYMENT IN A/R BILL
 N REVAMT,REVBILL,ERACHECK,BARBLIEN,FOUND,REVDATE,COLDA,ITEMDA,REVSCHED,REVERSAL,TAMOUNT
 N TRANS,BARFROM,BARTO,BARTYPE
 N CLMDA  ;BAR*1.8*6
 I $G(BARDBG) W !!,"LOOKING FOR MATCHING PAYMENT IN RPMS"
 S REVAMT=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",.04,"E")   ;E-CLAIM PAYMENT
 S REVBILL=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",.01,"E")   ;E-CLAIM
 S REVCHECK=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",201,"E")  ;CHECK/EFT TRACE
 S POSTAS=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",501,"I")   ;POST THIS CLAIM AS TYPE
 Q:POSTAS=138!(POSTAS=139)
 S CLMDA=0,BILLCHOS=""
 F  S CLMDA=$O(^BAREDI("I",DUZ(2),IMPDA,30,"B",BARBILL,CLMDA)) Q:'CLMDA!(BILLCHOS'="")  D
 .S BILLCHOS=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,1)),U)  ;A-CLAIM ; IF THIS IS POPULATED THEN THE CORRECT BILL WAS FOUND OR CHOSEN ALREADY
 I BILLCHOS S BARBLIEN=BILLCHOS
 E  S BARBLIEN=$$GETIEN^BAREDEB("B",BARBILL)
 I BARBLIEN="BILL NOT FOUND" D  Q
 .S CLMDA=$O(^BAREDI("I",DUZ(2),IMPDA,30,"B",BARBILL,""))
 .I '$D(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,4,"B",11)) D
 ..S ERRORS("BL NF")=""  ;BILL NOT FOUND IN RPMS. SET ONLY IF OLD ERROR 11 NOT SET
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 .K ERRORS
 I BARBLIEN="DUPLICATE BILLS FOUND" D  Q
 .S ERRORS("DUPB")=""  ;DUPLICATE BILLS FOUND IN RPMS
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 .K ERRORS
 Q:'BARBLIEN 0
 S FOUND=0
 S REVERSAL=0  ;NUMBER OF REVERSALS ALREADY SET UP FOR THIS AMOUNT.
 S TRANS=""
 F  S TRANS=$O(^BARTR(DUZ(2),"AC",BARBLIEN,TRANS),-1) Q:'TRANS!(FOUND)  D  ;REVERSAL CAN NOT APPLY TO A FUTURE PAYMENT
 .S TRANTYPE=$$GET1^DIQ(90050.03,TRANS_",",101,"E")
 .Q:TRANTYPE'="PAYMENT"&(TRANTYPE'="PAYMENT CREDIT")  ;OLD WILL BILL 'PAYMENT', NEW STUFF WILL BE 'PAYMENT CREDIT'
 .S TAMOUNT=$$GET1^DIQ(90050.03,TRANS_",",3.5,"E")
 .I TAMOUNT=REVAMT,$$GET1^DIQ(90050.03,TRANS_",",110,"I") S REVERSAL=REVERSAL+1 Q  ;#110 = DATE OF TRANSACTION REVERSED
 .I TAMOUNT=-REVAMT D
 ..S COLDA=$$GET1^DIQ(90050.03,TRANS_",",14,"I")
 ..S ITEMDA=$$GET1^DIQ(90050.03,TRANS_",",15,"I")
 ..;;;Q:'$D(^BARCOL(DUZ(2),"D",REVCHECK,COLDA,ITEMDA))  ;IF COLLECTION BATCH AND ITEM DON'T MATCH UP WE CAN'T POST
 .. I '$D(^BARCOL(DUZ(2),"D",REVCHECK,COLDA,ITEMDA)),'$D(^BARCOL(DUZ(2),"D",+REVCHECK,COLDA,ITEMDA)) Q  ;- BAR 1.8*23
 ..I REVERSAL S REVERSAL=REVERSAL-1 Q  ;MATCHING REVERSAL SO THIS PAYMENT MATCHES
 ..S FOUND=FOUND+1
 ..S REVDATE=$$GET1^DIQ(90050.03,TRANS_",",.01,"I")
 ..S REVSCHED=$$GET1^DIQ(90051.01,COLDA_",",28,"I")
 ..I REVSCHED="" S REVSCHED=$$GET1^DIQ(90051.1101,ITEMDA_","_COLDA_",",20,"I")
 ..S:REVSCHED="" REVSCHED="PRE-UFMS_COLLECTIONS"
 I 'FOUND D  Q
 .S ERRORS("PR NM R")=""  ;MATCHING PAYMENT NOT FOUND IN A/R TRANSACTION FILE
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 .K ERRORS
 ;NOW WE SHOULD HAVE A NON-MATCHED PAYMENT EQUALING OUR ERA REVERSAL
 K DIE,DIC,DR,DA,DIR
 S BARFROM=$$GET1^DIQ(90056.0205,REVDA_","_IMPDA_",",1.01,"I")
 S BARTO=$G(BARBLIEN)
 Q:BARFROM=""  ;DON'T MATCH TO A NON-MATCHED CLAIM
 S DIE=$$DIC^XBDIQ1(90056.0205)
 S BARTYPE=139
 ;S DR=DR=DR_"501///^S X=BARTYPE"  ;CREDIT TO OTHER BILL
 S DR="501///^S X=BARTYPE"  ;CREDIT TO OTHER BILL BAR*1.8*6 IM29724
 S DR=DR_";.12///^S X=REVDATE"
 S DR=DR_";301///^S X=REVSCHED"
 S DR=DR_";602///^S X=BARFROM"
 S DR=DR_";601///^S X=BARTO"
 S DA(1)=IMPDA
 S DA=REVDA
 D ^DIE
 ;HAD TROUBLE GETTING THE DIE CALL TO WORK FOR .12 AND 301
 S $P(^BAREDI("I",DUZ(2),DA(1),30,DA,0),U,12)=REVDATE
 S $P(^BAREDI("I",DUZ(2),DA(1),30,DA,3),U)=REVSCHED
 K DR,DIE,DIC,DIR
 K ERRORS
 Q
MCRERRS(MATCHES,NOMATCH,PAYMENTS,WHERE) ;EP - MCR ERRORS
 N ERRORS,CLMDA
 I MATCHES=1 D SETMATCH(.MATCHES) Q
 I PAYMENTS=0 D
 .I WHERE="INBILL" S ERRORS("PT NF B")=""
 .E  S ERRORS("PT NF E")=""
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 I MATCHES>0 D
 .I WHERE="INBILL" S ERRORS("MP MCR B")=""
 .E  S ERRORS("MP MCR E")=""
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 .S CLMDA=""
 .F  S CLMDA=$O(MATCHES(IMPDA,CLMDA)) Q:'CLMDA  D
 ..D ADDREAS^BAREDP04(IMPDA,CLMDA,.ERRORS)
 I NOMATCH>0 D
 .I WHERE="INBILL" S ERRORS("NM MCR B")=""
 .E  S ERRORS("NM MCR E")=""
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 .S CLMDA=""
 .F  S CLMDA=$O(NOMATCH(IMPDA,CLMDA)) Q:'CLMDA  D
 ..D ADDREAS^BAREDP04(IMPDA,CLMDA,.ERRORS)
 K ERRORS
 Q
REGERRS(MATCHES,NOMATCH,PAYMENTS,WHERE) ; EP 
 N ERRORS,CLMDA
 I MATCHES=1 D SETMATCH(.MATCHES) Q
 I PAYMENTS=0 D
 .I WHERE="INBILL" S ERRORS("PT NF B")=""
 .E  S ERRORS("PT NF E")=""
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 I MATCHES>1 D
 .I WHERE="INBILL" S ERRORS("MPB")=""
 .E  S ERRORS("MPE")=""
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 .S CLMDA=""
 .F  S CLMDA=$O(MATCHES(IMPDA,CLMDA)) Q:'CLMDA  D
 ..D ADDREAS^BAREDP04(IMPDA,CLMDA,.ERRORS)
 I NOMATCH>0 D
 .I WHERE="INBILL" S ERRORS("PR NM B")=""
 .E  S ERRORS("PR NM E")=""
 .D ADDREAS^BAREDP04(IMPDA,REVDA,.ERRORS)
 .S CLMDA=""
 .F  S CLMDA=$O(NOMATCH(IMPDA,CLMDA)) Q:'CLMDA  D
 ..D ADDREAS^BAREDP04(IMPDA,CLMDA,.ERRORS)
 K ERRORS
 Q
SETMATCH(MATCH) ;EP - SET TO MATCHING AND SET TRANSACTION TYPE
 N IMPDA,CLMDA,REVDA,CLIENS,REVIENS,BARFROM,BARTO,CNT
 S IMPDA=$O(MATCH(""))
 Q:IMPDA=""
 S CLMDA=$O(MATCH(IMPDA,""))
 Q:CLMDA=""
 S REVDA=$O(MATCH(IMPDA,CLMDA,""))
 Q:REVDA=""
 S CLIENS=CLMDA_","_IMPDA_","
 S REVIENS=REVDA_","_IMPDA_","
 I $O(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,4,0)) Q
 I $O(^BAREDI("I",DUZ(2),IMPDA,30,REVDA,4,0)) Q
 I $G(BARDBG) W !!,"PAYMENT REVERSAL: ",$$GET1^DIQ(90056.0205,CLIENS,.01,"E")
 I $G(BARDBG) W !,"MATCHED TO REVERSAL: ",$$GET1^DIQ(90056.0205,REVIENS,.01,"E")
 S BARFROM=$$GET1^DIQ(90056.0205,REVIENS,1.01,"I")
 S BARTO=$$GET1^DIQ(90056.0205,CLIENS,1.01,"I")
 Q:BARFROM=""!(BARTO="")  ;DO NOT MATCH TO A NON-MATCHED CLAIM
 I $G(BARDBG) W !,"PAYMENT CREDIT APPLIED FROM: ",BARFROM
 I $G(BARDBG) W !,"PAYMENT CREDIT APPLIED TO: ",BARTO
 K DA S CNT=0
 F DA=CLMDA,REVDA D
 .S CNT=CNT+1
 .K DR,DIE,DIC,DIR
 .S DIE=$$DIC^XBDIQ1(90056.0205)
 .I CNT=1 S TYPE=139  ;CREDIT FROM OTHER BILL
 .E  S TYPE=138  ;CREDIT TO OTHER BILL
 .S STAT="M"
 .S DR=".02///^S X=STAT"
 .S DR=DR_";501///^S X=TYPE"
 .I CNT=1 S DR=DR_";602///^S X=BARFROM"
 .E  S DR=DR_";601///^S X=BARTO"
 .S DA(1)=IMPDA
 .D ^DIE
 .K DR,DIE,DIC,DIR
 Q
ISREV(CLMDA,IMPDA) ;HEAT148388- BAR 1.8*24
 I +$$GET1^DIQ(90056.0205,CLMDA_","_IMPDA_",",.11)=22 Q 1
 Q 0
 ;----------------