Xlate iteration with a conditional segment INSERT

Clovertech Forums Cloverleaf Xlate iteration with a conditional segment INSERT

  • Creator
    Topic
  • #118210
    Matthew Brophy
    Participant

      we have a standard group iteration for OBX in an ORU message. We are looking to add and additional OBX result segment if conditions are met for one of the OBX segments.

      In testing, we can accomplish this by setting variables during the iteration loop.

      We populate the segment with the custom values (variables defined if the conditions are met).  Where we run into issues is condition is met on Loop#5, we populate the custom segment on Loop #6, but end up skipping the respective segment on Loop #7.  We’re just writing over that segment Loop instead of actually INSERTING an additional segment to the output.

       

      The placement of the inserted custom segment doesn’t matter, but the OBX count varies on the message.

       

      Attached images for reference

      Attachments:
      You must be logged in to view attached files.
    Viewing 1 reply thread
    • Author
      Replies
      • #118213
        Paul Bishop
        Participant

          When you need to add or remove OBX’s in a Xlate, you need to keep track of the counter (for OBX-1) and the index for the output OBX’s yourself.  The ITERATE command will handle the input portion fine.

          Use @obxCount for the output OBX-1 field and create a new index variable for the output field.  When I do this, I try to use the same number index but with a 1 added to it.  For example, %g1 is setup in the ITERATE, I would use %g11 for the index I control.

          Initialize the @obxCount to 1 (like you have already), and initialize %g11 to 0 (zero).  When you need to set or do math to an index, it is referenced by $%g11, but when used to index in a segment, just use the %g11 name.

          Start the loop and every time you complete the moves to the OBX segment, increase the counter and index by one (within the iterate).
          <pre>COPY =1 -> @obxCount
          COPY =0 -> $%g11
          ITERATE (using %g1 as your index and 1(0).1(0).3(0).0 as the basis)
          copy @obxCount -> 1(0).1(0).3(0).0(%g11).OBX(0).#1(0).[0]
          …all other copies to the OBX segments using %g11 for the output
          MATH: ADD @obxCount =1 -> @obxCount
          MATH: ADD $%g11 =1 -> $%g11
          if the condition is met for adding a new OBX
          copy @obxCount -> 1(0).1(0).3(0).0(%g11).OBX(0).#1(0).[0]
          …all other copies to the OBX segments using %g11 for the output
          MATH: ADD @obxCount =1 -> @obxCount
          MATH: ADD $%g11 =1 -> $%g11
          end-if
          end-iterate</pre>
          Hope this helps.

          Paul Bishop
          Carle Foundation Hospital
          Urbana, IL

        • #118214
          Jim Kosloskey
          Participant

            When I have ITERATE Variables I manage I like to use the 90s starting with 99 and working downward.

            2 reasons.

            1. it is unlikely I will have sufficient ITERATEs to naturally get to the 90’s so no danger of collision (ending up using the same variable in conflict)

            2. seeing something in the 90s alerts me and anyone else following me there are self managed Iteration Variables used inside the Xlate.

            Matthew if you would like a second set of eyes on the situation email me.

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

        Viewing 1 reply thread
        • You must be logged in to reply to this topic.