BARDYSV1 ; IHS/SD/TPF - DAYS IN A/R REPORT CALLS ;
;;1.8;IHS ACCOUNTS RECEIVABLE;**1,16,23,28**;OCT 26,2005;Build 92
;IHS/SD/POT-1.8*23-FEB 2013 CHANGED PTR TO INSURER TYPE
;IHS/SD/POT-1.8*23-APR 2013 RESOLVED NIL VALUES OF INSTYP AND ACTINS
;IHS/SD/SDR-1.8*28-Updated p23 documentation
;IHS/SD/SDR-1.8*28-HEAT224215 - Added code to look thru DUZ(2)s in 3P Bill file for visit IEN. Changed couple FM calls to be straight code.
; Lookups were failing due to multiple DUZ(2)s. Captured detail in "DET" subscript for detail report. Added code to populate last
; pymt all the time; was only populated if multiple pymts were made.
Q
;GET TOTAL DAYS NEEDED TO APPROVE A BILL
;AS WELL AS NEEDED TO EXPORT
;TPBDAYS(VISITIEN,VSITADMT,DAYSAPP,DAYSEXP,BILLNUM,AMTBILLD) ;EP -TOTAL DAYS FOR BILL
TPBDAYS(VISITIEN,VSITADMT) ;EP -TOTAL DAYS FOR BILL
Q:'VISITIEN 0
N TPBEXP,TPBAPPRO,TEMPAYS,BAMOUNT,BILL3P,TEMPAYS,TPBNOEXP
S TPBNOEXP=0
;start new bar*1.8*28 HEAT224215
S BILLNUM=0
S ABMDUZ(2)=0
F S ABMDUZ(2)=$O(^ABMDBILL(ABMDUZ(2))) Q:'ABMDUZ(2) D TPBDAYS2
Q
TPBDAYS2 ;EP
;end new bar*1.8*28 HEAT224215
S BILLIEN=""
S FIRST=0,LAST=0 ;bar*1.8*28 HEAT224215
S BATCHIEN=0,BATCHFIN=0 ;bar*1.8*28 HEAT224215
;F S BILLIEN=$O(^ABMDBILL(DUZ(2),"AV",VISITIEN,BILLIEN)) Q:'BILLIEN D ;bar*1.8*28 HEAT224215
F S BILLIEN=$O(^ABMDBILL(ABMDUZ(2),"AV",VISITIEN,BILLIEN)) Q:'BILLIEN D ;bar*1.8*28 HEAT224215
.;Q:'$$GETPRV(BILLIEN,$G(BARY("PRV")))
.S PROV=$$GETPRV^BARDYSV8(BILLIEN,$G(BARY("PRV"))) Q:'PROV ;FIND PROVIDER CHOSEN OR ONLY ATTEND OR RENDERING
.S PROV=$P($G(PROV,"^UNDEF"),U,2)
.;
.;S BILLSTAT=$$GET1^DIQ(9002274.4,BILLIEN_",",.04,"I") ;bar*1.8*28 HEAT224215
.S BILLSTAT=$P($G(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U,4) ;bar*1.8*28 HEAT224215
.S:BILLSTAT="" BILLSTAT="UNDEF"
.;BILL STATUS VALUES
.;'R'-REVIEWED
.;'A'-APPROVED
.;'B'-BILLED
.;'T'-TRANSFERRED TO FINANCE
.;'C'-COMPLETED
.;'P'-PARTIAL PAYMENT
.;'X'-CANCELLED
.I BILLSTAT="X" D Q ;3P BILL STATUS = CANCELLED
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","CANCELLED 3P BILLS","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","CANCELLED 3P BILLS","MONTHYR",MONTHYR))+1
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","CANCELLED 3P BILLS","MONTHYR",MONTHYR,BILLSTAT)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","CANCELLED 3P BILLS","MONTHYR",MONTHYR,BILLSTAT))+1
.;IF PROVIDER NOT CHOSEN SORT BY PROVIDER
.I '$D(BARY("PRV")) D
..S SUB4=PROV
.E S SUB4="UNCHOSEN"
.;
.;S BILL3P=$P($G(^ABMDBILL(DUZ(2),BILLIEN,0)),U)_" " ;bar*1.8*28 HEAT224215
.S BILL3P=$P($G(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U)_" " ;bar*1.8*28 HEAT224215
.S BILLAR=$O(^BARBL(DUZ(2),"B",BILL3P))
.S:BILLAR'="" BLLARIEN=$O(^BARBL(DUZ(2),"B",BILLAR,""))
.I '$G(BLLARIEN) S NOARIEN("MONTHYR")=$G(NOARIEN("MONTHYR"))+1 S NOARIEN=NOARIEN+1
.Q:'$G(BLLARIEN) ;CAN'T FIND CORRESPONDING A/R BILL
.S ARACCT=$$GET1^DIQ(90050.01,BLLARIEN_",",3)
.;
.S BAR=BLLARIEN
.D BILL^BARRCHK
.I 'BARP("HIT") D Q
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BILLREJT",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BILLREJT",SUB1,SUB2,"MONTHYR",MONTHYR))+1
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BILLREJT","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BILLREJT","MONTHYR",MONTHYR))+1
..S BILLREJT=BILLREJT+1
.;
.;S ACTINS=$$GET1^DIQ(9002274.4,BILLIEN_",",.17,"I") ;bar*1.8*23 IHS/SD/POT
.;S INSTYP=$$GET1^DIQ(9999999.18,ACTINS_",",.21,"I") ;bar*1.8*23 IHS/SD/POT
.;start new bar*1.8*23 IHS/SD/POT
.;S ACTINS=$$GET1^DIQ(9002274.4,BILLIEN_",",.08,"I") ;bar*1.8*28 HEAT224215
.S ACTINS=$P($G(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U,8) ;bar*1.8*28 HEAT224215
.;start old bar*1.8*28 HEAT224215
.;I ACTINS="" D Q
.;.W !,"3PB BILLIEN ",BILLIEN," MISSING POINTER TO INSURER FILE 9999999.18 (^AUTNINS) - VARIABLE ACTINS : ",ACTINS
.;.Q
.;end old bar*1.8*28 HEAT224215
.S INSTYP=$$GET1^DIQ(9999999.18,ACTINS_",",.211,"I")
.S INSTYP=$P($G(^AUTTINTY(INSTYP,0)),U,2)
.;start old bar*1.8*28 HEAT224215
.;I INSTYP="" D Q
.;.W !,"INSTYP IS MISSING FOR BILLIEN ",BILLIEN," ACTINS: ",ACTINS
.;.Q ;
.;end new bar*1.8*23 IHS/SD/POT
.;end old bar*1.8*28 HEAT224215
.S ACTINS=INSTYP_U_ACTINS
.;
.;IF NOT BILLING ENTITY CHOSEN DO SORT ON WHAT?
.I '$D(BARY("BI")) D
..S SUB3=ACTINS
.E S SUB3="UNCHOSEN"
.;S TPBEXP=$P($$GET1^DIQ(9002274.4,BILLIEN_",",.17,"E"),"@") ;DATE EXPORTED ;bar*1.8*28 HEAT224215
.S TPBEXP=DT ;bar*1.8*28 IHS/SD/SDR HEAT224215
.S:$P($G(^ABMDBILL(ABMDUZ(2),BILLIEN,1)),U,7) TPBEXP=$P($G(^ABMDTXST(ABMDUZ(2),$P($G(^ABMDBILL(ABMDUZ(2),BILLIEN,1)),U,7),0)),U) ;bar*1.8*28 HEAT224215
.S TPBEXP=$P($$CDT^BARDUTL(TPBEXP),"@") ;DATE EXPORTED ;bar*1.8*28 HEAT224215
.I TPBEXP'="" D
..S X=TPBEXP D ^%DT S TPBEXP=Y
.E S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BLLNOEXP","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BLLNOEXP","MONTHYR",MONTHYR))+1
.;start old bar*1.8*28 HEAT224215
.;S TPBAPPRO=$P($$GET1^DIQ(9002274.4,BILLIEN_",",.15,"I"),".")
.;S BAMOUNT=$$GET1^DIQ(9002274.4,BILLIEN_",",.21)
.;end old start new bar*1.8*28 HEAT224215
.S TPBAPPRO=$P($G(^ABMDBILL(ABMDUZ(2),BILLIEN,1)),U,5) ;date/time approved
.S BAMOUNT=$P($G(^ABMDBILL(ABMDUZ(2),BILLIEN,2)),U,1) ;billed amt
.;end new bar*1.8*28 HEAT224215
.;
.S AMTBILLD=AMTBILLD+BAMOUNT
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AMTBILLD",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AMTBILLD",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+BAMOUNT
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AMTBILLD","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AMTBILLD","MONTHYR",MONTHYR))+BAMOUNT
.;
.I BILLSTAT'="X" D
..S BILLNUM=BILLNUM+1
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BILLNUM",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BILLNUM",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+1
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BILLNUM","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","BILLNUM","MONTHYR",MONTHYR))+1
.;
.S DAYSAPP=DAYSAPP+$$DAYS(TPBAPPRO,VSITADMT)
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DAYSAPP","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DAYSAPP","MONTHYR",MONTHYR))+$$DAYS(TPBAPPRO,VSITADMT)
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DAYSAPP",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DAYSAPP",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS(TPBAPPRO,VSITADMT)
.;
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DAYSEXP",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DAYSEXP",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS(TPBEXP,VSITADMT)
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DAYSEXP","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DAYSEXP","MONTHYR",MONTHYR))+$$DAYS(TPBEXP,VSITADMT)
.;
.;S BILL3P=$P($G(^ABMDBILL(DUZ(2),BILLIEN,0)),U) ;bar*1.8*28 HEAT224215
.S BILL3P=$P($G(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U) ;bar*1.8*28 HEAT224215
.;S BILL3P=$$GET1^DIQ(9002274.4,BILLIEN_",",.01,"I") ;bar*1.8*28 HEAT224215
.;
.S TEMPAYS=$$FIRLSTPY^BARDYSV8(BILL3P) ;returns FIRST_U_LAST_U_BATCHFIN
.;
.;at this point there should be:
.; BATCHFIN from collection batch from first pymt on first bill, when batch was finalized
.; FIRST from first pymt on first bill
.; LAST from last pymt on last bill
.;
.;start old bar*1.8*28 HEAT224215
.;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U),VSITADMT)
.;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY","MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U),VSITADMT)
.;S TEMPAYS1=$S(+$P(TEMPAYS,U):$P(TEMPAYS,U),1:"UNDEF")
.;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY DATES","MONTHYR",MONTHYR,TEMPAYS1,$S(+$P(TEMPAYS,U,2):$P(TEMPAYS,U,2),1:"UNDEF"),$S(+$P(TEMPAYS,U,3):$P(TEMPAYS,U,3),1:"UNDEF"))=$$DAYS($P(TEMPAYS,U),VSITADMT)
.;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U,2),VSITADMT)
.;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY","MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U,2),VSITADMT)
.;end old start new bar*1.8*28 HEAT224215
.;
.S BARTREC=$S(BILLNUM>1:"~",1:U)_BILL3P_";"_TPBAPPRO_";"_$$DAYS(TPBAPPRO,VSITADMT)_";"_TPBEXP_";"_$$DAYS(TPBEXP,VSITADMT)_";"_$P(TEMPAYS,U,3)_";"_$$DAYS($P(TEMPAYS,U,3),VSITADMT)_";"_$P(TEMPAYS,U)_";" ;detail rec
.S BARTREC=BARTREC_$$DAYS($P(TEMPAYS,U),VSITADMT)_";"_$P(TEMPAYS,U,2)_";"_$$DAYS($P(TEMPAYS,U,2),VSITADMT)_";"_PROV_";"_BAMOUNT ;detail rec
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DET",VISITIEN)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DET",VISITIEN))_BARTREC ;detail rec
.;
.I +$G(TEMPAYS)'=0 D
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","TOT FIRST PAYMENT MADE","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","TOT FIRST PAYMENT MADE","MONTHYR",MONTHYR))+1
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DYSTOPAY",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DYSTOPAY",SUB1,SUB2,"MONTHYR",MONTHYR))+$$DAYS(BATCHFIN,VSITADMT) ;avg to pymt
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DYSTOPAY","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DYSTOPAY","MONTHYR",MONTHYR))+$$DAYS(BATCHFIN,VSITADMT) ;avg to pymt
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DYSTOPAY DATES","MONTHYR",MONTHYR,$S(+BATCHFIN:BATCHFIN,1:"UNDEF"),$S(+VSITADMT:VSITADMT,1:"UNDEF"),$$DAYS(BATCHFIN,VSITADMT))=""
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","TOT LAST PAYMENT MADE","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","TOT LAST PAYMENT MADE","MONTHYR",MONTHYR))+1
..;
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U),VSITADMT)
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY","MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U),VSITADMT)
.S TEMPAYS1=$S(+$P(TEMPAYS,U):$P(TEMPAYS,U),1:"UNDEF")
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY DATES","MONTHYR",MONTHYR,TEMPAYS1,$S(+$P(TEMPAYS,U,2):$P(TEMPAYS,U,2),1:"UNDEF"),$S(+$P(TEMPAYS,U,3):$P(TEMPAYS,U,3),1:"UNDEF"))=$$DAYS($P(TEMPAYS,U),VSITADMT)
.;
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U,2),VSITADMT)
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY","MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U,2),VSITADMT)
.;end new bar*1.8*28 HEAT224215
Q
;RETURN DIFF BETWEEN TWO DATES - see glossary item 2 page 19
DAYS(X1,X2) ;EP
N DATE1,DATE2
S:X1="" X1=DT
S:X2="" X2=DT
S DATE1=X1
S DATE2=X2
N AVG
D ^%DTC
S DIFF=$G(X)
S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DIFF BETWEEN TWO DATES",DATE1,DATE2,$S(DIFF'="":DIFF,1:"UNDEF"))=""
Q:'DIFF 0
Q DIFF
BARDYSV1 ; IHS/SD/TPF - DAYS IN A/R REPORT CALLS ;
+1 ;;1.8;IHS ACCOUNTS RECEIVABLE;**1,16,23,28**;OCT 26,2005;Build 92
+2 ;IHS/SD/POT-1.8*23-FEB 2013 CHANGED PTR TO INSURER TYPE
+3 ;IHS/SD/POT-1.8*23-APR 2013 RESOLVED NIL VALUES OF INSTYP AND ACTINS
+4 ;IHS/SD/SDR-1.8*28-Updated p23 documentation
+5 ;IHS/SD/SDR-1.8*28-HEAT224215 - Added code to look thru DUZ(2)s in 3P Bill file for visit IEN. Changed couple FM calls to be straight code.
+6 ; Lookups were failing due to multiple DUZ(2)s. Captured detail in "DET" subscript for detail report. Added code to populate last
+7 ; pymt all the time; was only populated if multiple pymts were made.
+8 QUIT
+9 ;GET TOTAL DAYS NEEDED TO APPROVE A BILL
+10 ;AS WELL AS NEEDED TO EXPORT
+11 ;TPBDAYS(VISITIEN,VSITADMT,DAYSAPP,DAYSEXP,BILLNUM,AMTBILLD) ;EP -TOTAL DAYS FOR BILL
TPBDAYS(VISITIEN,VSITADMT) ;EP -TOTAL DAYS FOR BILL
+1 IF 'VISITIEN
QUIT 0
+2 NEW TPBEXP,TPBAPPRO,TEMPAYS,BAMOUNT,BILL3P,TEMPAYS,TPBNOEXP
+3 SET TPBNOEXP=0
+4 ;start new bar*1.8*28 HEAT224215
+5 SET BILLNUM=0
+6 SET ABMDUZ(2)=0
+7 FOR
SET ABMDUZ(2)=$ORDER(^ABMDBILL(ABMDUZ(2)))
IF 'ABMDUZ(2)
QUIT
DO TPBDAYS2
+8 QUIT
TPBDAYS2 ;EP
+1 ;end new bar*1.8*28 HEAT224215
+2 SET BILLIEN=""
+3 ;bar*1.8*28 HEAT224215
SET FIRST=0
SET LAST=0
+4 ;bar*1.8*28 HEAT224215
SET BATCHIEN=0
SET BATCHFIN=0
+5 ;F S BILLIEN=$O(^ABMDBILL(DUZ(2),"AV",VISITIEN,BILLIEN)) Q:'BILLIEN D ;bar*1.8*28 HEAT224215
+6 ;bar*1.8*28 HEAT224215
FOR
SET BILLIEN=$ORDER(^ABMDBILL(ABMDUZ(2),"AV",VISITIEN,BILLIEN))
IF 'BILLIEN
QUIT
Begin DoDot:1
+7 ;Q:'$$GETPRV(BILLIEN,$G(BARY("PRV")))
+8 ;FIND PROVIDER CHOSEN OR ONLY ATTEND OR RENDERING
SET PROV=$$GETPRV^BARDYSV8(BILLIEN,$GET(BARY("PRV")))
IF 'PROV
QUIT
+9 SET PROV=$PIECE($GET(PROV,"^UNDEF"),U,2)
+10 ;
+11 ;S BILLSTAT=$$GET1^DIQ(9002274.4,BILLIEN_",",.04,"I") ;bar*1.8*28 HEAT224215
+12 ;bar*1.8*28 HEAT224215
SET BILLSTAT=$PIECE($GET(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U,4)
+13 IF BILLSTAT=""
SET BILLSTAT="UNDEF"
+14 ;BILL STATUS VALUES
+15 ;'R'-REVIEWED
+16 ;'A'-APPROVED
+17 ;'B'-BILLED
+18 ;'T'-TRANSFERRED TO FINANCE
+19 ;'C'-COMPLETED
+20 ;'P'-PARTIAL PAYMENT
+21 ;'X'-CANCELLED
+22 ;3P BILL STATUS = CANCELLED
IF BILLSTAT="X"
Begin DoDot:2
+23 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","CANCELLED 3P BILLS","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","CANCELLED 3P BILLS","MONTHYR",MONTHYR))+1
+24 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","CANCELLED 3P BILLS","MONTHYR",MONTHYR,BILLSTAT)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","CANCELLED 3P BILLS","MONTHYR",MONTHYR,BILLSTAT))+1
End DoDot:2
QUIT
+25 ;IF PROVIDER NOT CHOSEN SORT BY PROVIDER
+26 IF '$DATA(BARY("PRV"))
Begin DoDot:2
+27 SET SUB4=PROV
End DoDot:2
+28 IF '$TEST
SET SUB4="UNCHOSEN"
+29 ;
+30 ;S BILL3P=$P($G(^ABMDBILL(DUZ(2),BILLIEN,0)),U)_" " ;bar*1.8*28 HEAT224215
+31 ;bar*1.8*28 HEAT224215
SET BILL3P=$PIECE($GET(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U)_" "
+32 SET BILLAR=$ORDER(^BARBL(DUZ(2),"B",BILL3P))
+33 IF BILLAR'=""
SET BLLARIEN=$ORDER(^BARBL(DUZ(2),"B",BILLAR,""))
+34 IF '$GET(BLLARIEN)
SET NOARIEN("MONTHYR")=$GET(NOARIEN("MONTHYR"))+1
SET NOARIEN=NOARIEN+1
+35 ;CAN'T FIND CORRESPONDING A/R BILL
IF '$GET(BLLARIEN)
QUIT
+36 SET ARACCT=$$GET1^DIQ(90050.01,BLLARIEN_",",3)
+37 ;
+38 SET BAR=BLLARIEN
+39 DO BILL^BARRCHK
+40 IF 'BARP("HIT")
Begin DoDot:2
+41 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BILLREJT",SUB1,SUB2,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BILLREJT",SUB1,SUB2,"MONTHYR",MONTHYR))+1
+42 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BILLREJT","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BILLREJT","MONTHYR",MONTHYR))+1
+43 SET BILLREJT=BILLREJT+1
End DoDot:2
QUIT
+44 ;
+45 ;S ACTINS=$$GET1^DIQ(9002274.4,BILLIEN_",",.17,"I") ;bar*1.8*23 IHS/SD/POT
+46 ;S INSTYP=$$GET1^DIQ(9999999.18,ACTINS_",",.21,"I") ;bar*1.8*23 IHS/SD/POT
+47 ;start new bar*1.8*23 IHS/SD/POT
+48 ;S ACTINS=$$GET1^DIQ(9002274.4,BILLIEN_",",.08,"I") ;bar*1.8*28 HEAT224215
+49 ;bar*1.8*28 HEAT224215
SET ACTINS=$PIECE($GET(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U,8)
+50 ;start old bar*1.8*28 HEAT224215
+51 ;I ACTINS="" D Q
+52 ;.W !,"3PB BILLIEN ",BILLIEN," MISSING POINTER TO INSURER FILE 9999999.18 (^AUTNINS) - VARIABLE ACTINS : ",ACTINS
+53 ;.Q
+54 ;end old bar*1.8*28 HEAT224215
+55 SET INSTYP=$$GET1^DIQ(9999999.18,ACTINS_",",.211,"I")
+56 SET INSTYP=$PIECE($GET(^AUTTINTY(INSTYP,0)),U,2)
+57 ;start old bar*1.8*28 HEAT224215
+58 ;I INSTYP="" D Q
+59 ;.W !,"INSTYP IS MISSING FOR BILLIEN ",BILLIEN," ACTINS: ",ACTINS
+60 ;.Q ;
+61 ;end new bar*1.8*23 IHS/SD/POT
+62 ;end old bar*1.8*28 HEAT224215
+63 SET ACTINS=INSTYP_U_ACTINS
+64 ;
+65 ;IF NOT BILLING ENTITY CHOSEN DO SORT ON WHAT?
+66 IF '$DATA(BARY("BI"))
Begin DoDot:2
+67 SET SUB3=ACTINS
End DoDot:2
+68 IF '$TEST
SET SUB3="UNCHOSEN"
+69 ;S TPBEXP=$P($$GET1^DIQ(9002274.4,BILLIEN_",",.17,"E"),"@") ;DATE EXPORTED ;bar*1.8*28 HEAT224215
+70 ;bar*1.8*28 IHS/SD/SDR HEAT224215
SET TPBEXP=DT
+71 ;bar*1.8*28 HEAT224215
IF $PIECE($GET(^ABMDBILL(ABMDUZ(2),BILLIEN,1)),U,7)
SET TPBEXP=$PIECE($GET(^ABMDTXST(ABMDUZ(2),$PIECE($GET(^ABMDBILL(ABMDUZ(2),BILLIEN,1)),U,7),0)),U)
+72 ;DATE EXPORTED ;bar*1.8*28 HEAT224215
SET TPBEXP=$PIECE($$CDT^BARDUTL(TPBEXP),"@")
+73 IF TPBEXP'=""
Begin DoDot:2
+74 SET X=TPBEXP
DO ^%DT
SET TPBEXP=Y
End DoDot:2
+75 IF '$TEST
SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BLLNOEXP","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BLLNOEXP","MONTHYR",MONTHYR))+1
+76 ;start old bar*1.8*28 HEAT224215
+77 ;S TPBAPPRO=$P($$GET1^DIQ(9002274.4,BILLIEN_",",.15,"I"),".")
+78 ;S BAMOUNT=$$GET1^DIQ(9002274.4,BILLIEN_",",.21)
+79 ;end old start new bar*1.8*28 HEAT224215
+80 ;date/time approved
SET TPBAPPRO=$PIECE($GET(^ABMDBILL(ABMDUZ(2),BILLIEN,1)),U,5)
+81 ;billed amt
SET BAMOUNT=$PIECE($GET(^ABMDBILL(ABMDUZ(2),BILLIEN,2)),U,1)
+82 ;end new bar*1.8*28 HEAT224215
+83 ;
+84 SET AMTBILLD=AMTBILLD+BAMOUNT
+85 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","AMTBILLD",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","AMTBILLD",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+BAMOUNT
+86 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","AMTBILLD","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","AMTBILLD","MONTHYR",MONTHYR))+BAMOUNT
+87 ;
+88 IF BILLSTAT'="X"
Begin DoDot:2
+89 SET BILLNUM=BILLNUM+1
+90 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BILLNUM",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BILLNUM",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+1
+91 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BILLNUM","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","BILLNUM","MONTHYR",MONTHYR))+1
End DoDot:2
+92 ;
+93 SET DAYSAPP=DAYSAPP+$$DAYS(TPBAPPRO,VSITADMT)
+94 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DAYSAPP","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DAYSAPP","MONTHYR",MONTHYR))+$$DAYS(TPBAPPRO,VSITADMT)
+95 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DAYSAPP",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DAYSAPP",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS(TPBAPPRO,VSITADMT)
+96 ;
+97 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DAYSEXP",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DAYSEXP",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS(TPBEXP,VSITADMT)
+98 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DAYSEXP","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DAYSEXP","MONTHYR",MONTHYR))+$$DAYS(TPBEXP,VSITADMT)
+99 ;
+100 ;S BILL3P=$P($G(^ABMDBILL(DUZ(2),BILLIEN,0)),U) ;bar*1.8*28 HEAT224215
+101 ;bar*1.8*28 HEAT224215
SET BILL3P=$PIECE($GET(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U)
+102 ;S BILL3P=$$GET1^DIQ(9002274.4,BILLIEN_",",.01,"I") ;bar*1.8*28 HEAT224215
+103 ;
+104 ;returns FIRST_U_LAST_U_BATCHFIN
SET TEMPAYS=$$FIRLSTPY^BARDYSV8(BILL3P)
+105 ;
+106 ;at this point there should be:
+107 ; BATCHFIN from collection batch from first pymt on first bill, when batch was finalized
+108 ; FIRST from first pymt on first bill
+109 ; LAST from last pymt on last bill
+110 ;
+111 ;start old bar*1.8*28 HEAT224215
+112 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U),VSITADMT)
+113 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY","MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U),VSITADMT)
+114 ;S TEMPAYS1=$S(+$P(TEMPAYS,U):$P(TEMPAYS,U),1:"UNDEF")
+115 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","EARLYPAY DATES","MONTHYR",MONTHYR,TEMPAYS1,$S(+$P(TEMPAYS,U,2):$P(TEMPAYS,U,2),1:"UNDEF"),$S(+$P(TEMPAYS,U,3):$P(TEMPAYS,U,3),1:"UNDEF"))=$$DAYS($P(TEMPAYS,U),VSITADMT)
+116 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U,2),VSITADMT)
+117 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LASTPAY","MONTHYR",MONTHYR))+$$DAYS($P(TEMPAYS,U,2),VSITADMT)
+118 ;end old start new bar*1.8*28 HEAT224215
+119 ;
+120 ;detail rec
SET BARTREC=$SELECT(BILLNUM>1:"~",1:U)_BILL3P_";"_TPBAPPRO_";"_$$DAYS(TPBAPPRO,VSITADMT)_";"_TPBEXP_";"_$$DAYS(TPBEXP,VSITADMT)_";"_$PIECE(TEMPAYS,U,3)_";"_$$DAYS($PIECE(TEMPAYS,U,3),VSITADMT)_";"_$PIECE(TEMPAYS,U)_";"
+121 ;detail rec
SET BARTREC=BARTREC_$$DAYS($PIECE(TEMPAYS,U),VSITADMT)_";"_$PIECE(TEMPAYS,U,2)_";"_$$DAYS($PIECE(TEMPAYS,U,2),VSITADMT)_";"_PROV_";"_BAMOUNT
+122 ;detail rec
SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DET",VISITIEN)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DET",VISITIEN))_BARTREC
+123 ;
+124 IF +$GET(TEMPAYS)'=0
Begin DoDot:2
+125 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","TOT FIRST PAYMENT MADE","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","TOT FIRST PAYMENT MADE","MONTHYR",MONTHYR))+1
+126 ;avg to pymt
SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DYSTOPAY",SUB1,SUB2,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DYSTOPAY",SUB1,SUB2,"MONTHYR",MONTHYR))+$$DAYS(BATCHFIN,VSITADMT)
+127 ;avg to pymt
SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DYSTOPAY","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DYSTOPAY","MONTHYR",MONTHYR))+$$DAYS(BATCHFIN,VSITADMT)
+128 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DYSTOPAY DATES","MONTHYR",MONTHYR,$SELECT(+BATCHFIN:BATCHFIN,1:"UNDEF"),$SELECT(+VSITADMT:VSITADMT,1:"UNDEF"),$$DAYS(BATCHFIN,VSITADMT))=""
+129 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","TOT LAST PAYMENT MADE","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","TOT LAST PAYMENT MADE","MONTHYR",MONTHYR))+1
+130 ;
End DoDot:2
+131 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","EARLYPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","EARLYPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS($PIECE(TEMPAYS,U)
,VSITADMT)
+132 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","EARLYPAY","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","EARLYPAY","MONTHYR",MONTHYR))+$$DAYS($PIECE(TEMPAYS,U),VSITADMT)
+133 SET TEMPAYS1=$SELECT(+$PIECE(TEMPAYS,U):$PIECE(TEMPAYS,U),1:"UNDEF")
+134 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","EARLYPAY DATES","MONTHYR",MONTHYR,TEMPAYS1,$SELECT(+$PIECE(TEMPAYS,U,2):$PIECE(TEMPAYS,U,2),1:"UNDEF"),$SELECT(+$PIECE(TEMPAYS,U,3):$PIECE(TEMPAYS,U,3),1:"UNDEF"))=$$DAYS($PIECE(TEMPAYS,U),
VSITADMT)
+135 ;
+136 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","LASTPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","LASTPAY",SUB1,SUB2,SUB3,SUB4,VISITIEN,"MONTHYR",MONTHYR))+$$DAYS($PIECE(TEMPAYS,U,2)
,VSITADMT)
+137 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","LASTPAY","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","LASTPAY","MONTHYR",MONTHYR))+$$DAYS($PIECE(TEMPAYS,U,2),VSITADMT)
+138 ;end new bar*1.8*28 HEAT224215
End DoDot:1
+139 QUIT
+140 ;RETURN DIFF BETWEEN TWO DATES - see glossary item 2 page 19
DAYS(X1,X2) ;EP
+1 NEW DATE1,DATE2
+2 IF X1=""
SET X1=DT
+3 IF X2=""
SET X2=DT
+4 SET DATE1=X1
+5 SET DATE2=X2
+6 NEW AVG
+7 DO ^%DTC
+8 SET DIFF=$GET(X)
+9 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DIFF BETWEEN TWO DATES",DATE1,DATE2,$SELECT(DIFF'="":DIFF,1:"UNDEF"))=""
+10 IF 'DIFF
QUIT 0
+11 QUIT DIFF