Changing ^ to & in the OBR segment- but only OBR 32

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Changing ^ to & in the OBR segment- but only OBR 32

  • Creator
    Topic
  • #53616
    Frank Urbanija
    Participant

      I want to change the ^ to & in the OBR 32.1-5.  I am able to change all the ^ to & in the OBR segment but can’t just change for OBR 32.

      here is my current tcl

      set msgtext [msgget $mh]

                 set field_delimiter [cindex $msgtext 3]

                 foreach segment [split $msgtext “r”] {

                   if {[cequal [crange $segment 0 2] “OBR”]} {

                     regsub -all {^} $segment {&} segment

                   }

                   if {$segment != “”} {

                     lappend newmsg $segment }

                 }

                 msgset $mh [join $newmsg “r”]

                 return “{CONTINUE $mh}”

             }

    Viewing 4 reply threads
    • Author
      Replies
      • #78304
        Jerry Tilsley
        Participant

          Change your code:

          Code:


          if {[cequal [crange $segment 0 2] “OBR”]} {
                        regsub -all {^} $segment {&} segment
          }

          Code:


          if {[cequal [crange $segment 0 2] “OBR”]} {
                        set fields [split $segment $fsep]
                        set obr-32 [split [lindex $segment 32] $csep]
                        for {set i 0} {$i < 5} {incr i} {
                              set newfields {}
                              regsub -all {^} [lindex $obr-32 i] {&} newfield
                              lvarpop obr-32 $i $newfield
                        }
                         lvarpop $fields 32 [join $obr-32 $csep]
                         set segment [join $fields $fsep]
                      }

          I haven’t tested this code as is, but it should give you an idea of where to go.

        • #78305
          Robert Milfajt
          Participant

            Instead of looping throuch each segment in the message you can more quickly get the work done this way (something Charlie showed me)!

            Code:

            set msgtext [msgget $mh]
            set field_delimiter [cindex $msgtext 3]
            set segs [split $msgtext r]
            set OBRinds [lsearch -all -regexp $segs ^OBR]
            foreach OBRindx $OBRinds {
               set OBRflds [split [lindex $segs $OBRindx] $field_delimiter]
               set OBR_32 [lindex $OBRflds 32]
               if {$OBR_32 != “”} {
                   regsub -all {^} $OBR_32 {&} OBR_32
                   set OBRflds [lreplace $OBRflds 32 32 $OBR_32]
               }
               set segs [lreplace $segs $OBRindx $OBRindx $OBRflds]
            }
            msgset $mh [join $segs r]

            I haven’t run this code against real data, and apologize for any syntax errors you may find, but this whould get you where you need to go.  Of course, I’m open to a better way, if someone else has one.  That’s why this forum is so great!!!

            Robert Milfajt
            Northwestern Medicine
            Chicago, IL

          • #78306
            Jim Kosloskey
            Participant

              If you are in an Xlate this should be capable of being accomplished without any Tcl.

              COPY the inbound fields in OBR-32 to the outbound using sub-field notaiton – …OBR.#32.[0].[0] …OBR.#32.[0].[1] etc.

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

            • #78307
              Frank Urbanija
              Participant

                Ran Robert’s through testing tool and works but for some reason the join does not work and I am looking at that now.  When echo the message after the join does not display the joined message – it is blank.

                Thanks for your info and I reall appreciate the suggestions.

              • #78308
                Frank Urbanija
                Participant

                  Thanks just had to add the set newmsg [join $newmsg “r”] before doing the msgset $mh $newmsg.

                  You Clovertecher’s are great!!!

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