Trying to replace a sub field w/tcl

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Trying to replace a sub field w/tcl

  • Creator
    Topic
  • #48460
    Mark Brown
    Participant

      There’s a subfield that one of the ancillary systems wants the first three characters stripped.  Not being a tcl programmer, I cobbled together some code from a couple of procs to try to do this.  At first, it looks like it works okay.  But when I use more than one record in the testing tool, the field that I’m replacing the subfield in, is for some reason enclosed in braces ({}).  I’m not putting braces anywhere that I can see.  

      When I place an ‘echo’ to look at the field that contains the subfield, it looks okay.  But if I ‘echo’ the whole segment, that field is surrounded by braces.

      Here’s a snippet of the code:

      set msg [msgget $mh]

      set segmentList [split $msg r]

      set fieldSep [csubstr $msg 3 1]

      set subFieldSep [csubstr $msg 4 1]

      foreach segment $segmentList {

        if [regexp {RXE} [crange $segment 0 2]] {

            set fieldList [split $segment $fieldSep]

            set fieldTwo [lindex $fieldList 2]

            set fieldTwoList [split $fieldTwo $subFieldSep]

            set cdm [lindex $fieldTwoList 0]

            set description [lindex $fieldTwoList 1]

            set code [lindex $fieldTwoList 2]

            set drugData [string range $cdm 3 end]

            set fieldTwo [lreplace $fieldTwo 0 2 $drugData^$description^$code]

            set fieldList [lreplace $fieldList 2 2 $fieldTwo]

       

            set segment [join $fieldList $fieldSep]

       }

      append outBuff ${segment}r

      }

      Here’s an example output for the segment I’m changing. The shortened field is subfield 1 of RXE-2 (the 5905…etc).

      RXE|1^QD&2100&&1J1234567&&&99NSF^INDEF^200604072100^^R^^ONCE A DAY^^|{5905^STERILE WATER INJ.^L}|367||ML|SOLP||||4|SOLP|3.67||DIVANHOE|8620.1||||367||””||42|ML/HR||||||||||||||||||S||||||

      Any idea why the braces are showing up?

      Thanks,

    Viewing 1 reply thread
    • Author
      Replies
      • #58694
        Mike Grieger
        Participant

          I think the issue is in one of your statements:

                  set fieldTwo [lreplace $fieldTwo 0 2 $drugData^$description^$code]

          Using the lreplace in the case doesn’t make sense, as fieldTwo contains only one element as it was set –       ‘set fieldTwo [lindex $fieldList 2]’

          If you would change the ‘re-set’ of fieldTwo to:

               ‘set fieldTwo $drugData^$description^$code’

          it may work more as you are intending.

          Or, if you want to use lreplace commands, since it looks like you are only interested in the first subfield of field 2, only work on that one.  That is, don’t even worry about setting and replacing the other subfields, since they are not affected.  You split field 2 into subfields, take the first subfield, work on it, and only replace that subfield.  Then join it all back together.

        • #58695
          Mark Brown
          Participant

            Thanks!  Just doing the set instead of doing the lreplace did what I wanted.

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