VAFHLIN1 ;ALB/KCL/SCK/PHH,TDM - CREATE HL7 INSURANCE (IN1) SEGMENT ; 1/21/09 4:05pm
;;5.3;Registration;**122,190,670,740,754**;Aug 13, 1993;Build 46
;
;
; This generic function was designed to return the HL7 IN1 (Insurance)
; segment. This segment contains VA-specific patient insurance
; information. (All active insurance data for a patient including
; those insurance carriers that do not reimburse the VA i.e Medicare)
;
; SCK - modified for Insurance Encapsulation API
; 1. The Insurance API does not currently support the Pre-Certification flag
; in the IN1 segment, Field 28. No value will be returned for field 28.
; 2. The Insurance API does not support Line 2 or Line 3 of the address.
; The API returns a single address line.
;
EN(DFN,VAFSTR,VAFHLQ,VAFHLFS,VAFARRY,VAFHLECH) ; --
; Entry point to return HL7 IN1 segments.
;
; Input:
; DFN - internal entry number of the PATIENT (#2) file.
; VAFSTR - (optional) string of fields requested seperated
; by commas. If not passed, return all data fields.
; VAFHLQ - (optional) HL7 null variable.
; VAFHLFS - (optional) HL7 field separator.
; VAFARRY - (optional) user-supplied array name which will hold
; HL7 IN1 segments. Otherwise, ^TMP("VAFIN1",$J) will
; be used.
; VAFHLECH - (optional) HL7 encoding characters.
;
; Output:
; Array of HL7 IN1 segments
;
N VAFGRP,VAFI,VAFIDX,VAFINS,VAFNODE,VAFPHN,VAFY,VAF36,X,VAFX,VAFTMP
S VAFARRY=$G(VAFARRY),VAFIDX=0
;
; if VAFARRY not defined, use ^TMP("VAFIN1",$J)
S:(VAFARRY="") VAFARRY="^TMP(""VAFIN1"",$J)"
;
; if VAFHLQ or VAFHLFS not passed, use default HL7 variables
S VAFHLQ=$S($D(VAFHLQ):VAFHLQ,1:$G(HLQ)),VAFHLFS=$S($D(VAFHLFS):VAFHLFS,1:$G(HLFS))
S VAFHLECH=$S($D(VAFHLECH):VAFHLECH,1:$G(HLECH))
;
; if DFN not passed, exit
I '$G(DFN) S @VAFARRY@(1,0)="IN1"_VAFHLFS_1 G ENQ
;
; find all insurance data for a patient (IB SUPPORTED CALL)
; This uses the Encapsulated Insurance API to retrieve data into an array
; See IB*2*267 Release Notes v1.0 for flags and array ID's
S VAFX=$$INSUR^IBBAPI(DFN,,"R",.VAFTMP,"*")
;
; if no active insurance on file for patient, build IN1
I VAFX'=1 D
.; Build a null array if no insurance data returned
. F VAFI=1:1:24 S VAFINS(1,VAFI)=""
.; Merge array to remove first two nodes to simplify handling
E M VAFINS=VAFTMP("IBBAPI","INSUR")
;
ALL ; get all active insurance for patient
F VAFI=0:0 S VAFI=$O(VAFINS(VAFI)) Q:'VAFI D
.D BUILD
;
ENQ Q
;
;
BUILD ; Build array of HL7 (IN1) segments
S $P(VAFY,VAFHLFS,36)="",VAFIDX=VAFIDX+1
;
; if VAFSTR not passed, return all data fields
I $G(VAFSTR)']"" S VAFSTR="4,5,7,8,9,12,13,15,16,17,28,36"
S VAFSTR=","_VAFSTR_","
;
; sequential number (required field)
S $P(VAFY,VAFHLFS,1)=VAFIDX
;
; build HL7 (IN1) segment fields
I VAFSTR[",3," S $P(VAFY,VAFHLFS,3)=+$P(VAFINS(VAFI,1),U) ;Insurance company IEN (P-190)
I VAFSTR[",4," S $P(VAFY,VAFHLFS,4)=$S($P(VAFINS(VAFI,1),U,2)]"":$P(VAFINS(VAFI,1),U,2),1:VAFHLQ) ; Insurance Carrier Name
I VAFSTR[",5," S X=$$ADDR1(VAFI) S $P(VAFY,VAFHLFS,5)=$S(+X>0:X,1:VAFHLQ)
I VAFSTR[",7," S X=$$HLPHONE^HLFNC(VAFINS(VAFI,6)) S $P(VAFY,VAFHLFS,7)=$S(X]"":X,1:VAFHLQ) ; Insurance Co. Phone Number
I VAFSTR[",8," S $P(VAFY,VAFHLFS,8)=$S(VAFINS(VAFI,18)]"":VAFINS(VAFI,18),1:VAFHLQ) ; Group Number
I VAFSTR[",9," S $P(VAFY,VAFHLFS,9)=$S($P(VAFINS(VAFI,8),U,2)]"":$P(VAFINS(VAFI,8),U,2),1:VAFHLQ) ; Group Name ** The Insurance Encapsulation API doesnot return a "Group" Name, this field will display the Policy Name returned by the API
I VAFSTR[",12," S X=$$HLDATE^HLFNC(VAFINS(VAFI,10)) S $P(VAFY,VAFHLFS,12)=$S(X]"":X,1:VAFHLQ) ; Policy Effective Date
I VAFSTR[",13," S X=$$HLDATE^HLFNC(VAFINS(VAFI,11)) S $P(VAFY,VAFHLFS,13)=$S(X]"":X,1:VAFHLQ) ; Policy Expiration Date
I VAFSTR[",15," S $P(VAFY,VAFHLFS,15)=$S(+$P($G(VAFINS(VAFI,21)),"^")>0:+$P(VAFINS(VAFI,21),"^"),1:VAFHLQ) ; Plan Type (ptr. to Type of Plan (#355.1) file)
I VAFSTR[",16," S $P(VAFY,VAFHLFS,16)=$S(VAFINS(VAFI,13)]"":VAFINS(VAFI,13),1:VAFHLQ) ; Name of Insured
I VAFSTR[",17," S X=$$WHOSE($P(VAFINS(VAFI,12),U)) S $P(VAFY,VAFHLFS,17)=$S(X]"":X,1:VAFHLQ) ; Whose Insurance
;I VAFSTR[",28," S $P(VAFY,VAFHLFS,28)=VAFHLQ ; $S($P(VAFGRP,"^",6)]"":$P(VAFGRP,"^",6),1:VAFHLQ) ; Is Pre-Certification Required?
I VAFSTR[",36," S $P(VAFY,VAFHLFS,36)=$S(VAFINS(VAFI,14)]"":VAFINS(VAFI,14),1:VAFHLQ) ; Subscriber ID
;
; set all active insurance policies into array
S @VAFARRY@(VAFIDX,0)="IN1"_VAFHLFS_$G(VAFY)
Q
;
WHOSE(VAFWHO) ; Format Subscriber relationship for HL7 conversion
;
; Input: Subscriber relationship from Insurance API, ID=12
; P - Patient
; S - Spouse
; O - Other
;
; Output:
; v - Veteran
; s - Spouse
; o - Other
;
S:VAFWHO["P" VAFWHO="V"
Q $$LOW^XLFSTR(VAFWHO)
;
ADDR1(VAFI) ; Format insurance company address from Insurance API for HL7 conversion.
;
; Input:
; Index number for Insurance API array
;
; Output:
; String in the form of the HL7 address field
;
N VAFAD,VAFGL,RETVAL
S VAFAD=VAFINS(VAFI,2)_"^"_VAFINS(VAFI,23) ;Ins Addr Line 1 & 2
S VAFGL=VAFINS(VAFI,3)_"^"_$P(VAFINS(VAFI,4),U)_"^"_VAFINS(VAFI,5)
;
; convert DHCP address to HL7 format using HL7 utility
S RETVAL=$$HLADDR^HLFNC(VAFAD,VAFGL)
S $P(RETVAL,$E(VAFHLECH),8)=VAFINS(VAFI,24) ;Ins Addr Line 3
Q RETVAL
;
ADDR(VAFPTR) ; Format insurance company address for HL7 conversion
; Retained for backword compatibility
;
; Input:
; VAFPTR - pointer to Insurance Co. (#36) file
;
; Output:
; String in the form of the HL7 address field
;
N VAFAD,VAFADDR,VAFGL,VAFST
S VAFAD=""
;
; get (.11) node of Insurance Co. (#36) file
S VAFADDR=$G(^DIC(36,+VAFPTR,.11))
;
; 1st & 2nd street address lines
F VAFST=1,2 S VAFAD=VAFAD_"^"_$P(VAFADDR,"^",VAFST)
S VAFAD=$P(VAFAD,"^",2,99)
S VAFGL=$P(VAFADDR,"^",4) ; city
S VAFGL=VAFGL_"^"_$P(VAFADDR,"^",5) ; state
S VAFGL=VAFGL_"^"_$P(VAFADDR,"^",6) ; zip
;
; convert DHCP address to HL7 format using HL7 utility
Q $$HLADDR^HLFNC(VAFAD,VAFGL)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVAFHLIN1 6238 printed Dec 13, 2024@03:02:59 Page 2
VAFHLIN1 ;ALB/KCL/SCK/PHH,TDM - CREATE HL7 INSURANCE (IN1) SEGMENT ; 1/21/09 4:05pm
+1 ;;5.3;Registration;**122,190,670,740,754**;Aug 13, 1993;Build 46
+2 ;
+3 ;
+4 ; This generic function was designed to return the HL7 IN1 (Insurance)
+5 ; segment. This segment contains VA-specific patient insurance
+6 ; information. (All active insurance data for a patient including
+7 ; those insurance carriers that do not reimburse the VA i.e Medicare)
+8 ;
+9 ; SCK - modified for Insurance Encapsulation API
+10 ; 1. The Insurance API does not currently support the Pre-Certification flag
+11 ; in the IN1 segment, Field 28. No value will be returned for field 28.
+12 ; 2. The Insurance API does not support Line 2 or Line 3 of the address.
+13 ; The API returns a single address line.
+14 ;
EN(DFN,VAFSTR,VAFHLQ,VAFHLFS,VAFARRY,VAFHLECH) ; --
+1 ; Entry point to return HL7 IN1 segments.
+2 ;
+3 ; Input:
+4 ; DFN - internal entry number of the PATIENT (#2) file.
+5 ; VAFSTR - (optional) string of fields requested seperated
+6 ; by commas. If not passed, return all data fields.
+7 ; VAFHLQ - (optional) HL7 null variable.
+8 ; VAFHLFS - (optional) HL7 field separator.
+9 ; VAFARRY - (optional) user-supplied array name which will hold
+10 ; HL7 IN1 segments. Otherwise, ^TMP("VAFIN1",$J) will
+11 ; be used.
+12 ; VAFHLECH - (optional) HL7 encoding characters.
+13 ;
+14 ; Output:
+15 ; Array of HL7 IN1 segments
+16 ;
+17 NEW VAFGRP,VAFI,VAFIDX,VAFINS,VAFNODE,VAFPHN,VAFY,VAF36,X,VAFX,VAFTMP
+18 SET VAFARRY=$GET(VAFARRY)
SET VAFIDX=0
+19 ;
+20 ; if VAFARRY not defined, use ^TMP("VAFIN1",$J)
+21 if (VAFARRY="")
SET VAFARRY="^TMP(""VAFIN1"",$J)"
+22 ;
+23 ; if VAFHLQ or VAFHLFS not passed, use default HL7 variables
+24 SET VAFHLQ=$SELECT($DATA(VAFHLQ):VAFHLQ,1:$GET(HLQ))
SET VAFHLFS=$SELECT($DATA(VAFHLFS):VAFHLFS,1:$GET(HLFS))
+25 SET VAFHLECH=$SELECT($DATA(VAFHLECH):VAFHLECH,1:$GET(HLECH))
+26 ;
+27 ; if DFN not passed, exit
+28 IF '$GET(DFN)
SET @VAFARRY@(1,0)="IN1"_VAFHLFS_1
GOTO ENQ
+29 ;
+30 ; find all insurance data for a patient (IB SUPPORTED CALL)
+31 ; This uses the Encapsulated Insurance API to retrieve data into an array
+32 ; See IB*2*267 Release Notes v1.0 for flags and array ID's
+33 SET VAFX=$$INSUR^IBBAPI(DFN,,"R",.VAFTMP,"*")
+34 ;
+35 ; if no active insurance on file for patient, build IN1
+36 IF VAFX'=1
Begin DoDot:1
+37 ; Build a null array if no insurance data returned
+38 FOR VAFI=1:1:24
SET VAFINS(1,VAFI)=""
+39 ; Merge array to remove first two nodes to simplify handling
End DoDot:1
+40 IF '$TEST
MERGE VAFINS=VAFTMP("IBBAPI","INSUR")
+41 ;
ALL ; get all active insurance for patient
+1 FOR VAFI=0:0
SET VAFI=$ORDER(VAFINS(VAFI))
if 'VAFI
QUIT
Begin DoDot:1
+2 DO BUILD
End DoDot:1
+3 ;
ENQ QUIT
+1 ;
+2 ;
BUILD ; Build array of HL7 (IN1) segments
+1 SET $PIECE(VAFY,VAFHLFS,36)=""
SET VAFIDX=VAFIDX+1
+2 ;
+3 ; if VAFSTR not passed, return all data fields
+4 IF $GET(VAFSTR)']""
SET VAFSTR="4,5,7,8,9,12,13,15,16,17,28,36"
+5 SET VAFSTR=","_VAFSTR_","
+6 ;
+7 ; sequential number (required field)
+8 SET $PIECE(VAFY,VAFHLFS,1)=VAFIDX
+9 ;
+10 ; build HL7 (IN1) segment fields
+11 ;Insurance company IEN (P-190)
IF VAFSTR[",3,"
SET $PIECE(VAFY,VAFHLFS,3)=+$PIECE(VAFINS(VAFI,1),U)
+12 ; Insurance Carrier Name
IF VAFSTR[",4,"
SET $PIECE(VAFY,VAFHLFS,4)=$SELECT($PIECE(VAFINS(VAFI,1),U,2)]"":$PIECE(VAFINS(VAFI,1),U,2),1:VAFHLQ)
+13 IF VAFSTR[",5,"
SET X=$$ADDR1(VAFI)
SET $PIECE(VAFY,VAFHLFS,5)=$SELECT(+X>0:X,1:VAFHLQ)
+14 ; Insurance Co. Phone Number
IF VAFSTR[",7,"
SET X=$$HLPHONE^HLFNC(VAFINS(VAFI,6))
SET $PIECE(VAFY,VAFHLFS,7)=$SELECT(X]"":X,1:VAFHLQ)
+15 ; Group Number
IF VAFSTR[",8,"
SET $PIECE(VAFY,VAFHLFS,8)=$SELECT(VAFINS(VAFI,18)]"":VAFINS(VAFI,18),1:VAFHLQ)
+16 ; Group Name ** The Insurance Encapsulation API doesnot return a "Group" Name, this field will display the Policy Name returned by the API
IF VAFSTR[",9,"
SET $PIECE(VAFY,VAFHLFS,9)=$SELECT($PIECE(VAFINS(VAFI,8),U,2)]"":$PIECE(VAFINS(VAFI,8),U,2),1:VAFHLQ)
+17 ; Policy Effective Date
IF VAFSTR[",12,"
SET X=$$HLDATE^HLFNC(VAFINS(VAFI,10))
SET $PIECE(VAFY,VAFHLFS,12)=$SELECT(X]"":X,1:VAFHLQ)
+18 ; Policy Expiration Date
IF VAFSTR[",13,"
SET X=$$HLDATE^HLFNC(VAFINS(VAFI,11))
SET $PIECE(VAFY,VAFHLFS,13)=$SELECT(X]"":X,1:VAFHLQ)
+19 ; Plan Type (ptr. to Type of Plan (#355.1) file)
IF VAFSTR[",15,"
SET $PIECE(VAFY,VAFHLFS,15)=$SELECT(+$PIECE($GET(VAFINS(VAFI,21)),"^")>0:+$PIECE(VAFINS(VAFI,21),"^"),1:VAFHLQ)
+20 ; Name of Insured
IF VAFSTR[",16,"
SET $PIECE(VAFY,VAFHLFS,16)=$SELECT(VAFINS(VAFI,13)]"":VAFINS(VAFI,13),1:VAFHLQ)
+21 ; Whose Insurance
IF VAFSTR[",17,"
SET X=$$WHOSE($PIECE(VAFINS(VAFI,12),U))
SET $PIECE(VAFY,VAFHLFS,17)=$SELECT(X]"":X,1:VAFHLQ)
+22 ;I VAFSTR[",28," S $P(VAFY,VAFHLFS,28)=VAFHLQ ; $S($P(VAFGRP,"^",6)]"":$P(VAFGRP,"^",6),1:VAFHLQ) ; Is Pre-Certification Required?
+23 ; Subscriber ID
IF VAFSTR[",36,"
SET $PIECE(VAFY,VAFHLFS,36)=$SELECT(VAFINS(VAFI,14)]"":VAFINS(VAFI,14),1:VAFHLQ)
+24 ;
+25 ; set all active insurance policies into array
+26 SET @VAFARRY@(VAFIDX,0)="IN1"_VAFHLFS_$GET(VAFY)
+27 QUIT
+28 ;
WHOSE(VAFWHO) ; Format Subscriber relationship for HL7 conversion
+1 ;
+2 ; Input: Subscriber relationship from Insurance API, ID=12
+3 ; P - Patient
+4 ; S - Spouse
+5 ; O - Other
+6 ;
+7 ; Output:
+8 ; v - Veteran
+9 ; s - Spouse
+10 ; o - Other
+11 ;
+12 if VAFWHO["P"
SET VAFWHO="V"
+13 QUIT $$LOW^XLFSTR(VAFWHO)
+14 ;
ADDR1(VAFI) ; Format insurance company address from Insurance API for HL7 conversion.
+1 ;
+2 ; Input:
+3 ; Index number for Insurance API array
+4 ;
+5 ; Output:
+6 ; String in the form of the HL7 address field
+7 ;
+8 NEW VAFAD,VAFGL,RETVAL
+9 ;Ins Addr Line 1 & 2
SET VAFAD=VAFINS(VAFI,2)_"^"_VAFINS(VAFI,23)
+10 SET VAFGL=VAFINS(VAFI,3)_"^"_$PIECE(VAFINS(VAFI,4),U)_"^"_VAFINS(VAFI,5)
+11 ;
+12 ; convert DHCP address to HL7 format using HL7 utility
+13 SET RETVAL=$$HLADDR^HLFNC(VAFAD,VAFGL)
+14 ;Ins Addr Line 3
SET $PIECE(RETVAL,$EXTRACT(VAFHLECH),8)=VAFINS(VAFI,24)
+15 QUIT RETVAL
+16 ;
ADDR(VAFPTR) ; Format insurance company address for HL7 conversion
+1 ; Retained for backword compatibility
+2 ;
+3 ; Input:
+4 ; VAFPTR - pointer to Insurance Co. (#36) file
+5 ;
+6 ; Output:
+7 ; String in the form of the HL7 address field
+8 ;
+9 NEW VAFAD,VAFADDR,VAFGL,VAFST
+10 SET VAFAD=""
+11 ;
+12 ; get (.11) node of Insurance Co. (#36) file
+13 SET VAFADDR=$GET(^DIC(36,+VAFPTR,.11))
+14 ;
+15 ; 1st & 2nd street address lines
+16 FOR VAFST=1,2
SET VAFAD=VAFAD_"^"_$PIECE(VAFADDR,"^",VAFST)
+17 SET VAFAD=$PIECE(VAFAD,"^",2,99)
+18 ; city
SET VAFGL=$PIECE(VAFADDR,"^",4)
+19 ; state
SET VAFGL=VAFGL_"^"_$PIECE(VAFADDR,"^",5)
+20 ; zip
SET VAFGL=VAFGL_"^"_$PIECE(VAFADDR,"^",6)
+21 ;
+22 ; convert DHCP address to HL7 format using HL7 utility
+23 QUIT $$HLADDR^HLFNC(VAFAD,VAFGL)