web stats
Generate custom reject message - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2018, 09:38 AM
Mits87 Mits87 is offline
OBX.2 Kenobi
 
Join Date: Nov 2016
Posts: 58
Mits87 is on a distinguished road
Default Generate custom reject message

I am really new mirth and also not much familiar with Java script but my Mirth 3.3 source is set to TCP listener and i receive an HL7 ADT message. I have been using Filter on Source with Type as Rule builder to process message only if PID3.1 is available. What i want to achieve is if the message was filtered due to missing PID i will like to send AR message with details "Missing Patient ID". My end destination is also TCP listener(Not sure if this matters)

I have got below code in Global script(postprocess) which i got from different forum here.

Code:
function 
var msg = channelMap.get('msg'); 
setACK(sourceMsg,responseCode,responseMsg,responseStatus) {
    importPackage(com.mirth.connect.model);
    // responseStatus is an optional parameter
    if (!responseStatus)
        responseStatus = {'AA':Response.Status.SUCCESS,'AR':Response.Status.FILTERED,'AE':Response.Status.FAILURE}[responseCode] || Response.Status.UNKNOWN;
    var ack = <HL7Message/>;
    ack.MSH['MSH.1'] = sourceMsg.MSH['MSH.1'].toString();
    ack.MSH['MSH.2'] = sourceMsg.MSH['MSH.2'].toString();
    ack.MSH['MSH.3'] = sourceMsg.MSH['MSH.5'].copy();
    ack.MSH['MSH.4'] = sourceMsg.MSH['MSH.6'].copy();
    ack.MSH['MSH.5'] = sourceMsg.MSH['MSH.3'].copy();
    ack.MSH['MSH.6'] = sourceMsg.MSH['MSH.4'].copy();
    ack.MSH['MSH.7']['MSH.7.1'] = DateUtil.getCurrentDate('yyyyMMddHHmmss');
    ack.MSH['MSH.9']['MSH.9.1'] = sourceMsg.MSH['MSH.9']['MSH.9.1'].toString();
    ack.MSH['MSH.9']['MSH.9.2'] = sourceMsg.MSH['MSH.9']['MSH.9.2'].toString();
    ack.MSH['MSH.9']['MSH.9.3'] = 'ACK';
    ack.MSH['MSH.10'] = sourceMsg.MSH['MSH.10'].copy();
    ack.MSH['MSH.11'] = sourceMsg.MSH['MSH.11'].copy();
    ack.MSH['MSH.12'] = sourceMsg.MSH['MSH.12'].copy();
    ack.MSA['MSA.1']['MSA.1.1'] = responseCode;
    ack.MSA['MSA.2']['MSA.2.1'] = sourceMsg.MSH['MSH.10']['MSH.10.1'].toString();
    ack.MSA['MSA.3']['MSA.3.1'] = responseMsg;
    responseMap.put('ACK',new Response(responseStatus,SerializerFactory.getHL7Serializer().fromXML(ack)));
And under Source Filter i have Javascript rule with below code
Code:
if(msg['PID']['PID.3']['PID.3.1'].toString().length > 0) {
    return true;
}
    setACK(msg,'AR',"MIssing Patient ID.");
return false;
This still doesnt work i still get an error message for processing. On mirth documentation it says that use generateAckResponse but i am not sure how to do so
Reply With Quote
  #2  
Old 03-14-2018, 10:26 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 965
agermano is on a distinguished road
Default

It's part of the User API.

http://javadocs.mirthcorp.com/connec...Generator.html

You can also click View User API in the Mirth administrator to view this documentation hosted from your own server.
Reply With Quote
  #3  
Old 03-15-2018, 02:36 PM
Mits87 Mits87 is offline
OBX.2 Kenobi
 
Join Date: Nov 2016
Posts: 58
Mits87 is on a distinguished road
Default

@agermano thanks for your direction

So i crated a new transformer under source and got below code which is working well after i use "CustomACK" as response is there a way i can still use "Auto-generated(Destination complete)" as response as there is a chance where the destination may reject the message for some other reason.

Code:
var verified = false;

for each (var pid in msg['PID']['PID.3']) {
    if (pid['PID.3.1'].toString()) {
        verified = true;
        break;
    }
}

var ack;
if (verified) {
    ack = ACKGenerator.generateAckResponse(connectorMessage.getRawData(), "AA", "Accepted");
} else {
    ack = ACKGenerator.generateAckResponse(connectorMessage.getRawData(), "AE", "PID.3.1-Patient Identifier is missed");
    destinationSet.removeAll();
}

responseMap.put("CustomACK", ack);
Reply With Quote
  #4  
Old 03-21-2018, 12:01 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 965
agermano is on a distinguished road
Default

You might be able to get away without creating your own custom ACK. A reject is automatically sent when a message is filtered, but you have to decide where you want to do your filtering.

This table shows what kind of ack message will be auto generated based on your source response selection, and whether you filter in the source or destination.

Code:
autogenerate         | filter      | ack type auto-gen'd
---------------------+-------------+--------------------
after source trans   | source      | reject
after source trans   | destination | success
destination complete | source      | error (destination never runs in this case)
destination complete | destination | reject
The default is after the source transformer, which would allow you to do your filtering in the source to send your rejection messages. You can still filter in the destination, but the ack would be a success rather than reject. This default is recommended.

Under the summary tab of your channel, click the Set Data Types button. If you scroll down on the source connector inbound properties you will see a Response Generation section. You can change the default Rejected ACK Message from "Message Rejected" to a velocity variable, such as ${rejectMessage}. This will allow you to store the reason in a channelMap variable in your source filter like the following.

Code:
if(msg['PID']['PID.3']['PID.3.1'].toString().length > 0) {
    return true;
}
$c('rejectMessage', 'Missing Patient ID.');
return false;

If you meant you wanted to relay the ACK received from your destination back through the source, then that is different, and you can't use auto-generation. In that case, you would probably use the post-processor response to determine whether you need to create a custom reject message or relay the destination response.
Reply With Quote
Reply

Tags
custom ack, hl7

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


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