In this answer, I will give an example of using a template to create the new JSON message. For this example, we will use the following HL7 message:
MSH|^~\&|TEST|TEST000^E IM|EssexArchives|E IM|20120925173019||ADT^A04|1664213420006120|P|2.3.1|||NE|NE
EVN|A04|20120925173019
PID|1||661||Mouse^Minnie^S||19610301|F||B|6790 Oak St^^Plano^IL^60448^USA||^^^mmouse@mbc.com|(214) 669-0123 [123]||M|||237-12-9812|||N
PD1||||^Bailey^Todd^R^MD
NK1|1|""|E|3330 Keller Springs^^Carrollton^TX^75006|9725551212||||||||
NK1|1|Casey^Ben^G^MD|O|3790 W. First St^^Dallas^TX^75248|2146622000|2146621249|||||||Medical Clinic, PC
NK1|2|Bailey^William^R^MD|O|3790 West First Street^^Dallas^TX^75248|2145551211|2145551299|||||||Medical Clinic, PC
NK1|3|Pene^J^S^MD|O|123 Forget St^^Manchester^TX^75002|2145551212||||||||Medical Health Group
PV1|1|O|^^^E IM|||||^Pene^J^S
IN1|1||Aetna Life and Casualty|Aetna Life and Casualty|P O Box 1458^^Carrollton^TX^75006||(972) 662-1350||||||||P||S|||||||||||||||||||237129812
IN1|2||United Health Care SLCity|United Health Care SLCity|P O Box 30555^^Salt Lake City^UT^84130||(888) 267-3520||||||||S||S|||||||||||||||||||237129812
Now we create a new system variable that will be our template. Note in the template we are using node tags to identify the data that will be used in the template. In this case, I named the variable 'patient'.
{
"resourceType" : "Patient",
"identifier" : "/*{PID-3}*/",
"active" : null,
"name" : "/*{PID-5.2}*/ /*{PID-5.3}*/ /*{PID-5.1}*/",
"telecom" : "/*{PID-14}*/",
"gender" : "/*{PID-8}*/",
"birthDate" : "/*{PID-7}*/",
"deceasedBoolean" : null,
"deceasedDateTime" : null,
"address" :{
"resourceType" : "Address",
"use" : "home",
"type" : "physical",
"text" : "/*{PID-11}*/",
"line" : ["/*{PID-1.1}*/"],
"city" : "/*{PID-11.3}*/",
"district" : null,
"state" : "/*{PID-11.4}*/",
"postalCode" : "/*{PID-11.5}*/",
"country" : "USA",
"period" : null
},
"contact" : [{
"relationship" : null,
"name" : null,
"telecom" : {
"resourceType" : "ContactPoint",
"system" : "phone",
"value" : "/*{PID-14}*/",
"use" : "home",
"rank" : "1"
}
}],
"careProvider" : "/*{PD1-4}*/",
"managingOrganization" : "South Side Clinic"
}
Now in my first mapping node, I will add the following code to load this template and have QIE convert the node tags in the template to the data from the message.
example code:
var value = qie.evaluateTemplate(qie.getVariable('patient'), null, null, true);
message.setNode('/', value);
message.formatJSON(3);