DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Data Engineering
  3. Data
  4. FHIR Connector Implementation Using Mirth: HL7 Standard Data Exchange

FHIR Connector Implementation Using Mirth: HL7 Standard Data Exchange

Let's take a look at the FHIR connector implementation using Mirth and also explore the HL7 standard data exchange.

Shailesh Chaudhary user avatar by
Shailesh Chaudhary
·
Sep. 07, 18 · Tutorial
Like (2)
Save
Tweet
Share
18.91K Views

Join the DZone community and get the full member experience.

Join For Free

fhir (fast healthcare interoperability resources) is a new set of hl7 healthcare standards. its main focus is on the ease of implementation, based on restful http using xml or json. components called "resources" are used to store and exchange data between systems.

since mirth connect has http connectors and supports xml/json data, you might have already guessed that creating a fully-compliant fhir implementation has already been completely possible. what this extension provides is an even easier way for you to kick-start your new interface.

the fhir listener connector acts much like an http listener but also includes an assortment of fhir-specific settings as well as some helper/utility classes for working with responses. there is also an fhir sender destination connector and a new fhir resource builder available as both a transformer step type and code template type.

note: before implementing fhir connector, you need to download the fhir listener according to the version of mirth connect you are using.

firstly, we need to open 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.

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 set up 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-instancedestinationset.removeallexcept(['history']);} else


if


(interaction.startswith('search')) {// this will match search-system and search-typedestinationset.removeallexcept(['search']);} else


{// all other destinations should have a name equal to the interactiondestinationset.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 read 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, the 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. know more about mirth it solutions, https://www.tactionsoftware.com/healthcare-software-solutions/mirth-hl7-consulting/ read more as a mirth developer http://www.mirthcorp.com/community/wiki/display/mirth/example+channel

Connector (mathematics) Data (computing) Implementation Data exchange Database connection Requests

Published at DZone with permission of Shailesh Chaudhary. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Collaborative Development of New Features With Microservices
  • Strategies for Kubernetes Cluster Administrators: Understanding Pod Scheduling
  • What’s New in the Latest Version of Angular V15?
  • Top 11 Git Commands That Every Developer Should Know

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: