IBCNS1 ;ALB/AAS - INSURANCE MANAGEMENT SUPPORTED FUNCTIONS ; 22-JULY-91
;;Version 2.0 ; INTEGRATED BILLING ;; 21-MAR-94
;;Per VHA Directive 10-93-142, this routine should not be modified.
;
INSURED(DFN,IBINDT) ; -- Is patient insured
; --Input DFN = patient
; IBINDT = (optional) date insured (default = today)
; -- Output = 0 - not insured
; = 1 - insured
;
N J,X,IBINS S IBINS=0,J=0
I '$G(IBINDT) S IBINDT=DT
F S J=$O(^DPT(DFN,.312,J)) Q:'J S X=$G(^(J,0)) S IBINS=$$CHK(X,IBINDT) Q:IBINS
INSQ Q IBINS
;
PRE(DFN,IBINDT) ; -- is pre-certification required for patient
N X,Y,J,IBPRE
S IBPRE=0,J=0
S:'$G(IBINDT) IBINDT=DT
F S J=$O(^DPT(DFN,.312,J)) Q:'J S X=$G(^(J,0)) I $$CHK(X,IBINDT),$P($G(^IBA(355.3,+$P(X,"^",18),0)),"^",6) S IBPRE=1 Q
PREQ Q IBPRE
;
UR(DFN,IBINDT) ; -- is ur required for patient
N X,Y,J,IBPRE
S IBUR=0,J=0
S:'$G(IBINDT) IBINDT=DT
F S J=$O(^DPT(DFN,.312,J)) Q:'J S X=$G(^(J,0)) I $$CHK(X,IBINDT),$P($G(^IBA(355.3,+$P(X,"^",18),0)),"^",5) S IBUR=1 Q
URQ Q IBUR
;
CHK(X,Z,Y) ; -- check one entry for active
; -- Input X = Zeroth node of entry in insurance multiple (2.312)
; Z = date to check
; Y = 2 if want will not reimburse
; -- Output 1 = Insurance Active
; 0 = Inactive
;
N Z1,X1 S Z1=0
I $$INDEM(X) G CHKQ ; is and indemnity policy or company
S X1=$G(^DIC(36,+X,0)) G:X1="" CHKQ ;insurance company entry doesn't exist
I $P(X,"^",8) G:Z<$P(X,"^",8) CHKQ ;effective date later than care
I $P(X,"^",4) G:Z>$P(X,"^",4) CHKQ ;care after expiration date
G:$P(X1,"^",5) CHKQ ;insurance company inactive
I $G(Y)'=2 G:$P(X1,"^",2)="N" CHKQ ;insurance company will not reimburse
S Z1=1
CHKQ Q Z1
;
ACTIVE(IBCIFN) ; -- is this company active for this patient for this date
; -- called from input transform and x-refs for fields 101,102,103
; -- input
N ACTIVE,DFN,IBINDT
S DFN=$P(^DGCR(399,DA,0),"^",2),IBINDT=$S(+$G(^DGCR(399,DA,"U")):+$G(^("U")),1:DT)
;
ACTIVEQ Q ACTIVE
;
DD ; - called from input transform and x-refs for field 101,102,103
; - input requires da=internal entry number in 399
; - outputs IBdd(ins co.) array
N DFN S DFN=$P(^DGCR(399,DA,0),"^",2),IBINDT=$S(+$G(^DGCR(399,DA,"U")):+$G(^("U")),1:DT)
D ALLACT
DDQ K IBINDT Q
;
;
ALLACT ; -- return active insurance zeroth nodes in ibdd(ins co,entry in mult)
N X,X1
S (X1,IBDD)=0
F S X1=$O(^DPT(DFN,.312,X1)) Q:'X1 S X=$G(^(X,0)) I $$CHK(X,IBINDT) S IBDD(+X,X1)=X
;
ALLACTQ Q
;
HDR W !?4,"Insurance Co.",?22,"Policy #",?40,"Group",?52,"Holder",?60,"Effective",?70,"Expires" S X="",$P(X,"=",IOM-4)="" W !?4,X
Q
;
;
D1 N X Q:'$D(IBINS)
W !?4,$S($D(^DIC(36,+IBINS,0)):$E($P(^(0),"^",1),1,16),1:"UNKNOWN")
W ?22,$E($P(IBINS,"^",2),1,16)
W ?40,$E($$GRP^IBCNS($P(IBINS,"^",18)),1,10)
S X=$P(IBINS,"^",6) W ?52,$S(X="v":"SELF",X="s":"SPOUSE",1:"OTHER")
W ?60,$$DAT1^IBOUTL($P(IBINS,"^",8)),?70,$$DAT1^IBOUTL($P(IBINS,"^",4))
Q
;
ALL(DFN,VAR,ACT,ADT) ; -- find all insurance data on a patient
;
; -- input DFN = patient
; VAR = variable to output in format of abc
; or abc(dfn)
; or ^tmp($j,"Insurance")
; ACT = 1 if only active ins. desired
; = 2 if active and will not reimburse desired (medicare)
; ADT = if ACT=1, then ADT is the internal date to check
; active for, default = dt
;
; -- output var(0) =: number of entries insurance multiple
; var(x,0) =: ^dpt(dfn,.312,x,0)
; var(x,1) =: ^dpt(dfn,.312,x,1)
; var(x,2) =: ^dpt(dfn,.312,x,2)
;
N X
S X=0 I $G(ACT),$E($G(ADT),1,7)'?7N S ADT=DT
F S X=$O(^DPT(DFN,.312,X)) Q:'X D
.I $G(ACT),'$$CHK(^DPT(DFN,.312,X,0),ADT,$G(ACT)) Q
.S @VAR@(0)=$G(@VAR@(0))+1
.S @VAR@(X,0)=$$ZND(DFN,X)
.S @VAR@(X,1)=$G(^DPT(DFN,.312,X,1))
.S @VAR@(X,2)=$G(^DPT(DFN,.312,X,2))
.S @VAR@(X,355.3)=$G(^IBA(355.3,+$P($G(^DPT(DFN,.312,X,0)),"^",18),0))
ALLQ Q
;
ZND(DFN,NODE) ; -- set group number and group name back into zeroth node of ins. type
N X,Y S (X,Y)=""
I '$G(DFN)!('$G(NODE)) G ZNDQ
S X=$G(^DPT(+DFN,.312,+NODE,0))
S Y=$G(^IBA(355.3,+$P(X,"^",18),0)) I Y="" G ZNDQ
S $P(X,"^",3)=$P(Y,"^",4) ; move group number
S $P(X,"^",15)=$P(Y,"^",3) ; move group name
;
ZNDQ Q X
;
INDEM(X) ; -- is this and indemnity plan
; -- input zeroth node if insurance type field
N IBINDEM,IBCTP
S IBINDEM=1
I $P($G(^DIC(36,+X,0)),"^",13)=15 G INDEMQ ; company is indemnity co.
S IBCTP=$P($G(^IBA(355.3,+$P(X,"^",18),0)),"^",9)
I IBCTP,$P($G(^IBE(355.1,+IBCTP,0)),"^",3)=9 G INDEMQ ; plan is and indemnity plan
S IBINDEM=0
INDEMQ Q IBINDEM
IBCNS1 ;ALB/AAS - INSURANCE MANAGEMENT SUPPORTED FUNCTIONS ; 22-JULY-91
+1 ;;Version 2.0 ; INTEGRATED BILLING ;; 21-MAR-94
+2 ;;Per VHA Directive 10-93-142, this routine should not be modified.
+3 ;
INSURED(DFN,IBINDT) ; -- Is patient insured
+1 ; --Input DFN = patient
+2 ; IBINDT = (optional) date insured (default = today)
+3 ; -- Output = 0 - not insured
+4 ; = 1 - insured
+5 ;
+6 NEW J,X,IBINS
SET IBINS=0
SET J=0
+7 IF '$GET(IBINDT)
SET IBINDT=DT
+8 FOR
SET J=$ORDER(^DPT(DFN,.312,J))
IF 'J
QUIT
SET X=$GET(^(J,0))
SET IBINS=$$CHK(X,IBINDT)
IF IBINS
QUIT
INSQ QUIT IBINS
+1 ;
PRE(DFN,IBINDT) ; -- is pre-certification required for patient
+1 NEW X,Y,J,IBPRE
+2 SET IBPRE=0
SET J=0
+3 IF '$GET(IBINDT)
SET IBINDT=DT
+4 FOR
SET J=$ORDER(^DPT(DFN,.312,J))
IF 'J
QUIT
SET X=$GET(^(J,0))
IF $$CHK(X,IBINDT)
IF $PIECE($GET(^IBA(355.3,+$PIECE(X,"^",18),0)),"^",6)
SET IBPRE=1
QUIT
PREQ QUIT IBPRE
+1 ;
UR(DFN,IBINDT) ; -- is ur required for patient
+1 NEW X,Y,J,IBPRE
+2 SET IBUR=0
SET J=0
+3 IF '$GET(IBINDT)
SET IBINDT=DT
+4 FOR
SET J=$ORDER(^DPT(DFN,.312,J))
IF 'J
QUIT
SET X=$GET(^(J,0))
IF $$CHK(X,IBINDT)
IF $PIECE($GET(^IBA(355.3,+$PIECE(X,"^",18),0)),"^",5)
SET IBUR=1
QUIT
URQ QUIT IBUR
+1 ;
CHK(X,Z,Y) ; -- check one entry for active
+1 ; -- Input X = Zeroth node of entry in insurance multiple (2.312)
+2 ; Z = date to check
+3 ; Y = 2 if want will not reimburse
+4 ; -- Output 1 = Insurance Active
+5 ; 0 = Inactive
+6 ;
+7 NEW Z1,X1
SET Z1=0
+8 ; is and indemnity policy or company
IF $$INDEM(X)
GOTO CHKQ
+9 ;insurance company entry doesn't exist
SET X1=$GET(^DIC(36,+X,0))
IF X1=""
GOTO CHKQ
+10 ;effective date later than care
IF $PIECE(X,"^",8)
IF Z<$PIECE(X,"^",8)
GOTO CHKQ
+11 ;care after expiration date
IF $PIECE(X,"^",4)
IF Z>$PIECE(X,"^",4)
GOTO CHKQ
+12 ;insurance company inactive
IF $PIECE(X1,"^",5)
GOTO CHKQ
+13 ;insurance company will not reimburse
IF $GET(Y)'=2
IF $PIECE(X1,"^",2)="N"
GOTO CHKQ
+14 SET Z1=1
CHKQ QUIT Z1
+1 ;
ACTIVE(IBCIFN) ; -- is this company active for this patient for this date
+1 ; -- called from input transform and x-refs for fields 101,102,103
+2 ; -- input
+3 NEW ACTIVE,DFN,IBINDT
+4 SET DFN=$PIECE(^DGCR(399,DA,0),"^",2)
SET IBINDT=$SELECT(+$GET(^DGCR(399,DA,"U")):+$GET(^("U")),1:DT)
+5 ;
ACTIVEQ QUIT ACTIVE
+1 ;
DD ; - called from input transform and x-refs for field 101,102,103
+1 ; - input requires da=internal entry number in 399
+2 ; - outputs IBdd(ins co.) array
+3 NEW DFN
SET DFN=$PIECE(^DGCR(399,DA,0),"^",2)
SET IBINDT=$SELECT(+$GET(^DGCR(399,DA,"U")):+$GET(^("U")),1:DT)
+4 DO ALLACT
DDQ KILL IBINDT
QUIT
+1 ;
+2 ;
ALLACT ; -- return active insurance zeroth nodes in ibdd(ins co,entry in mult)
+1 NEW X,X1
+2 SET (X1,IBDD)=0
+3 FOR
SET X1=$ORDER(^DPT(DFN,.312,X1))
IF 'X1
QUIT
SET X=$GET(^(X,0))
IF $$CHK(X,IBINDT)
SET IBDD(+X,X1)=X
+4 ;
ALLACTQ QUIT
+1 ;
HDR WRITE !?4,"Insurance Co.",?22,"Policy #",?40,"Group",?52,"Holder",?60,"Effective",?70,"Expires"
SET X=""
SET $PIECE(X,"=",IOM-4)=""
WRITE !?4,X
+1 QUIT
+2 ;
+3 ;
D1 NEW X
IF '$DATA(IBINS)
QUIT
+1 WRITE !?4,$SELECT($DATA(^DIC(36,+IBINS,0)):$EXTRACT($PIECE(^(0),"^",1),1,16),1:"UNKNOWN")
+2 WRITE ?22,$EXTRACT($PIECE(IBINS,"^",2),1,16)
+3 WRITE ?40,$EXTRACT($$GRP^IBCNS($PIECE(IBINS,"^",18)),1,10)
+4 SET X=$PIECE(IBINS,"^",6)
WRITE ?52,$SELECT(X="v":"SELF",X="s":"SPOUSE",1:"OTHER")
+5 WRITE ?60,$$DAT1^IBOUTL($PIECE(IBINS,"^",8)),?70,$$DAT1^IBOUTL($PIECE(IBINS,"^",4))
+6 QUIT
+7 ;
ALL(DFN,VAR,ACT,ADT) ; -- find all insurance data on a patient
+1 ;
+2 ; -- input DFN = patient
+3 ; VAR = variable to output in format of abc
+4 ; or abc(dfn)
+5 ; or ^tmp($j,"Insurance")
+6 ; ACT = 1 if only active ins. desired
+7 ; = 2 if active and will not reimburse desired (medicare)
+8 ; ADT = if ACT=1, then ADT is the internal date to check
+9 ; active for, default = dt
+10 ;
+11 ; -- output var(0) =: number of entries insurance multiple
+12 ; var(x,0) =: ^dpt(dfn,.312,x,0)
+13 ; var(x,1) =: ^dpt(dfn,.312,x,1)
+14 ; var(x,2) =: ^dpt(dfn,.312,x,2)
+15 ;
+16 NEW X
+17 SET X=0
IF $GET(ACT)
IF $EXTRACT($GET(ADT),1,7)'?7N
SET ADT=DT
+18 FOR
SET X=$ORDER(^DPT(DFN,.312,X))
IF 'X
QUIT
Begin DoDot:1
+19 IF $GET(ACT)
IF '$$CHK(^DPT(DFN,.312,X,0),ADT,$GET(ACT))
QUIT
+20 SET @VAR@(0)=$GET(@VAR@(0))+1
+21 SET @VAR@(X,0)=$$ZND(DFN,X)
+22 SET @VAR@(X,1)=$GET(^DPT(DFN,.312,X,1))
+23 SET @VAR@(X,2)=$GET(^DPT(DFN,.312,X,2))
+24 SET @VAR@(X,355.3)=$GET(^IBA(355.3,+$PIECE($GET(^DPT(DFN,.312,X,0)),"^",18),0))
End DoDot:1
ALLQ QUIT
+1 ;
ZND(DFN,NODE) ; -- set group number and group name back into zeroth node of ins. type
+1 NEW X,Y
SET (X,Y)=""
+2 IF '$GET(DFN)!('$GET(NODE))
GOTO ZNDQ
+3 SET X=$GET(^DPT(+DFN,.312,+NODE,0))
+4 SET Y=$GET(^IBA(355.3,+$PIECE(X,"^",18),0))
IF Y=""
GOTO ZNDQ
+5 ; move group number
SET $PIECE(X,"^",3)=$PIECE(Y,"^",4)
+6 ; move group name
SET $PIECE(X,"^",15)=$PIECE(Y,"^",3)
+7 ;
ZNDQ QUIT X
+1 ;
INDEM(X) ; -- is this and indemnity plan
+1 ; -- input zeroth node if insurance type field
+2 NEW IBINDEM,IBCTP
+3 SET IBINDEM=1
+4 ; company is indemnity co.
IF $PIECE($GET(^DIC(36,+X,0)),"^",13)=15
GOTO INDEMQ
+5 SET IBCTP=$PIECE($GET(^IBA(355.3,+$PIECE(X,"^",18),0)),"^",9)
+6 ; plan is and indemnity plan
IF IBCTP
IF $PIECE($GET(^IBE(355.1,+IBCTP,0)),"^",3)=9
GOTO INDEMQ
+7 SET IBINDEM=0
INDEMQ QUIT IBINDEM