Regexp question

  • Creator
  • #51517
    Mark Perschbacher

    I have been using regexp with great success in a data conversion project, but have a question.  When I execute this string,

    regexp — {(FINAL DIAGNOSIS:.*?)GROSS DESCRIPTION} $obxlist3 {} item

    I am getting the requested text, but it is concatenating the OBX fields.  Here is the HL7 data

    Superficial perivascular dermatitis with eosinophils present with||||||F

    OBX|27|TX|SS09-4265$rpt^^99DHT||pustule formation in the epidermis.  

    Here is the returned text

    Superficial perivascular dermatitis with eosinophils present withpustule formation in the epidermis.

    Is there an additional expression I can add to the regexp to insert a space, or grab the blank spaces between the segments?

Viewing 11 reply threads
  • Author
    • #70591
      Chris Williams

      You need to insert those spaces into obxlist3 as you are building it, before your regexp call.

    • #70592

      Post your code, please.

      -- Max Drown (Infor)

    • #70593
      Mark Perschbacher

      Here ya go.  What this proc does it take the text from final diagnosis and source and places them in OBX 2 and 4 respectively.  I run it thru and ORU to vrl xlate.

      proc datadsurg { args } {

        keylget args MODE mode               ;# Fetch mode


        set dispList {}

        set signed_flag “”


        switch -exact — $mode {

            start {

                # Perform special init functions

                # N.B.: there may or may not be a MSGID key in args



            run {

                # ‘run’ mode always has a MSGID; fetch and process it

                keylget args MSGID mh

                set msg [msgget $mh]

                set fieldSep [string index $msg 3]

                set segmentList [split $msg r]


                 set obx [lrange [lregexp $segmentList {^OBX}] 0 end]

        set obxlist2 “”

      set obxlist “”

      foreach segment $obx {

          set field [lindex [split $segment $fieldSep] 5]

      set field [string trim $field]

      append obxlist2 “$field”

      set obxlist3 “”

      set signed [string first “FINAL DIAGNOSIS” $obxlist2]

      set obxlist3 [string range $obxlist2 $signed end]

      set list “”

      set source “”

      regexp — {(SPECIMEN:.*?)CLINICAL HISTORY} $obxlist2 {} source

      set found ” “

      set item “”

      set line “PROCEDURE/ADDENDA:”

      regexp — {(FINAL DIAGNOSIS:.*?)GROSS DESCRIPTION} $obxlist3 {} item

      echo $item

      if {[regexp — $line $obxlist3]} {

       regexp — {(PROCEDURE/ADDENDA:.*?)Electronically Signed Out} $obxlist3 {} list

      set obxlist [append item  “$found” “$list”]

      } else {

      regexp — {(FINAL DIAGNOSIS:.*?)GROSS DESCRIPTION} $obxlist3  {} obxlist


      set final [join $obxlist { }]

      set obx1 [lindex $obx 1]

      set obxa [lindex $obx 3]

      set obxb [split $obxa $fieldSep]

      set obx2 [split $obx1 $fieldSep]

      set obx3 [lindex $obx2 6]

      set obxe [lreplace $obxb 6 6 $source]

      set obx1 “”

      set obx6 [lreplace $obx2 6 6 $final]

      set obxa “”

      set segment [join $obx6 $fieldSep]

      set segment1 [join $obxe $fieldSep]

      set nmh [lindex $segmentList 5]

      set segmentList [lreplace $segmentList 6 6 $segment]

      set segmentList [lreplace $segmentList 8 8 $segment1]


      msgset $mh [join $segmentList r]



                set dispList “”                

                lappend dispList “CONTINUE $mh”


                return $dispList



            } ;# end run mode


            time {

                # Timer-based processing

                # N.B.: there may or may not be a MSGID key in args





        #return $dispList


    • #70594
      Chris Williams



      append obxlist2 “$field”



      append obxlist2 “$field “

    • #70595
      Mark Perschbacher

      That did the trick.  My hats off to all you tcl jockeys out there, many thanks.

    • #70596
      Anand Raghavan

      I would also try

      append obxlist2 “$fields+” in place of

      append obxlist2 “$field “

      as it makes for more readable code.  To someone else (apart from the coder) reading it, it is easy to miss the whitespace.

      Just a suggestion

    • #70597
      Chris Williams

      Sorry, but that doesn’t work. It would append the literal characters “s” and “+” to the contents of the variable. This is not a regular expression.

    • #70598
      Keith McLeod

      If this is creating a list,

      How about using:

      lappend obxlist2 $field

    • #70599
      Chris Williams

      It’s not creating a list, it’s using append to concatenate a series of strings that need a space added between them.

    • #70600
      Keith McLeod


      lappend obxlist2 $field

      set obxlist2 [join $obxlist2 ” “]

      Is $field a list?  This eliminates the space at the end unless that is what is required.

    • #70601
      Keith McLeod

      This might be of some use:

      concat(n)                    Tcl Built-In Commands                   concat(n)



            concat – Join lists together


            concat ?arg arg …?



            This  command  joins  each  of its arguments together with spaces after

            trimming leading and trailing white-space from each of  them.   If  all

            the arguments are lists, this has the same effect as concatenating them

            into a single list.  It permits any number of arguments; if no args are

            supplied, the result is an empty string.


            Although concat will concatenate lists (so the command:

                   concat a b {c d e} {f {g h}}

            will  return  “a b c d e f {g h}” as its result), it will also concate-

            nate things that are not lists, and hence the command:

                   concat ” a b {c   ” d ”  e} f”

            will return “a b {c d e} f” as its result.

            Note that the concatenation does not remove spaces from the  middle  of

            its arguments, so the command:

                   concat “a   b   c” { d e f }

            will  return  “a    b   c d e f” (i.e. with three spaces between the a,

            the b and the c).

      SEE ALSO

            append(n), eval(n)


            concatenate, join, lists

      Tcl                                   8.3                            concat(n)

    • #70602
      Chris Williams

      Mark is trying to create a single string that contains the contents of ALL of his OBX-5 fields. To do it correctly, there needs to be a space between each of the individual field contents. Otherwise, you wind up with the last word of the first field butted up against the first word of the next field. The extra space fixes that problem.

      This is not a list. Think of it as turning sentences into a paragraph. Once he creates this “master” string, he can then use regexp to parse it.

      This is a common technique when the sending system gives you multiple OBX segments, and the receiving system wants all of it in a single OBX.


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

Forum Statistics

Registered Users
Topic Tags