I have a situation where I need to solve a problem outside of an Xlate using a TCL script.
My TCL skills are a bit rusty.
I’ve been successful in setting up a list – and creating a foreach – that processes through the index that gets created to find the qualifying candidates for removal.
I’ve created some issues where I’m removing the OBX’s, but it’s throwing the index count off – so all of the candidates that should get removed – do not get removed. Oddly, it also looks like the items not removed (left behind) are every other OBX – 3 5 7 9
I’m looking to figure out if I can affect a change on the foreach to alter the count each time
it cycles through – so that it’s reset each time. Or if there is a better approach to removing the OBX’s that qualify and reassembling the message.
I’ve attached the script and test case file to test against – if anyone might be able to take a swing at it. In the test case file there are 10 OBX segments – only OBX|1| should avoid being eliminated. It won’t always be OBX|1| and there could be others that do not get eliminated. You should see that 1 3 5 7 9 still get
Thank you.
Here is a portion of the script
set indexOBX [lsearch -all $segmentList OBX*]
if { $debug == 1 } {echo indexOBX = $indexOBX}
# Candidate list for always being removed from ANY test with this result line
set obx3 { CV1ST COVSC CVHTL COVPS CVDAT CVHOS CVICU COVSQ CVHCW CVCON CVPRG CVDEV COVSS }
foreach idx $indexOBX {
set obxSeg [lindex $segmentList $idx]
if { $debug == 1 } { echo idx = $idx}
if { $debug == 1 } { echo obxSeg = $obxSeg }
set fieldList [split $obxSeg $fieldsep]
set field0 [lindex $fieldList 0] ;# we are isolating the OBX or the index count gets thrown off
if { $debug == 1 } {echo field0 before = $field0}
set field3 [lindex $fieldList 3]
if { $debug == 1 } { echo field3 before = $field3}
set subfieldList [split $field3 $subfieldsep]
if { $debug == 1 } { echo subfieldList before = $subfieldList}
set subfield1 [lindex $subfieldList 0 ]
set candidate [ lsearch -regexp -inline -all $obx3 $subfield1 ] ;#
if { $candidate ne “” && $field0 eq “OBX” } { ;# if the content in OBX3.0 is found in the candidate list remove this OBX
if { $debug == 1 } { echo candidate = $candidate found!}
set obxSeg
set segmentList [ lreplace $segmentList $idx $idx ] ;# join the segment back together
}
}
# set segmentList [ lreplace $segmentList $idx $idx ] ;# join the segment back together
set newMsg [join $segmentList \r]
Lawrence Nelson
System Architect - MaineHealth IT