HL7 Tutorial Part Two: Understanding HL7 Message Structure

The second video in the series of HL7 Messaging tutorials where we examine the structure of HL7 Messaging. This is the key tutorial for understanding HL7 Messages as it covers how to interpret HL7 Messages. Don't attempt HL7 integration work without getting these fundamentals covered.

Return to Tutorial Directory

Continue to Part 2: Understanding HL7 Message Structure.

Video Transcript

HL7 Tutorial 2:

Hello and welcome to this second video in the series of HL7 Messaging tutorials where focus on understanding HL7 message structure.

Let’s start with our sample HL7 message from the previous tutorial. I can make out a bit of information here. I can see a couple of names and a country but I don’t see the context of these. To explain what’s going on, let’s start by simplify this message right down to its most basic element. That’s better. Let’s imagine that this is our HL7 Message.

Well, all HL7 messages are divided up into Segments of related information, and these are always separated by a carriage return. Each of these segments are simply a separate line of the message.
The first Segment in every HL7 Message is always the Message Header, a Segment that conveys the metadata of the message like who sent it and when. The Message header is indicated in the first three letters of the segment as MSH.

In fact every Segment has its own three letter header that identifies what the segment is about. Some common HL7 Segments include:

PID or “Pid” - that provides patient identification.

NK1 - is a repeatable Segment that list the patient’s Next of Kin.

PV1 - provides details of the patients visit, such as doctors and dates.

SCH - Is for updating appointments in the hospitals schedule.

And OBR’s - That provides details of a group of observation results.

As we delve deeper into the HL7 Message structure we find that Segments are themselves divided up into Fields. These are normally separated by a pipe character between each of the fields. Fields each have an assigned value type that relates to its position in the Segment, so in this greatly simplified example PID Segment we might find

The Patients name is at PID-1

Their date of birth at PID-2

And details about where they live at PID-3.

So now let’s take a look at our actual HL7 Message to put what we’ve learnt so far into context.

This is our message loaded into a zoomed section of HL7 Soup. Notice how the pipes are highlighted in blue to help you see the field divisions.

So let’s look at how our simplified examples fields show in the actual hl7 message. Here we see the PID header, and like all of the Segment headers, it is emphasized with a bold blue, making it much easier to distinguish between segment headers and wrapped lines that were longer than would fit without continuing on the following line.

As for the fields we can see that the real segment holds a lot more data than our simplified sample, but just so you can spot them. Here’s the patients Name, their Date of birth, and their Address details.

Now, it’s pretty clear that colorful syntax alone does make locating where a field should be any easier, so let’s zoom out to the full hl7 soup window to see what features can help you to work with hl7 fields.
Let’s start by looking at our segment header. You’ve seen it shown in the hl7 message editor, but it is also shown in different ways elsewhere in the application. Here it is shown in the Interpretation panel, which we learnt from the first tutorial, gives us a human readable summary of the message. Here we see it with its official segment name above the segment grid.

We also get similar views of the Fields. If we have a look for the patients name field, we find it in the interpretation panel, also in the message editor, and in the segments grid.

One of the most helpful features here is that all of these locations are linked together, so when I click in the patient’s first name you can see that the first name is highlighted in the Hl7 message editor, with its own tooltip, that tells you the path to the field (PID.5.2) as well as the field’s description.

Over in the segments grid we can see another representation of the patients name, with each of its components broken up for easier editing, and with the given name highlighted in green, as that was the given name component of the patients name that I clicked.

Let’s now take a closer look at the HL7 Patient name in a bit more detail. It’s pretty easy to spot Sam Browns name, but what are all those green carets? You may have already guessed that they are field separators. They delimit the patients name into family name, given name, and in this sample message, a value that specifies the type of name - in this instance it is the patient’s birth name.

But what about all those carets between Sam and B? Something is missing? That’s because the segment grid is only showing fields which have values. But if I click the “Show Empty” button we see the grid expand to show fields that don’t have any value assigned.

So now we see those carets hold space for the patient’s middle name, their suffix, their prefix, and their degree. Let’s go back to the diagram now so we can continue looking at what divides the fields up.

We’ve seen how fields can be broken up into Components, and how we use a caret to delimit the items in a field. But we can go one step further still, as some Components can also be divided up into Sub-Components. For instance, the surname can be divided into two, creating a Surname and Surname Prefix Sub-Component, and these we delimit by the ampersand character.

Notice how we now have two items representing the patient’s surname. The surname fields first sub-component is also a representing a surname. You’ll need to be wary of this if you are doing integration work, as addressing these can be a little fiddly. A common work around is to address the lowest possible address for the value you are after. So for example in the actual HL7 Message you would address the Patients first name as PID-5.2 as there is no sub components for a first name value. But you would address the Surname as PID-5.1.1 to avoid any confusion between the two possible locations for the surnames value.

Another feature of HL7 Messaging is it allows some fields and components to be repeatable. For instance you might have two addresses; one for your home and another for your place of work. Well these can be done by repeating the field with a tilde character between each value.

I suggest you quickly load up HL7 Soup now and go through some of the sample messages to help familiarize the concept we’ve just covered. Take a close look at how the location paths (such as PID-5.1) identify where to find values, and notice how these are consistent across all HL7 messages.

Remember, you can download a free 30 day trial of HL7 Soup from www.HL7Soup.com, that will help you through this tutorial series.

In the next lesson we’ll take a closer look at the HL7 Event Types of MSH-9.

Download 30 Day Free Trial of HL7 Soup