Request – TCL script to remove NTE following OBX's targeted for removal

Homepage Clovertech Forums Cloverleaf Request – TCL script to remove NTE following OBX's targeted for removal

  • Creator
    Topic
  • #117847
    Lawrence Nelson
    Participant

    I’m wondering if anyone has a script, that they could please make available to me, to do the following action, or provide the instructions to meet the need.

    I have a working script where I locate and removing qualifying OBX’s from a result message.  I’ve been given a twist where they (now) also want ALL the NTE’s removed related to those same OBX’s being removed. I haven’t been able to target just those NTE – but instead, find that I’m just wiping out all the NTE in the entire message (not good) while I’m within the Foreach where I’m tapping out the OBX. I keep getting stuck in thinking Xlate and iteration mode with TCL and not coming up with a solution.

    The messages I work with may look like this for example –

    ORC |1

    OBR|1

    OBX|1

    OBX|2

         OBX  |3  <<< targeted for removal 

              NTE |1  <this should go

              NTE |2  <this should go

             NTE|3  <this should go

    OBX |4

    NTE|1

        OBX |5      <targeted for removal

             NTE |1  <this should go

             NTE |2 <this should go

            NTE| 3 <this should go

    OBX |6

    NTE |1

    NTE |2

    NTE| 3

     

    The message should end up like this :

    ORC |1

    OBR|1

    OBX|1

    OBX|2

         OBX |4

    NTE|1

          OBX |6   

    NTE |1

    NTE |2

    NTE| 3

     

    Thanks for any assistance you all may be a able to provide me.

     

    Lawrence Nelson

     

    Lawrence Nelson
    System Architect - MaineHealth IT

Viewing 5 reply threads
  • Author
    Replies
    • #117852
      Keith McLeod
      Participant

      An XLate makes this simple.  Do you have the tcl code you are working with?  I would speculate that when you remove the OBX segment that was targeted, you would remove NTE segments until you found a segment that is not an NTE.  Would you consider doing with an Xlate?

    • #117856
      Gene Millard
      Participant

      tcl code

      switch -exact — $mode {
      run {
      keylget args MSGID mh
      set msg [msgget $mh]
      set segmentList [split $msg \r]
      set killNte 0 ; # set killNte to 0 to not kill NTE segments
      foreach segment $segmentList {
      set segmentId [crange $segment 0 2]
      if {![string equal $segmentId NTE]} {
      set killNte 0
      }
      switch -exact — $segmentId {
      OBX {
      set line [split $segment |] ; # get segment
      set obx2 [lindex [split [lindex $line 2] ^] 0]
      if {[string equal $obx2 CWE] | [string equal $obx2 SN]} {
      set killNte 1
      continue
      }
      }
      NTE {
      if {$killNte} {
      continue
      }
      }
      }
      lappend line3 $segment
      }
      msgset $mh [join $line3 \r]
      lappend dispList “CONTINUE $mh”
      }
      }

      The Guthrie Clinic
      Sayre, PA

    • #117861
      Lawrence Nelson
      Participant

      Hi all –

      We have reasons why we didn’t go with an xlate – because there are SEVERAL xlates involved and the testing and regression testing we use – is extensive and time consuming so for this solution we are not using xlates.

      I’ve attached the script I’m using to remove the OBX’s

      I’m looking to figure out how to remove the NTE POST the OBX’s that are targeted for removal – but again – not effect NTE post OBX’s that will not be removed.

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

      Lawrence Nelson
      System Architect - MaineHealth IT

    • #117865
      Gene Millard
      Participant

      Attached is my code to do what you requested.

      It is very short.  I used what is in OBX-2 as the condition to kill the segments.

      It is the code that is listed above but it is the entire tcl.

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

      The Guthrie Clinic
      Sayre, PA

    • #117873
      Charlie Bursell
      Participant

      Gene:
      If I could make one small suggestion.

      Since ALL segments should be terminated with CR including the last segment, I would lappend the empty string to your list just prior to the join.

    • #117880
      Charlie Bursell
      Participant

      Sorry, my bad on the above,  assuming the IB message ends all segments, including the last, with CR, a CR will be appended to the last.

      The proc splits into a segment list in which the last item in the list will be the empty string so it will get appended.  I should have looked a bit more closely.

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

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,447
Topic Tags
288
Empty Topic Tags
10