web stats
Move a segment - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-08-2010, 09:39 AM
tranquil tranquil is offline
Mirth Newb
 
Join Date: Mar 2008
Location: Canada
Posts: 13
tranquil
Default 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!
Reply With Quote
  #2  
Old 10-08-2010, 09:52 AM
panickc panickc is offline
OBX.3 Kenobi
 
Join Date: Dec 2007
Posts: 127
panickc is an unknown quantity at this point
Default

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
Reply With Quote
  #3  
Old 10-08-2010, 12:28 PM
tranquil tranquil is offline
Mirth Newb
 
Join Date: Mar 2008
Location: Canada
Posts: 13
tranquil
Default

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.
Reply With Quote
  #4  
Old 10-10-2010, 01:50 AM
AlexToft AlexToft is offline
OBX.3 Kenobi
 
Join Date: Sep 2010
Location: Leeds, UK
Posts: 160
AlexToft is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 10-14-2010, 09:15 AM
tranquil tranquil is offline
Mirth Newb
 
Join Date: Mar 2008
Location: Canada
Posts: 13
tranquil
Default

Thank you very much. It's working!
Reply With Quote
  #6  
Old 10-14-2010, 02:38 PM
mourisj mourisj is offline
Mirth Guru
 
Join Date: Feb 2007
Location: Luxembourg
Posts: 407
mourisj is an unknown quantity at this point
Default

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
Reply With Quote
  #7  
Old 10-14-2010, 02:53 PM
mourisj mourisj is offline
Mirth Guru
 
Join Date: Feb 2007
Location: Luxembourg
Posts: 407
mourisj is an unknown quantity at this point
Default

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
Reply With Quote
Reply

Tags
createsegmentafter, move segment, segment

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 09:51 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation