Tcl Help – Removing OBX segment if OBX|5 value is blank

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Tcl Help – Removing OBX segment if OBX|5 value is blank

  • Creator
    Topic
  • #48185
    Arslan Khan
    Participant

      Hi All,

      I am in need of a tcl code to remove OBX segments from the result message when OBX|5 for that iteration is blank (or contain blank spaces).

      Using regexp, I am able to find OBX segments with blank spaces in OBX|5 but I don’t know how to remove those segments from the message itself.

      set OBX_Seg [getHL7Segment $msg OBX]

      set Result_Value [getHL7Field $OBX_Seg 5]

      #  Remove OBX segment if OBX|5 value is blank

      if {([regexp “^ *$” $Result_Value])} {

          — Need help for removing OBX segment from the message

         }

      Any help in this matter is highly appreciable.

      Thanks.

      Arslan

    Viewing 6 reply threads
    • Author
      Replies
      • #57935
        Michael Lacriola
        Participant

          You need to build a new message data from the segments that you wish to keep. What I have done in the past is to get msgdta from $mh, foreach segment that does not match your criteria, start adding the segment into a new list. The join the list and set msgdta from the $mh to the new value.

          This works and only takes a few lines of code.

        • #57936
          Rentian Huang
          Participant

            Arslan,

            Are you doing a BULKCOPY/PATHCOPY before this tcl?

            I think what you should do in your situation is:

            Code:

            ITERATE on OBX

              CALL:
              set OBX_Seg [getHL7Segment $msg OBX]
              set Result_Value [getHL7Field $OBX_Seg 5]
              if {([regexp “^ *$” $Result_Value])} {
                 set @flag “false”
              } else {
                 set @flag “true”
              }

              IF: @flag eq “true”
                       PATHCOPY on OBX

            Hope this helps,

            Sam  8)

          • #57937
            Arslan Khan
            Participant

              Sam,

              I just want to use a tcl to do this. I am almost close but some how missing something. Here is the code so far:

              *****************************************************

              set Fld_Sep [cindex $msg 3]; #  Field Separator “|”

              set Com_Sep [cindex $msg 4]; #  Component Separator “^”

              set Rep_Sep [cindex $msg 5]; #  Repetition Separator “~”

              set Esc_Chr [cindex $msg 6]; #  Escape Character “”

              set Sub_Sep [cindex $msg 7]; #  Subcomponent Separator “&”

              set Seg_List [split $msg r]

              set New_Seg_List “”

              foreach Segment $Seg_List {

                 set Seg_ID [crange $Segment 0 2]

                 if { ($Seg_ID == “OBX”) } {

              set Field_List [split $Segment $Fld_Sep]

              set Result_Value [lindex $Field_List 5]

                             if { ([regexp “^ *$” $Result_Value]) } {

                                     set Segment “”

                             }

                                 set New_Seg_List [lappend New_Seg_List $Segment]

                             }

              set msg [join $New_Seg_List r]

                             #  Replace message with new one created.

                             msgset $mh $msg

                         }

              ************************************************

              The above code, somehow, is spitting only the segments I want to remove!

              Any ideas?

              Arslan

            • #57938
              Jim Kosloskey
              Participant

                If you are doing an Xlate no Tcl is needed.

                If not using BULKCOPY:

                Check the OBX-5 field not equal to @null –

                  True – COPY your OBX stuff

                  False – don’t do anything

                If using BULKCOPY:

                  True – COPY @null to all OBX fields

                  False – don’t do anything.

                Jim Kosloskey

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

              • #57939
                Jonathan Hamilton
                Participant

                  Don’t set the variable when you do lappend.

                  How are you handling re-numbering the set-id in the OBX segments?  You will need to add code to renumber in situations where you remove an OBX.  I typically use a Tcl variable and incr it for each OBX.  If I receive a segment other than OBX after an OBX I reset the variable back to 1.

                  I tried to mock up the code to do what you need.  It should get you headed the right direction at least.

                  *****************************************************

                  set Fld_Sep [cindex $msg 3]; #  Field Separator “|”

                  set Com_Sep [cindex $msg 4]; #  Component Separator “^”

                  set Rep_Sep [cindex $msg 5]; #  Repetition Separator “~”

                  set Esc_Chr [cindex $msg 6]; #  Escape Character “”

                  set Sub_Sep [cindex $msg 7]; #  Subcomponent Separator “&”

                  set Seg_List [split $msg r]

                  set New_Seg_List “”

                  set obx_cnt 1

                  foreach Segment $Seg_List {

                     set Seg_ID [crange $Segment 0 2]

                     if { ($Seg_ID == “OBX”) } {

                         set Field_List [split $Segment $Fld_Sep]

                         set Result_Value [lindex $Field_List 5]

                         if { ! ([regexp “^ *$” $Result_Value]) } {

                             # Reverse the if logic to only do something if it isn’t true.

                             set splitSegment [lreplace $Field_List 1 1 $obx_cnt]

                             lappend New_Seg_List [join $splitSegment  $Fld_Sep]

                         }

                         incr obx_cnt

                     } else {

                         set obx_cnt 1

                     }

                  }

                  set msg [join $New_Seg_List r]

                  #  Replace message with new one created.

                  msgset $mh $msg

                  ************************************************

                  Jonathan

                • #57940
                  Rentian Huang
                  Participant

                    THIS IS AN EXCELLENT APPROACH!

                    😀

                  • #57941
                    Arslan Khan
                    Participant

                      Thanks for all your help guys!

                      Here is the final solution which worked for me!

                      =========================================

                      set msg [msgget $mh]

                      set Fld_Sep [cindex $msg 3]; #  Field Separator “|”

                      set Com_Sep [cindex $msg 4]; #  Component Separator “^”

                      set Rep_Sep [cindex $msg 5]; #  Repetition Separator “~”

                      set Esc_Chr [cindex $msg 6]; #  Escape Character “”

                      set Sub_Sep [cindex $msg 7]; #  Subcomponent Separator “&”

                      set Seg_List [split $msg r]

                      set New_Seg_List “”

                      set obx_cnt 1

                         foreach Segment $Seg_List {

                      set Seg_ID [crange $Segment 0 2]

                      if { ($Seg_ID == “OBX”) } {

                        set Field_List [split $Segment $Fld_Sep]

                        set Result_Value [lindex $Field_List 5]

                        if { ([regexp “^ *$” $Result_Value]) } {

                                              set Segment “”

                              incr obx_cnt -1

                                        }

                        set Segment [replaceHL7Field $Segment OBX 1 $obx_cnt]

                        incr obx_cnt

                                     }

                      set New_Seg_List [lappend New_Seg_List $Segment]

                      set msg [join $New_Seg_List r]

                                     #  Replace message with new one created.

                                     msgset $mh $msg

                         }

                      ========================================

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