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

BAR50EB.m

Go to the documentation of this file.
BAR50EB ; IHS/SD/TPF - AR ERA BALANCE CHECKER ; 01/28/2009
 ;;1.8;IHS ACCOUNTS RECEIVABLE;**5,6,10,20,21,22,23,24,26,28**;OCT 26,2005;Build 92
 ;
 ;THIS RTN CONTAINS THE BALANCE CHECKING NEED SO ERA POSTING DOES NOT ALLOW
 ;POSTING WHICH WILL NOT BE ACCEPTED BY UFMS
 ;
 ;BATCH - CHECKS THE TRANSACTIONS WITHIN A SINGLE ERA FILE BEING POSTED
 ;AGAINST A BATCH. THE PAYMENTS/ADJUSTMENTS FROM THE ERA FILE MUST BE <= THE 
 ;BATCH AMOUNT (#29) AND THE BATCH AMOUNT (#29) MUST BE >=0
 ;;P.OTTIS HEAT#82698 NOV 2012 LEADING ZEROES IN CHKECK # (POS)
 ;;                   MAR 2013 EXCLUDED COL BATCHES OLDER THAN 365 DAYS
 ;;                   10/10/2013 FIXED ERR MSG
 ;;HEAT147572 P.OTT ALLOW TRIBAL SITES ERA POSTING OF NEG BAL & CANCELLED BILLS 2/5/2014
 ;;HEAT151948 P.OTT 2/6/2014 FIXED PENDING ADJ. (NEGATIVE BILL BALANCE)
 ;IHS/SD/SDR 1.8*26 - HEAT170856 Changed IHSNEGB to IHSCANCB for ERA > ITM check.
 ;IHS/SD/SDR 1.8*28 - CR8346 HEAT275351 - Fixed so matched with reason NTP won't get counted in matched total.
 ;IHS/DIT/CPC 1.8*28 - CR9372 Change position of ADDREAS 
 Q
 ;
 ;TYPE = "ERA" FOR INTERNAL ERA FILE CHECK, RPMS = COMPARE ERA TO RPMS BILL
NEGBAL(IMPDA,TYPE) ;EP - CHECK FOR NEGATIVE BALANCE W/IN ERA AND IF POSTED AGAINST RPMS
 Q:$G(TYPE)=""
 I $G(BARDBG) W !!!,"CHECKING FOR NEGATIVE BALANCE IF MATCHED ERA CLAIMS ARE POSTED..."  ;bar*1.8*20
 N BARBILL,BARANS,BARTOT,BARPAY,BARADJ,ADJDA,ERRORS,CHECKTOT,ALLADJ
 N ERACHECK,CLMDA,TCLMDA,CLM,ERRORS,BILLCHOS,BARTYPE,BARREAS
 S (BARBAL,BARTOT,ALLADJ)=0
 K CHECKTOT
 S BARBILL=""
 K BARCNT,BARAMT,BARTOT  ;bar*1.8*20
 S CLMCNT=0
 S CLMDA=0
 K ^XTMP("BAR-LIST",$J,DUZ(2))
 F  S CLMDA=$O(^BAREDI("I",DUZ(2),"F",BARCHK,IMPDA,CLMDA)) Q:'CLMDA  D
 .S BARBILL=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U)
 .S ^XTMP("BAR-LIST",$J,DUZ(2),BARBILL,CLMDA)=""
 S BARBILL=""
 F  S BARBILL=$O(^XTMP("BAR-LIST",$J,DUZ(2),BARBILL)) Q:BARBILL=""  D
 .S CLMCNT=+$G(CLMCNT)+1  ;bar*1.8*20 REQ4
 .S BARPAY=0
 .;WAS A BILL CHOSEN OR MATCHED EARLIER IN BAR50P04?
 .S CLMDA=0,BILLCHOS=""
 .F  S CLMDA=$O(^BAREDI("I",DUZ(2),IMPDA,30,"B",BARBILL,CLMDA)) Q:'CLMDA  D
 ..S CLMCNT=CLMCNT+1
 ..S (BARTOT,BARADJ,BARPAY)=0
 ..S BILLCHOS=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,1)),U)  ;A-CLAIM ; IF THIS IS POPULATED THEN THE CORRCET BILL WAS FOUND OR CHOSEN ALREADY
 ..S BARSTAT=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,2)  ;bar*1.8*20 REQ5
 ..S BARTOT("CNT")=+$G(BARTOT("CNT"))+1,BARTOT("AMT")=+$G(BARTOT("AMT"))+$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,4) ;bar*1.8*20
 ..I BARSTAT="M" S BARCNT("MATCHED")=+$G(BARCNT("MATCHED"))+1,BARAMT("MATCHED")=+$G(BARAMT("MATCHED"))+$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,4)  ;bar*1.8*20
 ..I BARSTAT'="M" S BARCNT("UNMATCHED")=+$G(BARCNT("UNMATCHED"))+1,BARAMT("UNMATCHED")=+$G(BARAMT("UNMATCHED"))+$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,4)  ;bar*1.8*20
 ..Q:BARSTAT'="M"  ;only display matched claims bar*1.8*20
 ..I $G(BARDBG) W !!,CLMCNT,?4,"ERA BILL: ",BARBILL  ;bar*1.8*20 REQ4
 ..I BILLCHOS S BARBLIEN=BILLCHOS
 ..E  S BARBLIEN=$$GETIEN("B",BARBILL)
 ..I BARBLIEN="BILL NOT FOUND" D
 ...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
 ..I BARBLIEN="DUPLICATE BILLS FOUND" D
 ...S ERRORS("DUPB")=""  ;DUPLICATE BILLS FOUND IN RPMS
 ..I BARBLIEN S BARBAL=$$GET1^DIQ(90050.01,BARBLIEN_",",15,"I")  ;CURRENT BILL AMOUNT
 ..E  S BARBAL=0
 ..I $G(BARDBG) W ?41,"CURRENT BILL AMT(RPMS): ",$J($FN(BARBAL,",",2),14)  ;bar*1.8*20 REQ4
 ..;
 ..S BARADJ=0
 ..I $$DONOTPR(IMPDA,CLMDA) Q  ;new code
 ..;Q:$$OVERIDE^BAR50EP1(CLMDA)  ;MRS:BAR*1.8*10 D159-1 AND 2
 ..;Q:$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,2)="P"  ;DON'T PROCESS POSTED CLAIMS
 ..;S CLSTATUS=$P($P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,11)," ")  ;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
 ..;Q:(U_"1"_U_"2"_U_"3"_U_"4"_U_"19"_U_"20"_U_"21"_U_"22"_U)'[(U_CLSTATUS_U)  ;ADDED 4 (DENIALS) PER EMAIL OF 7/31
 ..;DENIAL ADJUSTMENTS CLP02=4 WERE CREATING NEGATIVE BALANCES
 ..S ERACHECK=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,2)),U)
 ..S BARAMT=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,4)
 ..S BARPAY=BARPAY+BARAMT
 ..I $G(BARDBG) W !?3,$S(BARBILL'=$$GET1^DIQ(90050.01,BILLCHOS,".01"):"("_$$GET1^DIQ(90050.01,BILLCHOS,".01")_")",1:""),?59,"PYMT: ",$J($FN(BARAMT,",",2),14)  ;bar*1.8*20 REQ4
 ..;
 ..;S CHECKTOT(ERACHECK)=$G(CHECKTOT(ERACHECK))+BARAMT  ;bar*1.8*28 IHS/SD/SDR CR8346 HEAT275351
 ..I ((BARSTAT="M")&(+$O(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,4,0))=0)) S CHECKTOT(ERACHECK)=$G(CHECKTOT(ERACHECK))+BARAMT  ;only count postable amounts  ;bar*1.8*28 IHS/SD/SDR CR8346 HEAT275351
 ..S ADJDA=0
 ..F  S ADJDA=$O(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,30,ADJDA)) Q:'+ADJDA  D
 ...S BARAMT=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,30,ADJDA,0)),U,2)
 ...S BARCAT=$$GET1^DIQ(90056.0208,ADJDA_","_CLMDA_","_IMPDA_",",.04,"E")
 ...S BARCATN=$$GET1^DIQ(90056.0208,ADJDA_","_CLMDA_","_IMPDA_",",.04,"I") ;P.OTT 2/6/2014 HEAT151948
 ...S BARREAS=$$GET1^DIQ(90056.0208,ADJDA_","_CLMDA_","_IMPDA_",",.05,"E")
 ...I $G(BARDBG) W !?3,"A/R CAT:",$E(BARCAT,1,11) ;,"  (",BARCAT,")" R ASD
 ...I $G(BARDBG) W ?23,"A/R RSN:",$E(BARREAS,1,27)
 ...I $G(BARDBG) W ?60,"ADJ:",$J($FN(BARAMT,",",2),15)
 ...I BARCATN=21 Q  ;PENDING  3/5/14 P.OTT HEAT151948
 ...I BARCATN=22 Q  ;GEN INFO P.OTT HEAT151948
 ...S BARADJ=BARADJ+BARAMT
 ...S ALLADJ=ALLADJ+BARAMT
 ..S BARTOT=BARPAY+BARADJ
 ..I $G(BARDBG) W !,?28,"BILL BALANCE IF ERA CLAIM IS POSTED: ",$J($FN(BARBAL-BARTOT,",",2),14)
 ..;---chk for neg bal
 ..I ((BARSTAT="M")&(+$O(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,4,0))'=0)) Q  ;bar*1.8*28 IHS/SD/SDR CR8346 HEAT275351
 ..I BARBAL-BARTOT<0 D
 ...Q:BARSTAT'="M"!($D(ERRORS("DUPB")))  ;don't put error on claim if not matched or if duplicate bills  bar*1.8*20 REQ5
 ...I '$$IHSNEGB^BARUFUT(DUZ(2)) Q  ;P.OTT 2/5 2014 HEAT147572
 ...S ERRORS("NEGR")=""
 ..I $D(ERRORS) D ADDREAS^BAR50P04(IMPDA,CLMDA,.ERRORS)  ;IHS/DIT/CPC 1.8*28 - Move out of loop 
 ...;S TCLMDA=""
 ...;F  S TCLMDA=$O(^BAREDI("I",DUZ(2),IMPDA,30,"B",BARBILL,TCLMDA)) Q:TCLMDA=""  D
 ....;I $$DONOTPR(IMPDA,CLMDA) Q  ;new code
 ....;Q:$$OVERIDE^BAR50EP1(TCLMDA)                         ;MRS:BAR*1.8*10 D159-1 AND 2
 ....;Q:$P($G(^BAREDI("I",DUZ(2),IMPDA,30,TCLMDA,0)),U,2)="P"  ;DON'T PROCESS POSTED CLAIMS
 ....;S CLSTATUS=$P($P($G(^BAREDI("I",DUZ(2),IMPDA,30,TCLMDA,0)),U,11)," ")  ;E-CLAIM STATUS CODE (CLP02) BAR*1.8*6 IM29637
 ....;I CLSTATUS="" S CLSTATUS=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,2)),U,4)  ;MRS:BAR*1.8*10
 ....;Q:(U_"1"_U_"2"_U_"3"_U_"4"_U_"19"_U_"20"_U_"21"_U_"22"_U)'[(U_CLSTATUS_U)  ;ADDED 4 (DENIALS) PER EMAIL/CONVERSATION WITH ADRIAN 7/31
 ....;D ADDREAS^BAR50P04(IMPDA,TCLMDA,.ERRORS)
 ..K ERRORS
 ..; ------
 D CHECKTOT(.CHECKTOT) ;CHECK ERA CHECK TOTALS AGAINST BATCH/ITEM TOTAL
 Q
 ;
CHECKTOT(CHECKTOT) ;CHECK ERA CHECK TOTALS AGAINST BATCH/ITEM TOTAL
 N ERRORS,CLMDA,ALLPAY,ERACHECK,CLSTATUS
 N BPR02  ;BAR*1.8*6 SCR119 IHS/SD/TPF
 W !
 W !?2,"  Matched Bills: ",$J(+$G(BARCNT("MATCHED")),5)," for $",$J($FN(+$G(BARAMT("MATCHED")),",",2),12)
 W !?2,"Unmatched Bills: ",$J(+$G(BARCNT("UNMATCHED")),5)," for $",$J($FN(+$G(BARAMT("UNMATCHED")),",",2),12)
 W !?2,"    Total Bills: ",$J(+$G(BARTOT("CNT")),5)," for $",$J($FN(+$G(BARTOT("AMT")),",",2),12)
 W !
 S ERACHECK="" F  S ERACHECK=$O(CHECKTOT(ERACHECK)) Q:ERACHECK=""  D
 .S CLMDA=""
 .S CLMDA=$O(^BAREDI("I",DUZ(2),"F",ERACHECK,IMPDA,CLMDA))
 .S BPR02=+$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,2)),U,5)  ;BPR MONETARY AMOUNT BAR*1.8*6 SCR119 IHS/SD/TPF
 .I $G(BARDBG) W !?2,"CHECKING ERA CHECK TOTALS FOR ",ERACHECK," TOTAL ",$J($FN(CHECKTOT(ERACHECK),",",2),15)  ;bar*1.8*20 REQ4
 .;
 .D GETITMTO(ERACHECK,CHECKTOT(ERACHECK),.ERRORS,BPR02)  ;GET BATCH/ITEM TOTAL  BAR*1.8*6 SCR119 IHS/SD/TPF
 .I $D(ERRORS) D
 ..S CLMDA=""
 ..F  S CLMDA=$O(^BAREDI("I",DUZ(2),"F",ERACHECK,IMPDA,CLMDA)) Q:CLMDA=""  D
 ... I $$DONOTPR(IMPDA,CLMDA) Q  ;new code
 ... ;Q:$$OVERIDE^BAR50EP1(CLMDA)     ;MRS:BAR*1.8*10 D159-1 AND 2
 ... ;Q:$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,2)="P"  ;DON'T PROCESS POSTED CLAIMS
 ... ;S CLSTATUS=$P($P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,11)," ")  ;E-CLAIM STATUS CODE (CLP02) BAR*1.8*6 IM29637
 ... ;I CLSTATUS="" S CLSTATUS=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,2)),U,4)  ;MRS:BAR*1.8*10
 ... ;Q:(U_"1"_U_"2"_U_"3"_U_"4"_U_"19"_U_"20"_U_"21"_U_"22"_U)'[(U_CLSTATUS_U)  ;ADDED 4 (DENIALS) PER EMAIL/CONVERSATION WITH ADRIAN 7/31
 ... D ADDREAS^BAR50P04(IMPDA,CLMDA,.ERRORS)
 .K ERRORS
 Q
 ;
GETIEN(BARX,BARBILL) ;EP - FIND AR BILL IEN
 N BARTMP
 S (BARBIEN,BARCNT)=0
 I '$D(^BARBL(DUZ(2),"B",BARBILL)) S BARX="G"   ; Pharmacy POS
 F  S BARBIEN=$O(^BARBL(DUZ(2),BARX,BARBILL,BARBIEN)) Q:'+BARBIEN  D
 . S BARCNT=BARCNT+1
 . S BARTMP(BARBIEN)=""
 I BARCNT=0 Q "BILL NOT FOUND"   ;BILL NOT FOUND IN RPMS
 I BARCNT>1 Q "DUPLICATE BILLS FOUND"   ;DUPES FOUND
 S BARBIEN=$O(BARTMP(""))
 Q BARBIEN
 ;
XGETIEN(BARX,BARBILL) ;NEW CODEEP - FIND AR BILL IEN 12/10/2013
 N BARTMP,BARXBILL,BARRET
 S BARRET=""
 S BARX="G",BARXBILL=BARBILL
 I $D(^BARBL(DUZ(2),BARX,BARXBILL)) S BARRET=$$GETIT() Q BARRET
 S BARX="G",BARXBILL=+BARBILL
 I $D(^BARBL(DUZ(2),BARX,BARXBILL)) S BARRET=$$GETIT() Q BARRET
 S BARX="B",BARXBILL=BARBILL
 I $D(^BARBL(DUZ(2),BARX,BARXBILL)) S BARRET=$$GETIT() Q BARRET
 S BARX="B",BARXBILL=+BARBILL
 I $D(^BARBL(DUZ(2),BARX,BARXBILL)) S BARRET=$$GETIT() Q BARRET
 Q BARRET
GETIT() N BARBIEN
 S BARCNT=0
 S BARBIEN=0 F  S BARBIEN=$O(^BARBL(DUZ(2),BARX,BARXBILL,BARBIEN)) Q:'+BARBIEN  D
 . S BARCNT=BARCNT+1
 . S BARTMP(BARBIEN)=""
 I BARCNT=0 Q "BILL NOT FOUND"   ;BILL NOT FOUND IN RPMS
 I BARCNT>1 Q "DUPLICATE BILLS FOUND"   ;DUPES FOUND
 S BARBIEN=$O(BARTMP(""))
 Q BARBIEN
 ;
GETITMTO(ERACHECK,ERATOTAL,ERRORS,BRP02) ;EP - GIVEN ERACHECK GET BATCH ITEM TOTALS FOR ERA CHECK ;BAR*1.8*6 SCR119 IHS/SD/TPF
 N BARCOLDA,BARITMDA,ITEMTOT,BARXCHK,BARTODAY,%H ;P.OTT
 ;S X=DT D H^%DTC ;GET $H-FORMAT
 S BARTODAY=+$H ;%H
 S BARXCHK=$$BARXCHK^BAREDP09(ERACHECK) ;P.OTT
 S BARCOLDA=$O(^BARCOL(DUZ(2),"D",BARXCHK,""))
 I 'BARCOLDA,(BPR02=0) Q  ;BAR*1.8*6 SCR119 DON'T REQUIRE A BATCH NONPAY CHECK FOR A BPR02=0 IHS/SD/TPF
 I 'BARCOLDA D  Q
 .S ERRORS("NB")=""  ;NO BATCH FOUND FOR ERA CHECK
 .I $G(BARDBG) W !,"NO BATCH FOUND FOR ERA CHECK"
 W !
 S BPOSTBAL=0 ;BATCH POSTING BALANCE
 S BARCOLDA="" F  S BARCOLDA=$O(^BARCOL(DUZ(2),"D",BARXCHK,BARCOLDA)) Q:BARCOLDA=""  D
 .NEW X,BARCBDT,BARCB ;P.OTT
 .S BARCB=$$GET1^DIQ(90051.01,BARCOLDA_",",.01,"A")
 .S X=$$GET1^DIQ(90051.01,BARCOLDA_",",4,"I")
 .D H^%DTC ;GET $H-FORMAT
 .S BARCBDT=%H
 .IF BARTODAY-BARCBDT>365 D  Q  ;DONT SHOW THIS MSG: 10/10/2013 
 .;;;. S BARMSG="IGNORING COLL. BATCH "_BARCB_" EIN# "_BARCOLDA_" TOO OLD: ("_X_")"
 .;;;. I $G(BARDBG) W !,BARMSG
 .;
 .I $G(BARDBG) W !,?2,"CHECKING BATCH: ",BARCB ;P.OTT SHOW ONLY 'NEW' CB 10/10/2013 
 .S BPOSTBAL=BPOSTBAL+$$GET1^DIQ(90051.01,BARCOLDA_",",17,"E")  ;BAR*1.8*6 LOOK AT BATCH POSTING TOTAL NOT ITEM CREDIT TOTALS
 .I $G(BARDBG) W " POSTING BALANCE: ",BPOSTBAL
 I ERATOTAL>BPOSTBAL D
 .I '$$IHSNEGB^BARUFUT(DUZ(2)) Q  ;P.OTT 2/6 2014 HEAT147572
 .S ERRORS("ERA > ITM")=""  ;ERA TOTAL GREATER THAN BATCH/ITEM TOTAL
 .I $G(BARDBG) D  ;
 ..W !,"ERA TOTAL PAYMENTS AND ADJUSTMENTS OF ",ERATOTAL
 ..W !,"IS GREATER THAN BATCH POSTING BALANCE OF ",BPOSTBAL
 Q
DONOTPR(IMPDA,CLMDA) ;CALLED FROM 3 DIFFERENT PLACES
 N CLSTATUS
 I $$OVERIDE^BAR50EP1(CLMDA) Q 1  ;MRS:BAR*1.8*10 D159-1 AND 2
 I $P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,2)="P"  Q 2 ;DON'T PROCESS POSTED CLAIMS
 S CLSTATUS=$P($P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,11)," ")  ;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 (U_"1"_U_"2"_U_"3"_U_"4"_U_"19"_U_"20"_U_"21"_U_"22"_U)'[(U_CLSTATUS_U) Q 3  ;ADDED 4 (DENIALS) PER EMAIL OF 7/31
 ;DENIAL ADJUSTMENTS CLP02=4 WERE CREATING NEGATIVE BALANCES
 Q 0
 ;EOR - IHS/DIT/CPC 1.8*28