Example Channel - rbeckman-nextgen/test-mc GitHub Wiki

  1. Mirth Connect
  2. Home
  3. FHIR Connector Extension (3.6)

Mirth Connect : Example Channel

Created by Nick Rupley, last modified on Jun 07, 2018

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

This guide is separated into the following sections:

Icon

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

https://github.com/nextgenhealthcare/fhir-example-channels

 

Importing the Example Channel

Download the channel here, according to the version of Mirth Connect you're using:

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:

PostgreSQL:

CREATE SEQUENCE resource_sequence
  INCREMENT 1
  START 1;

CREATE TABLE resource
(
  sequence_id bigint NOT NULL DEFAULT nextval('resource_sequence'::regclass),
  name character varying(255) NOT NULL,
  id character varying(255) NOT NULL,
  version integer NOT NULL,
  data xml,
  mimetype character varying(255),
  last_modified timestamp with time zone DEFAULT now(),
  deleted boolean,
  request_method character varying,
  request_url character varying,
  CONSTRAINT resource_pkey PRIMARY KEY (sequence_id),
  CONSTRAINT resource_unq UNIQUE (name, id, version)
);

 SQL Server:

CREATE TABLE resource_sequence
(
  id BIGINT NOT NULL
);

INSERT INTO resource_sequence VALUES (1);

CREATE TABLE resource
(
  sequence_id BIGINT NOT NULL,
  name NVARCHAR(255) NOT NULL,
  id NVARCHAR(255) NOT NULL,
  version INTEGER NOT NULL,
  data XML,
  mimetype NVARCHAR(255),
  last_modified DATETIMEOFFSET DEFAULT CURRENT_TIMESTAMP,
  deleted BIT,
  request_method NVARCHAR(MAX),
  request_url NVARCHAR(MAX),
  CONSTRAINT resource_pkey PRIMARY KEY (sequence_id),
  CONSTRAINT resource_unq UNIQUE (name, id, version)
);

**
**

 

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:

PostgreSQL:

# The type of database server (postgres, sqlserver).
fhirDBDatabaseType = postgres
# The JDBC Driver class to use when connecting to the FHIR database.
fhirDBDriver = org.postgresql.Driver
# The JDBC connection URL to use when connecting to the FHIR database.
fhirDBUrl = jdbc:postgresql://localhost:5432/fhirdb
# The username to use when connecting to the FHIR database.
fhirDBUsername = postgres
# The password to use when connecting to the FHIR database.
fhirDBPassword = postgres
# The maximum amount of retry attempts when a database connection fails.
fhirDBMaxRetries = 3

SQL Server:

# The type of database server (postgres, sqlserver).
fhirDBDatabaseType = sqlserver
# The JDBC Driver class to use when connecting to the FHIR database.
fhirDBDriver = net.sourceforge.jtds.jdbc.Driver
# The JDBC connection URL to use when connecting to the FHIR database.
fhirDBUrl = jdbc:jtds:sqlserver://localhost:1433/fhirdb
# The username to use when connecting to the FHIR database.
fhirDBUsername = sa
# The password to use when connecting to the FHIR database.
fhirDBPassword = admin
# The maximum amount of retry attempts when a database connection fails.
fhirDBMaxRetries = 3

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:

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

if (interaction == 'operation') {
    // Operation destinations will have a name of "$name".
    destinationSet.removeAllExcept([sourceMap.get('fhirOperationName')]);
} else if (interaction.startsWith('history')) {
    // This will match history-system, history-type, and history-instance
    destinationSet.removeAllExcept(['history']);
} else if (interaction.startsWith('search')) {
    // This will match search-system and search-type
    destinationSet.removeAllExcept(['search']);
} else {
    // All other destinations should have a name equal to the interaction
    destinationSet.removeAllExcept([interaction]);
}

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.

Attachments:

FHIR Listener.xml (text/xml)
image2018-5-18 13:25:6.png (image/png)
image2018-5-18 13:25:30.png (image/png)
FHIR Listener.xml (text/xml)
image2018-5-18 13:40:5.png (image/png)
image2018-5-18 13:54:35.png (image/png)
image2018-5-18 14:14:18.png (image/png)
image2018-5-18 14:35:28.png (image/png)
image2018-5-18 14:55:26.png (image/png)
FHIR Listener.xml (text/xml)
FHIR Listener.xml (text/xml)
patient-test-file.txt (text/plain)

Comments:

Hello,

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

Posted by rajatshetty at Apr 04, 2019 19:25

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?

 

Thanks

Posted by saqib at Apr 15, 2019 07:45

Hello!

 

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

 

Thanks

Posted by saqib at Apr 19, 2019 05:42

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

Posted by shishirakram at Jun 16, 2019 21:51

Document generated by Confluence on Nov 11, 2019 08:40

Atlassian

⚠️ **GitHub.com Fallback** ⚠️