web stats
Skip to end of metadata
Go to start of metadata

Before continuing, read the FHIR Connector overview and user guide if you haven't already:

This guide is separated into the following sections:


This example channel is also hosted on our public GitHub repository! Contribute and collaborate with us to make it even better!



Importing the Example Channel

Then open the Mirth Connect Administrator, navigate to the Channels view, and click on Import Channel to the left. Select the channel XML file, and then click Open.

The channel comes bundled with a couple of code template libraries, so make sure to choose Yes and then Import when it prompts you:

Then you'll be taken to the edit channel view:

Click on Save Changes to save the channel.


Creating the Database

This example channel depends on a database to store resource information. It is setup to support PostgreSQL or SQL Server, though you can modify the code templates to support others. Once you create a schema (e.g. "fhirdb"), here are the other create statements you need:


 SQL Server:


Adding the Configuration Map Properties

The example channel also relies on some configuration map properties to store database connection information. If you don't already have configuration map properties set, you can just import this file:


SQL Server:

Otherwise, you can just add them to the configuration map table:

Make sure to change the connection information (URL, username, and password) as needed.


Notes on Implementation

First, note that certain interactions have been selectively enabled for certain resource types. For this example we'll only actually be implementing some interactions, so this is largely for illustration. You can enable or disable interactions as you see fit, so that the generated conformance statement will reflect that support to clients.

On the source connector settings, we also have a custom "response" variable selected. This indicates that the FhirResponse object the FHIR Listener uses will be retrieved from the response map.

Source Transformer

Here we just have a single step. We use destination set filtering to decide in advance which destination to send a message to. Each destination is named according to one of the possible FHIR interactions, like "create" or "update". Because the interaction of the request will be in the "fhirInteraction" source map variable, we can use that to directly filter on destinations:


We'll just look at one, the "create" destination. As the name implies, this destination will handle all create interactions that flow through the channel. It's a JavaScript Writer that will take a resource posted to the channel and store it in a database (the one you created above). The JavaScript code in the destination simply inserts the resource into the database, and uses FhirResponseFactory to create a FhirResponse object. Then it places that response into the response map, with the key "response".

The other destinations in the channel are much the same. For example the "read" destination will use similar code to select resource data from the same database table, and return the data in an appropriate FhirResponse object. The "history" and "search" destinations are a little more complex because it involves selecting multiple resources and compiling them into a Bundle resource.


Sending Sample Requests

Once you've made any necessary tweaks to the channel or configuration map (like pointing it to your local database), save and deploy it. The FHIR Listener channel will be up and running, and you should be able to request the home page at the URL http://localhost:9001/r3/, or the conformance statement at the URL http://localhost:9001/r3/metadata. Note that the IP, port, or base context path may be different depending on your source connector settings. If you request a resource (like the conformance statement) in a web browser, it will return the HTML template with the resource narrative (if available):

Creating a Patient Resource

After verifying the /metadata endpoint works correctly, try creating a new Patient resource. Doing so is simple, just POST a request to http://localhost:9001/r3/Patient. You can go here to get some example patient resources: Resource Patient - Examples.

If you choose an XML-formatted resource, use "application/fhir+xml" for the Content-Type. If you choose JSON, use "application/fhir+json".

After sending the request, the channel should receive the message, and you can view it in the message browser:

Notice how the fhirType variable contains "Patient", and the fhirInteraction variable contains "create", which is correct. Back in whatever HTTP client you're using, you should have received a 201 (Created) status code, and also a Location header. The Location header contains a URL telling the client where to issue a "vread" interaction to retrieve the same resource you just created.

Reading a Patient Resource at a Specific Version

If you copy that URL and issue a new GET request to it, it should return the same resource XML that you POSTed earlier. Again in the message browser, you can view the vread request that came in, and verify the response data that was sent back to the client:

Binary Resources

You can also create and read Binary resources. Issue another POST request, but this time to the address http://localhost:9001/r3/Binary (again, URL may change depending on source connector settings). Use the Content-Type "application/pdf", and select a testing PDF for the actual HTTP payload. You should see the same "create" request in the message browser, but the PDF will be stored as an attachment instead, and the content of the Binary resource will be a replacement token, like "${ATTACH:efe4cd42-de30-4e80-b1d4-1e15dbd646f9}".

Finally in the HTTP response, you should get the same Location header. If you copy that URL and issue a new GET request to it, it should return the same PDF that you created previously.


Next Steps

This sample channel is intended as a starting point to teach you the basics of FHIR resources/interactions and how the FHIR Listener works with them. From here, feel free to tweak the destinations or add more as you see fit. The trial-use standard basically just tells you what to do with resources (create them, update them, etc.), and you can use Mirth Connect to customize the actual implementation however you wish.

  • No labels


  1. Hello,

    We are using the Mirth 3.7. Does this version of Mirth Example - FHIR Listener?

  2. Hello!

    I have followed the steps with (Mirth v 3.7.1 & postgreSql). But, when I try to send a message ( patient-test-file.txt ), Mirth is showing error on line

    in Source Transformer i.e interaction is null.

    var interaction = sourceMap.get('fhirInteraction');

    Any Ideas, why?



  3. Hello!


    When whenever I click on some resource for example patient or observation it get stuck. Any reason why so.



  4. I've published a bundle with Patient and other resources inside....Now how to retrieve that patient resource from that bundle alone?