How to loop from bottom to top and then check for condition

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf How to loop from bottom to top and then check for condition

  • Creator
    Topic
  • #54834
    Vijay Dunnala
    Participant

      Hi All,

      OBX 5 is a repeating field, need to loop from the last OBX  if  in the OBX_5 has any value then it should STOP the iteration and send all the OBX segments where it finds the value till the First OBX.

      Example: Inbound message

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

      OBX|1|TX|||   Test                  Results||||||C

      OBX|2|TX|||


      ||||||C

      OBX|3|TX||| ||||||C

      OBX|4|TX|||  ABO/RH||||||C

      OBX|5|TX|||>   BLOOD TYPE           A POS         ||||||C

      OBX|6|TX||| ||||||C

      OBX|7|TX|||>   ANTIBODY SCREEN      NEGATIVE       ||||||C

      OBX|8|TX|||


      ||||||C

      OBX|9|TX||| ||||||C

      OBX|10|TX||| ||||||C

      OBX|11|TX||| ||||||C

      OBX|12|TX||| ||||||C

      OBX|13|TX||| ||||||C

      OBX|14|TX||| ||||||C

      Outbound Message:

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

      OBX|1|TX|||   Test                  Results||||||C

      OBX|2|TX|||


      ||||||C

      OBX|3|TX||| ||||||C

      OBX|4|TX|||  ABO/RH||||||C

      OBX|5|TX|||>   BLOOD TYPE           A POS         ||||||C

      OBX|6|TX||| ||||||C

      OBX|7|TX|||>   ANTIBODY SCREEN      NEGATIVE       ||||||C

      OBX|8|TX|||


      ||||||C

      Thanks,

      Vijay.

    Viewing 2 reply threads
    • Author
      Replies
      • #83155
        Paul Bishop
        Participant

          This should do it for you:

          Just noticed that your example has a space instead of nulls.  You can add a string trim (done below now) to take care of that.

          set msg [msgget $mh]

          set fldSep [string index $msg 3]

          set segList [split $msg r]

          set OBXloc [lsearch -all -regexp $segList {^OBX}]

          set found_data N

          foreach loc [lsort -integer -descreasing $OBXloc] {

          Paul Bishop
          Carle Foundation Hospital
          Urbana, IL

        • #83156
          Mark Thompson
          Participant

            Hi Vijay,

            In your example, the OBX segments are in the same order in both the original and final message.  If that is what you want, you can do the whole thing in a translate without Tcl code.

            The trick is to iterate twice through the OBX segments.  The first time through you set a counter to the highest OBX that contains data, but don’t send anything.  The second time through, you send all of the OBX segments until you reach the desired count.

            - Mark Thompson
            HealthPartners

          • #83157
            Vijay Dunnala
            Participant

              Thank you Mark and Paul

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