I understand your problem: the HRL defines only one message, while your file consists of multiple messages and therefore multiple HRLs.
I don’t really have a tcl-proc that would suit you. I can only give you one where the input is a file where each message is a STA-segment followed by several TXT-segments. This is repeated several times in one file. So with this proc I split this one file into several messages:
######################################################################
# Name: verwerk_specbrief_3
# Purpose: Omzetten van de specialistenbrief zoals die, via een ‘ish-hcm’ file, wordt aan
# aangeboden naar het HRL-formaat specbrief.
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (”start”, “run” or “time”)
# MSGID message handle
# ARGS user-supplied arguments:
#
#
# Returns: tps disposition list:
# Disposition list bevat berichten in ‘specbrief’ VRL-formaat
#
proc verwerk_specbrief_3 { args } {
keylget args MODE mode ;# Fetch mode
set dispList {} ;# Nothing to return
switch -exact — $mode {
start {
# Perform special init functions
# N.B.: there may or may not be a MSGID key in args
}
run {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
# Kill van originele bericht (hele file)
lappend dispList “KILL $mh”
set seglist [split [msgget $mh] nr]
set lengthSTA 1259
set lengthTXT 250
set leegSTA [string repeat ” ” $lengthSTA]
set leegTXT [string repeat ” ” $lengthTXT]
set firsthead 1
set newmsg “”
foreach seg $seglist {
# Lege regels eruit halen!
if {[clength $seg] > 2} {
set segnaam [string range $seg 0 2];
if {$segnaam == “STA”} {
# Indien STA-segment en het is niet het eerste STA-segment: nieuw bericht versturen!
if {$firsthead != 1} {
set mhn [msgcreate $newmsg];
lappend dispList “CONTINUE $mhn”;
}
# ‘newmsg’ wordt nu gelijk aan de eerste 1259 karakters van het STA-segment
set newmsg [string range “${seg}${leegSTA}” 0 $lengthSTA];
set firsthead 0;
} else {
# Dit is het TXT segment; van de eerste 250 karakters worden de gevulde karakters genomen (trim)
set tekst [string range $seg 3 [expr $lengthTXT + 3]];
set newmsg [cconcat $newmsg “TXT” [string range “${tekst}${leegTXT}” 0 [expr $lengthTXT – 1]]];
}
}
}
# Na afloop van alle segmenten het laatste bericht nog versturen
set mhn [msgcreate $newmsg];
lappend dispList “CONTINUE $mhn”;
}
time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
}
shutdown {
# Doing some clean-up work
}
default {
error “Unknown mode ‘$mode’ in verwerk_specbrief_3”
}
}
return $dispList
}
Of course all comments are in Dutch… But I hope you get my drift.
Afterwards you said you need to put the messages together again. You could do this by putting all messages in a file again.
Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands