web stats
If statement limit - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2018, 05:44 AM
rutledj rutledj is offline
Mirth Guru
 
Join Date: Nov 2010
Location: North Carolina
Posts: 372
rutledj is on a distinguished road
Default If statement limit

Is there a practical limit to the number of if/else statements that can be in a single transformer? We have one file reader channel with multiple destinations based on file name.

The file names look something like this: gLFJ1784_ACK, gLFJ1784_NOT, gKFH1784_ACK, gKFH1784_NOT etc.

The if/else looks like this:

Code:
if ((sourceMap.get('originalFilename').indexOf('gLFJ1784') != -1) && (sourceMap.get('originalFilename').indexOf('ACK') != -1)) 
{
    destinationSet.removeAllExcept('gLFJ1784_ACK');
}
else if ((sourceMap.get('originalFilename').indexOf('gLFJ1784') != -1) && (sourceMap.get('originalFilename').indexOf('NOT') != -1)) 
{
    destinationSet.removeAllExcept('gLFJ1784_NOT');
}

The portion before the underscore will change based on practice.

The _ACK files will go to a different destination than _NOT files. So in this case there are 4 destinations, one for each file type.

As we add more practices there is the potential to have over 250 different file types. All the files are read from the same source folder. So that is 250 if/else statements and 250 destinations on one channel.

Does anyone see a problem with this approach or am I pressing the limits of the channel design?

Thanks,
Rut
Reply With Quote
  #2  
Old 06-07-2018, 08:06 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 252
agermano is on a distinguished road
Default

That shouldn't be a problem, but you can likely generalize your transformer step so that you don't need to change it when you add new practices.

In your example here, where your filename exactly matches the destination name, you could do:
Code:
if (connectorMessage.getDestinationIdMap().containsKey($('originalFilename'))) {
	destinationSet.removeAllExcept([$('originalFilename')]);
}
else {
	throw "Destination not found for : " + $('originalFilename');
}
If there is some other identifier in the filename to make the filename unique, you can first derive the destination name from the filename (likely with a regex) and then do the same as above.
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 -8. The time now is 03:27 AM.


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