Request for TCL guidance on how to remove targeted OBX's on an ORU message

Clovertech Forums Cloverleaf Request for TCL guidance on how to remove targeted OBX's on an ORU message

  • Creator
    Topic
  • #117491
    Lawrence Nelson
    Participant

      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]

       

      Attachments:
      You must be logged in to view attached files.

      Lawrence Nelson
      System Architect - MaineHealth IT

    Viewing 6 reply threads
    • Author
      Replies
      • #117495
        Paul Bishop
        Participant

          I’ve done similar actions of removing OBX segments from messages based on the values.  One thing I found is to go through the OBX list backwards so the index isn’t messed up as you remove segments:

          foreach loc [lsort -integer -decreasing $OBXloc] {

          I also use the lvarpop command to remove the identified segments rather than creating an empty segment.

          lvarpop segList $loc

          So your overall logic would be:

          <pre>foreach loc [lsort -integer -decreasing $OBXloc] {
          set OBX [split [lindex $segList $loc] $fldSep]
          set obx_3 [lindex [split [lindex $OBX 3] $subSep] 0]
          if {logic for checking obx_3 value finds match} {
          lvarpop segList $loc
          }
          }
          msgset $mh [join $segList \r]
          lappend dispList “CONTINUE $mh”</pre>

          Paul Bishop
          Carle Foundation Hospital
          Urbana, IL

          • #117497
            Lawrence Nelson
            Participant

              The tip on LREVERSE worked! PROBLEM SOLVED!

              Thank you Paul!

              Lawrence Nelson
              System Architect - MaineHealth IT

          • #117496
            Jim Kosloskey
            Participant

              I am just curious why you are not doing this in an Xlate?

              email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

              • #117503
                Lawrence Nelson
                Participant

                  Hello Jim –

                  Passed by Whitmore Bolles School recently?

                  To answer your question – we would have had to touch multiple (MANY) Xlates. Which in our organization would have meant all kinds of regression testing – with each external organization > after touching each one of them. A bureaucratic nightmare… this particular issue revolves around getting COVID content on results to the CDC and NOT to other entities that do not need that content. So – in our structure placing it the TPS Outbound Data is the best solution. The version of the script I implemented also narrowed things down with a qualifier on the test code in OBR:4 as well – so I’m not tearing every message with an OBX apart and putting it back together.

                  Best –

                  Lawrence Nelson

                  Lawrence Nelson
                  System Architect - MaineHealth IT

              • #117504
                Jim Kosloskey
                Participant

                  I have not been back to that area of Dearborn for nearly 7 years. We are now about 200 miles away. I am not even sure if that school still exists.

                  I am glad you have a proper solution.

                  email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

                • #117505
                  David Barr
                  Participant

                    On this line:

                    set segmentList [ lreplace $segmentList $idx $idx ] ;# join the segment back together

                    I think that comment is wrong. You’re removing an item from the list, not joining the segment. And I think you need to increment an offset (something like “incr deleteCount”) so that when you do your segment lookup it won’t be off by one the next time through the loop (change “set obxSeg [lindex $segmentList $idx]” to “set obxSeg [lindex $segmentList [expr $idx-$deleteCount]]”).

                    I think would usually do something like building a new list based on the old list rather than removing elements from the old list while I’m looping over it. And I’d probably loop over every single segment and check if it’s an OBX segment as I look at it rather than using a search at the beginning to find the numbers of the OBXs which will change as the list is modified.

                  • #117508
                    Charlie Bursell
                    Participant

                      I disagree David.  The way Paul does it will not skew the location so no need to increment/decrement location.  I have done this many tiles and always as Paul presented.

                      • #117518
                        David Barr
                        Participant

                          Both ways work. The disadvantage to going backwards is that when I’m removing segments, I usually want to renumber the set IDs of the segments that I’m keeping. If you go forwards, then you know what the new set ID will be as you look at each segment. If you go backwards, it requires a second pass to update the set IDs.

                      • #117517
                        Paul Bishop
                        Participant

                          Where do you think I learned that trick!

                          Paul Bishop
                          Carle Foundation Hospital
                          Urbana, IL

                        • #117531
                          Paul Bishop
                          Participant

                            David – valid point.  I didn’t worry about that since I knew the message was going through a translate for other things and I handled the OBX-1 values there.

                            Paul Bishop
                            Carle Foundation Hospital
                            Urbana, IL

                        Viewing 6 reply threads
                        • You must be logged in to reply to this topic.