No announcement yet.

XML to HL7 v2.5.1

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 ( == "RXA")
    {"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.

  • #2
    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) {"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.