replacehl7 proc

  • Creator
    Topic
  • #51390
    Mark Perschbacher
    Participant

    I just copied this from Clovertech, and plugged in some data.  When I run it through the Testing Tool, I am gettin a “invalid command name error.”  Anybody see what is wrong?

    #

    ######################################################################

    # replaceHL7Field – generic routine to replace the data in an HL7 field

    # Args: msg       the entire HL7 message

    #       segmentID the name of the segment containing the field to replace

    #       fieldID   the index of the field to replace

    #       data      the data that will replace the current contents of the field

    #

    # Returns: the an entire HL7 message

    #

    proc replacehl7 {msg segmentID fieldID data {fieldSeparator “|”}}  {

       set segmentList [split $msg r]

       set newSegmentList “”

       set data “5555”

       foreach segment $segmentList {

           if {[crange $segment 0 2] == OBX} {

               set fieldList [split $segment $fieldSeparator]

               set fieldList [lreplace $fieldList 5 5 $data]

               set segment [join $fieldList $fieldSeparator]

           }

           set newSegmentList [lappend newSegmentList $segment]

       }

       return [join $newSegmentList r]

Viewing 7 reply threads
  • Author
    Replies
    • #70071

      Did you run mktclindex?

      -- Max Drown (Infor)

    • #70072
      Mark Perschbacher
      Participant

      Yes, and I rebooted the server just in case.  For some reason that proc is not showing up in the Testing tool now.  There is aI may need to give Healthvision a call.

    • #70073
      Mark Perschbacher
      Participant

      Not sure what the issue was, but the proc is showing up.  Upon closer inspection, I am getting a “missing close-brace” error in the Testing window.

    • #70074

      You’re missing the close brace for the proc.

      Code:

      ######################################################################
      # replaceHL7Field – generic routine to replace the data in an HL7 field
      # Args: msg       the entire HL7 message
      #       segmentID the name of the segment containing the field to replace
      #       fieldID   the index of the field to replace
      #       data      the data that will replace the current contents of the field
      #
      # Returns: the an entire HL7 message
      #
      proc replacehl7 {msg segmentID fieldID data {fieldSeparator “|”}}  {

        set segmentList [split $msg r]
        set newSegmentList “”
        set data “5555”
        foreach segment $segmentList {
            if {[crange $segment 0 2] == OBX} {
                set fieldList [split $segment $fieldSeparator]
                set fieldList [lreplace $fieldList 5 5 $data]
                set segment [join $fieldList $fieldSeparator]
            }
            set newSegmentList [lappend newSegmentList $segment]
        }
        return [join $newSegmentList r]
      }

      -- Max Drown (Infor)

    • #70075
      Mark Perschbacher
      Participant

      That was it.  Thanks for being the other set of eyes.

    • #70076
      Robert Milfajt
      Participant

      One lreplace gotcha from someone who has been bitten.

      If you replace an element, in this case 6th (0,1,2,3,4,5), in a list that has less than 6 elements, you get a TCL error and the message fails.

      I always use llength in conjunction with lreplace, or do something to guarantee the list has at least x elements (append null fields), where x is the element I am replacing.

      Any advice on this from others would be refreshing.

      Robert Milfajt
      Northwestern Medicine
      Chicago, IL

    • #70077
      Jim Kosloskey
      Participant

      llength is good – I guess one could also use a catch.

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

    • #70078
      Charlie Bursell
      Participant

      Here is what I teach in Level 3 and Tcl classes.

      If there is any doubt the list is long enough do something like:

      Assume you will replace index 6 (7th item)

      while {[llength $list] <= 7} {lappend list ""}

      I have been in many discussions with the Tcl community about this.  I considere it a bug.  They do not.   😡

      Also applies to linsert

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

Forum Statistics

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