Template-Driven HL7 → FHIR Conversion¶
The fastest way to produce a FHIR resource from an HL7 v2 message is to store a JSON template of the resource as a System Variable with embedded node tags, then call qie.evaluateTemplate() from a mapping node to substitute the source values. The template is written once and re-used across every channel that produces that resource type.
A minimal Patient template stored as a System Variable named PatientTemplate looks like this:
{
"resourceType": "Patient",
"id": "/*{s:PID-3.1}*/",
"identifier": [
{ "system": "urn:oid:1.2.3.4.5", "value": "/*{s:PID-3.1}*/" }
],
"active": true,
"name": [
{
"use": "official",
"family": "/*{s:PID-5.1}*/",
"given": [ "/*{s:PID-5.2}*/", "/*{s:PID-5.3}*/" ]
}
],
"gender": "/*{s:PID-8}*/",
"birthDate": "/*{s:PID-7}*/",
"address": [
{
"line": [ "/*{s:PID-11.1}*/" ],
"city": "/*{s:PID-11.3}*/",
"state": "/*{s:PID-11.4}*/",
"postalCode": "/*{s:PID-11.5}*/",
"country": "/*{s:PID-11.6}*/"
}
]
}
The /*{ ... }*/ wrappers are JSON-safe node tags. The comment markers keep the template parseable as JSON in editors and validators, and QIE strips them at evaluation time. The s: prefix reads from the Source message; use m: for the working Message or mc: for the messageCache.
The mapping-node script that applies the template is short:
var patient = qie.evaluateTemplate(
qie.getVariable('PatientTemplate'), // template
null, // parameters
null, // escapeFor
true // isJSON
);
message = qie.createJSONMessage('{}');
message.setNode('/', patient);
The fourth argument (isJSON = true) tells QIE to escape substituted values for JSON. Special characters in PID-5.1 like quotes or backslashes are escaped so the produced JSON stays well-formed.
For a step-by-step build of an end-to-end channel that ingests an ADT message and POSTs a Patient resource to a public FHIR sandbox, see HL7 v2 to FHIR with a Template in the FHIR Quickstart.