TCL Script to remove empty IN1 or IN2

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf TCL Script to remove empty IN1 or IN2

  • Creator
    Topic
  • #54184
    Femina Jaffer
    Participant

      Hello,

      Can anyone help me to write a tcl script to eliminate empty IN1 (eg. IN1|1|)segments?

      Incoming File (Flat File) has multiple MSH messages (more then 1), eg.

      MSH

      EVN

      PID

      PV1

      IN1|1|  —-REMOVE THIS SEGMENT

      MSH

      EVN

      PID

      PV1

      IN1|1|wsewew|wewew|

      IN2|2|erererer|232dsd|

      This is what I had so far; but not sure what I am doing wrong…I have written so many similar code; but, I just cannot get this to work!!

      # Get the hl7 segments

         set fldsep [csubstr $msg 3 1] ;# Field sep, usually “|”

         set subsep [csubstr $msg 4 1] ;# SubField sep (^)

         set insegs [split $msg r]    ;# Inbound segments

         set outmsg “”  ;# Holds new message

      # Loop through looking for OBX segments.

      # To remove obx5 if it is blank and don’t store in new message

       foreach seg $insegs {

           if {[regexp — {^IN1} $seg]} {

      echo padh

             regsub -all — {IN1|d*?||r+} $seg {} seg

             append outmsg $seg r

             } else {

                    append outmsg $seg r

                    }

        }

      #

      # Now continue message

      #

        msgset $mh $outmsg ;# Store buffer in original message

        return “{CONTINUE $mh}”

      }

      Thank you,

      Femina

    Viewing 2 reply threads
    • Author
      Replies
      • #80479
        Elisha Gould
        Participant

          Your regex has an extra ‘|’ and ‘r’ that you are looking for. Its also better to look from the start in case there is a match someware else on the line. ie:

          Code:

          regsub -all — {^IN1|d*?|$} $seg {} seg

          Another way of doing this would be:

          Code:


          set outmsg {}
          foreach seg $insegs {
             set fields [split $seg $fldsep]
             if {!([lindex $fields 0] eq “IN1” && [llength $fields] <= 3)} {
                 lappend outmsg $seg
             }
          }
          set outmsg [join $outmsg "r"]

        • #80480
          Earl Coppedge Jr
          Participant

            I use this to remove ZRV segments.

            set msg [msgget $mh]

            set segmentList [split $msg r]

            set position [lsearch -regexp $segmentList ^ZRV]

            lvarpop segmentList $position                           ;# delete segment

            set newMsg [join $segmentList r]

            msgset $mh $newMsg

          • #80481
            Femina Jaffer
            Participant

              Thank you all for your suggestions and tips, they helped and I was able to get this going.

              Thanks again!

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