web stats
XML to HL7 v2.5.1 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 05-25-2018, 03:41 AM
gojoshi gojoshi is offline
OBX.1 Kenobi
Join Date: Jul 2013
Posts: 50
gojoshi is on a distinguished road
Default XML to HL7 v2.5.1

Hello Everyone,

I've been trying to convert an XML message to HL7 v2.5.1, but has not worked out..

I get an XML response from my end point in the below format:

<S:Envelope >
<return>HL7 message Goes Here </return>

I need to modify the HL7 message from the above XML response.

I found a code that Nick Rupley had posted here, which works as expected, and converts the message to XML -here:

Using Nicks code, I wrote the following:

if (msg.*::['Body'].*::['submitSingleMessageResponse'].*::['return'].toString().length > 0)
var xmlMsg = new XML(SerializerFactory.getHL7Serializer().toXML(msg .*::['Body'].*::['submitSingleMessageResponse'].*::['return'].toString()));

var hl7Msg = SerializerFactory.getSerializer('HL7V2').fromXML(x mlMsg);
for each (seg in hl7Msg.children())
if (seg.name().toString() == "RXA")
logger.info("Found RXA");

When I run the above code, I get -
TypeError: Cannot find function children in object MSH|^~\&|...Rest of HL7 message...

It sees the content of the variable "hl7Msg" as a string...

If anyone can please advise on how to resolve this, it would be greatly appreciated.
Reply With Quote
Old 05-25-2018, 06:22 AM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,159
agermano is on a distinguished road

var hl7String = msg.*::['Body'].*::['submitSingleMessageResponse'].*::['return'].toString();
if (hl7String.length > 0) {
  var xmlString = SerializerFactory.getSerializer('HL7V2').toXML(hl7String);
  var xmlMsg = new XML(xmlString);

  if (xmlMsg.RXA.length() > 0) {
    logger.info("Found RXA");
  // not needed unless you want to modify the hl7 message and convert it back to a string
  var hl7String2 = SerializerFactory.getSerializer('HL7V2').fromXML(xmlMsg);
The thing to remember is that the serializers convert from one string type to another string type. Calling new XML() on an xml string will convert it to an xml object that you can manipulate. Passing an xml object to the serializer, as is done in the last line of the code, calls an implicit toString() on the object.
Reply With Quote

string, string function, string to hl7, xml, xml to hl7

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 01:56 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation