web stats
Mirth Community - View Single Post - Message validation
View Single Post
  #4  
Old 02-21-2012, 04:07 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Unfortunately, in that case you'll have to build the ACK yourself. Fortunately, it's a relatively easy thing to do:

Code:
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)));
}
For example, if you want to send an AR NACK back for ADTs, you could do this:

Code:
if (msg['MSH']['MSH.9']['MSH.9.1'].toString() == 'ADT')
	setACK(msg,'AR',"We don't take kindly to the likes of you.");
else
	setACK(msg,'AA','Pull up a chair.');
Reply With Quote