web stats
Blank Templates - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2012, 06:27 AM
ffowler ffowler is offline
OBX.1 Kenobi
 
Join Date: May 2011
Posts: 42
ffowler is on a distinguished road
Default Blank Templates

Good day to all!
Hoping to get a little insight on a small problem I am having. I have a blank template as follows:

MSH|^~\&|PD|PD|ENG|LAB||||||P|2.3||
PID|1||||^^||||||^^^^|||||||||
PV1|1|O|PD^||||^^||||||||||||||||||||||||||||||||| ||||||
ORC|||||||||^^^^^R|^^||||
OBR|||||||||||||||||||||||||||
OBX|1|TX|||MICRO REPORT FOLLOWS:||||||
NTE||||


All is good with me populating the fields I need to. However, there are times when a segment is sent by the client which is not on the template (i.e DG1, IN1 etc...). They are not always sent so I did not put them into the template. But I want to include those extra segments unchanged. For some reason, with my current setup, they are deleted.

My question is, how can I include the segments which are not a part of the template.

Thank you in advance for any and all assistance.
Reply With Quote
  #2  
Old 04-13-2012, 06:29 AM
ffowler ffowler is offline
OBX.1 Kenobi
 
Join Date: May 2011
Posts: 42
ffowler is on a distinguished road
Default

Another problem with this is, there could be multiple segments.

Thanks again.
Reply With Quote
  #3  
Old 04-13-2012, 06:39 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 4,226
narupley is on a distinguished road
Default

If you want to add segments to your outbound message, just do: "tmp.appendChild(segment);" So if you want to copy over all DG1 segments, you could do something like:

Code:
for each (dg1 in msg.DG1)
     tmp.appendChild(dg1.copy());
Reply With Quote
  #4  
Old 04-13-2012, 06:53 AM
ffowler ffowler is offline
OBX.1 Kenobi
 
Join Date: May 2011
Posts: 42
ffowler is on a distinguished road
Default

Thank you very much for you quick response Sir Sage.
May I ask just one more question to this point.
Using your script, will that put the DG1 segments at the end of the rest of the defined segments or will they be placed in the same position as they come in?
Reply With Quote
  #5  
Old 04-13-2012, 06:59 AM
ffowler ffowler is offline
OBX.1 Kenobi
 
Join Date: May 2011
Posts: 42
ffowler is on a distinguished road
Default

Hmm.. This coding adds to the end of the segments. Is there another function that will add the undefined segments to their incoming position?
<thinking out loud> Unless I use createSegmentAfter and scroll thru each DG1?...
Reply With Quote
  #6  
Old 04-13-2012, 07:09 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 4,226
narupley is on a distinguished road
Default

That will add them to the end of the message, not in the order that they appear. The problem with adding them in the order that they appear is that you have already defined an outbound message that has a MSH, PID, PV1, ORC, OBR, OBX and NTE segment.

Instead, what I would do is just create a bare-bones outbound template like "MSH|^~\&", iterate through each segment in msg in order, and add them (in order) to tmp as necessary.
Reply With Quote
  #7  
Old 04-13-2012, 07:13 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 4,226
narupley is on a distinguished road
Default

Quote:
Originally Posted by ffowler View Post
Hmm.. This coding adds to the end of the segments. Is there another function that will add the undefined segments to their incoming position?
<thinking out loud> Unless I use createSegmentAfter and scroll thru each DG1?...
You can't do that easily with your current setup, because the "incoming position" and the position you've pre-defined in your outbound template may be different.

An extensive outbound template with multiple segments really should only be used when you're absolutely sure of what the expected format is going to be. If there are dynamic elements to the outbound message that depend on what the format of the incoming message is, then it's better to either 1) not use an outbound template at all and instead just modify msg, or 2) only use a bare-bones outbound template and add to it dynamically.
Reply With Quote
  #8  
Old 04-13-2012, 07:24 AM
ffowler ffowler is offline
OBX.1 Kenobi
 
Join Date: May 2011
Posts: 42
ffowler is on a distinguished road
Default

After trying a couple of things, and listening to your advice, I will go with option 1 and Not use the template. Too many variables with this client so it is best to have the most flexibility. Alas, no more drag and drop.

Again my thanks for your input and patience.
Reply With Quote
  #9  
Old 04-13-2012, 07:30 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 4,226
narupley is on a distinguished road
Default

You can still use an outbound template and take advantage of the drag-and-drop functionality, and then just remove it when you're done. Then at the top of your code you'll have to manually initialize tmp, and at the end of your code you'll just have to overwrite msg with "msg = tmp.copy();".
Reply With Quote
Reply

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 -7. The time now is 06:51 PM.


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