re-order obx segs last to first using tcl

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library re-order obx segs last to first using tcl

  • Creator
    Topic
  • #53136
    Jennifer Johnson
    Participant

    Looking to reverse order of obx segments using tcl without the lreverse command. Field values do not need any manipulation. Just each segment moved. Thank you!

Viewing 2 reply threads
  • Author
    Replies
    • #76689

      You could try the tcl lsort command with the -decreasing command.

      http://www.tcl.tk/man/tcl8.0/TclCmd/lsort.htm

      -- Max Drown (Infor)

    • #76690

      Here’s a simple example.

      Code:

      lappend obx_segments 1||||5||| 2||||5||| 3||||5||| 4||||5||| 5||||5||| 6||||5||| 7||||5||| 8||||5||| 9||||5||| 10||||5|||

      puts $obx_segments

      set obx_segments [lsort -decreasing -dictionary $obx_segments]

      puts $obx_segments

      Output:

      Code:

      1||||5||| 2||||5||| 3||||5||| 4||||5||| 5||||5||| 6||||5||| 7||||5||| 8||||5||| 9||||5||| 10||||5|||
      10||||5||| 9||||5||| 8||||5||| 7||||5||| 6||||5||| 5||||5||| 4||||5||| 3||||5||| 2||||5||| 1||||5|||

      -- Max Drown (Infor)

    • #76691
      Charlie Bursell
      Participant

      Simple

      Assume $SEGMENTS is a list of all HL7 segments

      set revLoc [lsort -integer -decreasing

                         [lsearch -all -regexp $SEGMENTS {^OBX}]]

      set obxLst [lsearch -all -inline -regexp $SEGMENTS {^OBX}]

      foreach loc $revLoc OBX $obxLst {

                     set SEGMENTS [lreplace $SEGMENTS $loc $loc $OBX]

      }

Viewing 2 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,118
Forums
28
Topics
9,293
Replies
34,435
Topic Tags
286
Empty Topic Tags
10