web stats
Custom response message creation after source filter step itself. - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2019, 06:50 AM
taanil taanil is offline
Mirth Newb
 
Join Date: Jun 2018
Posts: 10
taanil is on a distinguished road
Default Custom response message creation after source filter step itself.

Hello All,

I have a channel, whose source is 'TCP Listener' and destination is 'Database Writer'.

I have created a filter to check if the receiving message is of type 'ORM^O01'. If it is other than 'ORM^O01' event type, i reject the message. In the return acknowledgement, i want to inform the sender with a reason why the message has been rejected. Kindly inform the steps briefly to do it. I saw few posts, but nothing i found an explaination of generating the custom response during source filtering step itself.

Thank you so much !!.

Last edited by taanil; 09-18-2019 at 06:54 AM.
Reply With Quote
  #2  
Old 09-18-2019, 09:33 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,282
cory_cole is on a distinguished road
Default

https://www.mirthcorp.com/community/...ght=custom+ack
Reply With Quote
  #3  
Old 09-18-2019, 10:02 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road
Default

That thread will get you most of the way there. The unanswered question in the last post I think is the same as yours.

You can store your filter reason to a channelMap variable in the source filter, then access it in the post-processor to populate the ACK.

The following line will likely set httpResponse to null if the message was filtered at the source since 'Destination1' wouldn't have run at all. 'Destination1' should match the actual name of your destination for which you want to check the status. Alternatively, you can just assume that if you didn't set a filter reason you want to return an AA response.
Code:
var httpResponse = responseMap.get('Destination1');
Reply With Quote
  #4  
Old 09-19-2019, 11:08 PM
taanil taanil is offline
Mirth Newb
 
Join Date: Jun 2018
Posts: 10
taanil is on a distinguished road
Default

Thank you cory_cole and agermano.
I want to do another improvement, which is, if the message is not filtered, i want to return the default acknowledgement which was generated by Mirth.
Like this, in postprocessor,

if (message.getConnectorMessages().get(0).getStatus() == 'FILTERED') {
return ACKGenerator.generateAckResponse(message.getConnec torMessages().get(0).getRawData(),'AR', 'Message is Filtered');
}
else
{
--> Here i want to return the default acknowledgement. How to get the default acknowledgement ?
}

Last edited by taanil; 09-20-2019 at 04:25 AM.
Reply With Quote
  #5  
Old 09-20-2019, 07:10 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,282
cory_cole is on a distinguished road
Default

I don't think that you should have to do anything. It should be the default if it doesn't go into the if loop.
Reply With Quote
  #6  
Old 09-21-2019, 09:15 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road
Default

The default is an AA code with an empty message. It won't generate if you don't have auto-generate selected, but you create it the same way as your custom filtered ACK.

From your previous question, I assume you will be potentially returning several different filter reasons, but if it's always the same reason, you don't need to do any of this custom stuff. You can just edit the Rejected ACK Message in your source inbound data type properties and the auto-generate will use your custom message instead of the default.
Reply With Quote
  #7  
Old 09-23-2019, 12:12 AM
taanil taanil is offline
Mirth Newb
 
Join Date: Jun 2018
Posts: 10
taanil is on a distinguished road
Default

For the below 'Postprocessor' code, if the message is filtered, control enters the 'if' condition, then the client receives an acknowledgement.
Code:
if (message.getConnectorMessages().get(0).getStatus() == 'FILTERED') {
	return ACKGenerator.generateAckResponse(message.getConnectorMessages().get(0).getRawData(), 'AR', channelMap.get('ErrorStatus'));	
}
If the message is not filtered, the control doesnt enter the 'if' condition. In this case, the client waits for the acknowledgement, and ultimately times out. Because, there was no code to generate and return acknowledgement for success scenarios.

I think, as agermano confirmed, once the Source --> Source Settings --> Response is changed to 'Postprocessor', it becomes entirely the 'Postprocessors' responsibility to generate and return the acknowledgement for both filtered and success scenarios. Then i changed 'Preprocessor' script to below, it returned the acknowledgement to the client.

Code:
if (message.getConnectorMessages().get(0).getStatus() == 'FILTERED') {
	return ACKGenerator.generateAckResponse(message.getConnectorMessages().get(0).getRawData(), 'AR', channelMap.get('ErrorStatus'));	
}
else {
	return ACKGenerator.generateAckResponse(message.getConnectorMessages().get(0).getRawData(), 'AA', 'SUCCESS');
}
My question is, in the else condition, instead of me creating the success acknowledgement by calling 'generateAckResponse', is there a object which i can get which is already generated for success scenario by Mirth, then this helps me to use the default acknowledgement code and message ? then, this leaves me to worry only about 'AR'.

"From your previous question, I assume you will be potentially returning several different filter reasons, but if it's always the same reason, you don't need to do any of this custom stuff. You can just edit the Rejected ACK Message in your source inbound data type properties and the auto-generate will use your custom message instead of the default."
--> We have different filters and would like to send the actual reason why we rejected the message. For example, if the order is not new 'NW', then we will reject with the message 'Only new orders are accepted'. Another one, if the event is not 'ORM^O01' we will reject, then the message is 'Only 'ORM^O01' events are supported' and so on...

Last edited by taanil; 09-23-2019 at 01:01 AM.
Reply With Quote
  #8  
Old 09-23-2019, 07:08 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road
Default

Quote:
Originally Posted by taanil View Post
I think, as agermano confirmed, once the Source --> Source Settings --> Response is changed to 'Postprocessor', it becomes entirely the 'Postprocessors' responsibility to generate and return the acknowledgement for both filtered and success scenarios.
This is correct.

Quote:
Originally Posted by taanil View Post
My question is, in the else condition, instead of me creating the success acknowledgement by calling 'generateAckResponse', is there a object which i can get which is already generated for success scenario by Mirth, then this helps me to use the default acknowledgement code and message?
Mirth will not automatically generate any response for you, because you are no longer using one of the "auto-generate" options. The ACKGenerator is there to make the task of creating an ACK response yourself easier.

This basically does the same thing, but maybe it's closer to what you want?

Code:
var sourceRawContent = message.getConnectorMessages().get(0).getRawData();
var ackCode = 'AA';
var ackMessage = 'SUCCESS';

if (message.getConnectorMessages().get(0).getStatus() == 'FILTERED') {
	ackCode = 'AR';
	ackMessage = channelMap.get('ErrorStatus'));	
}

return ACKGenerator.generateAckResponse(sourceRawContent, ackCode, ackMessage);
Reply With Quote
  #9  
Old 09-26-2019, 03:43 AM
taanil taanil is offline
Mirth Newb
 
Join Date: Jun 2018
Posts: 10
taanil is on a distinguished road
Default

Thank you for this.
Another question, how about AE error handling when we do not opt for "auto-generate" option ?
I think errors are very broad and can be anything. How can we know in PostProcessor if there was any error so that we can create 'AE' ack code return messages ?

Last edited by taanil; 09-27-2019 at 03:00 AM.
Reply With Quote
  #10  
Old 09-26-2019, 09:43 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road
Default

message in the post-processor is an instance of ImmutableMessage from the User API. When you call getConnectorMessages, you get a Map holding an ImmutableConnectorMessage for the source and each destination that ran. The source connector is always 0, and the number for each destination will match the Id column on the destinations tab of your channel. These are not always sequential if destinations were reordered or deleted.

Code:
message.getConnectorMessages().get(0).getStatus() == 'FILTERED'
When you're calling the above expression from the previous post you're checking the status of the source connector. You might need to adjust the logic, but something like this should work.

Code:
// Set up default values for success
var sourceRawContent = message.getConnectorMessages().get(0).getRawData();
var ackCode = 'AA';
var ackMessage = 'SUCCESS';

// Send AR with reason if source connector was filtered
if (message.getConnectorMessages().get(0).getStatus() == Status.FILTERED) {
	ackCode = 'AR';
	ackMessage = channelMap.get('ErrorStatus'));	
}

// Send AE if the source or any destinations had an error
for (var connectorMessage in Iterator(message.getConnectorMessages().values())) {
    if (connectorMessage.getStatus() == Status.ERROR) {
        ackCode = 'AE';
        ackMessage = 'ERROR';
        break; // we don't need to keep looking after we find one
    }
}

return ACKGenerator.generateAckResponse(sourceRawContent, ackCode, ackMessage);
Reply With Quote
Reply

Tags
acknowledgement, custom message, filter, response

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 05:51 AM.


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