BARDYSVS ; IHS/SD/TPF - DAYS IN A/R REPORT BY VISIT ;
;;1.8;IHS ACCOUNTS RECEIVABLE;**16,28**;OCT 26, 2005;Build 92
;IHS/SD/SDR - 1.8*28 - HEAT224215 CR8345 - Added code so it will look through DUZ(2)s for 3P Bill entry. Removed a couple FM calls and replaced with straight
; code so they will work correctly with multiple DUZ(2)s. Removed check for HOSPITAL LOCATION. It was using it instead of VISIT LOCATION, which is
; wrong. Added code to capture detail info.
;
Q
;GIVEN A DATE RANGE CALCULATE NUMBER OF VISITS FOR THAT MONTH IN THE VISIT FILE
BYVISIT(START,END) ;EP -
K ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT")
N ENTRY
S ENTRY=START-.01
S END=END_".24"
I $E(END,6,7)="00" S $E(END,6,7)="31"
D INITVIS^BARDYSUT ;INITIALIZE COUNTERS TO ZERO
S OLDMOYR=$E(START,2,5)
S ENTRYNUM=0,VISITNUM=0
F S ENTRY=$O(^AUPNVSIT("B",ENTRY)) Q:ENTRY=""!(ENTRY>END) D
.S ENTRYNUM=ENTRYNUM+1
.S THISYR=$E(DT,1,3)
.;FOR TESTING COMMENT OUT
.;I (THISYR-$E(VSITADMT,1,3))>0 S MONTHYR="Ovr 1 Yr"
.S Y=ENTRY X ^DD("DD") S MONTHYR=$P($P(Y,"@"),",",2)_" "_$E(ENTRY,4,5)
.I $E(ENTRY,6,7)="00" S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","00 DAY","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","00 DAY","MONTHYR",MONTHYR))+1
.;Q:$E(ENTRY,6,7)="00" ;ENTRIES WITH NO DAY ARE ALL "E"VENT SERVICE CATEGORIES.
.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","ENTRY NUM","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","ENTRY NUM","MONTHYR",MONTHYR))+1
.;W !,"ENTRY: ",ENTRY
.S VISITIEN=""
.F S VISITIEN=$O(^AUPNVSIT("B",ENTRY,VISITIEN)) Q:'VISITIEN D
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","IEN VISIT","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","IEN VISIT","MONTHYR",MONTHYR))+1
..S DELEFLAG=$$GET1^DIQ(9000010,VISITIEN_",",.11,"I")
..;I DELEFLAG S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DELEFLAG","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DELEFALG","MONTHYR",MONTHYR))+1 Q ;bar*1.8*28 IHS/SD/SDR HEAT224215
..I DELEFLAG S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DELEFLAG","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DELEFLAG","MONTHYR",MONTHYR))+1 Q ;bar*1.8*28 IHS/SD/SDR HEAT224215
..S DEPCOUNT=$$GET1^DIQ(9000010,VISITIEN_",",.09)
..I 'DEPCOUNT S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DEPCOUNT","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DEPCOUNT","MONTHYR",MONTHYR))+1 Q
..S VISITNUM=VISITNUM+1
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","IEN NUM","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","IEN NUM","MONTHYR",MONTHYR))+1
..;W !?5,"VISIT IEN: ",VISITIEN
..I $$GET1^DIQ(9000010,VISITIEN_",",.11,"I") Q ;DELETE FLAG = 1 if deleted
..S DISCHARG=$$DISCHARG^BARDYSUT(VISITIEN) ;IS THERE A DISCHARGE DATE?
..;I DISCHARG'=0 Q:DISCHARG<START!(DISCHARG>END) ;NOT SURE ABOUT THIS LOGIC
..S SERVCATI=$$GET1^DIQ(9000010,VISITIEN_",",.07,"I")
..;should the next screen be done before or after the count of visits is made?
..I "^A^D^H^O^I^S^R^T^"'[(U_SERVCATI_U) D Q
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","SERVCAT","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","SERVCAT","MONTHYR",MONTHYR))+1
..S SERVCAT=$$GET1^DIQ(9000010,VISITIEN_",",.07,"E")
..S MERGED=$$GET1^DIQ(9000010,VISITIEN_",",.37) ;SCREEN OUT MERGED VISITS
..I MERGED'="" D Q
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","MERGED","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","MERGED","MONTHYR",MONTHYR))+1
..S LOCENC=$$GET1^DIQ(9000010,VISITIEN_",",.06,"I")
..I $G(BARY("LOC"))'="" Q:LOCENC'=$G(BARY("LOC")) ;NOT LOCATION CHOSEN
..S:LOCENC="" LOCENC="UNDEF"
..;S DUZ2=$$GET1^DIQ(9000010,VISITIEN_",",.22,"I") ;bar*1.8*28 IHS/SD/SDR HEAT224215
..;S:DUZ2="" DUZ2=DUZ(2) ;bar*1.8*28 IHS/SD/SDR HEAT224215
..S DUZ2=LOCENC ;bar*1.8*28 IHS/SD/SDR HEAT224215
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LOCENC",LOCENC,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","LOCENC",LOCENC,"MONTHYR",MONTHYR))+1
..;
..S PACKAGE=$$GET1^DIQ(9000010,VISITIEN_",",.24)
..;PACKAGE=NULL CHECK MAY NOT BE CORRECT. WE JUST DON'T PULL ANYTHING IN TEST W/O IT
..;I '(($E(PACKAGE,1,2)="SD")!($E(PACKAGE,1,3)="BSD")!($E(PACKAGE,1,3)="CIA")!(PACKAGE="")) D Q ;DON'T PULL IF NOT CREATED BY THESE PACKAGES
..;.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","PACKREJ","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","PACKREJ","MONTHYR",MONTHYR))+1
..;.S PACKREJ=$G(PACKREJ)+1
..;
..S CLINIC=$$GET1^DIQ(9000010,VISITIEN_",",.08,"I") ;CLINIC STOP
..I 'CLINIC D Q ;IF NO CLINIC NO BILL WILL BE PRODUCED COMMENTED FOR TESTING
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOCLINIC","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOCLINIC","MONTHYR",MONTHYR))+1
..;S:CLINIC="" CLINIC="UNDEF"
..I $D(BARY("CLIN")) Q:'$D(BARY("CLIN",CLINIC)) ;NOT CHOSEN CLINIC
..;
..;I BAR("LOC")="BILLING" SORT BY DUZ(2)
..;I BAR("LOC")="VISIT" SORT BY VISIT LOCATION
..;LOCATION TYPE FOR REPORTS
..I BAR("LOC")="BILLING" D
...S SUB1=DUZ2
..E S SUB1=LOCENC
..;VISIT TYPE OR CLINIC SORT
..I BARY("SORT")="C" D
...S SUB2=CLINIC
..E S SUB2=SERVCAT
..;
..;S BILLIEN=$O(^ABMDBILL(DUZ(2),"AV",VISITIEN,"")) ;bar*1.8*28 IHS/SD/SDR HEAT224215
..;start new bar*1.8*28 IHS/SD/SDR HEAT224215
..S BARCHK=0
..S ABMDUZ(2)=0
..F S ABMDUZ(2)=$O(^ABMDBILL(ABMDUZ(2))) Q:'ABMDUZ(2) D Q:BARCHK
...S BILLIEN=$O(^ABMDBILL(ABMDUZ(2),"AV",VISITIEN,0))
...I BILLIEN S BARCHK=1
..;end new bar*1.8*28 IHS/SD/SDR HEAT224215
..I 'BILLIEN D ;Q
...;W !,"VISITIEN: ",VISITIEN," HAS NO BILLS CAN'T FIND A PROVIDER"
...;IF NO BILL CAN WE FIND A PROVIDER RELATED TO THE VISIT?
...S VPROV=$$PRVCHK^BARDYSUT(VISITIEN)
...S:VPROV=0 VPROV="UNDEF"
...;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(NUMVISIT(LOCENC,SUB2,"MONTHYR",MONTHYR))+1
...;S NUMVISIT=NUMVISIT+1
...;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR))+1
...;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
...;I ($E(PACKAGE,1,2)="SD")!($E(PACKAGE,1,3)="BSD")!($E(PACKAGE,1,3)="CIA") D
...;.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN","MONTHYR",MONTHYR))+1
...;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS","MONTHYR",MONTHYR))+1
...;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
..I BILLIEN D
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","WITBILLS",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","WITBILLS",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","WITBILLS","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","WITBILLS","MONTHYR",MONTHYR))+1
..;
..I 'BILLIEN Q ;bar*1.8*28 IHS/SD/SDR HEAT224215
..;S BILLSTAT=$$GET1^DIQ(9002274.4,BILLIEN_",",.04,"I") ;bar*1.8*28 IHS/SD/SDR HEAT224215
..S BILLSTAT=$P($G(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U,4) ;bar*1.8*28 IHS/SD/SDR HEAT224215
..S:BILLSTAT="" BILLSTAT="UNDEF"
..;W !!,"BILL: ",$$GET1^DIQ(9002274.4,BILLIEN_",",.01,"I")
..;W !?5,"BILL STATUS: ",BILLSTAT
..I BILLSTAT="X" D ;BILL STATUS = CANCELLED
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS","MONTHYR",MONTHYR))+1
..;.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
..;K PROV
..;I BILLIEN S PROV=$$GETPRV^BARDYSV1(BILLIEN,$G(BARY("PRV"))) Q:'PROV ;FIND PROVIDER CHOSEN OR ONLY ATTEND OR RENDERING
..;S PROV=$P($G(PROV,"^UNDEF"),U,2)
..;IF USER DID NOT CHOSE A PROVIDER THEN SORT BY PROVIDER
..;IF THE NEXT SCREEN IS TAKEN OUT YOU GET A LOT OF ZEROES. THE ONLY DATA IS
..;CREATED AND REVIEWED DAYS
..;
..;VISIT & BILL PASSES ALL SCREENS
..;now is this the correct logic for "check ins"
..;OR IS IT IF THE VISITIEN HAS AN ENTRY IN V HOSPITALIZTION?
..I ($E(PACKAGE,1,2)="SD")!($E(PACKAGE,1,3)="BSD")!($E(PACKAGE,1,3)="CIA") D
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN","MONTHYR",MONTHYR))+1
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
...S NUMVISIT=NUMVISIT+1
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR))+1
..E D
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
...S NUMVISIT=NUMVISIT+1
...S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR))+1
..;
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","VISIT IEN","MONTHYR",MONTHYR,VISITIEN)=""
..S VSITCRET=$P($$GET1^DIQ(9000010,VISITIEN_",",.02,"I"),".")
..S VSITADMT=$P($$GET1^DIQ(9000010,VISITIEN_",",.01,"I"),".")
..S VPCCREV=$P($$GET1^DIQ(9000010,VISITIEN_",",.13,"I"),".")
..S PCCREV=$$GETREV(VISITIEN,VPCCREV)
..S BARTREC=VISITIEN_U_MONTHYR_U_LOCENC_U_VSITADMT_U_VSITCRET_U_$$DAYS^BARDYSV1(+VSITCRET,+VSITADMT)_U_PCCREV_U_$$DAYS^BARDYSV1(+PCCREV,+VSITADMT) ;detail rec ;bar*1.8*28 IHS/SD/SDR HEAT224215
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DET",VISITIEN)=BARTREC ;detail rec ;bar*1.8*28 IHS/SD/SDR HEAT224215
..;NOW GO GET THE AVG'S FOR THE CLAIMS GENERATED BY THIS VISIT
..S CREDAYS=CREDAYS+$$DAYS^BARDYSV1(+VSITCRET,+VSITADMT)
..S REVDAYS=REVDAYS+$$DAYS^BARDYSV1(+PCCREV,+VSITADMT)
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DATE DIFF",VISITIEN,$$DAYS^BARDYSV1(+PCCREV,+VSITADMT))=PCCREV_U_VSITADMT
..;FOR SORTING WHEN USER SELECTS SORT BY VISIT USE SERVICE CATEGORY
..;
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","CREDAYS",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","CREDAYS",LOCENC,SUB2,"MONTHYR",MONTHYR))+$$DAYS^BARDYSV1(+VSITCRET,+VSITADMT)
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","REVDAYS",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","REVDAYS",LOCENC,SUB2,"MONTHYR",MONTHYR))+$$DAYS^BARDYSV1(+PCCREV,+VSITADMT)
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","CREDAYS","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","CREDAYS","MONTHYR",MONTHYR))+$$DAYS^BARDYSV1(+VSITCRET,+VSITADMT)
..S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","REVDAYS","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","REVDAYS","MONTHYR",MONTHYR))+$$DAYS^BARDYSV1(+PCCREV,+VSITADMT)
..;
..;D TPBDAYS^BARDYSV1(VISITIEN,VSITADMT,.TPBAPP,.TPBEXP,.NUMBILLS,.BILLAMT)
..D TPBDAYS^BARDYSV1(VISITIEN,VSITADMT)
D PRINTVIS^BARDYSPR
D ^%ZISC
Q
;
GETREV(VISITIEN,VPCCREV) ;EP - GET PCC REVIEW DATE
;PER DAVID BATTESE GET REVIEW DATE FROM V CHART AUDIT IF TURNED ON
N TMP,QUEAUDIT,EARLIEST
S QUEAUDIT=$$GET1^DIQ(9001000,DUZ(2)_",",.12,"I") ;FIELD 'EHR/CHART AUDIT START DATE' FROM 'PCC MASTER CONTROL'
Q:$G(VSITADMT)<QUEAUDIT VPCCREV ;IF ADMIT DATE IS BEFORE AUDIT WAS TURNED ON GET REVIEW DATE FROM 'DATE LAST MODIFIED'
D ;OTHERWISE SEE IF YOU CAN GET IT IN THE 'V CHART AUDIT' FILE
.S (PCCREV,TMP)="" ;^AUPNVCA = V CHART AUDIT
.F S TMP=$O(^AUPNVCA("AD",VISITIEN,TMP)) Q:'TMP D
..I $$GET1^DIQ(9000010.45,TMP_",",.04)="R" D ;CHART AUDIT STATUS, R=REVIEWED/COMPLETE I=INCOMPLETE
...S PCCREV=$$GET1^DIQ(9000010.45,TMP_",",.01) ;DATE OF AUDIT
I PCCREV S PCCREV=PCCREV_"A" ;IF A "R" DATE OF AUDIT WAS FOUND THEN USE IT
E S PCCREV=VPCCREV_"V" ;OTHERWISE STAY WITH THE 'DATE LAST MODIFIED'
Q PCCREV
BARDYSVS ; IHS/SD/TPF - DAYS IN A/R REPORT BY VISIT ;
+1 ;;1.8;IHS ACCOUNTS RECEIVABLE;**16,28**;OCT 26, 2005;Build 92
+2 ;IHS/SD/SDR - 1.8*28 - HEAT224215 CR8345 - Added code so it will look through DUZ(2)s for 3P Bill entry. Removed a couple FM calls and replaced with straight
+3 ; code so they will work correctly with multiple DUZ(2)s. Removed check for HOSPITAL LOCATION. It was using it instead of VISIT LOCATION, which is
+4 ; wrong. Added code to capture detail info.
+5 ;
+6 QUIT
+7 ;GIVEN A DATE RANGE CALCULATE NUMBER OF VISITS FOR THAT MONTH IN THE VISIT FILE
BYVISIT(START,END) ;EP -
+1 KILL ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT")
+2 NEW ENTRY
+3 SET ENTRY=START-.01
+4 SET END=END_".24"
+5 IF $EXTRACT(END,6,7)="00"
SET $EXTRACT(END,6,7)="31"
+6 ;INITIALIZE COUNTERS TO ZERO
DO INITVIS^BARDYSUT
+7 SET OLDMOYR=$EXTRACT(START,2,5)
+8 SET ENTRYNUM=0
SET VISITNUM=0
+9 FOR
SET ENTRY=$ORDER(^AUPNVSIT("B",ENTRY))
IF ENTRY=""!(ENTRY>END)
QUIT
Begin DoDot:1
+10 SET ENTRYNUM=ENTRYNUM+1
+11 SET THISYR=$EXTRACT(DT,1,3)
+12 ;FOR TESTING COMMENT OUT
+13 ;I (THISYR-$E(VSITADMT,1,3))>0 S MONTHYR="Ovr 1 Yr"
+14 SET Y=ENTRY
XECUTE ^DD("DD")
SET MONTHYR=$PIECE($PIECE(Y,"@"),",",2)_" "_$EXTRACT(ENTRY,4,5)
+15 IF $EXTRACT(ENTRY,6,7)="00"
SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","00 DAY","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","00 DAY","MONTHYR",MONTHYR))+1
+16 ;Q:$E(ENTRY,6,7)="00" ;ENTRIES WITH NO DAY ARE ALL "E"VENT SERVICE CATEGORIES.
+17 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","ENTRY NUM","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","ENTRY NUM","MONTHYR",MONTHYR))+1
+18 ;W !,"ENTRY: ",ENTRY
+19 SET VISITIEN=""
+20 FOR
SET VISITIEN=$ORDER(^AUPNVSIT("B",ENTRY,VISITIEN))
IF 'VISITIEN
QUIT
Begin DoDot:2
+21 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","IEN VISIT","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","IEN VISIT","MONTHYR",MONTHYR))+1
+22 SET DELEFLAG=$$GET1^DIQ(9000010,VISITIEN_",",.11,"I")
+23 ;I DELEFLAG S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DELEFLAG","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","DELEFALG","MONTHYR",MONTHYR))+1 Q ;bar*1.8*28 IHS/SD/SDR HEAT224215
+24 ;bar*1.8*28 IHS/SD/SDR HEAT224215
IF DELEFLAG
SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DELEFLAG","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DELEFLAG","MONTHYR",MONTHYR))+1
QUIT
+25 SET DEPCOUNT=$$GET1^DIQ(9000010,VISITIEN_",",.09)
+26 IF 'DEPCOUNT
SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DEPCOUNT","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DEPCOUNT","MONTHYR",MONTHYR))+1
QUIT
+27 SET VISITNUM=VISITNUM+1
+28 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","IEN NUM","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","IEN NUM","MONTHYR",MONTHYR))+1
+29 ;W !?5,"VISIT IEN: ",VISITIEN
+30 ;DELETE FLAG = 1 if deleted
IF $$GET1^DIQ(9000010,VISITIEN_",",.11,"I")
QUIT
+31 ;IS THERE A DISCHARGE DATE?
SET DISCHARG=$$DISCHARG^BARDYSUT(VISITIEN)
+32 ;I DISCHARG'=0 Q:DISCHARG<START!(DISCHARG>END) ;NOT SURE ABOUT THIS LOGIC
+33 SET SERVCATI=$$GET1^DIQ(9000010,VISITIEN_",",.07,"I")
+34 ;should the next screen be done before or after the count of visits is made?
+35 IF "^A^D^H^O^I^S^R^T^"'[(U_SERVCATI_U)
Begin DoDot:3
+36 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","SERVCAT","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","SERVCAT","MONTHYR",MONTHYR))+1
End DoDot:3
QUIT
+37 SET SERVCAT=$$GET1^DIQ(9000010,VISITIEN_",",.07,"E")
+38 ;SCREEN OUT MERGED VISITS
SET MERGED=$$GET1^DIQ(9000010,VISITIEN_",",.37)
+39 IF MERGED'=""
Begin DoDot:3
+40 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","MERGED","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","MERGED","MONTHYR",MONTHYR))+1
End DoDot:3
QUIT
+41 SET LOCENC=$$GET1^DIQ(9000010,VISITIEN_",",.06,"I")
+42 ;NOT LOCATION CHOSEN
IF $GET(BARY("LOC"))'=""
IF LOCENC'=$GET(BARY("LOC"))
QUIT
+43 IF LOCENC=""
SET LOCENC="UNDEF"
+44 ;S DUZ2=$$GET1^DIQ(9000010,VISITIEN_",",.22,"I") ;bar*1.8*28 IHS/SD/SDR HEAT224215
+45 ;S:DUZ2="" DUZ2=DUZ(2) ;bar*1.8*28 IHS/SD/SDR HEAT224215
+46 ;bar*1.8*28 IHS/SD/SDR HEAT224215
SET DUZ2=LOCENC
+47 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","LOCENC",LOCENC,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","LOCENC",LOCENC,"MONTHYR",MONTHYR))+1
+48 ;
+49 SET PACKAGE=$$GET1^DIQ(9000010,VISITIEN_",",.24)
+50 ;PACKAGE=NULL CHECK MAY NOT BE CORRECT. WE JUST DON'T PULL ANYTHING IN TEST W/O IT
+51 ;I '(($E(PACKAGE,1,2)="SD")!($E(PACKAGE,1,3)="BSD")!($E(PACKAGE,1,3)="CIA")!(PACKAGE="")) D Q ;DON'T PULL IF NOT CREATED BY THESE PACKAGES
+52 ;.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","PACKREJ","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","PACKREJ","MONTHYR",MONTHYR))+1
+53 ;.S PACKREJ=$G(PACKREJ)+1
+54 ;
+55 ;CLINIC STOP
SET CLINIC=$$GET1^DIQ(9000010,VISITIEN_",",.08,"I")
+56 ;IF NO CLINIC NO BILL WILL BE PRODUCED COMMENTED FOR TESTING
IF 'CLINIC
Begin DoDot:3
+57 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NOCLINIC","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NOCLINIC","MONTHYR",MONTHYR))+1
End DoDot:3
QUIT
+58 ;S:CLINIC="" CLINIC="UNDEF"
+59 ;NOT CHOSEN CLINIC
IF $DATA(BARY("CLIN"))
IF '$DATA(BARY("CLIN",CLINIC))
QUIT
+60 ;
+61 ;I BAR("LOC")="BILLING" SORT BY DUZ(2)
+62 ;I BAR("LOC")="VISIT" SORT BY VISIT LOCATION
+63 ;LOCATION TYPE FOR REPORTS
+64 IF BAR("LOC")="BILLING"
Begin DoDot:3
+65 SET SUB1=DUZ2
End DoDot:3
+66 IF '$TEST
SET SUB1=LOCENC
+67 ;VISIT TYPE OR CLINIC SORT
+68 IF BARY("SORT")="C"
Begin DoDot:3
+69 SET SUB2=CLINIC
End DoDot:3
+70 IF '$TEST
SET SUB2=SERVCAT
+71 ;
+72 ;S BILLIEN=$O(^ABMDBILL(DUZ(2),"AV",VISITIEN,"")) ;bar*1.8*28 IHS/SD/SDR HEAT224215
+73 ;start new bar*1.8*28 IHS/SD/SDR HEAT224215
+74 SET BARCHK=0
+75 SET ABMDUZ(2)=0
+76 FOR
SET ABMDUZ(2)=$ORDER(^ABMDBILL(ABMDUZ(2)))
IF 'ABMDUZ(2)
QUIT
Begin DoDot:3
+77 SET BILLIEN=$ORDER(^ABMDBILL(ABMDUZ(2),"AV",VISITIEN,0))
+78 IF BILLIEN
SET BARCHK=1
End DoDot:3
IF BARCHK
QUIT
+79 ;end new bar*1.8*28 IHS/SD/SDR HEAT224215
+80 ;Q
IF 'BILLIEN
Begin DoDot:3
+81 ;W !,"VISITIEN: ",VISITIEN," HAS NO BILLS CAN'T FIND A PROVIDER"
+82 ;IF NO BILL CAN WE FIND A PROVIDER RELATED TO THE VISIT?
+83 SET VPROV=$$PRVCHK^BARDYSUT(VISITIEN)
+84 IF VPROV=0
SET VPROV="UNDEF"
+85 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(NUMVISIT(LOCENC,SUB2,"MONTHYR",MONTHYR))+1
+86 ;S NUMVISIT=NUMVISIT+1
+87 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR))+1
+88 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
+89 ;I ($E(PACKAGE,1,2)="SD")!($E(PACKAGE,1,3)="BSD")!($E(PACKAGE,1,3)="CIA") D
+90 ;.S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","AVGCHKIN","MONTHYR",MONTHYR))+1
+91 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS","MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS","MONTHYR",MONTHYR))+1
+92 ;S ^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS",SUB1,SUB2,"MONTHYR",MONTHYR)=$G(^XTMP("BARDYSVS",$J,"DAYS TO COL VISIT","NOBILLS",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
End DoDot:3
+93 IF BILLIEN
Begin DoDot:3
+94 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","WITBILLS",SUB1,SUB2,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","WITBILLS",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
+95 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","WITBILLS","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","WITBILLS","MONTHYR",MONTHYR))+1
End DoDot:3
+96 ;
+97 ;bar*1.8*28 IHS/SD/SDR HEAT224215
IF 'BILLIEN
QUIT
+98 ;S BILLSTAT=$$GET1^DIQ(9002274.4,BILLIEN_",",.04,"I") ;bar*1.8*28 IHS/SD/SDR HEAT224215
+99 ;bar*1.8*28 IHS/SD/SDR HEAT224215
SET BILLSTAT=$PIECE($GET(^ABMDBILL(ABMDUZ(2),BILLIEN,0)),U,4)
+100 IF BILLSTAT=""
SET BILLSTAT="UNDEF"
+101 ;W !!,"BILL: ",$$GET1^DIQ(9002274.4,BILLIEN_",",.01,"I")
+102 ;W !?5,"BILL STATUS: ",BILLSTAT
+103 ;BILL STATUS = CANCELLED
IF BILLSTAT="X"
Begin DoDot:3
+104 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NOBILLS","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NOBILLS","MONTHYR",MONTHYR))+1
End DoDot:3
+105 ;.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
+106 ;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
+107 ;K PROV
+108 ;I BILLIEN S PROV=$$GETPRV^BARDYSV1(BILLIEN,$G(BARY("PRV"))) Q:'PROV ;FIND PROVIDER CHOSEN OR ONLY ATTEND OR RENDERING
+109 ;S PROV=$P($G(PROV,"^UNDEF"),U,2)
+110 ;IF USER DID NOT CHOSE A PROVIDER THEN SORT BY PROVIDER
+111 ;IF THE NEXT SCREEN IS TAKEN OUT YOU GET A LOT OF ZEROES. THE ONLY DATA IS
+112 ;CREATED AND REVIEWED DAYS
+113 ;
+114 ;VISIT & BILL PASSES ALL SCREENS
+115 ;now is this the correct logic for "check ins"
+116 ;OR IS IT IF THE VISITIEN HAS AN ENTRY IN V HOSPITALIZTION?
+117 IF ($EXTRACT(PACKAGE,1,2)="SD")!($EXTRACT(PACKAGE,1,3)="BSD")!($EXTRACT(PACKAGE,1,3)="CIA")
Begin DoDot:3
+118 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","AVGCHKIN",SUB1,SUB2,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","AVGCHKIN",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
+119 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","AVGCHKIN","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","AVGCHKIN","MONTHYR",MONTHYR))+1
+120 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NUMVISIT",SUB1,SUB2,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NUMVISIT",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
+121 SET NUMVISIT=NUMVISIT+1
+122 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR))+1
End DoDot:3
+123 IF '$TEST
Begin DoDot:3
+124 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NUMVISIT",SUB1,SUB2,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NUMVISIT",LOCENC,SUB2,"MONTHYR",MONTHYR))+1
+125 SET NUMVISIT=NUMVISIT+1
+126 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","NUMVISIT","MONTHYR",MONTHYR))+1
End DoDot:3
+127 ;
+128 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","VISIT IEN","MONTHYR",MONTHYR,VISITIEN)=""
+129 SET VSITCRET=$PIECE($$GET1^DIQ(9000010,VISITIEN_",",.02,"I"),".")
+130 SET VSITADMT=$PIECE($$GET1^DIQ(9000010,VISITIEN_",",.01,"I"),".")
+131 SET VPCCREV=$PIECE($$GET1^DIQ(9000010,VISITIEN_",",.13,"I"),".")
+132 SET PCCREV=$$GETREV(VISITIEN,VPCCREV)
+133 ;detail rec ;bar*1.8*28 IHS/SD/SDR HEAT224215
SET BARTREC=VISITIEN_U_MONTHYR_U_LOCENC_U_VSITADMT_U_VSITCRET_U_$$DAYS^BARDYSV1(+VSITCRET,+VSITADMT)_U_PCCREV_U_$$DAYS^BARDYSV1(+PCCREV,+VSITADMT)
+134 ;detail rec ;bar*1.8*28 IHS/SD/SDR HEAT224215
SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DET",VISITIEN)=BARTREC
+135 ;NOW GO GET THE AVG'S FOR THE CLAIMS GENERATED BY THIS VISIT
+136 SET CREDAYS=CREDAYS+$$DAYS^BARDYSV1(+VSITCRET,+VSITADMT)
+137 SET REVDAYS=REVDAYS+$$DAYS^BARDYSV1(+PCCREV,+VSITADMT)
+138 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","DATE DIFF",VISITIEN,$$DAYS^BARDYSV1(+PCCREV,+VSITADMT))=PCCREV_U_VSITADMT
+139 ;FOR SORTING WHEN USER SELECTS SORT BY VISIT USE SERVICE CATEGORY
+140 ;
+141 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","CREDAYS",SUB1,SUB2,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","CREDAYS",LOCENC,SUB2,"MONTHYR",MONTHYR))+$$DAYS^BARDYSV1(+VSITCRET,+VSITADMT)
+142 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","REVDAYS",SUB1,SUB2,"MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","REVDAYS",LOCENC,SUB2,"MONTHYR",MONTHYR))+$$DAYS^BARDYSV1(+PCCREV,+VSITADMT)
+143 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","CREDAYS","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","CREDAYS","MONTHYR",MONTHYR))+$$DAYS^BARDYSV1(+VSITCRET,+VSITADMT)
+144 SET ^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","REVDAYS","MONTHYR",MONTHYR)=$GET(^XTMP("BARDYSVS",$JOB,"DAYS TO COL VISIT","REVDAYS","MONTHYR",MONTHYR))+$$DAYS^BARDYSV1(+PCCREV,+VSITADMT)
+145 ;
+146 ;D TPBDAYS^BARDYSV1(VISITIEN,VSITADMT,.TPBAPP,.TPBEXP,.NUMBILLS,.BILLAMT)
+147 DO TPBDAYS^BARDYSV1(VISITIEN,VSITADMT)
End DoDot:2
End DoDot:1
+148 DO PRINTVIS^BARDYSPR
+149 DO ^%ZISC
+150 QUIT
+151 ;
GETREV(VISITIEN,VPCCREV) ;EP - GET PCC REVIEW DATE
+1 ;PER DAVID BATTESE GET REVIEW DATE FROM V CHART AUDIT IF TURNED ON
+2 NEW TMP,QUEAUDIT,EARLIEST
+3 ;FIELD 'EHR/CHART AUDIT START DATE' FROM 'PCC MASTER CONTROL'
SET QUEAUDIT=$$GET1^DIQ(9001000,DUZ(2)_",",.12,"I")
+4 ;IF ADMIT DATE IS BEFORE AUDIT WAS TURNED ON GET REVIEW DATE FROM 'DATE LAST MODIFIED'
IF $GET(VSITADMT)<QUEAUDIT
QUIT VPCCREV
+5 ;OTHERWISE SEE IF YOU CAN GET IT IN THE 'V CHART AUDIT' FILE
Begin DoDot:1
+6 ;^AUPNVCA = V CHART AUDIT
SET (PCCREV,TMP)=""
+7 FOR
SET TMP=$ORDER(^AUPNVCA("AD",VISITIEN,TMP))
IF 'TMP
QUIT
Begin DoDot:2
+8 ;CHART AUDIT STATUS, R=REVIEWED/COMPLETE I=INCOMPLETE
IF $$GET1^DIQ(9000010.45,TMP_",",.04)="R"
Begin DoDot:3
+9 ;DATE OF AUDIT
SET PCCREV=$$GET1^DIQ(9000010.45,TMP_",",.01)
End DoDot:3
End DoDot:2
End DoDot:1
+10 ;IF A "R" DATE OF AUDIT WAS FOUND THEN USE IT
IF PCCREV
SET PCCREV=PCCREV_"A"
+11 ;OTHERWISE STAY WITH THE 'DATE LAST MODIFIED'
IF '$TEST
SET PCCREV=VPCCREV_"V"
+12 QUIT PCCREV