VAFHLRO1 ;BP/JRP - UTILITIES FOR BUILDING HL7 ROLE SEGMENT;11/18/1997 ;;5.3;Registration;**160**;Aug 13, 1993 ; ; FIXLEN(INARR,OUTARR,MAXLEN,WORKSUB) ;Fixed length copy/collapse ; ;Input : INARR - Input array (full global reference) ; OUTARR - Output array (full global reference) ; MAXLEN - Maximum length (defaults to 245) ; WORKSUB - Subscript [in OUTARR] to begin from (defaults to 0) ;Output : None ; INARR() will be collapsed into OUTARR() ;Notes : Validity and existance of input is assumed ; : OUTARR() is not initialized (i.e. KILLed) on input ; : Sample input & output with maximum length of 4 ; INARR(1)=12345 OUTARR(0)=1234 ; INARR(1,2)=ABCD OUTARR(1)=5ABC ; INARR(2)=567 OUTARR(2)=D567 ; ; S MAXLEN=$G(MAXLEN) S:(MAXLEN<1) MAXLEN=245 S WORKSUB=$G(WORKSUB) S:(WORKSUB<1) WORKSUB=0 ;Declare variables N ROOT,VALUE,RESULT ;Declare variables for recursive portion of call N LENVAL,LENRES,LEN,LENOVR ;Remember root of INARR S ROOT=$$OREF^DILF(INARR) ;Work down INARR S RESULT="" F S INARR=$Q(@INARR) Q:((INARR="")!(INARR'[ROOT)) D .;Grab value to append .S VALUE=$G(@INARR) .;Recusively do fix length copy/collapse .D FIXLEN1 ;If anything still left in RESULT, put into OUTARR() S:(RESULT'="") @OUTARR@(WORKSUB)=RESULT ;Done Q ; FIXLEN1 ;Recursive portion of FIXLEN ; ;Input : VALUE - Value to append to RESULT ; RESULT - Working & resulting value ; OUTARR - Array to place max length results into (full global) ; WORKSUB - Working subscript in OUTARR (where to put results) ; MAXLEN - Maximum length for RESULT ;Output : None ; If max length was exceeded, then OUTARR(WORKSUB) will contain ; the leading portion of appending, WORKSUB will be incremented ; by 1, and RESULT will contain what was left. If max length ; was not exceeded, then VALUE will be appended to RESULT and ; OUTARR(WORKSUB) will be left unchanged. ;Notes : Validity and existance of input is assumed ; : Declarations done in FIXLEN ; : VALUE may be modified by this call ; ;VALUE is null - done Q:(VALUE="") ;Get lengths of VAL & RES S LENVAL=$L(VALUE) S LENRES=$L(RESULT) ;Determine what resulting length will be S LEN=LENRES+LENVAL ;Max length will not be exceeded - append and quit I (LEN