Announcement

Collapse
No announcement yet.

Move a segment

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Move a segment

    Hello

    I have a message format that comes in as follows:

    MSH|
    PID|
    OBR|
    OBX|
    ZED|
    OBX|

    I need to move the 'ZED' segment to the end of the message. I thought i could use createSegmentAfter but the issue i am encoutereing is that each message could have a different number of OBX segments. One message could have 1 OBX segment while the next could have 100. How can i ensure the ZED segment is always the last segment?

    Thanks!

  • #2
    Just loop thru the message until you hit the ZED, save it in a new var, delete segment, then continue looping until at the end of the message, then createsegmentafter.

    -cp

    Comment


    • #3
      Thanks for the advice. When i try this a ZED is placed after each OBX. Would you be able to supply a snippet of code that shows how to properly accomplish?

      Regards.

      Comment


      • #4
        myvar = msg['ZED'];
        delete msg['ZED'];
        createSegment('ZED', msg);
        msg['ZED'] = myvar;

        createSegmentAfter *sounds* like what you're after, but it's not; not in this situation with repeating OBX segs. Plain old createSegment will drop it at the end of the msg quite happily for you.

        Comment


        • #5
          Thank you very much. It's working!

          Comment


          • #6
            Inoticed that you can also do the following:

            - do all your transformations as required on your data.
            - Add a last transformer steplike this:

            Code:
            tmp['MSH'] = msg['MSH'];
            tmp['EVN'] = msg['EVN'];
            tmp['PV1'] = msg['PV1'];
            tmp['PID'] = msg['PID'];
            tmp['PV2'] = msg['PV2'];
            and place an appropriate EMPTY message template in the Outbound message template field:

            Code:
            MSH|^~\&||||||||||2.2|
            EVN||||||
            PV2||||||||||
            PID|||^^||^^^^||||||^^^^^|||||||||||||||||
            PV1|||^^^|||||^|||^^^||||||||^^|||||||||||||||||||||||||||
            with the segments in the order you want to see them in your outgoing message.

            The destination File Writer template should contain the ${message.encodedData}
            JJ Mouris
            FFE Luxembourg
            IT-Department

            Comment


            • #7
              The template may even be reduced to:

              Code:
              MSH
              EVN
              PV2
              PID
              PV1
              It also handles Z-segments (if you add them) and repetitions.
              If you add segments in your template that don't exist in your message, it does not matter.
              If you don't add segments that exist in your message, they will be dropped.
              JJ Mouris
              FFE Luxembourg
              IT-Department

              Comment

              Working...
              X