Sidebar

Converting HL7 message to XML

0 votes
936 views
asked Sep 13, 2019 by jason-d-8641 (120 points)
Is it possible to map a HL7 message and then convert it to XML with the changes from the mappings?

1 Answer

0 votes

Yes, this can be done within QIE.

When making this change it is helpful to keep in mind that there are two objects created when a message is received. One is the 'Source' and the other is 'Message'. Initially, both objects are exactly the same and hold a copy of the message received. 

There are two ways to accomplish this task. For simple XML files, it may be easier to map each field in the HL7 message separately as follows.

Step one is to convert the message object from an HL7 message type to XML.

message = qie.createXMLMessage("<Patient></Patient>", 'UTF-8');

Step two is then to map the source HL7 Nodes to the XML XPATH. Here is an example line of code that copies the patient id to the XML patient identifier node path.

message.setNode("/Patient/identifier/@value", source.getNode("PID-3"));

 

The second way and for more complex XML messages it is often easier to create a template representing the new XML message which is saved as a System Variable and then adding Node Tags in the template that reference the HL7 fields.

Example Template:

<patient id="{PID-2}" mrn="{PID-3}" timestamp="{SYSTEM_DATE[yyyy-MM-dd hh:mm:ss]}">
  <demographics>
    <nameGiven>{PID-5.2}</nameGiven>
    <nameFirst>{PID-5.1}</nameFirst>
    <birthDate>{PID-7}</birthDate>
    <ssn>{PID-19}</ssn>
  </demographics>
</patient>

And the finial step is to evaluate the template and create the XML message. First we get the template and pass it the qie.evaluateTemplate function. This function is what replaces the HL7 Node Tags with the data from a given message. Then we create the message object with the new XML message. 

message = qie.createXMLMessage(qie.evaluateTemplate(qie.getVariable('HL7toXML Template')), 'UTF-8');

 

Both examples are available in the channel download link below and can be imported into QIE for testing. 

Sample HL7 to XML Channel

If you do not have QIE installed a free version can be acquired and installed here.

answered Sep 13, 2019 by amanda-w-3695 (4,840 points)
edited Sep 20, 2019 by gary-t-8719
...