2
votes

I want to write a simple "web service" that I can use Mirth to send HL7 messages to. This "web service" could be as simple as a CGI script, and would just need to accept the HL7 message as a string (and possibly a couple of other values) as a POST request using Mirth's HTTP sender.

This seems simple enough, but how should this "web service" send back the ACK to let Mirth know if everything is OK or something went wrong? Is there a specific format that Mirth is expecting as a response? Or is there some way to tell Mirth what to expect?

Note: I do not want to use Mirth on the receiving end.

1

1 Answers

2
votes

The short answer is that it's completely up to you... Mirth Connect can accommodate any response (or lack thereof) and perform custom user-logic to decide whether the response is "successful" or not.

You could have your external web service generate an HL7 v2.x ACK and send that back. Then on the HTTP Sender side, make sure your Response data types are set to HL7 v2.x, and enable "Validate Response" in the destination settings.

You can also have your web service generate a completely custom response and do custom validation on the MC side. For example if you have your web service send back a response like this:

{
    "success": true,
    "message": "Message received successfully."
}

Then you can set your Response data types to JSON, and do this in the response transformer:

if (msg.success !== true) {
    responseStatus = ERROR;
}
responseStatusMessage = msg.message;

You can also validate purely on the response status code. By default with an HTTP Sender, the message status will be set to SENT only if the HTTP request returned with a status of < 400. Anything else and the status will be left as QUEUED (or ERROR if queuing is disabled).

You can override that behavior in the response transformer though. Maybe you only want it to be SENT if the status is specifically 200 (and not other 2xx or 3xx codes). Set your Response data types to Raw (so that the response transformer will execute even when there is no response), and do this in the response transformer:

var responseStatusLine = $('responseStatusLine');
var responseCode = parseInt(responseStatusLine.split(' ')[1], 10);
if (responseCode != 200) {
    responseStatus = ERROR;
    responseStatusMessage = responseStatusLine.substr(responseStatusLine.indexOf(' ')).trim();
}