-1

I am really new mirth and also not much familiar with Java script but I 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)

function 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

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.

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141

1 Answers1

1

In the receiver channel's Source Transformer you may add the following as the first step:

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("ACK", ack);

There might be more than one PID sent in the message. Also, the response is likely AE code, unless it's stated differently in your profile. The AR is reserved for other type of verification. This code snippet does not check if the incoming message uses enhanced acknowledgement mode. Obviously, you need to set the channel's Source connector Response to ACK.

Shamil
  • 910
  • 4
  • 17
  • Thanks for your help @Shamil i did try this and it works perfect but the challenge is if the end system rejects the message for any other reason that response wont be passed to source. Again i am new to mirth so may that's my knowledge gap. – mitesh patel Mar 14 '18 at 22:53
  • So, after asking in Mirth forum, it should be clear as mud now. Right? – Shamil Mar 21 '18 at 21:21
  • Yes i did get clarification now :) – mitesh patel Mar 23 '18 at 00:44