TCL help to remove unwanted OBX and associated NTE segments

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf TCL help to remove unwanted OBX and associated NTE segments

  • Creator
    Topic
  • #51100
    James Mellor
    Participant

    I have a proc on a raw route. I need help in removing the NTEs associated with the unwanted OBXs I am already removing based on whats in OBX:5.

    This is my code that removes the unwanted OBXs.

    Thanks in advance for suggestions, etc.


    proc strip_OBX_seg { args } {

       global HciConnName

       set mode [keylget args MODE]

       set context [keylget args CONTEXT]

       if { ! [info exists HciConnName] } {

    set HciConnName “UNKNOWN_TD”

       }

       switch -exact — $mode {

    start {

       return “” ;# Nothing specific

    }

    run {

       set mh [keylget args MSGID] ;# Message handle

       set msg [msgget $mh] ;# The message

    #

    # 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 “DNR” and don’t store in new message

       foreach seg $insegs {

                              if {[regexp — {^OBX} $seg]} {

          set fld5 [lindex [split $seg $fldsep] 5]

          # If field 5 is “DNR” or “TNP”, toss it, else save it in the buffer

          if {[cequal [string trim $fld5 0] “DNR”] || [cequal [string trim $fld5 0] “TNP”]} {continue}

                                append outmsg $seg r

            } else {

                                append outmsg $seg r

                               }

                            }

    #

    # Now continue message

    #

       msgset $mh $outmsg ;# Store buffer in original message

       return “{CONTINUE $mh}”

    }

    shutdown {

       # Doing some clean-up work

    }

    default {

       return “” ;# don’t know what to do

    }

      }

    }


Viewing 4 reply threads
  • Author
    Replies
    • #68794
      Gary Atkinson
      Participant

      Be careful of adding in an extra r in your append statement.

    • #68795
      Charlie Bursell
      Participant

      This gets a little tricky in that the location of subsequent OBX segments would change as you removed segments.

      Assuming that associated NTE segments follow the OBX upto the next OBX and assuming you have Cloverleaf 5.4.1 or greater, I would do something like below:

      # Get location of all OBX and associated NTE segments and mark for removal

      foreach loc [lsearch -all -regexp $segments {^OBX} {

         set obx [split [lindex $segments $loc] $fldSep]

         set fld5 [lindex $obx 5]

         if {$fld5 eq “DNR” || $fld5 eq “TNP”} {

             set segments [lreplace $segments $loc $loc REPLACE]

             set nteLoc [expr $loc + 1]

             while {[string equal -len 3 [lindex $segments $nteLoc] NTE]} {

                 set segments [lreplace $segments $nteLoc $nteLoc REPLACE]

                 incr nteLoc

             }

         }

      }

      # Remove any marked segments

      set loc [lsearch -exact $segments REPLACE]

      while {$loc >= 0} {

         lvarpop segments $loc

         set loc [lsearch -exact $segments REPLACE]

      }

      msgset $mh [join $segments r}

      I haven’t tested this so I may have fat-fingered something  ðŸ˜€

    • #68796
      David Barr
      Participant

      Gary Atkinson wrote:

      Be careful of adding in an extra r in your append statement.

      Why?  Every segment should be followed by a r, including the last one.

    • #68797
      David Barr
      Participant

      David Barr wrote:

      Gary Atkinson wrote:

      Be careful of adding in an extra r in your append statement.

      Why?

    • #68798
      James Mellor
      Participant

      Thanks Charlie for your help. That worked perfectly for what I needed to accomplish.

Viewing 4 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,296
Replies
34,439
Topic Tags
287
Empty Topic Tags
10