Actual Problem :
HL7 file coming out of HL7 Accelerator is having empty new line character in-between segments.
Segment looked like
ORC|RE|
^XXX|123454^^12234^L||CM||^^^^20120823120000||20120823120000|||1104869304^Doctor^hello^J^^^^^^^^^
Cause for this problem.
The XML file that was fed into HL7 Accelerator had as new line character in those elements
<ORC_2_PlacerOrderNumber><EI_0_EntityIdentifier> {cr}{lf}
</EI_0_EntityIdentifier>
</ORC_2_PlacerOrderNumber>
Solution :
Pass the XML through xslt transformation before sending it to HL7 accelerator
Here is the code that does the transformation.
public static String xslRemoveEmptyNodes(String xdoc)
{
string strXmlOutput = xdoc;
try
{
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xdoc);
string xslstring = @"<xsl:stylesheet version=’1.0′ xmlns:xsl=’http://www.w3.org/1999/XSL/Transform’>
<xsl:output method=’xml’ omit-xml-declaration=’yes’ indent=’yes’/>
<xsl:template match=""node()|@*"">
<xsl:copy>
<xsl:apply-templates select=""node()|@*""/>
</xsl:copy>
</xsl:template>
<xsl:template match=""*[not(@*) and not(*) and not(text()) ]""/>
</xsl:stylesheet>";
Stream xslOutStream = new MemoryStream();
StringWriter writer = new StringWriter();
using (XmlReader reader = XmlReader.Create(new StringReader(xslstring)))
{
XslCompiledTransform myXslTransform;
myXslTransform = new XslCompiledTransform();
myXslTransform.Load(reader);
myXslTransform.Transform(xDoc, null, writer);
}
strXmlOutput = writer.ToString();
int index = strXmlOutput.IndexOf("<ns1:") < 0 ? 0 : strXmlOutput.IndexOf("<ns1:");
strXmlOutput = strXmlOutput.Substring(index);
}
}
Errors encountered during the process
Alternate Error Number: 301
Alternate Error Description: XmlReader not positioned at root elment of ‘ORU_R01_24_GLO_DEF’
Alternate Encoding System: HL7-BTA
Fix for this Error
Add a line <xsl:output method=’xml’ omit-xml-declaration=’yes’ indent=’yes’/> in your xslt transformation.