BizTalk: Log HL7 Parsing Errors

HL7 Disassembler writes parsing errors in windows event log and there is no documented way to get those error through code to log in custom database or some other data store.

Here is what HL7 pipeline writes into event log:

SNAGHTML1c204d9

we can get these error in code by writing a wrapper disassembler component on top of HL7 OOTB Disassembler

Omitting details about how to write a custom pipeline component, we just need to override Disassemble and GetNext methods

  public HL7DASM()
        {
            HL7Dasm = new HL72fDasm();
        }
      public new void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            HL7Dasm.Disassemble(pContext, pInMsg);
        }

If HL7 party is configured to return ACKs, GetNext() method will execute multiple times.

public new IBaseMessage GetNext(IPipelineContext pContext)
        {
            IBaseMessage msg = HL7Dasm.GetNext(pContext);

            if (msg != null && !msg.BodyPart.Data.CanSeek)  //if parsing fails, stream is not seekable
            {

                 FieldInfo ParserErrorField = HL7Dasm.GetType().GetField("mBodyErrors", BindingFlags.NonPublic | BindingFlags.Instance); 
var ParserError = (System.Collections.ArrayList)ParserErrorField.GetValue(HL7Dasm);
              
StringBuilder errorList = new StringBuilder();

                foreach (HL7Error error in ParserError)
                   {
                     errorList.AppendLine(error.ToString());
                   }
    // now errorList string contains all parsing errors details in same format as in windows event log
                }
              }
            return msg;
        }

 

About these ads
Posted in BizTalk. 1 Comment »

One Response to “BizTalk: Log HL7 Parsing Errors”

  1. Dheer Says:

    HI,
    This is really a nice post .. I am also trying to do that same but not able to get the things working .. can you please provide me the entire code of this component.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: