A pretty simple proc will suffice. Assume a batch file of the form:
FHS BHS MSH….. MSH…. BTS FTS
Strip off and save the header/trailers for inspection, etc. Get the HL7 messages and send one at a time through the engine.
Modify to fit specific needs
run {
# Get the IB message as a list
keylget args MSGID mh
# Get msg and remove CR if any
set ib [string map {r “”} [msgget $mh]]
# Make it a list
set ibMsg [split $ib n]
# Always KILL original
set dispList
# just in case make sure variables are set
set FHS “”; set BHS “”; set BTS “”; set FTS “”
# Remove and save headers and trailers
foreach var {FHS BHS BTS FTS} {
set loc [lsearch -regexp $ibMsg “^$var”]
if {$loc >= 0 } { set $var [lvarpop ibMsg $loc] }
}
# The list now contains only MSH … etc
# Make all LF = CR
set ibMsg [join $ibMsg r]
# Put a new-line between each message
regsub -all — {rMSH} $ibMsg “rnMSH” ibMsg
# Simply step through each and build HL7 message
foreach msg [split $ibMsg n] {
# Make sure there is only a single CR after last
# segment
set msg “[string trimright $msg r]r”
# New message
set nmh [msgcopy $mh]
# Put new message
msgset $nmh $msg
# Put in disposition list
lappend dispList “CONTINUE $nmh”
}
# Send it through the engine
return $dispList
}