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 Download section, and import the channel Convert HL7 to FHIR Patient - Example 2.xml
into your Mirth® Connect server.
Overwrite: All
link in the top-right and then click Import.
When you've imported the channel, go to the Source tab, and click Edit Transformer to view the source transformer. You will 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 will see many of the same FHIR Resource Builders from the first channel.
For example, the "Create FHIR Patient Identifier" code template creates a new function: createPatientIdentifier(pid3). The "pid3" argument is passed in, and then used in the builder properties:
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 you saw previously.
function createAndConsolidateFhirPatient(msg) {
return consolidate(cleanupFhirPatient(createFhirPatient(msg)));
}
Deploy the channel and send a sample ADT message to it (look at the Convert HL7 to FHIR Patient - Example 1 for a sample ADT). As before, you will 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!