Click here to Skip to main content
15,351,229 members
Articles / Programming Languages / C#
Posted 1 Jun 2015


7 bookmarked

Integrating HL7 into Medical Applications with LEADTOOLS

1 Jun 2015CPOL5 min read
The LEADTOOLS HL7 SDK simplifies the integration of complex HL7 standards into any healthcare application.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.


Health Level Seven (HL7) Messaging has gained widespread popularity and acceptance as a flexible standard of exchanging structured electronic health information. HL7 can enable communication and interoperability between standardized information and imaging systems such as Electronic Health Records (EHR), Hospital Information System (HIS), Radiology Information System (RIS), Laboratory Information System (LIS) and Picture Archiving and Communication System (PACS), as well as any individual practice management or front-office application used by healthcare providers for tasks such as billing and patient tracking.

Naturally, a standard capable of such immense benefit comes at a cost of a steep learning curve. Though each of these disparate applications can now talk with one another, developers must implement an interface to handle incoming and outgoing HL7 messages. The LEADTOOLS HL7 SDK simplifies the integration of complex HL7 standards into any healthcare application. Furthermore, if you have a requirement to build a DICOM/PACS solution with HL7 messaging support, LEADTOOLS includes several pre-built HL7 interfaces for updating patients and modality scheduling (MWL/MPPS). With the comprehensive medical imaging technology in LEADTOOLS, developers can create full-featured, HL7-compliant PACS in record time.

Creating and Parsing HL7 Messages with LEADTOOLS

At the core of LEADTOOLS HL7 functionality is the ability to create and parse raw HL7 messages. These text-based messages are a conglomeration of codes, values and separators such as pipes (|) and carets (^). There are over 100 message types and each has its own combination of rows and expected piped values. For example, the following is a basic HL7 message for admitting a patient. The message type (ADT_A01) identifies the message as a patient admit, and the patient's ID, Name and Sex are stored in the PID row.


There is still much to fill out such as the patient's contact information, the doctor he is seeing, his reported symptoms, etc. As you may guess, this can get confusing, especially when you factor in variations between different versions and subversions of HL7.

LEADTOOLS greatly simplifies the creation of messages like the one above with the Leadtools.Medical.HL7 namespace. Its classes and enumerations offer developers a straightforward framework for creating and parsing HL7 messages. You don't need to concern yourself with counting pipes and constantly going back and forth between the specification to make sure you don't accidentally mix up the patient's name and birth date with a single missing character. LEADTOOLS includes data models for each message type in today's most popular HL7 versions (2.6, 2.5.1, 2.3.1) which can be enumerated to generate messages in a much more human-readable fashion. The following code snippet creates an ADT_A01 message for admitting a patient and fills in some of the basic patient identification values.

// Create and cast the message to the model and create the default segments to fill in
ADT_A01 msg = (ADT_A01)Leadtools.Medical.HL7.V2x.Models.MessageFactory.New("ADT_A01", "V26");

// Set header information
msg.MSH.Sending_Application.Value = "LTHL7Demo";
msg.MSH.Sending_Facility.Value = "LEADTOOLS";
msg.MSH.Date_Time_of_Message.Value = MessageConstructor.CurTime();
msg.MSH.Message_Type.MessageCode.Value = "ADT";
msg.MSH.Message_Type.TriggerEvent.Value = "A01";
msg.MSH.Message_Control_ID.Value = UniqueId.New;
msg.MSH.Processing_ID.Value = "1";
msg.MSH.Version_ID.VersionID.Value = "2.6";

// Set Patient info
msg.PID.Patient_ID.IDNumber.Value = PatientId;
msg.PID.Patient_Name[0].FamilyName.Value = PatientLastName;
msg.PID.Patient_Name[0].GivenName.Value = PatientFirstName;

When receiving a message, LEADTOOLS can parse the raw text into the correct data model. This can then be displayed or mapped to the appropriate UI elements in your application. As shown below, it only takes a few lines of code to parse a piped message into an IHL7MessageItem which can be easily enumerated and represented in a tree view as done in the LEADTOOLS HL7 Messaging demo.

PipeMessageConverter pmc = new PipeMessageConverter();
MessageStructureConverter msc = new MessageStructureConverter();

MessageStructure ms = pmc.PipeMessageToMessageStructure(strMessage);
IHL7MessageItem msg = msc.MessageStructureToMessage(ms, 
   new MessageStructureConverter.Options() { 
      Parse_RepeatableParentGroupFirst = true, Forgive_IncompleteMessage = true 

Image 1

Figure 1: Our example ADT_A01 message created and displayed with the LEADTOOLS HL7 Messaging demo

PACS Integration

Beyond the LEADTOOLS HL7 SDK's ability to streamline the development of HL7 interfaces for EHR, HIS, RIS and more, LEADTOOLS truly flexes its muscle for developers who need to create a PACS solution with support for receiving HL7 messages. Its comprehensive PACS Framework and DICOM Storage Server offer high-level classes and OEM-ready components for developing a PACS with little effort.

As with many disparate medical applications which have given rise to the need for HL7, PACS started off as an isolated entity within a hospital or healthcare practice used for storing DICOM images. However, the value of interoperability has changed the landscape and brought PACS into the fold so it can communicate with front-office applications that manage patient information and billing. For example, a patient may not have visited their orthopedic specialist for years but now needs another X-ray or MRI. Since their previous visit they got married or moved. The receptionist's patient admittance application can send out HL7 messages to each system in the network, including the PACS, and the old records from the patient's last visit from years ago can be easily found and reviewed by the doctor during the current exam.

The LEADTOOLS DICOM Storage Server includes a Patient Updater Add-in that handles this common scenario by listening for HL7 messages sent from any application within the practice or network. Once the message is received, the values can be parsed and then submitted to the PACS image store.

public override void OnHl7Message(Leadtools.Medical.HL7.V2x.Models.IHL7MessageItem hl7msg)
   string OriginalPatientId = string.Empty;
   string PatientId = string.Empty;
   string GivenName = string.Empty;
   string FamilyName = string.Empty;
   string Sex = string.Empty;

   // Parse and decode the HL7 message
   string MessageName = MessageItemCracker.GetMessageName(hl7msg);

   if (MessageName == "ADT_A01")
      ADT_A01 msg = (ADT_A01)hl7msg;

      // Get PatientID so we know which record to update
      OriginalPatientId = PatientId = msg.PID.Patient_ID.IDNumber.Value;

      // Get values that need to change
      FamilyName = msg.PID.Patient_Name[0].FamilyName.Surname.Value;
      GivenName = msg.PID.Patient_Name[0].GivenName.Value;
      Sex = msg.PID.Administrative_Sex.Value;
      // ...other values such as Birthdate, reason, etc.

      // Update PACS with information from message

Since HL7 does not define rules for sending and receiving messages, LEADTOOLS provides the source code for this plug-in so it can be fully customized to suit the needs of any environment. The plug-in includes the ability to listen for TCP connections, but can be easily modified for other connection types or to monitor a folder of text files holding the HL7 message data.


Interoperability is a must-have in today's digital healthcare sector to lower costs and minimize risk. HL7 is well-established worldwide as the messaging standard for the exchange of patient care and clinical information, but can be a complex realm to dive into for software developers. SDKs like LEADTOOLS help programmers stay in line with HL7 compliance and not fall behind on their project deadlines. When PACS and DICOM are also on the table, LEADTOOLS' world-class imaging technology in its PACS Framework and DICOM Storage Server can be a huge game-changer for the developer. These frameworks save months of development time and give developers peace of mind while they create dynamic, modern medical applications interconnected through HL7.

Download the Full HL7 Example

You can download the fully functional demo which includes the features discussed above. To run this example you will need the following:

  • LEADTOOLS free 60 day evaluation
  • Visual Studio 2008 or later
  • Browse to the LEADTOOLS Examples folder (e.g. C:\LEADTOOLS 19\Examples\) where you can find example projects for this and many more technologies in LEADTOOLS


Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team ( or call us at 704-332-5532.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Help desk / Support LEAD Technologies, Inc.
United States United States
Since 1990, LEAD has established itself as the world's leading provider of software development toolkits for document, medical, multimedia, raster and vector imaging. LEAD's flagship product, LEADTOOLS, holds the top position in every major country throughout the world and boasts a healthy, diverse customer base and strong list of corporate partners including some of the largest and most influential organizations from around the globe. For more information, contact or
Group type: Organisation (No members)

Comments and Discussions

GeneralVariances in HL7 Pin
David Rush14-Jun-15 9:03
professionalDavid Rush14-Jun-15 9:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.