Custom Web Service Connections from Mirth Connect

Mirth Connect is the Swiss Army knife of open source integration engines with specific Healthcare support for HL7 message integration. Mirth has out of the box connectors for FTP, HTTP (GET/POST), JMS, SMTP, LLP and Web Services but if the out of the box capabilities is not sufficient, we can use the “JavaScript Writer” destination to create our own custom connector.

In the open source version of Mirth Connect, there is no support for secure HTTPS. This is available from Mirth in their commercial offering but in this blog entry, I’m going to take you through using the JavaScript writer destination to create our own simple HTTPS sender.

Mirth Connect uses the Rhino JavaScript engine which gives us access to Java classes and libraries. While JavaScript itself does not have the low-level HTTPS protocol support we need, it turns out that the library does and we can leverage that in this example to POST a message to an HTTPS endpoint as follows:

In an existing channel, create a new destination connector of type “JavaScript Writer” and paste the following into it:

In this example above, we are POSTing the contents of the message object to the server and then reading the response back into a buffer which is then placed in the channel map variable “response”.

In the case where the response is actually an HL7 message (such as an ACK) you could append the following code which will parse the HL7 response using the Mirth serializer and then extract fields from it:

Posted in:

Leave a Reply