VAFHLZIR ;ALB/SEK,TDM - Create generic HL7 ZIR segment ; 6/3/10 9:43am
;;5.3;PIMS;**33,94,151,466,653,1015,1016**;JUN 30, 2012;Build 20
;
;
EN(VAFIEN,VAFSTR,VAFNUM,VAFENC) ; This generic extrinsic function was designed to
; return the HL7 ZIR segment. This segment contains
; VA-specific information pertaining to income relation type
; data for a veteran and any applicable relations.
;
; Input - VAFIEN as internal entry number of the INCOME RELATION file.
; VAFSTR as the string of fields requested seperated by commas.
; VAFNUM as the number desired for the SET ID (default = 1)
; VAFENC as Outpatient Encounter IEN (from file #409.68)
;
; NOTE: Input variable VAFENC was added as part of the Ambulatory
; Care Reporting project.
;
; *****Also assumes all HL7 variables returned from*****
; INIT^HLTRANS are defined.
;
; Output - String of data forming the ZIR segment.
;
;
N VAFDFN,VAFERR,VAFENODE,VAFNODE,VAFY,X,RELTYP,DCHILD
I $G(VAFSTR)']"" G QUIT
S VAFENC=+$G(VAFENC)
I '$G(VAFIEN)&('VAFENC) G QUIT
S $P(VAFY,HLFS,14)="",VAFSTR=","_VAFSTR_","
S VAFNODE=$G(^DGMT(408.22,+$G(VAFIEN),0))
I $G(VAFNODE)']""&('VAFENC) G QUIT
S $P(VAFY,HLFS,1)=$S($G(VAFNUM):VAFNUM,1:1)
S RELTYP=+$P($G(^DGPR(408.12,+$P($G(^DGMT(408.21,+$P(VAFNODE,"^",2),0)),"^",2),0)),"^",2)
S DCHILD=$S(((RELTYP>2)&(RELTYP<7)):1,1:0)
I VAFSTR[",2," S $P(VAFY,HLFS,2)=$$YN^VAFHLFNC($P(VAFNODE,"^",5)) ; Married last calendar year
I VAFSTR[",3," S $P(VAFY,HLFS,3)=$$YN^VAFHLFNC($P(VAFNODE,"^",6)) ; Lived with patient
;I VAFSTR[",4," S X=$P(VAFNODE,"^",7),$P(VAFY,HLFS,4)=$S(X]"":X,1:HLQ) ; Amount contributed to spouse
I VAFSTR[",4," S X=$P(VAFNODE,"^",$S(DCHILD:19,1:7)),$P(VAFY,HLFS,4)=$S(X]"":X,1:HLQ) ; Amount contributed to spouse/child
I VAFSTR[",5," S $P(VAFY,HLFS,5)=$$YN^VAFHLFNC($P(VAFNODE,"^",8)) ; Dependent children (y/n)
I VAFSTR[",6," S $P(VAFY,HLFS,6)=$$YN^VAFHLFNC($P(VAFNODE,"^",9)) ; Incapable of self-support
I VAFSTR[",7," S $P(VAFY,HLFS,7)=$$YN^VAFHLFNC($P(VAFNODE,"^",10)) ; Contributed to support
I VAFSTR[",8," S $P(VAFY,HLFS,8)=$$YN^VAFHLFNC($P(VAFNODE,"^",11)) ; Child had income
I VAFSTR[",9," S $P(VAFY,HLFS,9)=$$YN^VAFHLFNC($P(VAFNODE,"^",12)) ; Income available to you
I VAFSTR[",10," S X=$P(VAFNODE,"^",13),$P(VAFY,HLFS,10)=$S(X]"":X,1:HLQ) ; Number of dependent children
;
; ALB/ESD - Data elements 11,12,13 added as part of Ambulatory Care
; Reporting Project requirements.
;
I VAFSTR[",11,"!(VAFSTR[",12,")!(VAFSTR[",13,") D
. ;
. ;- If no encounter ptr, encounter node or DFN elements 11 - 13 = HLQ
. I ('VAFENC) S VAFERR=1 Q
. S VAFENODE=$$SCE^DGSDU(VAFENC) I VAFENODE']"" S VAFERR=1 Q
. S VAFDFN=$P(VAFENODE,"^",2) S:VAFDFN="" VAFERR=1 Q
I VAFSTR[",11," S $P(VAFY,HLFS,11)=$S('$G(VAFERR):+$$DEP^VAFMON(VAFDFN,$P(VAFENODE,"^")),1:HLQ) ;Total Dependents
I VAFSTR[",12," S $P(VAFY,HLFS,12)=$S('$G(VAFERR):+$$INCOME^VAFMON(VAFDFN,$P(VAFENODE,"^")),1:HLQ) ;Patient Income
;
;- If outpat encounter node exists, get appointment type &
; eligibility of encounter and make call to get means test indicator
I VAFSTR[",13," S $P(VAFY,HLFS,13)=$S('$G(VAFERR):$$MTI^SCDXUTL0(VAFDFN,$P(VAFENODE,"^"),$P(VAFENODE,"^",13),$P(VAFENODE,"^",10),VAFENC),1:HLQ) ;Means Test Indicator
;
;- If MT Indicator not = code AN, C, or G, change number of dependents
; to XX (not applicable)
I VAFSTR[",11," I '$G(VAFERR) D
. I $P(VAFY,HLFS,13)'="AN"&($P(VAFY,HLFS,13)'="C")&($P(VAFY,HLFS,13)'="G") S $P(VAFY,HLFS,11)="XX" ;Total Dependents not applicable for MT indicators AS,N,X,U
;
I VAFSTR[",14," S X=$P(VAFNODE,"^",18),$P(VAFY,HLFS,14)=$S(X=0:"N",X=1:"Y",1:HLQ) ; Dependent child school indicator
;
QUIT Q "ZIR"_HLFS_$G(VAFY)
VAFHLZIR ;ALB/SEK,TDM - Create generic HL7 ZIR segment ; 6/3/10 9:43am
+1 ;;5.3;PIMS;**33,94,151,466,653,1015,1016**;JUN 30, 2012;Build 20
+2 ;
+3 ;
EN(VAFIEN,VAFSTR,VAFNUM,VAFENC) ; This generic extrinsic function was designed to
+1 ; return the HL7 ZIR segment. This segment contains
+2 ; VA-specific information pertaining to income relation type
+3 ; data for a veteran and any applicable relations.
+4 ;
+5 ; Input - VAFIEN as internal entry number of the INCOME RELATION file.
+6 ; VAFSTR as the string of fields requested seperated by commas.
+7 ; VAFNUM as the number desired for the SET ID (default = 1)
+8 ; VAFENC as Outpatient Encounter IEN (from file #409.68)
+9 ;
+10 ; NOTE: Input variable VAFENC was added as part of the Ambulatory
+11 ; Care Reporting project.
+12 ;
+13 ; *****Also assumes all HL7 variables returned from*****
+14 ; INIT^HLTRANS are defined.
+15 ;
+16 ; Output - String of data forming the ZIR segment.
+17 ;
+18 ;
+19 NEW VAFDFN,VAFERR,VAFENODE,VAFNODE,VAFY,X,RELTYP,DCHILD
+20 IF $GET(VAFSTR)']""
GOTO QUIT
+21 SET VAFENC=+$GET(VAFENC)
+22 IF '$GET(VAFIEN)&('VAFENC)
GOTO QUIT
+23 SET $PIECE(VAFY,HLFS,14)=""
SET VAFSTR=","_VAFSTR_","
+24 SET VAFNODE=$GET(^DGMT(408.22,+$GET(VAFIEN),0))
+25 IF $GET(VAFNODE)']""&('VAFENC)
GOTO QUIT
+26 SET $PIECE(VAFY,HLFS,1)=$SELECT($GET(VAFNUM):VAFNUM,1:1)
+27 SET RELTYP=+$PIECE($GET(^DGPR(408.12,+$PIECE($GET(^DGMT(408.21,+$PIECE(VAFNODE,"^",2),0)),"^",2),0)),"^",2)
+28 SET DCHILD=$SELECT(((RELTYP>2)&(RELTYP<7)):1,1:0)
+29 ; Married last calendar year
IF VAFSTR[",2,"
SET $PIECE(VAFY,HLFS,2)=$$YN^VAFHLFNC($PIECE(VAFNODE,"^",5))
+30 ; Lived with patient
IF VAFSTR[",3,"
SET $PIECE(VAFY,HLFS,3)=$$YN^VAFHLFNC($PIECE(VAFNODE,"^",6))
+31 ;I VAFSTR[",4," S X=$P(VAFNODE,"^",7),$P(VAFY,HLFS,4)=$S(X]"":X,1:HLQ) ; Amount contributed to spouse
+32 ; Amount contributed to spouse/child
IF VAFSTR[",4,"
SET X=$PIECE(VAFNODE,"^",$SELECT(DCHILD:19,1:7))
SET $PIECE(VAFY,HLFS,4)=$SELECT(X]"":X,1:HLQ)
+33 ; Dependent children (y/n)
IF VAFSTR[",5,"
SET $PIECE(VAFY,HLFS,5)=$$YN^VAFHLFNC($PIECE(VAFNODE,"^",8))
+34 ; Incapable of self-support
IF VAFSTR[",6,"
SET $PIECE(VAFY,HLFS,6)=$$YN^VAFHLFNC($PIECE(VAFNODE,"^",9))
+35 ; Contributed to support
IF VAFSTR[",7,"
SET $PIECE(VAFY,HLFS,7)=$$YN^VAFHLFNC($PIECE(VAFNODE,"^",10))
+36 ; Child had income
IF VAFSTR[",8,"
SET $PIECE(VAFY,HLFS,8)=$$YN^VAFHLFNC($PIECE(VAFNODE,"^",11))
+37 ; Income available to you
IF VAFSTR[",9,"
SET $PIECE(VAFY,HLFS,9)=$$YN^VAFHLFNC($PIECE(VAFNODE,"^",12))
+38 ; Number of dependent children
IF VAFSTR[",10,"
SET X=$PIECE(VAFNODE,"^",13)
SET $PIECE(VAFY,HLFS,10)=$SELECT(X]"":X,1:HLQ)
+39 ;
+40 ; ALB/ESD - Data elements 11,12,13 added as part of Ambulatory Care
+41 ; Reporting Project requirements.
+42 ;
+43 IF VAFSTR[",11,"!(VAFSTR[",12,")!(VAFSTR[",13,")
Begin DoDot:1
+44 ;
+45 ;- If no encounter ptr, encounter node or DFN elements 11 - 13 = HLQ
+46 IF ('VAFENC)
SET VAFERR=1
QUIT
+47 SET VAFENODE=$$SCE^DGSDU(VAFENC)
IF VAFENODE']""
SET VAFERR=1
QUIT
+48 SET VAFDFN=$PIECE(VAFENODE,"^",2)
IF VAFDFN=""
SET VAFERR=1
QUIT
End DoDot:1
+49 ;Total Dependents
IF VAFSTR[",11,"
SET $PIECE(VAFY,HLFS,11)=$SELECT('$GET(VAFERR):+$$DEP^VAFMON(VAFDFN,$PIECE(VAFENODE,"^")),1:HLQ)
+50 ;Patient Income
IF VAFSTR[",12,"
SET $PIECE(VAFY,HLFS,12)=$SELECT('$GET(VAFERR):+$$INCOME^VAFMON(VAFDFN,$PIECE(VAFENODE,"^")),1:HLQ)
+51 ;
+52 ;- If outpat encounter node exists, get appointment type &
+53 ; eligibility of encounter and make call to get means test indicator
+54 ;Means Test Indicator
IF VAFSTR[",13,"
SET $PIECE(VAFY,HLFS,13)=$SELECT('$GET(VAFERR):$$MTI^SCDXUTL0(VAFDFN,$PIECE(VAFENODE,"^"),$PIECE(VAFENODE,"^",13),$PIECE(VAFENODE,"^",10),VAFENC),1:HLQ)
+55 ;
+56 ;- If MT Indicator not = code AN, C, or G, change number of dependents
+57 ; to XX (not applicable)
+58 IF VAFSTR[",11,"
IF '$GET(VAFERR)
Begin DoDot:1
+59 ;Total Dependents not applicable for MT indicators AS,N,X,U
IF $PIECE(VAFY,HLFS,13)'="AN"&($PIECE(VAFY,HLFS,13)'="C")&($PIECE(VAFY,HLFS,13)'="G")
SET $PIECE(VAFY,HLFS,11)="XX"
End DoDot:1
+60 ;
+61 ; Dependent child school indicator
IF VAFSTR[",14,"
SET X=$PIECE(VAFNODE,"^",18)
SET $PIECE(VAFY,HLFS,14)=$SELECT(X=0:"N",X=1:"Y",1:HLQ)
+62 ;
QUIT QUIT "ZIR"_HLFS_$GET(VAFY)