Help relacing a value

Clovertech Forums Read Only Archives Cloverleaf Tcl Library Help relacing a value

  • Creator
    Topic
  • #51350
    Mike Campbell
    Participant

      We are creating a new XLT for ORU messages.  The vendor is sending the OBX-5 data with a .br in the message.  We need to change all of those to the ~ {tilde}.  The attachment has a sample mesasge as well as the instream tcl proc.  

      The error we are getting is included as well.  Any ideas as to what we need to go to correct the issue and get the tilde in the record?

      Thanks.

      Mike Campbell

      Nebraska Methodist Health System

      mike.campbell@nmhs.org

    Viewing 6 reply threads
    • Author
      Replies
      • #69828
        Chris Williams
        Participant

          Mike,

          You need to escape the backslashes in your regexp. You’re currently escaping the “.” and the “}”. Hence the missing brace error which manifests itself as EOF in list element. Sometimes it is easier to debug these things by placing the code in a file and sourcing it in hcitcl.

          Code:

          set result [regexp {.br} $xlateInVals match]


          should be

          Code:

          set result [regexp {\.br\} $xlateInVals match]


          Cheers.

        • #69829
          Mike Campbell
          Participant

            I have fixed the ‘escape’ character as request.  Now, the entire line is being eliminated, not just changing the .br to a tilde.  The log looks like:

            {History: Age: 28 years. LMP not sure. Conception: spontaneous..br____________________________________________________________________________.brDating:.brConception Date:       09/01/2009      EDC:    05/25/2010      GA by Conception:       13w0d.br____________________________________________________________________________.brFirst Trimester Scan:

            .brSingleton gestation..brFetal Anatomy:.brSkull / Brain: appears normal. Spine: appears normal. Heart: appears normal. Abdomen: appears normal. Stomach: not examined. Bladder: not examined. Hands: both visible. Feet: both visible. Cardiac abnormality. .br .brFetal heart activity: present. Fetal heart rate: 125 bpm. .brAmniotic fluid: normal. AFI

             60.0 cm. .brPlacenta: anterior-low lying. Placenta accreta. .br\.br____________________________________________________________________________.brReport Summary:.brImpression: Type something there. Yes. .br\.brRecommendations: Continue to monitor patient}

            W variable is: .br

            Y variable is: ~

            I added the echo of the W and Y variable just to see if those were set correctly.

            proc br_to_tilde     {} {

               upvar xlateId       xlateId  

                xlateInList   xlateInList    

                xlateInTypes  xlateInTypes  

                xlateInVals   xlateInVals    

                xlateOutList  xlateOutList  

                xlateOutTypes xlateOutTypes  

                xlateOutVals  xlateOutVals

             echo $xlateInVals

             set $xlateOutVals $xlateInVals

             set result [regexp {\.br\} $xlateInVals match]

             if {$result >=0} {

               set var $xlateInVals

               set x “\.br\”

               set w $x

               set y “~”

               set var [string map

              $var]    

                 set xlateOutVals $var

                 echo “W variable is:” $w

                 echo “Y variable is:” $y

               }

              }

          • #69830

            Try it like this:

            Code:

            set var [string map -nocase {\.br\ ~} $var]

            When you’re dealing with backslashes and escapes, I’ve found string map to be much easier to use than regsub. In string map, most characters do not hold any special meaning with the notable exception of the backslash itself.

            -- Max Drown (Infor)

          • #69831
            Mike Campbell
            Participant

              I know we’ve got something really dumb here.  Tried all sorts of different things, but the reformatted message isn’t ever getting sent.  The log shows the tilde in the $var, but its not in the message.

              {Report Summary:.brImpression: New report summary for ViewPoint testing..brThis is line two.}

              var before is {Report Summary:.brImpression: New report summary for ViewPoint testing..brThis is line two.}

              X variable is: .br

              Y variable is: ~

              var after is {Report Summary:~Impression: New report summary for ViewPoint testing.~This is line two.}

              {Report Summary:~Impression: New report summary for ViewPoint testing.~This is line two.}

            • #69832

              Try this. Remember that xlateInVals and xlateOutVals are lists.

              proc br_to_tilde [code]proc br_to_tilde

              -- Max Drown (Infor)

            • #69833

              I fixed some errors in my code above. May need to refresh the page.

              -- Max Drown (Infor)

            • #69834
              Mike Campbell
              Participant

                There were a couple of things we changed that finally got it to work.  First off it didn’t work to ‘run’ the tcl code from the xlt.  Then Charlie B. suggested a tweak or two that solved it.  

                “The first thing to *ALWAYS* remember is that xlateInVals and xlateOutVals are lists and should be treated as such.

                Also no need to set xlateOutVals to xlateInVals as, at inbound, they are equal anyway.  Remember the default action is to copy input to output.

                Writing your proc  more succinctly  I would do something like:

                set var [string map

                  [lindex $xlateInVals 0]]

                  set xlateOutVals

                  No need for an if statement.  If there are no .br we have done nothing.  Note however, we first remove the value in xlateInVals from a list context to string and assign xlateOutVals as a list of one element”

                  Again..thanks all for the suggestions and help!

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