Welcome Guest! To enable all features, please Login or Register.



Last Go to last post Unread Go to first unread post
#1 Posted : Friday, April 28, 2017 9:59:14 AM(UTC)


Groups: Registered, Tech Support, Administrators
Posts: 71

Was thanked: 4 time(s) in 3 post(s)

Attached is a simple sample application developed in Visual Studio 2017 using .NET 4.5.2 that demonstrates how you can use LEADTOOLS to parse HL7 messages and retrieve each individual value from the message. This application assumes that you already have the LEADTOOLS Medical SDK installed and references the DLLs from the default installation directory:

<Install Directory>\LEADTOOLS 19\Bin\Dotnet4\Win32

In this application, the PipeMessageConverter, MessageStructure, MessageStructureConverter, and IHL7MessageItem classes are used to take in the HL7 message as a string and provide you with an IHL7MessageItem object that contains all the data that was parsed from the string:


PipeMessageConverter pmc = new PipeMessageConverter();
MessageStructure ms = pmc.PipeMessageToMessageStructure(@"MSH|^~\&|||||201302060735||ORM^O01||T|2.3.1|||
   OBR||12345|RA20130206|R PEL AP||||||||||||99999^ER^DOC|||273135625|||||RA||||||dfdfdf|sfsfsdfsd sdf fdf fdsf|||||201302061000|
MessageStructureConverter msc = new MessageStructureConverter();
IHL7MessageItem hl7msg = msc.MessageStructureToMessage(ms, new MessageStructureConverter.Options() { Add_NoneStandardSegmentToRoot = true, Ignore_NoneStandardSegment = true, Parse_RepeatableParentGroupFirst = true, Forgive_IncompleteMessage = true }).Message;


At this point we have the individual HL7 nodes and now we just need to loop through the nodes and retrieve each data field. For this we will use the INodeItem interface:


static void GetAllItems(INodeItem nodeItem)
   foreach (INodeItem sub in nodeItem.Nodes)

static void FindFields(INodeItem nodeItem)
   if (nodeItem.Fields.Count == 0)

   for (int seq = 0; seq < nodeItem.Fields.Count; seq++)
      for (int rep = 0; rep < nodeItem.Fields[seq].Repetitions.Count; rep++)
         IField f = nodeItem.Fields[seq].Repetitions[rep];

         if (!f.IsEmpty)
            Console.WriteLine(nodeItem.ToString() + "   " + (seq + 1).ToString() + "   " + f.Value.ToString());

         if (f.HasSubComponents)
               string DeepValue = f.DeepValue;
               if (!string.IsNullOrEmpty(DeepValue))
                  Console.WriteLine(nodeItem.ToString() + "   " + (seq + 1).ToString() + "   " + DeepValue.ToString());

The demo prints out each field that is retrieved and its information to the console (node name, sequence number, and value), but at that point you have the individual values and their corresponding attributes so you can store them as needed.
File Attachment(s):
SimpleHL7Parser.zip (12kb) downloaded 294 time(s).
Aaron Brasington
Developer Support Engineer
LEAD Technologies, Inc.


Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2019, Yet Another Forum.NET
This page was generated in 0.079 seconds.