Question: Can you create a transformation step for converting an HL7 v2.4 ADT_A01 message to FHIR R4 in the Mirth Connect integration engine?
ChatGPT 4o answer 2024
Certainly! Transforming an HL7 v2.4 ADT_A01 message to a FHIR R4 Patient resource in Mirth Connect requires familiarity with both HL7v2 and FHIR message structures. Below, I’ll guide you through the steps to set up a transformation channel in Mirth Connect to map an ADT_A01 message to a FHIR R4 Patient resource.
Prerequisites
- Mirth Connect installed and configured.
- Knowledge of the structure of HL7 v2.4 ADT_A01 messages.
- Understanding of the FHIR R4 Patient resource JSON structure.
Step 1: Set up the Mirth Connect Channel
- Create a New Channel in Mirth Connect and name it something like ADT to FHIR Transformation.
- Set the Source Connector to accept HL7v2 messages. This could be configured as a TCP Listener, File Reader, or other suitable source connector depending on your input source.
- Set the Destination Connector to output JSON (FHIR format). You may want to use a REST API, File Writer, or Database Writer, depending on the destination requirements.
Step 2: Configure the Source Transformer
- Go to the Source Transformer in your Mirth channel and add a new step.
- Choose JavaScript as the type for your transformation step.
Step 3: Write JavaScript for Transformation
Add the following JavaScript code to transform the HL7 ADT_A01 message to FHIR R4 Patient JSON:
// Initialize the FHIR Patient resource
var patientResource = {
resourceType: "Patient",
id: $('MSH-10'), // Unique identifier from MSH segment
identifier: [
{
system: "urn:oid:2.16.840.1.113883.4.1", // Example for MRN system OID
value: $('PID-3.1') // MRN from PID segment
}
],
active: true,
name: [
{
use: "official",
family: $('PID-5.1'), // Last Name
given: [$('PID-5.2')] // First Name
}
],
telecom: [
{
system: "phone",
value: $('PID-13.1'), // Phone Number
use: "home"
},
{
system: "email",
value: $('PID-13.4'), // Email if available
use: "home"
}
],
gender: $('PID-8') === 'M' ? 'male' : 'female', // Gender mapping
birthDate: DateUtil.formatDate($('PID-7'), 'yyyyMMdd', 'yyyy-MM-dd'), // DOB with format change
address: [
{
use: "home",
line: [$('PID-11.1')], // Address line
city: $('PID-11.3'), // City
state: $('PID-11.4'), // State
postalCode: $('PID-11.5') // ZIP/Postal Code
}
]
};
// Add managing organization if available
if ($('PV1-3.1')) {
patientResource.managingOrganization = {
reference: "Organization/" + $('PV1-3.1') // Organization reference
};
}
// Convert the JavaScript object to JSON
var fhirPatientJson = JSON.stringify(patientResource, null, 2);
// Map the JSON output to the destination
msg = fhirPatientJson;
Explanation of the Transformation Code
- Resource Initialization: The patientResource object is initialized with the necessary FHIR R4 Patient resource fields.
- Identifier: The identifier is mapped from PID-3.1 (MRN), with a sample OID for the system.
- Name: The name fields use PID-5 for last and first names.
- Telecom: Phone and email details are mapped from PID-13.
- Gender: The gender field maps ‘M’ and ‘F’ to ‘male’ and ‘female’, as per FHIR requirements.
- Birth Date: Formats the birth date from yyyyMMdd (HL7) to yyyy-MM-dd (FHIR).
- Address: Maps address components from PID-11.
- Managing Organization: Maps organization information if present from PV1-3.
Step 4: Configure the Destination Connector
- Go to the Destination Connector and set the data type to JSON if you’re outputting JSON directly.
- Use msg as the output variable, as it contains the JSON representation of the FHIR Patient resource.
- Configure the destination endpoint (such as REST API URL or file location) to send the transformed JSON message to your FHIR-compliant system.
Step 5: Test the Channel
- Deploy the channel and send a test ADT_A01 HL7 message to verify the transformation.
- Check the output in your configured destination to ensure that the JSON format conforms to FHIR R4 standards.
Additional Notes
- Testing and Validation: Use FHIR validators or online tools to ensure the output JSON complies with FHIR R4 standards.
- Enhancements: You may want to add error handling and additional mappings depending on specific fields in your ADT message or FHIR implementation requirements.
This setup will transform an incoming HL7 v2.4 ADT_A01 message into a FHIR R4 Patient resource, ready to be consumed by a FHIR-compliant system.
