PRCVUTSC ;WOIFO/DST - Convert non-formatted string ; 2/11/03 4:52pm
;;5.1;IFCAP;**81**;Oct 20, 2000
;Per VHA Directive 10-93-142, this routine should not be modified.
;
CONV(STR,ACT,SC) ;
;
; Initial data for HL7, HL() array, will be used in this routine.
; Such as HL("ECH"), HL("FS")...
;
; Input:
; STR - A string to be convert
; ACT - Action, E - from escape sequences to special char
; C - from special char to escape sequences
; SC - String of special character used in this HL7 message
; SC char 1 - Field separator
; char 2 - Component separator
; char 3 - Repetition separator
; char 4 - Escape sequence character
; char 5 - Subcomponent separator
;
; Output:
; STR1 - A converted string
;
N LEN,SP,SP1,STR1,PRCVFS,PRCVCS,PRCVRS,PRCVES,PRCVSS
I $L($G(STR))=0!($L($G(ACT))=0) Q ""
S PRCVFS=$E(SC,1)
S PRCVCS=$E(SC,2)
S PRCVRS=$E(SC,3)
S PRCVES=$E(SC,4)
S PRCVSS=$E(SC,5)
S LEN=$L(STR)
I ACT="C" D TOC Q STR1
;
TOE ; Converted from Escape Sequences to special characters
; PRCVFS <== \F\ Field separator
; PRCVCS <== \S\ Component separator
; PRCVRS <== \R\ Repetition separator
; PRCVES <== \E\ Escape sequence character
; PRCVSS <== \T\ Sub-component separator
;
N I,J,K,LEN1,SE,SE1,SP,STR2
S LEN1=0
S STR1=STR
;
; Go through special characters listed in CH and converted, one by one.
;
F K=1:1 Q:$P($T(CH+K),";;",2)']"" D
. S SE=$P($P($T(CH+K),";;",2),";",2) ; correspond special character
. F I=1:1 S STR2(I)=$P(STR1,SE,I) Q:STR2(I)="" S SE1(I)=SE
. K STR2(I)
. F J=1:1:I-1 S LEN1=LEN1+$L(STR2(J))+$L(SE1(J))
. I LEN1>$L(STR1) K SE1(I-1)
. S LEN1=0
. S SP=$P($P($T(CH+K),";;",2),";",1)
. S STR2=""
. F I=1:1 Q:$G(STR2(I))']"" D
.. S STR2=STR2_STR2(I)
.. S:$D(SE1(I)) STR2=STR2_@SP
. S STR1=STR2
. K SP,STR2
Q STR1
;
TOC ; Converted from special characters to Escape Sequences
; PRCVFS ==> \F\ Field separator
; PRCVCS ==> \S\ Component separator
; PRCVRS ==> \R\ Repetition separator
; PRCVES ==> \E\ Escape sequence character
; PRCVSS ==> \T\ Sub-component separator
;
N C1,I
S STR1=""
F I=1:1:LEN D
. S C1=$E(STR,I)
. S STR1=STR1_$S(C1=PRCVFS:"\F\",C1=PRCVCS:"\S\",C1=PRCVRS:"\R\",C1=PRCVES:"\E\",C1=PRCVSS:"\T\",1:C1)
. Q
Q
;
CH ; Convert characters
;;PRCVFS;\F\;Field separator
;;PRCVCS;\S\;Component separator
;;PRCVRS;\R\;Repetition separator
;;PRCVES;\E\;Escape sequence character
;;PRCVSS;\T\;Subcomponent separator
;;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPRCVUTSC 2652 printed Dec 13, 2024@02:20:22 Page 2
PRCVUTSC ;WOIFO/DST - Convert non-formatted string ; 2/11/03 4:52pm
+1 ;;5.1;IFCAP;**81**;Oct 20, 2000
+2 ;Per VHA Directive 10-93-142, this routine should not be modified.
+3 ;
CONV(STR,ACT,SC) ;
+1 ;
+2 ; Initial data for HL7, HL() array, will be used in this routine.
+3 ; Such as HL("ECH"), HL("FS")...
+4 ;
+5 ; Input:
+6 ; STR - A string to be convert
+7 ; ACT - Action, E - from escape sequences to special char
+8 ; C - from special char to escape sequences
+9 ; SC - String of special character used in this HL7 message
+10 ; SC char 1 - Field separator
+11 ; char 2 - Component separator
+12 ; char 3 - Repetition separator
+13 ; char 4 - Escape sequence character
+14 ; char 5 - Subcomponent separator
+15 ;
+16 ; Output:
+17 ; STR1 - A converted string
+18 ;
+19 NEW LEN,SP,SP1,STR1,PRCVFS,PRCVCS,PRCVRS,PRCVES,PRCVSS
+20 IF $LENGTH($GET(STR))=0!($LENGTH($GET(ACT))=0)
QUIT ""
+21 SET PRCVFS=$EXTRACT(SC,1)
+22 SET PRCVCS=$EXTRACT(SC,2)
+23 SET PRCVRS=$EXTRACT(SC,3)
+24 SET PRCVES=$EXTRACT(SC,4)
+25 SET PRCVSS=$EXTRACT(SC,5)
+26 SET LEN=$LENGTH(STR)
+27 IF ACT="C"
DO TOC
QUIT STR1
+28 ;
TOE ; Converted from Escape Sequences to special characters
+1 ; PRCVFS <== \F\ Field separator
+2 ; PRCVCS <== \S\ Component separator
+3 ; PRCVRS <== \R\ Repetition separator
+4 ; PRCVES <== \E\ Escape sequence character
+5 ; PRCVSS <== \T\ Sub-component separator
+6 ;
+7 NEW I,J,K,LEN1,SE,SE1,SP,STR2
+8 SET LEN1=0
+9 SET STR1=STR
+10 ;
+11 ; Go through special characters listed in CH and converted, one by one.
+12 ;
+13 FOR K=1:1
if $PIECE($TEXT(CH+K),";;",2)']""
QUIT
Begin DoDot:1
+14 ; correspond special character
SET SE=$PIECE($PIECE($TEXT(CH+K),";;",2),";",2)
+15 FOR I=1:1
SET STR2(I)=$PIECE(STR1,SE,I)
if STR2(I)=""
QUIT
SET SE1(I)=SE
+16 KILL STR2(I)
+17 FOR J=1:1:I-1
SET LEN1=LEN1+$LENGTH(STR2(J))+$LENGTH(SE1(J))
+18 IF LEN1>$LENGTH(STR1)
KILL SE1(I-1)
+19 SET LEN1=0
+20 SET SP=$PIECE($PIECE($TEXT(CH+K),";;",2),";",1)
+21 SET STR2=""
+22 FOR I=1:1
if $GET(STR2(I))']""
QUIT
Begin DoDot:2
+23 SET STR2=STR2_STR2(I)
+24 if $DATA(SE1(I))
SET STR2=STR2_@SP
End DoDot:2
+25 SET STR1=STR2
+26 KILL SP,STR2
End DoDot:1
+27 QUIT STR1
+28 ;
TOC ; Converted from special characters to Escape Sequences
+1 ; PRCVFS ==> \F\ Field separator
+2 ; PRCVCS ==> \S\ Component separator
+3 ; PRCVRS ==> \R\ Repetition separator
+4 ; PRCVES ==> \E\ Escape sequence character
+5 ; PRCVSS ==> \T\ Sub-component separator
+6 ;
+7 NEW C1,I
+8 SET STR1=""
+9 FOR I=1:1:LEN
Begin DoDot:1
+10 SET C1=$EXTRACT(STR,I)
+11 SET STR1=STR1_$SELECT(C1=PRCVFS:"\F\",C1=PRCVCS:"\S\",C1=PRCVRS:"\R\",C1=PRCVES:"\E\",C1=PRCVSS:"\T\",1:C1)
+12 QUIT
End DoDot:1
+13 QUIT
+14 ;
CH ; Convert characters
+1 ;;PRCVFS;\F\;Field separator
+2 ;;PRCVCS;\S\;Component separator
+3 ;;PRCVRS;\R\;Repetition separator
+4 ;;PRCVES;\E\;Escape sequence character
+5 ;;PRCVSS;\T\;Subcomponent separator
+6 ;;