web stats
Destination Set Filter Sending Messages to Wrong Destination, Bug? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2020, 02:52 PM
GrnMtnBuckeye GrnMtnBuckeye is offline
What's HL7?
 
Join Date: Jan 2016
Posts: 5
GrnMtnBuckeye is on a distinguished road
Default Destination Set Filter Sending Messages to Wrong Destination, Bug?

Using Mirth Connect Server 3.8.1, Java Version 1.8.0_181, we just set up a new destination set filter for EDI X12 messages with the following javascript Source Transformer:

switch (msg['GS']['GS.03']['GS.03.1'].toString()) {
case 'ACME':
destinationSet.removeAllExcept('Destination_ACME') ;
break;
case 'ARMS':
destinationSet.removeAllExcept('Destination_ARMS') ;
break;
default:
destinationSet.removeAllExcept('Destination_Unknow n');
break;
}

The ACME customer had the correct destination configured in mirth, The ARMS customer didn't actually have a destination by the name of 'Destination_ARMS' configured in mirth, 'Destination_Unknown' was configured as a file writer destination (in case someone sends a message to the source for a new customer without notifying my team that we need to set up a new destination).

When we did our testing, we found that records with 'ARMS" in GS.03 were being routed to Destination_ACME AND Destination_Unknown. This appears to be caused by the fact that the Destination Set Filter was set for GS.03 value of ARMS to route to a destination that didn't yet exist. I would expect that this situation would cause an error instead of sending potentially sensitive information to the wrong customer. Is this a bug or is there something different we should have done in our javascript? If it is a bug, please point me to the proper steps to log it. Thanks in advance!

Last edited by GrnMtnBuckeye; 01-21-2020 at 02:30 PM. Reason: errant space in a word
Reply With Quote
  #2  
Old 01-21-2020, 02:29 PM
GrnMtnBuckeye GrnMtnBuckeye is offline
What's HL7?
 
Join Date: Jan 2016
Posts: 5
GrnMtnBuckeye is on a distinguished road
Default Bug Confirmed - Workaround: Use Destination IDs Instead

I posted a similar question in the Mirth Slack Channel and was told that this is indeed a known bug with the Destination Set Filter. The default behavior of a channel is to send to all destinations. If the Destination Set Filter code fails to "resolve" the destination name to an ID for the string you are passing, it will fail and therefore do nothing (filter nothing and revert to default behavior of sending to all destinations).

@agermano suggested that I could pass an array to the filter instead of the string but I am a Javascript noob and none of my array attempts were successful so I used the Destination ID instead of Destination string. Even using a Destination ID that is inactive will work fine, without sending to all the other destinations. This isn't ideal because it makes the channel less portable from one environment to the next (have to double check Destination IDs when you import channel), but it meets my intent so I'm calling it a viable workaround at least.

New Code ('Destination_ACME' has ID of 2, 'Destination_ARMS' has ID of 4, and 'Destination_Unknown' has ID of 3):

switch (msg['GS']['GS.03']['GS.03.1'].toString()) {
case 'ACME':
destinationSet.removeAllExcept(2) ;
break;
case 'ARMS':
destinationSet.removeAllExcept(4) ;
break;
default:
destinationSet.removeAllExcept(3);
break;
}
Reply With Quote
  #3  
Old 01-22-2020, 02:25 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,106
agermano is on a distinguished road
Default

Try this:
Code:
switch (msg['GS']['GS.03']['GS.03.1'].toString()) {
    case 'ACME':
        destinationSet.removeAllExcept(['Destination_ACME']);
        break;
    case 'ARMS':
        destinationSet.removeAllExcept(['Destination_ARMS']);
        break;
    default:
        destinationSet.removeAllExcept(['Destination_Unknown']);
        break;
}
Another option that I've used when I need to always send to a particular destination, in addition to which ever one is selected by the switch statement:

Code:
var keep = ['Always Run'];

switch (msg['GS']['GS.03']['GS.03.1'].toString()) {
    case 'ACME':
        keep.push('Destination_ACME');
        break;
    case 'ARMS':
        keep.push('Destination_ARMS');
        break;
    default:
        keep.push('Destination_Unknown');
        break;
}

destinationSet.removeAllExcept(keep);
destinationSet.removeAllExcept also returns a boolean value indicating whether anything was actually removed, so in your original code you also could have checked the return value and thrown an exception or something (to cause the message to error) if you were telling it to only keep a destination that didn't exist.
Reply With Quote
  #4  
Old 02-14-2020, 11:26 AM
GrnMtnBuckeye GrnMtnBuckeye is offline
What's HL7?
 
Join Date: Jan 2016
Posts: 5
GrnMtnBuckeye is on a distinguished road
Default Solution Works - Thanks!

@agermano, that works perfectly. Thanks!


For others trying to follow the conversation, this is what I used instead of the code from my original post and it is working well:

switch (msg['GS']['GS.03']['GS.03.1'].toString()) {
case 'ACME':
destinationSet.removeAllExcept(['Destination_ACME']);
break;
case 'ARMS':
destinationSet.removeAllExcept(['Destination_ARMS']);
break;
default:
destinationSet.removeAllExcept(['Destination_Unknown']);
break;
}

The only caveat is that if I were to deactivate one of the destinations without changing the destination set filter, i.e. disable Destination_ARMS, but then send a message in with 'ARMS' in GS.03.1, it will not go to any destination (not even default). It will sit on source with no place to go. This is fine with me but worth noting in case someone else is expecting it to follow the "default" logic. With this code, if there is a match it will follow that path, even if the path is to something that doesn't currently "exist." This is logical when you look at it, and is way better than sending to all. I could code around it by creating a variable to hold the destination id and running a null check to push the messages to default but it is really an outlier scenario anyway.
Reply With Quote
Reply

Tags
#destinationset, #edi, #filter, #javascript, #x12

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:29 AM.


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