Strip a segment from a message based on a value in segment

Clovertech Forums Cloverleaf Strip a segment from a message based on a value in segment

  • Creator
    Topic
  • #118488
    Mike Pyne
    Participant

      Hello,

      I am looking to strip an entire segment out based on the value in OBX.3. Basically, if OBX.3 is equal to “Text Report File Name”, I want to strip that entire OBX segment out. I was wondering if anyone could help out.

      MSH|^~\&|IM||||20210201114846||ORU^R01|13|P|2.4|1||AL|NE

      PID|1||0001016|M1036|ZZTEST^DANIEL^||19780101|M||1|2 TECHNOLOGY DR^^WESTBOROUGH^MA^01581^||(555)121-2121|||||V00000112235

      PV1|1|O|PULH^^^^^^||||BERNMI^BERNSTEIN^MICHAEL^A|BERNMI^BERNSTEIN^MICHAEL^A||||||||||||11||||||||||||||||||||||||20210126105600

      ORC|RE|4449001||||||||||AAROGI^AARON^GILA^

      OBR|1|4449001||PULM.PFT^PULMONARY FUNCTION TEST^|||20210201114338|||||||||AAROGI^AARON^GILA^|||||||||D||||||\S\

      OBX|1|ED|Report File Name||TES|||||||||20210201114846||||BreezeSuite|20210201114846

      OBX|2|TX|Text Report File Name||Site: Stamford Hospital|||||||||20210201114846||||BreezeSuite|20210201114846

      OBX|3|TX|Text Report File Name||ID: 0001016  Name: ZZTEST, DANIEL|||||||||20210201114846||||BreezeSuite|20210201114846

      OBX|4|TX|Text Report File Name||Visit Date: 02/01/2021|||||||||20210201114846||||BreezeSuite|20210201114846

    Viewing 4 reply threads
    • Author
      Replies
      • #118489
        Jim Kosloskey
        Participant

          If you are using an Xlate,

          You will need to maintain your own repetition variable (counter) for the OB OBX Group.

          COPY =0 to $%g99 (this will set your counter %g99 to zero).

          ITERATE (assume%g1 is the variable of the ITERATE) over the OBX Group, inside that ITERATE check the OBX-3 for the value you seek with an ELSE, If it is found, do nothing

          ELSE

          PATHCOPY (or use COPYs) the IB OBX using %g1 appropriately placed in the IB address path and %g99 in the OB Address Path.

          MATH ADD =1 $%g99 –> $%g99 (this will increment your counter for the next repetition.

          If you would like me to assist, email me.

           

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

        • #118494
          Mike Pyne
          Participant

            Thanks Jim, I was hoping to accomplish this with TCL, not an Xlate.

          • #118495
            Charlie Bursell
            Participant

              Easy enough in Tcl

              set msg [msgget $mh]

              set fldSep [string index $msg 3]
              set segList [split $msg \r]

              foreach loc  [lsearch -all -regexp  {^OBX} $segList] {

              set fld3 [lindex  [split [lindex $segList $loc] $fldSep] 3]
              if {$flds3 eq “Text Report File Name”} {
              set DELE $loc
              break
              }

              }

              if {$DELE| {lvarpop segList $DELE}

              msgset $mh [join $segList \r]

              return “{CONTINUE $mh}”

              Assumes only one segment will have phrase.  If more let me know or simply modify Tcl

              I did not test so maybe some fat fingering 🙂

               

              • #118502
                Mike Pyne
                Participant

                  Thanks for the response Charlie! In this case, multiple segments would have the phrase “Text Report File Name”. Would it be a big change to do this for multiple OBX segments instead of just one?

              • #118504
                Charlie Bursell
                Participant

                  Sure enough

                  set msg [msgget $mh]

                  set fldSep [string index $msg 3]
                  set segList [split $msg \r]

                  set DELE “”

                  foreach loc  [lsearch -all -regexp  {^OBX} $segList] {

                  set fld3 [lindex  [split [lindex $segList $loc] $fldSep] 3]
                  if {$flds3 eq “Text Report File Name”} {
                  lappend DELE $loc
                  }

                  }

                  # Executing list from bottom up so as not to skew location

                  foreach loc [lsort -integer -decreasing $DELE]  { lvarpop segList $loc}

                  msgset $mh [join $segList \r]

                  return “{CONTINUE $mh}”

                • #118512
                  Steven G
                  Participant

                    Here is what I used to kill multiple OBX segments I do not want based on OBX3 value. I did not bother to correct the segment counts in OBX2:

                    run {
                    #Set typical variables
                    keylget args MSGID mh
                    set msg [msgget $mh]
                    set fieldSep [string index $msg 3]
                    set subFieldSep [string index $msg 4]
                    set segmentList [split $msg \r]
                    set msgTRIG [getField $msg MSH 8 1]

                    #Remove any OBX segment with a value of “Text Report File Name”
                    set segCnt [llength $segmentList]
                    for {set i 0} {$i<$segCnt} {incr i} {
                    set seg [lindex $segmentList $i]
                    set segFieldLst [split $seg $fieldSep]
                    set segType [lindex $segFieldLst 0]
                    set obxType [lindex $segFieldLst 2]
                    #Remove any OBX that is not a Numeric Value
                    if {[string equal $segType “OBX”] && [string equal $obxType “Text Report File Name”] } {
                    set segmentList [lreplace $segmentList $i $i]
                    set i [expr $i -1]
                    }

                    }
                    #Apply all of the changes to the MH.
                    set msg [join $segmentList \r]

                    msgset $mh $msg
                    lappend dispList “CONTINUE $mh”
                    }

                Viewing 4 reply threads
                • You must be logged in to reply to this topic.