Good afternoon. I have a vendor who can only accept an ORU if it has one OBR with corresponding OBXs. Our Nursing Assessment ORUs have multiple OBRs with corresponding OBXs, not always the same amount of OBXs to OBRs.
Right now I’m able to pull the “base HL7” out and I can pull each individual OBR but I’m having trouble getting the corresponding OBXs and then putting everything together into their own messages. Right now my tcl is a mess so any help would be appreciated.
run {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
set msg [msgget $mh]
set segList [split $msg “\r”]
set dispList
set obrLoc [lsearch -regexp $segList {^OBR}]
incr obrLoc -1
set baseHL7 [lrange $segList 0 $obrLoc]
#echo “$baseHL7”
foreach loc [lsearch -all -regexp $segList {^OBR}] {
set OBR [lindex $segList $loc]
echo “$loc”
set newMsg [lappend baseHL7 $OBR]
echo “$OBR”
}
foreach loc [lsearch -all -regexp $segList {^OBX}] {
set OBX [lindex $segList $loc]
echo “$loc”
echo “$OBX”
}
set OBXloc $loc
incr OBXloc
# echo “$OBXloc”
set OBX [lindex $segList $OBXloc]
#echo “$OBX”
while {[regexp {^OBX} $OBX]} {
set newMsg [lappend newMsg $OBX]
incr OBXloc
set OBX [lindex $segList $OBXloc]
#echo “$OBX”
#echo “$newMsg”
}
#msgset $mh [join $newMsg “\r”]
#lappend dispList “CONTINUE $mh”
}