HL7 v2.x to FHIR Conversions - rbeckman-nextgen/test-mc GitHub Wiki

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

Mirth Connect : HL7 v2.x to FHIR Conversions

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:

Along with the Example Channel, we're also providing some sample code templates, transformers, and channels to help you kickstart any HL7 v2.x to FHIR conversions you need to do.

Icon

The code made available here is not guaranteed to work 100% in all cases! As with any HL7 interface, some extra tweaks are usually needed to ensure that it fits your specific workflow.

 

This page is separated into the following sections:

Icon

These examples are also hosted on our public GitHub repository! Contribute and collaborate with us to make them even better!

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

 

Downloads

Overview

If you've never worked with FHIR before, converting HL7 v2.x messages to FHIR resources may seem a daunting task. However the FHIR documentation actually provides a lot of useful information that can cover most of the broad strokes.

For the examples in this section, we're going to be looking at taking an HL7 v2.x ADT, and creating a FHIR Patient resource that represents the demographic information present in the message.

From the Patient documentation page, click on Mappings, and search for "HL7 v2". Or go directly to this link: http://hl7.org/fhir/STU3/patient-mappings.html#v2

You'll see that most of the FHIR resource properties have corresponding HL7 v2.x segment and field mappings. For example, the Patient.identifier property is mapped to the PID-3 field. But how exactly does each individual PID-3 component map into the identifier property?

Return to the Content tab, and look at the structure of the resource. You'll see that the "identifier" property is of type Identifier.

Click on Identifier to navigate to the documentation page for that data type: http://hl7.org/fhir/STU3/datatypes.html#Identifier. Then click on Mappings to view the HL7 v2.x mappings for that data type: http://hl7.org/fhir/STU3/datatypes-mappings.html#Identifier

This should give you enough information to be able to map pieces of the HL7 message into the corresponding FHIR resource properties. To see how, read on...

Convert HL7 to FHIR Patient - Example 1

Download the "Convert HL7 to FHIR Patient - Example 1.xml" file from the Downloads section, and import the channel into your Mirth Connect server.

This channel includes the "HL7 v2.x to FHIR Helper Functions" code template library. If you already have that library imported, you may see a dialog asking whether or not you want to overwrite the library. To overwrite the library and all of its code templates, click the "Overwrite: All" link in the top-right, and then click Import.

If you don't want to overwrite any libraries or code templates, click Cancel, then Yes when prompted to continue without importing. Then make sure the library is enabled for your newly imported channel:

 

Once you've imported the channel, go to the Source tab, and click Edit Transformer to view the source transformer. You'll see quite a few Iterator steps with FHIR Resource Builders. These are dynamically creating the identifiers, names, telecoms, etc. that will go into the final Patient resource. For example, step 0-0 "Create Identifier" handles the creation of a single Identifier data type:

The parent Iterator step will loop through each PID-3 field, create a new Identifier for the field, and add it to an array. We use the name "identifiers" and store it as a local variable. That means that the variable "identifiers" will only be accessible in this transformer. This variable is used later on in step 9, "Create Patient":

In this example we're also storing the Patient object as a local variable, "patient". The final step calls a couple of helper methods in the code template library to consolidate and cleanup any properties in the Patient that were empty or non-valued.

msg = consolidate(cleanupFhirPatient(patient));

Check out the "HL7 v2.x to FHIR Helper Functions" library if you're wondering what exactly those code templates are doing.

 

Deploy the channel, and send a sample ADT message through it:

MSH|^~\&|ADT1|SHM|SHMADT|SHM|200812091126|SECURITY|ADT^A01^ADT_A01|MSG00001|P|2.5|
EVN|A01|200812091126||
PID|1|1001|1001^5^M11^ADT1^MR^SHM~123456789^^^USSSA^SS||OHALLAHAN^COLLEEN^^||19850704|F||2106-3|1200 N ELM STREET^^NEWPORT BEACH^CA^92660-1020^US^H|OC|(949) 555-1234|(949) 555-5678||S||PATID1001^2^M10^ADT1^AN^A|123456789|U1234567^CA|
NK1|1|O'HALLAHAN^BRITTANY^M|SIS^SISTER||||N^NEXT-OF-KIN
PV1|1|I|2000^2012^01||||001122^ZOIDBERG^JOHN^|||SUR||||1|A0|

If you look at the Source Encoded data or the Destination Raw data, you'll see that it has been converted into a FHIR JSON resource!

{
  "resourceType" : "Patient",
  "identifier" : [
    {
      "type" : {
        "text" : "MR"
      },
      "system" : "ADT1",
      "value" : "1001"
    },
    {
      "type" : {
        "text" : "SS"
      },
      "system" : "USSSA",
      "value" : "123456789"
    }
  ],
  "name" : [
    {
      "use" : "usual",
      "family" : "OHALLAHAN",
      "given" : [
        "COLLEEN"
      ]
    }
  ],
  "telecom" : [
    {
      "system" : "phone",
      "value" : "(949) 555-1234",
      "use" : "home"
    },
    {
      "system" : "phone",
      "value" : "(949) 555-5678",
      "use" : "work"
    }
  ],
  "gender" : "female",
  "birthDate" : "1985-07-04",
  "deceasedBoolean" : false,
  "address" : [
    {
      "use" : "home",
      "text" : "1200 N ELM STREET  NEWPORT BEACH CA 92660-1020 US",
      "line" : [
        "1200 N ELM STREET"
      ],
      "city" : "NEWPORT BEACH",
      "state" : "CA",
      "postalCode" : "92660-1020",
      "country" : "US"
    }
  ],
  "maritalStatus" : {
    "text" : "S"
  },
  "multipleBirthBoolean" : false,
  "contact" : [
    {
      "relationship" : [
        {
          "text" : "SISTER",
          "id" : "SIS"
        },
        {
          "text" : "NEXT-OF-KIN",
          "id" : "N"
        }
      ],
      "name" : {
        "use" : "usual",
        "family" : "O'HALLAHAN",
        "given" : [
          "BRITTANY",
          "M"
        ]
      },
      "gender" : "unknown"
    }
  ]
}

Convert HL7 to FHIR Patient - Example 2

The first example channel used the FHIR Resource Builder transformer step to create a FHIR Patient resource from an HL7 ADT. This next channel will do the same thing, but using code templates instead. The advantage to using code templates is that you can re-use the same code/builder across multiple transformers, connectors, and channels.

Download the "Convert HL7 to FHIR Patient - Example 2.xml" file from the Downloads section, and import the channel into your Mirth Connect server.

Icon

This channel includes both the "HL7 v2.x to FHIR Helper Functions" and "HL7 v2.x to FHIR Creation Functions" code template libraries. Follow the instructions in the previous section to make sure you have both of these libraries linked to your newly imported channel.

 

Once you've imported the channel, go to the Source tab, and click Edit Transformer to view the source transformer. You'll see that now there's only a single, simple Message Builder step:

To actually see what's happening, go back to the Channels view, then click "Edit Code Templates" to enter the Code Templates view. In the "Creation Functions" library, you'll see many of the same FHIR Resource Builders that we saw from the first channel.

For example, the "Create FHIR Patient Identifier" code template creates a new function: createPatientIdentifier(pid3). The "pid3" argument gets passed in, and then used in the builder properties:

To handle iterating through multiple segments/fields, separate code templates are created. For example, the "Create FHIR Patient Identifiers" code template takes in a PID segment, iterates through all PID-3 fields, and returns an array of FHIR Identifier objects:

function createPatientIdentifiers(pid) {
    var identifiers = Lists.list();
    for (var i = 0; i < pid['PID.3'].length(); i++) {
        identifiers.add(createPatientIdentifier(pid['PID.3'][i]));
    }
    return identifiers.toArray();
}

The "Create FHIR Patient" code template brings it all together to construct the Patient resource. Then finally, the "Create and Consolidate FHIR Patient" code template calls the createFhirPatient method, and then also does the cleanup and consolidation that we saw before.

function createAndConsolidateFhirPatient(msg) {
    return consolidate(cleanupFhirPatient(createFhirPatient(msg)));
}

Deploy the channel and send a sample ADT message to it (look at the previous section for a sample ADT). As before, you'll see that the Source Raw data is the HL7 ADT, and the Source Encoded / Destination Raw data is the JSON representation of the FHIR Patient resource!

Next Steps

As with the FHIR Listener Example Channel, these sample code templates and channels are only meant to be a starting point. You will likely need to tweak them in order to fit your specific use-cases. The FHIR documentation pages are a great starting place to see how the HL7 to FHIR mapping should take place. Perhaps try building on these examples to also create an associated Encounter resource from the ADT!

Attachments:

HL7 v2.x to FHIR Helper Functions.xml (application/x-upload-data)
HL7 v2.x to FHIR Creation Functions.xml (text/xml)
Transformer - Convert HL7 v2.x to FHIR Patient.xml (text/xml)
Convert HL7 to FHIR Patient - Example 1.xml (text/xml)
Convert HL7 to FHIR Patient - Example 1.xml (text/xml)
Convert HL7 to FHIR Patient - Example 2.xml (text/xml)
image2018-5-24 11:57:41.png (image/png)
image2018-5-24 12:2:4.png (image/png)
image2018-5-24 12:49:55.png (image/png)
image2018-5-24 12:50:2.png (image/png)
image2018-5-24 13:2:27.png (image/png)
image2018-5-24 13:7:59.png (image/png)
image2018-5-24 13:11:15.png (image/png)
image2018-5-24 13:25:11.png (image/png)
image2018-5-24 13:31:0.png (image/png)

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

Atlassian

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