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

BAR50P4A.m

Go to the documentation of this file.
BAR50P4A ; IHS/SD/SDR - MATCH REASONS AND CLAIMS - 2 ; 01/09/2009
 ;;1.8;IHS ACCOUNTS RECEIVABLE;**20,21,23,24,26**;OCT 26, 2005;Build 17
 ;CLM/CLM2 split BARFROM BAREDP04 due to size
 ;IHS/SD/POT - 1.8*23 HEAT82698  NOV 2012,JAN 2013 LEADING/MISSING ZEROES IN BILL #
 ;IHS/SD/POT - 1.8*23 BETA TEST SEP 2013 YAK: SWAPPED CHK001 AND CHK002 (FIXED POS CLAIMS)
 ;IHS/SD/POT - 1.8*23 12/2/2012 RECORD ONLY UNMATCHED ITEMS (deactivated ->p24)
 ;IHS/SD/POT - 1.8*24 - 2/12/2014 MATCHING MANUAL BILLS (NO ALPHA)
 ;IHS/SD/SDR - 1.8*26 - Updated p23, p24 documentation
 ;IHS/SD/SDR - 1.8*26 - HEAT166023 - Made change to treat a negative bill amount as a positive number and use it to
 ;  try matching the bill amount to the RPMS bill amount.
 ;
PAYER ;EP
 S IENS=BARCKIEN_","_IMPDA_","
 S EPAYER=$$GET1^DIQ(90056.02011,IENS,".06")
 D ^XBFMK
 S DIC=$$DIC^XBDIQ1(90056.24)
 S DIC(0)="SMQ"
 S X=EPAYER
 D ^DIC
 Q:+Y<0  ;stop here if no match in A/R EDI BILL LOGIC file
 W !!,"A matching ""override"" has been set up for this A/R Account",!
 S BARIEN=+Y
 D DISPLAY^BAR50MCH
 D ^XBFMK
 K DIR
 S DIR(0)="Y"
 S DIR("A")="Do you wish to continue with the A/R Bill Matching using this criteria?"
 S DIR("B")="N"
 D ^DIR
 I Y=0 S QFLG=1 Q
 Q
 ;start old bar*1.8*23 IHS/SD/POT
 ;CLM ;EP
 ;S BARX="B"
 ;K BILMATCH S BILMATCH=0  ;bar*1.8*20
 ;I $$GET1^DIQ(90056.0205,IENS,1.01)'="" D  Q
 ;.S BARBIEN=$$GET1^DIQ(90056.0205,IENS,1.01,"I")
 ;.D CLM3
 ;.;S (BARCNT,BILMATCH)=1,BILMATCH(BARBIEN)="",BARTMP(BARBIEN)="" I $G(DEBUG) W "  MATCHED"  ;bar*1.8*20
 ;;I '$D(^BARBL(DUZ(2),"B",BARBILL)) S BARX="G"  ;Pharmacy POS  ;bar*1.8*20 REQ4
 ;I $O(^BARBL(DUZ(2),"B",$S(($L(+BARBILL)=$L(BARBILL)):BARBILL_"-",1:BARBILL)))'[BARBILL S BARX="G"  ;Pharmacy POS  ;bar*1.8*20 REQ4
 ;;K BILMATCH S BILMATCH=0  ;bar*1.8*20
 ;S (BARBIEN,BARCNT)=0
 ;;start new code bar*1.8*20 REQ4
 ;I BARX="G" D CLM2 Q
 ;S BARSAVE=BARBILL
 ;F  S BARBILL=$O(^BARBL(DUZ(2),"B",$S(($L(+BARBILL)=$L(BARBILL)):BARBILL_"-",1:BARBILL))) Q:(BARBILL'[BARSAVE)  D CLM2
 ;S BARBILL=BARSAVE
 ;;
 ;Q
 ;;end new code REQ4
 ;CLM2 ;
 ;F  S BARBIEN=$O(^BARBL(DUZ(2),BARX,BARBILL,BARBIEN)) Q:'+BARBIEN  D
 ;.D CLM3
 ;.I (ERABILL'=BARAMT)!(ERADOS'=BARDOS) Q
 ;.S BARCNT=BARCNT+1
 ;.S BARTMP(BARBIEN)=""
 ;Q
 ;CLM3 ;
 ;S ERABILL=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,5)  ;E-BILLED
 ;S ERADOS=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,8)  ;E-DOS BEGIN
 ;S BARDOS=$$GET1^DIQ(90050.01,BARBIEN,102,"I")  ;DOS BEGIN
 ;S ERATYPE=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,11)  ;E-CLM STATUS CD
 ;;S X=ERADOS D ^%DT S ERADOS=Y  ;bar*1.8*21 SDR
 ;S BARDOS=$$Y2KD2^BARDUTL(BARDOS)  ;bar*1.8*21 SDR
 ;S BARAMT=$$GET1^DIQ(90050.01,BARBIEN,13,"I")  ;AMT BILLED
 ;I $G(DEBUG) W !,"ERA BILL : ",BARBILL  ;bar*1.8*20 REQ4
 ;I $G(DEBUG) W !,"ERA BILL : ",$$GET1^DIQ(90056.0205,BAREIENS,.01)  ;bar*1.8*20 REQ4
 ;I $G(DEBUG) W ?35,"ERA BILL TYPE: ",ERATYPE
 ;I $G(DEBUG) W !,"ERA BILLED: ",ERABILL,?25,"ERA DOS: ",ERADOS
 ;I $G(DEBUG) W !,"A/R BILLED: ",BARAMT,?25,"A/R DOS: ",BARDOS
 ;I ERABILL<0 S ERABILL=-ERABILL I $G(DEBUG) W ?50,"ERA BILL IS A NEGATIVE AMOUNT"
 ;I (ERABILL=BARAMT),(ERADOS=BARDOS) S BILMATCH=BILMATCH+1,BILMATCH(BARBIEN)="" I $G(DEBUG) W "  MATCHED"
 ;Q
 ;end old start new bar*1.8*23 IHS/SD/POT
CLM(BAREIENS,BARBILL,BARX,BARMMFLG) ;EP
 NEW BARMMTOT,BARMCNT,BARMMTYP ;P.OTT
 S BARMMVAL="" ;RETURN VALUE OF MATCHED ITEM
 S BARCNT=0
 K BILMATCH S BILMATCH=0
 ;
 S BARMMFLG=0 ;NEGATIVE IF MATCH, 0 IF NO MATCH 1 FOR BILLED AMOUNT MATCH, 2 FOR DOS MATCH
 S BARMMTOT=0 ;COUNT OF MISMATCHES
 F I=0:1:3 S BARMMCNT(I)=0
 S BARFND=0
 I $$GET1^DIQ(90056.0205,IENS,1.01)'="" D  Q
 .S BARBIEN=$$GET1^DIQ(90056.0205,IENS,1.01,"I")
 .S BARFND=10
 .S BARX="B"
 .I $D(^BARBL(DUZ(2),"G",BARBILL))!$D(^BARBL(DUZ(2),"G",+BARBILL)) S BARX="G"
 .S BARTMP=$$FINDING(BARBILL) I +BARTMP S BARX="G",(BARBILL)=$P(BARTMP,"^",2)
 .I $$CLM3(1,BARBIEN,IMPDA,CLMDA,.BARMMTYP) ;JUST DISPLAY (1ST PARAM=1)
 .Q
 S BARX="G"
 I $D(^BARBL(DUZ(2),BARX,BARTEST)) D  Q  ;CHK001
 .S BARFND=1050
 .D CLM2(BARX,BARTEST,.BARMMFLG)
 .Q
 ;
 S BARX="G"  ;6/10/13
 I $D(^BARBL(DUZ(2),BARX,+BARTEST)) D  Q  ;CHK002
 .S BARFND=1051
 .D CLM2(BARX,+BARTEST,.BARMMFLG)
 .Q
 ;-------------------------------------------------2/27/2013>
 S BARX="B"
 I $D(^BARBL(DUZ(2),BARX,BARTEST)) D  Q
 .S BARFND=1052
 .D CLM2(BARX,BARTEST,.BARMMFLG)
 .Q
 ;-------------------------------------------------2/27/2013<
 ;TRY TO MATCH MANUAL BILL (form: nnnnn-IHS-WHATEVER) 2/13/2014
 ;
 S BARX="G"
 ;
 ;S BARSAVE=+BARBILL,BARBILL=+BARBILL_"@"  ;bar*1.8*24 IHS/SD/POT
 S BARSAVE=+BARBILL  ;bar*1.8*24 IHS/SD/POT
 S BARBILL=+BARBILL_"-"  ;bar*1.8*24 IHS/SD/POT
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 .S BARFND=104
 .D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND Q  ;Found in POS
 S BARBILL=BARSAVE
 ;
 S BARX="B"
 ; 
 S BARSAVE=+BARBILL
 S BARBILL=+BARBILL_"-" ;2/12/2014
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 .S BARFND=105
 .D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND Q  ;found in A/R
 S BARBILL=BARSAVE
 ;---------------------------------------------------------------------------------- END 2/13/2014
 S BARX="G"
 ;
 ;S BARSAVE=+BARBILL,BARBILL=+BARBILL_"@"  ;bar*1.8*24 IHS/SD/POT
 S BARSAVE=+BARBILL  ;bar*1.8*24 IHS/SD/POT
 S BARBILL=+BARBILL_"-"  ;bar*1.8*24 IHS/SD/POT
 ;start new bar*1.8*24 IHS/SD/POT
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 .S BARFND=104
 .D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND Q  ;If found in POS do not search in A/R -->
 ;
 S BARBILL=BARSAVE
 ;
 S BARX="B"
 ; 
 S BARSAVE=+BARBILL,BARBILL=+BARBILL_"@"
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 .S BARFND=105
 .D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND Q  ;If found in POS do not search in A/R -->
 ;
 S BARBILL=BARSAVE
 ;end new bar*1.8*24 IHS/SD/POT
 ;
 ;CHK POS (OPTION WITH MISSING LEADING ZEROES) -------------------------
 ;
 S BARTMP=$$FINDING(BARBILL)
 I +BARTMP S BARX="G",(BARBILL)=$P(BARTMP,"^",2) D
 .S BARX="G",BARFND=100
 .D CLM2("G",BARBILL,.BARMMFLG)
 .Q
 I BARFND Q  ;if found in POS do not search in A/R -->
 ;
 ;CHK POS (OPTION WITH LEADING ZEROES)
 ;
 I $D(^BARBL(DUZ(2),"G",BARBILL)) D
 .S BARX="G",BARFND=1
 .D CLM2("G",BARBILL,.BARMMFLG)
 .Q
 I BARFND Q  ;If found in POS do not search in A/R -->
 ;
 ;CHK POS (OPTION WITH NO LEADING ZEROES)
 ;
 I +BARBILL'=BARBILL I $D(^BARBL(DUZ(2),"G",+BARBILL)) D
 .S BARX="G",BARFND=2
 .D CLM2("G",+BARBILL,.BARMMFLG) ;CHK POS
 I BARFND Q  ;If found in POS do not search in A/R -->
 ;
 S BARX="B" ;
 ;CHK POS (OPTION WITH LEADING ZEROES) -------------------------
 I $D(^BARBL(DUZ(2),BARX,BARBILL)) D
 .S BARFND=3
 .D CLM2(BARX,BARBILL,.BARMMFLG)
 .Q
 I BARFND Q  ;If found in POS do not search in A/R -->
 ; 
 S BARSAVE=+BARBILL,BARBILL=+BARBILL_"@"
 ;
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 .S BARFND=4
 .D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND Q  ;If found in POS do not search in A/R -->
 ;
 S BARBILL=BARSAVE
 ;
 ;CHK POS (OPTION WITH NO LEADING ZEROES) -------------------------
 ;
 I +BARBILL'=BARBILL I $D(^BARBL(DUZ(2),BARX,+BARBILL)) D  ;
 .S BARFND=5
 .D CLM2(BARX,+BARBILL,.BARMMFLG)
 I BARFND Q  ;If found in POS do not search in A/R -->
 ; 
 ; 
 S BARSAVE=+BARBILL,BARBILL=+BARBILL_"@"
 ;
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 .S BARFND=6
 .D CLM2(BARX,BARBILL,.BARMMFLG)
 S BARBILL=BARSAVE
 Q
 ;
 ;
CLM2(BARX,BARBILL,BARMMFLG) ;
 S BARMMFLG=0
 S BARBIEN=0 F  S BARBIEN=$O(^BARBL(DUZ(2),BARX,BARBILL,BARBIEN)) Q:'+BARBIEN  D
 .I $$CLM3(2,BARBIEN,IMPDA,CLMDA,.BARMMTYP) D  Q  ;BLOCK FOR MATCHED
 ..S BARCNT=BARCNT+1
 ..S BARTMP(BARBIEN)="" ;ARRAY OF MATCHED BILLS
 ..S BARMMFLG=-1
 ..Q  ;
 .;COUNTING TYPES OF UNMATCHED
 .S BARMMTOT=BARMMTOT+1 ;COUNT OF MISMATCHES (MM)
 .S BARMMCNT(BARMMTYP)=BARMMCNT(BARMMTYP)+1 ;COUNT TYPES OF MM
 .QUIT
 I $G(BARDBG) I BARMMCNT(1)+BARMMCNT(2)=1 D  ;ONE OR THE OTHER; NOT BOTH!
 .I BARMMCNT(1) S BARMMFLG=1
 .I BARMMCNT(2) S BARMMFLG=2
 .Q
 Q
CLM3(BARFROM,BARBIEN,IMPDA,CLMDA,BARMMTYP) ;
 NEW ERABILL,ERADOS,BARDOS,BARAMT,ERATYPE
 S ERABILL=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,5)  ;E-BILLED
 S ERADOS=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,8)  ;E-DOS BEGIN
 S BARDOS=$$GET1^DIQ(90050.01,BARBIEN,102,"I")  ;DOS BEGIN
 S ERATYPE=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,11)  ;E-CLM STATUS CD
 S BARDOS=$$Y2KD2^BARDUTL(BARDOS)  ;
 S BARAMT=$$GET1^DIQ(90050.01,BARBIEN,13,"I")  ;AMT BILLED
 S BARMMTYP=0 ;MATCH
 ;
 ;I ERABILL<0 S ERABILL=-ERABILL D  Q 0  ;bar*1.8*26 IHS/SD/SDR HEAT166023
 I ERABILL<0 S ERABILL=-ERABILL D  ;bar*1.8*26 IHS/SD/SDR HEAT166023
 .D BLHDR ;P.OTT 12/2/2013
 .I $G(BARDBG) D INS^BAR50DET($C(9,9)_"ERA BILL IS A NEGATIVE AMOUNT",1)
 ;
 I (+ERABILL=+BARAMT),(ERADOS=BARDOS) D  Q 1 ;P.OTT 12/2/2013
 .D BLHDR ;P.OTT 12/2/2013
 .S BILMATCH=BILMATCH+1,BILMATCH(BARBIEN)=""
 .Q  ;OK
 ; ---- NOT MATCHED - OTHER REASON FALL THRU
 I BARFROM=1 QUIT 0
 ;BARMMTYP=0 - MATCH
 ;BARMMTYP=1 ONLY AMOUNT NOT MATCHED
 ;BARMMTYP=2 ONLY DOS NOT MATCHED
 ;BARMMTYP=3 AMOUNT & DOS NOT MATCHED
 ;
 D BLHDR ;P.OTT 12/2/2013
 I (+ERABILL'=+BARAMT),(ERADOS'=BARDOS) S BARMMTYP=3 D  Q 0
 .I $G(BARDBG) D INS^BAR50DET(" NOT MATCHED",1) Q  ;
 I (+ERABILL'=+BARAMT),(ERADOS=BARDOS) S BARMMTYP=1 D  Q 0
 .I $G(BARDBG) D INS^BAR50DET(" PARTIAL MATCH: DOS OK. AMT DIFF: "_$J(ERABILL-BARAMT,5,2)_"$",1) S BARMMVAL=BARDOS
 I (ERADOS'=BARDOS),(+ERABILL=+BARAMT) S BARMMTYP=2 D  Q 0
 .I $G(BARDBG) D INS^BAR50DET(" PARTIAL MATCH: AMOUNT OK",1) S BARMMVAL=BARAMT
 ; ---- NOT MATCHED - OTHER REASON FALL THRU 
 Q 0
BLHDR ;
 I $G(BARDBG) D  ;P.OTT 12/2/2013
 .D NOMATCH^BAR50DET
 .D INS^BAR50DET("ERA BILL : "_$$GET1^DIQ(90056.0205,BAREIENS,.01),0)
 .D INS^BAR50DET($C(9,9)_"ERA BILL TYPE: "_ERATYPE,1)
 .D INS^BAR50DET("ERA BILLED: "_ERABILL_$C(9,9)_"ERA DOS: "_ERADOS,0)
 .D INS^BAR50DET("A/R BILLED: "_BARAMT_$C(9,9)_"A/R DOS: "_BARDOS,0)
 .D INS^BAR50DET("BAR BILL : "_BARBILL,0)
 Q
 ;end new bar*1.8*23 IHS/SD/POT
TRANSCK ;EP
 Q:$G(BARBIEN)=""  ;no bill number matched
 S BARTFLG=0
 S BARBTCH=$$GET1^DIQ(90056.02011,BARCKIEN,.07)
 S BARITEM=$$GET1^DIQ(90056.02011,BARCKIEN,.08)
 S BARTR=0,BARTFLG=0
 F  S BARTR=$O(^BARTR(DUZ(2),"AC",BARBIEN,BARTR)) Q:'BARTR  D  Q:(BARTFLG=1)
 .S BARTBTCH=$$GET1^DIQ(90050.03,BARTR,14)
 .S BARTITEM=$$GET1^DIQ(90050.03,BARTR,15)
 .I BARTBTCH'="",BARITEM'="",BARBTCH=BARTBTCH,BARITEM=BARTITEM S BARTFLG=1
 I BARTFLG S ERRORS("HTRN")=""
 Q
 ;start new bar*1.8*23 IHS/SD/POT
FINDING(BARBILL) ;RETURNS 1^BARXBILL (WITH MISSED OR ADDED LEADING ZERORS); OR 0
 N BARXBILL,BARRET,IXX ;REWRITE JAN 2013
 I $E(BARBILL)'="0" D  Q BARRET
 .S BARRET=0
 .S BARXBILL=BARBILL
 .F IXX=1:1 Q:($L(BARXBILL)=20)  D  Q:BARRET
 ..S BARXBILL="0"_BARXBILL
 ..I $D(^BARBL(DUZ(2),"G",BARXBILL)) S BARRET="1^"_BARXBILL
 ..Q
 .Q
 I $E(BARBILL)="0" D  Q BARRET
 .S BARRET=0
 .S BARXBILL=BARBILL
 .F IXX=1:1 Q:$E(BARXBILL,1)'="0"  D  Q:BARRET
 ..S BARXBILL=$E(BARXBILL,2,999) I BARXBILL=""  Q
 ..I $D(^BARBL(DUZ(2),"G",BARXBILL)) S BARRET="1^"_BARXBILL
 ..Q
 .Q
 I BARBILL=+BARBILL D  Q BARRET
 .S BARXBILL=+BARBILL
 .I $D(^BARBL(DUZ(2),"G",BARXBILL)) S BARRET="1^"_BARXBILL
 .Q
 Q ""  ;NEVER FALLS THROUGH
 ;end new bar*1.8*23 IHS/SD/POT