web stats
filters before transformers? or, deleting segments? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2011, 01:42 PM
DavidL DavidL is offline
OBX.1 Kenobi
 
Join Date: Sep 2011
Location: Dayton Ohio
Posts: 43
DavidL is on a distinguished road
Default filters before transformers? or, deleting segments?

I'm working on a project where our notifications arrive via delimited text files.

I need to route the message based on the file contents. I know how to do that; I have a filter working already.

But, in order for the filter to work, I basically have to parse the file contents.
Which I'm doing again in a transformer in the secondary channel anyway.

My first thought was, OK, I'll add a transformer. But, based on what I've seen here and the tutorials, I would guess that filters execute before transformers, in which case this would not work ... is that correct?

My second thought was, I could just fold most or all of the transformer into the filter, i.e. alter the message contents in the filter, before calling router.routeMessage() (if I decide to call it, that is).
And I can in fact get the new / transformed information into the message. However, I don't seem to be able to remove the 'delimited' segment.

I'm sure I can find a workaround ... but I'd like to do this correctly. And parsing the file contents twice (even if the files are small) is certainly less than optimal, so I'm not starting out well
Reply With Quote
  #2  
Old 11-16-2011, 05:32 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

Is there a reason you can't transform the filter at source?

If you can't, you could try setting a channelMap variable for the message based on whatever rules and filter based on that...something like this:

In the source transformer (I'm using MSH.10...use whatever's appropriate)

Code:
channelMap.put(msg['MSH']['MSH.10']['MSH.10.1'].toString(),'True');
In your destination filter (where you want to filter this message):
Code:
if (${msg['MSH']['MSH.10']['MSH.10.1'].toString() == 'True') {

return false;

} else {
return true;
}
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
  #3  
Old 11-16-2011, 05:58 AM
DavidL DavidL is offline
OBX.1 Kenobi
 
Join Date: Sep 2011
Location: Dayton Ohio
Posts: 43
DavidL is on a distinguished road
Default

OK, that probably wasn't very clear.

I guess what I'm asking is:
1. How do I go about altering, or preferably replacing, the message contents for downstream consumers?
(I do know how to store things into the channel map; but that won't work if I'm routing the message to a separate channel.)

2. Is it possible to get a transformer to execute before a filter?

TIA
Reply With Quote
  #4  
Old 11-16-2011, 06:05 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

Hi;

I had this problem when I first started with Mirth. I didn't realize that there were filters and transformers on the source tab.

So you do your transformations in the source tab and they will carry through to your destinations.
That is the only way to transform a message prior to your destination filters.

Things to keep in mind when doing this:

Source transformations will carry through to every destination in the channel.

If you have several destinations and need to the message to arrive intact at any of them you need to use the channelMap to determine whether a message should be filtered or not.
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
  #5  
Old 11-16-2011, 06:25 AM
DavidL DavidL is offline
OBX.1 Kenobi
 
Join Date: Sep 2011
Location: Dayton Ohio
Posts: 43
DavidL is on a distinguished road
Default

What I'd like to do is take the input i.e.
<delimited><row><column1>foo</column1>...</row></delimited>
and transform it into something like
<message><timestamp>...</timestamp><formtype>...</formtype></message>

... so that downstream I can just iterate over the message elements without needing to care about what kind of message it is. (At some point I will need to care, but I'm trying to keep my JavaScript code as granular and generic as possible.)

But, in order to do that, I want to replace (not augment) the message content ... otherwise I will have to have extra code downstream to deal with (ignore) the "delimited" segment/element downstream.

I can add stuff to the message just fine; that's not the problem. What I want to do is remove the 'delimited' segment. Or, alternatively, replace the message object entirely.

A secondary --and somewhat separate -- concern is that, if possible, I'd like to avoid parsing the message twice.

My guess would be I'm missing something really obvious ... but then again I'm not claiming to be anything other than a n00b
Reply With Quote
  #6  
Old 11-16-2011, 07:23 AM
DavidL DavidL is offline
OBX.1 Kenobi
 
Join Date: Sep 2011
Location: Dayton Ohio
Posts: 43
DavidL is on a distinguished road
Default

Aha!

In my case it was the opposite ... I knew you could do transformers & filters on the source connector, but I had forgotten you could do them on destinations as well. So I can put a transformer on the source connector, and the routing filter on the destination side ... that should take care of the order-of-execution issue. Thanks!

Do you by any chance have any nuggets of wisdom concerning the transformation?
Reply With Quote
  #7  
Old 11-16-2011, 09:06 AM
duggram duggram is offline
OBX.1 Kenobi
 
Join Date: Nov 2010
Location: ABQ, NM
Posts: 29
duggram is on a distinguished road
Default

Davids,

Would you consider using a system of router channels? Or what Mirth Corp calls chaining? I've worked with this at large corp sites. It offers decoupling that allows for a lot of varied manipulations.
Reply With Quote
  #8  
Old 11-16-2011, 09:24 AM
DavidL DavidL is offline
OBX.1 Kenobi
 
Join Date: Sep 2011
Location: Dayton Ohio
Posts: 43
DavidL is on a distinguished road
Default

I believe that's what I'm doing, if I remember the introductory material correctly. (I'm calling router.routeMessage() to invoke another channel.)

My question was about manipulating the "msg" data structure (and secondarily about doing so efficiently).
Reply With Quote
  #9  
Old 11-16-2011, 09:37 AM
DavidL DavidL is offline
OBX.1 Kenobi
 
Join Date: Sep 2011
Location: Dayton Ohio
Posts: 43
DavidL is on a distinguished road
Default

I believe I've discovered at least part of the issue.

Since my original source data is delimited text, the 'delimited' element is the root node in the XML representation of the message, and I can't get rid of it.

However, after I create the additional segment(s) in the structure I want, I *can* get rid of the (one and only) 'row' element/segment.

I should have figured this out sooner, based on the fact(s) that (1) other segments I created showed up "inside" the 'delimited' element, and (2) I didn't need to use 'delimited' as a segment name when reading the message fields (i.e. you use msg['foo'] rather than msg['delimited']['foo']).

Last edited by DavidL; 11-16-2011 at 09:37 AM. Reason: fixed quoting
Reply With Quote
  #10  
Old 11-16-2011, 10:42 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

What method are you using to pick up the messages?

The fact that you have to deal with XML is a bit confusing.

Can you post a sample message?
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
Reply

Tags
delimited, filter, segment, transform

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 03:53 PM.


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