How to remove semi colons from OBX messages

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf How to remove semi colons from OBX messages

  • Creator
    Topic
  • #53113
    Yamil Velez
    Participant

      Hi All

         Is there a way to create a pre proc TCL that would remove semi colons from any OBX starting from field 5 onward.   Below is the code I have,  I am able to put all the OBX segments into a list but I am not able to remove semi colon starting from field 5 onward with out effect the fields before.

      Note that this character is the subfield delimiter for the sending system HL7 messages.

      #Note: $segid = OBX

                                    set i 0

                                    set segmentList [split $msgdata r]

                                    foreach segment $segmentList {

                                          if [cequal [csubstr $segment 0 3] $segid] {

                                           lappend segment3 $segment

                     

                       }

                           

                               

                                  incr i

              }

      set b [regsub -all {x3b} $segment3 {}]

      Thanks in advance for any help provided.

      Yamil

    Viewing 8 reply threads
    • Author
      Replies
      • #76603
        David Barr
        Participant

          There are many ways to do this.  Probably the easiest thing for you to do is to add another loop in your segment loop to go through each field in the segment. Replace the semicolons in each field, join them back together into a new segment and append the new segment to a new message.

        • #76604
          Yamil Velez
          Participant

            Hi David

              The problem is that I need to start the semi colon replace from field 5 onward.  I need to keep the semi colons before that field.   How can I guid my regsub to start in field 5

            Thanks

            Yamil

          • #76605
            Daniel Lee
            Participant

              I think what David is saying is just loop through your fields like you’re looping through your segments.

              Code:

              set fieldCount 0
              foreach field $segment3 {
                if {$fieldCount >= 5} {
                   set field [regsub -all {x3b} $field {}]
                }
                lappend newSegment3 $field
                incr fieldCount
              }

              There may be bugs in the above code but it should be enough to get you started if that’s the way you want to do it.

            • #76606

              I would use string map instad of regsub.

              Code:

              set var “ansdandnfd;sadflkasdflkasd”
              puts $var
              set var [string map {; {}} $var]
              puts $var

              -- Max Drown (Infor)

            • #76607
              Daniel Lee
              Participant

                Quote:

                I would use string map instad of regsub.

                Is it faster?  If so do you know why?

              • #76608
                James Cobane
                Participant

                  I believe it is more efficient/faster since the ‘string’ command is an internal Tcl command vs. ‘regsub’ which is an extended/external command.

                  Jim Cobane

                  Henry Ford Health

                • #76609
                  Jim Kosloskey
                  Participant

                    Just my .02 – it is also easier for most folks to understand.

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

                  • #76610
                    Tom Rioux
                    Participant

                      Ah Max!  Charlie has taught you well!

                    • #76611
                      Simone Heckmann
                      Participant

                        Just because I’m in love with regular expressions

                        and solving problems with no more than one line of code is my hobby,

                        let me give this a try:

                        Code:

                        while {[regsub -all -linestop {(OBX(?:|.*?){4}|.*);(.*)} $msg {12} msg]} {}

                        This is the result I get when running it with a bogus test string:

                        Code:

                        hcitcl>set msg “OBX|asdf;asdf|xcvbx;yxcv|sdfg|sdfg;sdfg|rtzu;ertz;|
                        OBX|asdf;asdf|xcvbx;yxcv|sdfg|sdfg;sdfg|rtzu;ertz;|sdfg ; sdfg |;|sdjfgsj|sdjfhg
                        OBX|asdf;asdf|xcvbx;yxcv|sdfg|sdfg;sdfg|rtzu;ertz;|;
                        OBX|asdf;asdf||sdfg|sdfg;sdfg|rtzu;ertz;|”;
                        hcitcl>
                        hcitcl>
                        hcitcl>while {[regsub -all -linestop {(OBX(?:|.*?){4}|.*);(.*)} $msg {12} ms
                        g]} {}
                        hcitcl>echo $msg
                        OBX|asdf;asdf|xcvbx;yxcv|sdfg|sdfg;sdfg|rtzuertz|
                        OBX|asdf;asdf|xcvbx;yxcv|sdfg|sdfg;sdfg|rtzuertz|sdfg  sdfg ||sdjfgsj|sdjfhg
                        OBX|asdf;asdf|xcvbx;yxcv|sdfg|sdfg;sdfg|rtzuertz|
                        OBX|asdf;asdf||sdfg|sdfg;sdfg|rtzuertz|
                        hcitcl>

                        Don’t forget to be awesome!

                        Simone

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