Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

Resolving Common BizTalk HL7 Issues

Kevin Morillo

I have often run into the same errors in my time developing BizTalk HL7 applications to interface with various HL7 EHR systems.  These errors stem from using out of the box BizTalk maps to transform HL7 messages using the Microsoft BizTalk Accelerator for HL7.  Here are two of the errors that I have come across that others might have too…

1. Error happened in body during serialization

Error happened in body during serialization
Error # 1

Alternate Error Number: 301
Alternate Error Description: XmlReader not positioned at root elment of ‘ADT_A01_25_GLO_DEF’
Alternate Encoding System: HL7-BTA

This error is thrown by the BizTalk HL7 assembler pipeline BTAHL72XSendPipeline.  The pipeline is stating that it was unable to recognize the first few characters of the HL7 XML message sent to the pipeline.  This is caused by the existence of the XML declaration at the top of the message produced in a BizTalk transform shape, assignment shape, or in a helper class.

<?xml version="1.0" encoding="utf-8"?>

In my case, when creating an HL7 message in a helper class I used an XmlWriter to aid in executing a map through c# instead of orchestration transform shape.  The resolution was to add an XmlWriterSettings object with the ‘OmitXmlDeclaration’ setting set to true.  However, there are many other ways to remove the XML declaration.

VirtualStream output = new VirtualStream();
XmlWriterSettings s = new XmlWriterSettings();
<strong>s.OmitXmlDeclaration = true;</strong>

using (XmlWriter outputWriter = XmlWriter.Create(output, <strong>s</strong>))
    //transform code here


2. Extra line breaks in HL7 message created by BizTalk

One common error is the existing of many line breaks when trying to assemble a message using the BTAHL7 2X Send Pipeline.














This is caused by the empty XML elements within the source XML document sent to the send port pipeline.


There are two ways to fix this.  One is to change the BizTalk map to prevent the transfer of empty elements.  The other is to remove all empty elements from the XML message in C#.  Using a lambda expression against an XDocument is a simple way to do this:

public static string RemoveEmptyNodes(string xml)
XDocument xd = XDocument.Parse(xml);
xd.Descendants().Where(e => e.IsEmpty || String.IsNullOrWhiteSpace(e.Value)).Remove();
return xd.ToString();

As you can see, using BizTalk‘s out of the box functionality with the Microsoft HL7 Accelerator for BizTalk may present some small issues, though they can be easily resolved.


Tags: BizTalk, hl7,

Related Articles

BizTalk SQL Time format
Common BizTalk Deployment Issues & Solutions

1 Comment. Leave new

I spent today researching in depth the issue causing the problem behind #2 with extra line breaks being injected into the HL7 message when there are empty nodes in the mapped document. What I found is that this is not actually the cause and in fact the HL7Assembler in BizTalk does not inject these values into the content.

If you set a pipeline component before the HL7Assembler and attach to it’s process or simply attach to the HL7Assembler and debug it’s code in Visual Studio you’d see that the data being received by the assembler and or first component contains a newline in the field.

In my case the problem was caused by the xml content getting formatted for readability by a BizTalk orchestration. This occurred when creating an xml document in C# code and assigning it to an XmlDocument message in the orchestration as follows.

XmlDocumentMessage = Class.MethodToGetXmlDocument();

After troubleshooting I found that if assigned in the following manner the BizTalk orchestration does not format the xml document for readability and therefore no newlines are injected into the content.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>