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

IBTUTL5.m

Go to the documentation of this file.
  1. IBTUTL5 ;ALB/OEC - CLAIMS TRACKING UTILITY ROUTINE ;16-JAN-09
  1. ;;2.0;INTEGRATED BILLING;**399**;21-MAR-94;Build 8
  1. ;;Per VHA Directive 2004-038, this routine should not be modified.
  1. ;
  1. OPT(IBOE,IBDT) ; - Has the outpatient encounter been billed?
  1. ; Input: IBOE=pointer to outpatient encounter in file #409.68
  1. ; IBDT=event date CLAIMS TRACKING(#356)
  1. ;
  1. ; ; *Pre-set variables: DFN=patient IEN, RIMB=bill rate
  1. ;
  1. ;
  1. I '$G(DFN)!('$G(IBDT))!('$G(RIMB))!('$G(IBOE)) S IBRTN=0 G OPTQ
  1. N IBCN,IBCPT,IBCT,IBDATA,IBDAY,IBDIV,IBXX,IBYD,IBYY,IBZ,IBMRA,IBCPTSUM,IBTCHRG,IBRTN,IBAUTH
  1. ; - Check to be sure the encounter is billable.
  1. I $$INPT^IBAMTS1(DFN,IBDT\1_.2359) S IBRTN=0 G OPTQ ; Became inpatient same day.
  1. I $$ENCL^IBAMTS2(IBOE)["1" S IBRTN=0 G OPTQ ; "ao^ir^sc^swa^mst^hnc^cv^shad" encounter.
  1. ;
  1. ;
  1. ; - Gather all procedures associated with the encounter.
  1. D GETCPT^SDOE(IBOE,"IBYY") I '$G(IBYY) S IBRTN=0 G OPTQ ; Check CPT qty.
  1. ;
  1. ; - Determine the encounter division.
  1. S IBDIV=+$P($$GETOE^SDOE(IBOE),U,11) S:'IBDIV IBDIV=+$$PRIM^VASITE()
  1. ;
  1. ; - Build array of all billable encounter procedures.
  1. S IBXX=0 F S IBXX=$O(IBYY(IBXX)) Q:'IBXX D
  1. . ;
  1. . ; - Get procedure pointer and code.
  1. . S IBZ=+IBYY(IBXX),IBCN=$P($$CPT^ICPTCOD(IBZ),"^",2)
  1. . ;
  1. . ; - Ignore LAB services for vets with Medicare Supplemental coverage.
  1. . I IBCN>79999,IBCN<90000 Q
  1. . ;
  1. . ; - Get the institutional/professional charge components.
  1. . S IBCPT(IBZ,1)=+$$BICOST^IBCRCI(RIMB,3,IBDT,"PROCEDURE",IBZ,"",IBDIV,"",1)
  1. . S IBCPT(IBZ,2)=+$$BICOST^IBCRCI(RIMB,3,IBDT,"PROCEDURE",IBZ,"",IBDIV,"",2)
  1. . ;
  1. . ; - Eliminate components without a charge.
  1. . S IBCPTSUM(IBZ)=+$G(IBCPT(IBZ,1))+$G(IBCPT(IBZ,2))
  1. . I 'IBCPT(IBZ,1) K IBCPT(IBZ,1)
  1. . I 'IBCPT(IBZ,2) K IBCPT(IBZ,2)
  1. ;
  1. I '$D(IBCPT) S IBRTN=0 G OPTQ ; Quit if no billable procedures remain.
  1. ;
  1. ; - Look at all of the vet's bills for the day and eliminate
  1. ; from the array those procedures that have been billed.
  1. S IBXX=0 S IBDAY=$E(IBDT,1,7)
  1. F S IBXX=$O(^DGCR(399,"AOPV",DFN,IBDAY,IBXX)) Q:'IBXX D
  1. . ;
  1. . ; - Perform general checks on the claim.
  1. . S IBDATA=$$CKBIL^IBTUBOU(IBXX) Q:IBDATA=""
  1. . S IBAUTH=$P($G(IBDATA),U,2)
  1. . I $G(IBAUTH)<2&($G(IBAUTH)>5) Q
  1. . ; - The episode has been billed. Check the revenue code multiple for
  1. . ; all procedures billed on the claim.
  1. . S IBYY=0
  1. . F S IBYY=$O(^DGCR(399,IBXX,"RC",IBYY)) Q:'IBYY S IBYD=^(IBYY,0) D
  1. . . ;
  1. . . ; - Get the procedure code,charge type and total charges for the revenue code.
  1. . . S IBZ=$P(IBYD,U,6)
  1. . . S IBCT=$S($P(IBYD,U,12):$P(IBYD,U,12),1:$P(IBDATA,U,4))
  1. . . S IBTCHRG=$P(IBYD,U,4)
  1. . . I 'IBZ!('IBCT) Q ; Can't determine code/charge type for procedure.
  1. . . ; Delete procedure from unbilled procedures array.
  1. . . I $G(IBTCHRG)'<$G(IBCPTSUM(IBZ)) K IBCPT(IBZ)
  1. . . I $D(IBCPT(IBZ,IBCT)) K IBCPT(IBZ,IBCT)
  1. ;
  1. ; - Again, quit if no billable procedures remain.
  1. I '$D(IBCPT) S IBRTN=0 G OPTQ
  1. ; - If there are billable procedures return TOTAL AMOUNT
  1. I $D(IBCPT) S (IBZ,IBCT,IBRTN)=0
  1. F S IBZ=$O(IBCPT(IBZ)) Q:'IBZ D
  1. .F S IBCT=$O(IBCPT(IBZ,IBCT)) Q:'IBCT D
  1. ..S IBRTN=IBRTN+IBCPT(IBZ,IBCT)
  1. ;
  1. OPTQ K IBCPT Q IBRTN
  1. ;
  1. ;
  1. ADMDT(DFN,EPDT) ;
  1. ;
  1. ;Returns the next Admission dt for CLAIMS TRACKING entry with RNB 72 HR Rule
  1. ; input : DFN (required) := Pointer to PATIENT file (#2)
  1. ; from CLAIMS TRACKING file (#356)
  1. ; EPDT (required): = Episode dt field (.06) from
  1. ; CLAIMS TRAKCING file (#356)
  1. ;
  1. ; output : If patient has an admission after episode dt
  1. ; IBADMDT := ADMISSION DT
  1. ; IF NO ADMISSION DT IBADMDT := NULL
  1. ;
  1. K IBADMDT,ADMID,EPID,ADMIFN
  1. I '$G(DFN)!('$G(EPDT)) S IBADMDT="" G ADMDTQ
  1. I '$D(^DGPM("ATID1",DFN)) S IBADMDT="" G ADMDTQ ; REF DBIA419
  1. S ADMID=9999999.999999-EPDT,EPID=ADMID,ADMIFN=0,X=0
  1. F X=1:1:1 S ADMID=$O(^DGPM("ATID1",DFN,ADMID),-1) Q:'ADMID D
  1. .S ADMIFN=+$O(^DGPM("ATID1",DFN,ADMID,0))
  1. .I $D(^DGPM(ADMIFN,0)) S IBADMDT=$E($P(^(0),U),1,7)
  1. ;
  1. ;Format date for PRINTED and EXCEL RNB report
  1. ;
  1. I $G(IBEXCEL) S IBADMDT=$$DT^IBJD($G(IBADMDT),1)
  1. I '$G(IBEXCEL) S IBADMDT=$$DTE^IBJDB22($G(IBADMDT))
  1. ;
  1. ADMDTQ ;
  1. ;
  1. S:'$D(IBADMDT) IBADMDT=""
  1. Q IBADMDT
  1. ;
  1. ;
  1. RXAMT(EPDT,RXIEN) ;
  1. ;
  1. ; -- input epdt := episode date from CLAIMS TRACKING(#356)
  1. ; RXIEN := RX field from CLAIMS TRACKING(#356)
  1. ;
  1. ; -- output 0 if RX billed or -1 if RX not billed
  1. ;
  1. I '$G(EPDT)!('$G(IBRX)) S IBRTN=-1 G RXAMTQ
  1. N IBRXCLM,IBCLM,IBRTN,IBAUTH,IBMRA
  1. S IBRX=$$FILE^IBRXUTL(RXIEN,.01)
  1. S IBRXCLM=0
  1. F S IBRXCLM=$O(^IBA(362.4,"B",IBRX,IBRXCLM)) Q:'IBRXCLM D
  1. .I $P(^IBA(362.4,IBRXCLM,0),U,3)=EPDT S IBCLM=$P(^(0),U,2)
  1. I '$G(IBCLM) S IBRTN=-1 G RXAMTQ
  1. I $G(IBCLM) S IBAUTH=$P($$CKBIL^IBTUBOU(IBCLM),U,2)
  1. I $G(IBAUTH)>2!($G(IBAUTH)<5) S IBRTN=0 G RXAMTQ
  1. E S IBRTN=-1 G RXAMTQ
  1. ;
  1. RXAMTQ Q IBRTN
  1. ;
  1. ;
  1. PRSAMT(EPDT,PRST) ;
  1. ;
  1. ; input epdt := episode date from CLAIMS TRACKING(#356)
  1. ; prst := prosthetic item from CLAIMS TRACKING(#356)
  1. ;
  1. ; ouptut 0 if prosthetics item billed or -1 if item not billed
  1. ;
  1. I '$G(EPDT)!('$G(PRST)) S IBRTN=-1 G PRSAMTQ
  1. N IBPRCLM,IBCLM,IBRTN,IBAUTH,IBMRA
  1. S IBPRCLM=0
  1. F S IBPRCLM=$O(^IBA(362.5,"AE",PRST,IBPRCLM)) Q:'IBPRCLM D
  1. .S IBCLM=$P(^IBA(362.5,IBPRCLM,0),U,2)
  1. I '$G(IBCLM) S IBRTN=-1 G PRSAMTQ
  1. I $G(IBCLM) S IBAUTH=$P(^DGCR(399,IBCLM,0),U,13)
  1. I $G(IBAUTH)'<2&($G(IBAUTH)'>5) S IBRTN=0 G PRSAMTQ
  1. E S IBRTN=-1 G PRSAMTQ
  1. ;
  1. ;
  1. PRSAMTQ Q IBRTN
  1. ;
  1. ;
  1. RELBIL(IEN,EPDT,DFN,ENCTYP) ;
  1. ;
  1. ; ---- Input IEN := IEN of encounter
  1. ; epdt := Episode Date from CLAIMS TRACKING
  1. ; DFN := Patient file (#2) IEN
  1. ; ENCTYP := Type of encounter 1=inpatient 2=Outpatient
  1. ; 3=Prosthetics 4=Prescription
  1. ;
  1. ; Output Related Bills IF NO RELATED BILL IBRTN=""
  1. ; IF RELATED BILLS
  1. ; IBRTN= #OF RELATED BILLS;RELATED BILL
  1. ;
  1. I '$G(EPDT)!('$G(DFN))!('$G(ENCTYP)) S IBRTN=-1 G RELBILQ
  1. ;
  1. I ENCTYP=1 S IBRTN=$$INPTREL(DFN,EPDT) G RELBILQ
  1. ;
  1. I ENCTYP=2 S IBRTN=$$OPTREL(DFN,EPDT) G RELBILQ
  1. ;
  1. I ENCTYP=3 S IBRTN=$$RXREL(IEN,EPDT) G RELBILQ
  1. ;
  1. I ENCTYP=4 S IBRTN=$$PROSREL(IEN,EPDT) G RELBILQ
  1. ;
  1. RELBILQ Q IBRTN
  1. ;
  1. ;
  1. INPTREL(DFN,EPDT) ;
  1. ;
  1. ;
  1. I '$G(DFN)!('$G(EPDT)) S IBRTN=-1 Q IBRTN
  1. N IBCLM,IBDATA,IBN0,IBCLM,IBCNT,IBRTN
  1. S (IBCLM,IBCNT,IBRTN)=0
  1. F S IBCLM=$O(^DGCR(399,"C",DFN,IBCLM)) Q:'IBCLM D
  1. .Q:$P($G(^DGCR(399,IBCLM,0)),U,5)'=1
  1. .Q:$E($P($G(^DGCR(399,IBCLM,0)),U,3),1,7)'=EPDT S IBDATA=$$CKBIL^IBTUBOU(IBCLM,1) Q:'+IBDATA
  1. .S IBN0=^DGCR(399,IBCLM,0) Q:IBRTN[$P(^(0),U)
  1. .S IBCNT=IBCNT+1,$P(IBRTN,";",1)=IBCNT
  1. .S $P(IBRTN,";",IBCNT+1)=$P(IBN0,U)_$S($P(IBN0,U,27)=1:"i",$P(IBN0,U,27)=2:"p",1:"")
  1. I IBRTN=0 S IBRTN=-1
  1. Q IBRTN
  1. ;
  1. ;
  1. OPTREL(DFN,EPDT) ;
  1. ;
  1. ;
  1. I '$G(DFN)!('$G(EPDT)) S IBRTN=-1 Q IBRTN
  1. N IBXX,IBCNT,IBN0,IBDATA,IBXX,IBCNT,IBRTN
  1. S (IBXX,IBCNT,IBRTN)=0
  1. F S IBXX=$O(^DGCR(399,"AOPV",DFN,EPDT,IBXX)) Q:'IBXX D
  1. .S IBDATA=$$CKBIL^IBTUBOU(IBXX) Q:'+IBDATA
  1. .S IBN0=^DGCR(399,IBXX,0)
  1. .Q:IBRTN[$P(^(0),U)
  1. .S IBCNT=IBCNT+1,$P(IBRTN,";",1)=IBCNT
  1. .S $P(IBRTN,";",IBCNT+1)=$P(IBN0,U)_$S($P(IBN0,U,27)=1:"i",$P(IBN0,U,27)=2:"p",1:"")
  1. I IBRTN=0 S IBRTN=-1
  1. Q IBRTN
  1. ;
  1. ;
  1. PROSREL(IEN,EPDT) ;
  1. ;
  1. ;INPUT IEN=POINTER TO FILE 660
  1. ; EPDT=DATE PROS ITEM ISSUED
  1. ;
  1. ;OUTPUT IBRTN=-1 IF NOT BILL FOUND OR
  1. ; # OF RELATED;RELATED BILLS
  1. ;
  1. N IBXX,IBCLM,IBYY,IBCNT,IBRTN,IBDATA,IBN0
  1. I '$G(IEN) S IBRTN=-1 Q IBRTN
  1. S (IBXX,IBYY,IBCNT,IBRTN)=0
  1. F S IBXX=$O(^IBA(362.5,"AE",IEN,IBXX)) Q:'IBXX D
  1. .S IBCLM=$P(^IBA(362.5,IBXX,0),U,2)
  1. .I '$D(^DGCR(399,IBCLM,0)) Q
  1. .S IBN0=^DGCR(399,IBCLM,0) Q:IBRTN[$P(^(0),U)
  1. .I $P(IBN0,U,13)<2!($P(IBN0,U,13)>5) Q
  1. .S IBCNT=IBCNT+1,$P(IBRTN,";",1)=IBCNT
  1. .S $P(IBRTN,";",IBCNT+1)=$P(IBN0,U)_$S($P(IBN0,U,27)=1:"i",$P(IBN0,U,27)=2:"p",1:"")
  1. I IBRTN=0 S IBRTN=-1
  1. Q IBRTN
  1. ;
  1. ;
  1. RXREL(IEN,EPDT) ;
  1. ;
  1. ;
  1. N IBCLM,IBYY,IBRX,IBRTN,IBCNT
  1. I '$G(IEN) S IBRTN=-1 Q IBRTN
  1. S IBRX=$$FILE^IBRXUTL(IEN,.01)
  1. S (IBYY,IBCNT,IBRTN)=0
  1. F S IBYY=$O(^IBA(362.4,"B",IBRX,IBYY)) Q:'IBYY D
  1. .Q:$P(^IBA(362.4,IBYY,0),U,3)'=EPDT S IBCLM=$P(^(0),U,2)
  1. .S IBDATA=$$CKBIL^IBTUBOU(IBCLM) Q:'+IBDATA
  1. .S IBN0=^DGCR(399,IBCLM,0) Q:IBRTN[$P(^(0),U)
  1. .S IBCNT=IBCNT+1,$P(IBRTN,";",1)=IBCNT
  1. .S $P(IBRTN,";",IBCNT+1)=$P(IBN0,U)_$S($P(IBN0,U,27)=1:"i",$P(IBN0,U,27)=2:"p",1:"")
  1. I IBRTN=0 S IBRTN=-1
  1. Q IBRTN
  1. ;
  1. ;