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.