Question
· Oct 1, 2017

Convert HL7 to XML

Hi We have a need in our Ensemble production to take HL7 ver 2.3 and provide an XML representation of it to provide to non-HL7 consumers. What would be the prefereed way to do it. Are there are pre-defined XML schemas in Ensemble that could be use ? We are currently on Ensemble 2015.2

Discussion (2)0
Log in or sign up to continue

One way of doing it.. In my opinion its ugly to read but it accomplishes what you require..

set ioOutStream = ##class(%IO.StringStream).%New()

do ##class(EnsLib.HL7.Util.FormatSimpleXMLv2).OutputDocument(sourceHL7Message, .st, ioOutStream, sourceHL7Message.Separators)
for segCount=1:1:sourceHL7Message.SegCountGet()
{
    set segment = sourceHL7Message.GetSegmentAt(segCount, .st)
    quit:$$$ISERR(st)
    do ##class(EnsLib.HL7.Util.FormatSimpleXMLv2).OutputSegment(segment, .st, ioOutStream, sourceHL7Message.Separators, segCount, segment.Name, sourceHL7Message)
}

do ##class(EnsLib.HL7.Util.FormatSimpleXMLv2).OutputDocumentEnd(sourceHL7Message, .st, ioOutStream, sourceHL7Message.Separators)

set sourceXMLStream = ##class(%Stream.GlobalCharacter).%New()
do sourceXMLStream.CopyFrom(ioOutStream)

The sourceXMLStream contains XML like...

<SimpleHL7v2 TypeName="MDM_T02" Identifier="GUID-MESSAGE-ID" SegCount="8" Description="Medical document management - Original document notification and content">
<Segment Index="1" Name="MSH" FieldCount="19" SegPath="MSH">
        <Field Index="1">|</Field>
        <Field Index="2">^~\&amp;</Field>
        <Field Index="3">MEDISOFT</Field>
        <Field Index="4">OPTH</Field>
        <Field Index="7">20151106103857</Field>
        <Field Index="9">
                <Component Index="1">MDM</Component>
                <Component Index="2">T02</Component>
        </Field>
        <Field Index="10">GUID-MESSAGE-ID</Field>
        <Field Index="11">P</Field>
        <Field Index="12">2.4</Field>
</Segment>

<Segment Index="2" Name="EVN" FieldCount="5" SegPath="EVN">

        <Field Index="2">20151106103855</Field>

</Segment>...

Hi!

HL7 has an XML Schema that you can import as Ensemble classes. You can use these classes to implement your business services and operations web services. Here is the XML schema link.

Another way of using this XML Schema is not to import them as classes. Instead, use the XML Schema importing tool we have on Ensemble Management Portal and use EnsLib.EDI.XML.Document with it. You could receive plain XML text and transform it into an EnsLib.EDI.XML.Document. It will be faster to process than to transform it to objects. If you are interested, I can share some code.

All that being said, I strongly suggest NOT TO DO ANY OF THIS.

HL7v2 XML encoding isn't used anywhere and the natural reasoning behind using it is just ridiculous. If you are asking someone to support HL7v2 and they are willing to spend their time implementing the standard, then explain to them that it is best for them to simply implement it the way 99% of the world uses it: with the normal |^~& separators. It's a text string that they can simply embed into their web service call.

There are these two XML encoding versions:

  •  EnsLib.HL7.Util.FormatSimpleXMLv2 - provided by Ensemble (example you have already on this post)
  • The XML encoding from HL7 itself (link I gave you above) 

Both encodings are horrible since they won't give you pretty field names that you can simply transform into an object and understand the meaning of the fields just by reading their names. Here is what an class generated from the standard HL7v2 XML Schema looks like (the PID segment):

Class HL7251Schema.PID.CONTENT Extends (%Persistent, %XML.Adaptor) [ ProcedureBlock ]
{

Parameter XMLNAME = "PID.CONTENT";

Parameter XMLSEQUENCE = 1;

Parameter XMLTYPE = "PID.CONTENT";

Parameter XMLIGNORENULL = 1;

Property PID1 As HL7251Schema.PID.X1.CONTENT(XMLNAME = "PID.1", XMLREF = 1);

Property PID2 As HL7251Schema.PID.X2.CONTENT(XMLNAME = "PID.2", XMLREF = 1);

Property PID3 As list Of HL7251Schema.PID.X3.CONTENT(XMLNAME = "PID.3", XMLPROJECTION = "ELEMENT", XMLREF = 1) [ Required ];

Property PID4 As list Of HL7251Schema.PID.X4.CONTENT(XMLNAME = "PID.4", XMLPROJECTION = "ELEMENT", XMLREF = 1);

You see? No semantics. Just structure. So, why not simply send the HL7v2 standard text through your Web Service or HTTP service? Here are the advantages of using the standard HL7v2 text encoding instead of the XML encoding:

  • You will all be working with the HL7 standard as 99% of the world that uses HL7v2 does instead of trying to use something that never caught up (XML encoding)
  • Ensemble brings Business Services and Business Operations out of the box to receive/send HL7v2 text messages through TCP, FTP, File, HTTP and SOAP. So you wouldn't have to code much in Ensemble to process them.
  • It takes less space (XML takes a lot of space)
  • It takes less processing (XML is heavier to parse)
  • Using the XML schema won't really help you with anything since both XML encoding systems provide just a dumb structure for your data, without semantics.

Kind regards,

AS

Class HL7251Schema.PID.CONTENT Extends (%Persistent, %XML.Adaptor) [ ProcedureBlock ]
{

Parameter XMLNAME = "PID.CONTENT";

Parameter XMLSEQUENCE = 1;

Parameter XMLTYPE = "PID.CONTENT";

Parameter XMLIGNORENULL = 1;

Property PID1 As HL7251Schema.PID.X1.CONTENT(XMLNAME = "PID.1", XMLREF = 1);

Property PID2 As HL7251Schema.PID.X2.CONTENT(XMLNAME = "PID.2", XMLREF = 1);

Property PID3 As list Of HL7251Schema.PID.X3.CONTENT(XMLNAME = "PID.3", XMLPROJECTION = "ELEMENT", XMLREF = 1) [ Required ];

Property PID4 As list Of HL7251Schema.PID.X4.CONTENT(XMLNAME = "PID.4", XMLPROJECTION = "ELEMENT", XMLREF = 1);