Can anyone help me to write a tcl script to eliminate empty IN1 (eg. IN1|1|)segments?
Incoming File (Flat File) has multiple MSH messages (more then 1), eg.
MSH
EVN
PID
PV1
IN1|1| —-REMOVE THIS SEGMENT
MSH
EVN
PID
PV1
IN1|1|wsewew|wewew|
IN2|2|erererer|232dsd|
This is what I had so far; but not sure what I am doing wrong…I have written so many similar code; but, I just cannot get this to work!!
# Get the hl7 segments
set fldsep [csubstr $msg 3 1] ;# Field sep, usually “|”
set subsep [csubstr $msg 4 1] ;# SubField sep (^)
set insegs [split $msg r] ;# Inbound segments
set outmsg “” ;# Holds new message
# Loop through looking for OBX segments.
# To remove obx5 if it is blank and don’t store in new message
foreach seg $insegs {
if {[regexp — {^IN1} $seg]} {
echo padh
regsub -all — {IN1|d*?||r+} $seg {} seg
append outmsg $seg r
} else {
append outmsg $seg r
}
}
#
# Now continue message
#
msgset $mh $outmsg ;# Store buffer in original message
return “{CONTINUE $mh}”
}
Thank you,
Femina