VAFHLZEL ;ALB/ESD,KCL,SCK,JRP - Creation of ZEL segment ; 11/23/99
;;5.3;Registration;**122,160,195,243,342**;Aug 13, 1993
;
;
EN(DFN,VAFSTR,VAFNUM) ; This function call has been left for backwards
; compatability and is superceeded by EN1^VAFHLZEL. This function
; call is designed to build the HL7 ZEL segment. This segment contains
; VA-specific patient eligibility data. Because a patient can have
; more than eligibility, the ZEL segment for the patient's primary
; eligibility will be the output of the function call and all other
; eligibilities will be returned in the array VAFZEL. Because this
; call was not designed to accomodate a segment length greater than
; 245, sequence numbers 1 to 24 are the only fields supported.
;
;Input: DFN - Pointer to PATIENT file (#2)
; VAFSTR - String of fields requested separated by commas
; VAFNUM - Eligibility number to determine type of data
; returned
; 1 = primary eligibility only
; 2 = all eligibilities
; VAFMSTDT - Date to use when getting MST status (optional)
; Assumes existance of the HL7 enconding characters
; (HLFS,HLENC,HLQ)
;
;Output: The ZEL segment for the patient's primary eligibility
;
; VAFZEL(1..N) - If all eligibilities are chosen, an array of
; string(s) forming the ZEL segments for the patient's
; other entitled eligibilities.
;
;Notes: All fields will be returned with the primary eligibility
; : Eligibility Code, Long ID, and Short ID will be the only
; fields returned for other eligibilities
; : VAFZEL is initialized (KILLed) on entry
;
N VAFPRIM,X,MAXSEQ
;Build segment using newer call
D EN1($G(DFN),$G(VAFSTR),$G(VAFNUM),.VAFZEL)
;Make output backward compatible
S MAXSEQ=25
S VAFPRIM=$P(VAFZEL(1),HLFS,1,MAXSEQ+1)
K VAFZEL(1)
S X=1
F S X=+$O(VAFZEL(X)) Q:'X D
.S VAFZEL(X-1)=$P(VAFZEL(X),HLFS,1,MAXSEQ+1)
.K VAFZEL(X)
Q VAFPRIM
;
EN1(DFN,VAFSTR,VAFNUM,VAFZEL) ; This procedure call is designed to build the
; HL7 ZEL segment. This segment contains VA-specific patient
; eligibility data. Because a patient can have more than eligibility,
; the ZEL segment(s) will be returned in the array VAFZEL. This call
; superceeds $$EN^VAFHLZEL because it accomodates a segment length
; greater than 245.
;
;Input: DFN - Pointer to PATIENT file (#2)
; VAFSTR - String of fields requested separated by commas
; VAFNUM - Eligibility number to determine type of data
; returned
; 1 = primary eligibility only (default)
; 2 = all eligibilities
; .VAFZEL - Array to return segment(s) in
; VAFMSTDT - Date to use when getting MST status (optional)
; Existance of HL7 enconding characters (HLFS,HLENC,HLQ) assumed
;
;Output: VAFZEL(X) = ZEL segment (first 245 characters)
; VAFZEL(X,Y) = Remaining portion of ZEL segment in 245 chunks
;
;Notes: VAFZEL(1) will be the primary eligibility
; : VAFZEL(2..n) will be other eligibilities
; : All fields will be returned with the primary eligibility
; : Eligibility Code, Long ID, and Short ID will be the only
; fields returned for other eligibilities
; : Fields will not be split across nodes in VAFZEL()
; : VAFZEL is initialized (KILLed) on entry
;
N VAFPELIG,VAFNODE,VAFPRIM,VAFHLZEL,VAFSETID,VAFELPTR,VAFMAXL,X
K VAFZEL
S VAFMAXL=245
I '$G(DFN)!($G(VAFSTR)="") S VAFZEL(1)="ZEL"_HLFS Q
S VAFNUM=$S('$D(VAFNUM):1,VAFNUM'<2:2,1:1)
S VAFSTR=","_VAFSTR_","
;Build ZEL segment for primary eligibility
S VAFPELIG=$G(^DPT(DFN,.36))
S VAFNODE=$G(^DPT(DFN,"E",+VAFPELIG,0))
S VAFSETID=1 D GETDATA^VAFHLZE1,MAKESEG
;Only build for primary elig.
Q:VAFNUM=1
;Build ZEL segments for other eligibilities
S VAFELPTR=0
F S VAFELPTR=$O(^DPT(DFN,"E",VAFELPTR)) Q:'VAFELPTR I VAFELPTR'=+VAFPELIG D
.S VAFNODE=$G(^DPT(DFN,"E",VAFELPTR,0))
.S VAFSETID=VAFSETID+1 D GETDATA^VAFHLZE1,MAKESEG
;Done
Q
;
MAKESEG ;Make segment using obtained data
;Input: Existance of the following variables is assumed
; VAFSETID = Number denoting Xth repetition of the ZEL segment
; VAFMAXL = Maximum length of each node (defaults to 245)
; VAFHLZEL(SeqNum) = Value
; HL7 encoding characters (HLFS, HLENC, HLQ)
;
;Output: VAFZEL(VAFSETID) = ZEL segment (first VAFMAXL characters)
; VAFZEL(VAFSETID,x) = Remaining portion of ZEL segment in
; VAFMAXL character chunks (if needed)
; beginning with a field seperator
;
;Notes: VAFZEL(VAFSETID) is initialized (KILLed) on input
; : Fields will not be split across nodes in VAFZEL()
;
N SEQ,SPILL,SPILLON,SPOT,LASTSEQ,VAFY
K VAFZEL(VAFSETID)
S VAFZEL(VAFSETID)="ZEL"
S VAFMAXL=+$G(VAFMAXL) S:'VAFMAXL VAFMAXL=245
S VAFY=$NA(VAFZEL(VAFSETID))
S (SPILL,SPILLON)=0
S LASTSEQ=+$O(VAFHLZEL(""),-1)
F SEQ=1:1:LASTSEQ D
.;Make sure maximum length won't be exceeded
.I ($L(@VAFY)+$L($G(VAFHLZEL(SEQ)))+1)>VAFMAXL D
..;Max length exceeded - start putting data on next node
..S SPILL=SPILL+1
..S SPILLON=SEQ-1
..S VAFY=$NA(VAFZEL(VAFSETID,SPILL))
.;Add to string
.S SPOT=(SEQ+1)-SPILLON
.S $P(@VAFY,HLFS,SPOT)=$G(VAFHLZEL(SEQ))
;Done
Q
VAFHLZEL ;ALB/ESD,KCL,SCK,JRP - Creation of ZEL segment ; 11/23/99
+1 ;;5.3;Registration;**122,160,195,243,342**;Aug 13, 1993
+2 ;
+3 ;
EN(DFN,VAFSTR,VAFNUM) ; This function call has been left for backwards
+1 ; compatability and is superceeded by EN1^VAFHLZEL. This function
+2 ; call is designed to build the HL7 ZEL segment. This segment contains
+3 ; VA-specific patient eligibility data. Because a patient can have
+4 ; more than eligibility, the ZEL segment for the patient's primary
+5 ; eligibility will be the output of the function call and all other
+6 ; eligibilities will be returned in the array VAFZEL. Because this
+7 ; call was not designed to accomodate a segment length greater than
+8 ; 245, sequence numbers 1 to 24 are the only fields supported.
+9 ;
+10 ;Input: DFN - Pointer to PATIENT file (#2)
+11 ; VAFSTR - String of fields requested separated by commas
+12 ; VAFNUM - Eligibility number to determine type of data
+13 ; returned
+14 ; 1 = primary eligibility only
+15 ; 2 = all eligibilities
+16 ; VAFMSTDT - Date to use when getting MST status (optional)
+17 ; Assumes existance of the HL7 enconding characters
+18 ; (HLFS,HLENC,HLQ)
+19 ;
+20 ;Output: The ZEL segment for the patient's primary eligibility
+21 ;
+22 ; VAFZEL(1..N) - If all eligibilities are chosen, an array of
+23 ; string(s) forming the ZEL segments for the patient's
+24 ; other entitled eligibilities.
+25 ;
+26 ;Notes: All fields will be returned with the primary eligibility
+27 ; : Eligibility Code, Long ID, and Short ID will be the only
+28 ; fields returned for other eligibilities
+29 ; : VAFZEL is initialized (KILLed) on entry
+30 ;
+31 NEW VAFPRIM,X,MAXSEQ
+32 ;Build segment using newer call
+33 DO EN1($GET(DFN),$GET(VAFSTR),$GET(VAFNUM),.VAFZEL)
+34 ;Make output backward compatible
+35 SET MAXSEQ=25
+36 SET VAFPRIM=$PIECE(VAFZEL(1),HLFS,1,MAXSEQ+1)
+37 KILL VAFZEL(1)
+38 SET X=1
+39 FOR
SET X=+$ORDER(VAFZEL(X))
IF 'X
QUIT
Begin DoDot:1
+40 SET VAFZEL(X-1)=$PIECE(VAFZEL(X),HLFS,1,MAXSEQ+1)
+41 KILL VAFZEL(X)
End DoDot:1
+42 QUIT VAFPRIM
+43 ;
EN1(DFN,VAFSTR,VAFNUM,VAFZEL) ; This procedure call is designed to build the
+1 ; HL7 ZEL segment. This segment contains VA-specific patient
+2 ; eligibility data. Because a patient can have more than eligibility,
+3 ; the ZEL segment(s) will be returned in the array VAFZEL. This call
+4 ; superceeds $$EN^VAFHLZEL because it accomodates a segment length
+5 ; greater than 245.
+6 ;
+7 ;Input: DFN - Pointer to PATIENT file (#2)
+8 ; VAFSTR - String of fields requested separated by commas
+9 ; VAFNUM - Eligibility number to determine type of data
+10 ; returned
+11 ; 1 = primary eligibility only (default)
+12 ; 2 = all eligibilities
+13 ; .VAFZEL - Array to return segment(s) in
+14 ; VAFMSTDT - Date to use when getting MST status (optional)
+15 ; Existance of HL7 enconding characters (HLFS,HLENC,HLQ) assumed
+16 ;
+17 ;Output: VAFZEL(X) = ZEL segment (first 245 characters)
+18 ; VAFZEL(X,Y) = Remaining portion of ZEL segment in 245 chunks
+19 ;
+20 ;Notes: VAFZEL(1) will be the primary eligibility
+21 ; : VAFZEL(2..n) will be other eligibilities
+22 ; : All fields will be returned with the primary eligibility
+23 ; : Eligibility Code, Long ID, and Short ID will be the only
+24 ; fields returned for other eligibilities
+25 ; : Fields will not be split across nodes in VAFZEL()
+26 ; : VAFZEL is initialized (KILLed) on entry
+27 ;
+28 NEW VAFPELIG,VAFNODE,VAFPRIM,VAFHLZEL,VAFSETID,VAFELPTR,VAFMAXL,X
+29 KILL VAFZEL
+30 SET VAFMAXL=245
+31 IF '$GET(DFN)!($GET(VAFSTR)="")
SET VAFZEL(1)="ZEL"_HLFS
QUIT
+32 SET VAFNUM=$SELECT('$DATA(VAFNUM):1,VAFNUM'<2:2,1:1)
+33 SET VAFSTR=","_VAFSTR_","
+34 ;Build ZEL segment for primary eligibility
+35 SET VAFPELIG=$GET(^DPT(DFN,.36))
+36 SET VAFNODE=$GET(^DPT(DFN,"E",+VAFPELIG,0))
+37 SET VAFSETID=1
DO GETDATA^VAFHLZE1
DO MAKESEG
+38 ;Only build for primary elig.
+39 IF VAFNUM=1
QUIT
+40 ;Build ZEL segments for other eligibilities
+41 SET VAFELPTR=0
+42 FOR
SET VAFELPTR=$ORDER(^DPT(DFN,"E",VAFELPTR))
IF 'VAFELPTR
QUIT
IF VAFELPTR'=+VAFPELIG
Begin DoDot:1
+43 SET VAFNODE=$GET(^DPT(DFN,"E",VAFELPTR,0))
+44 SET VAFSETID=VAFSETID+1
DO GETDATA^VAFHLZE1
DO MAKESEG
End DoDot:1
+45 ;Done
+46 QUIT
+47 ;
MAKESEG ;Make segment using obtained data
+1 ;Input: Existance of the following variables is assumed
+2 ; VAFSETID = Number denoting Xth repetition of the ZEL segment
+3 ; VAFMAXL = Maximum length of each node (defaults to 245)
+4 ; VAFHLZEL(SeqNum) = Value
+5 ; HL7 encoding characters (HLFS, HLENC, HLQ)
+6 ;
+7 ;Output: VAFZEL(VAFSETID) = ZEL segment (first VAFMAXL characters)
+8 ; VAFZEL(VAFSETID,x) = Remaining portion of ZEL segment in
+9 ; VAFMAXL character chunks (if needed)
+10 ; beginning with a field seperator
+11 ;
+12 ;Notes: VAFZEL(VAFSETID) is initialized (KILLed) on input
+13 ; : Fields will not be split across nodes in VAFZEL()
+14 ;
+15 NEW SEQ,SPILL,SPILLON,SPOT,LASTSEQ,VAFY
+16 KILL VAFZEL(VAFSETID)
+17 SET VAFZEL(VAFSETID)="ZEL"
+18 SET VAFMAXL=+$GET(VAFMAXL)
IF 'VAFMAXL
SET VAFMAXL=245
+19 SET VAFY=$NAME(VAFZEL(VAFSETID))
+20 SET (SPILL,SPILLON)=0
+21 SET LASTSEQ=+$ORDER(VAFHLZEL(""),-1)
+22 FOR SEQ=1:1:LASTSEQ
Begin DoDot:1
+23 ;Make sure maximum length won't be exceeded
+24 IF ($LENGTH(@VAFY)+$LENGTH($GET(VAFHLZEL(SEQ)))+1)>VAFMAXL
Begin DoDot:2
+25 ;Max length exceeded - start putting data on next node
+26 SET SPILL=SPILL+1
+27 SET SPILLON=SEQ-1
+28 SET VAFY=$NAME(VAFZEL(VAFSETID,SPILL))
End DoDot:2
+29 ;Add to string
+30 SET SPOT=(SEQ+1)-SPILLON
+31 SET $PIECE(@VAFY,HLFS,SPOT)=$GET(VAFHLZEL(SEQ))
End DoDot:1
+32 ;Done
+33 QUIT