2024 Global Cyber Confidence Index

Arrow pointing right
ExtraHop Logo
  • Productschevron right
  • Solutionschevron right
  • Why ExtraHopchevron right
  • Blogchevron right
  • Resourceschevron right

Arrow pointing leftBlog

Guide to HL7 Analytics

Terry Shaver

April 22, 2015

What is HL7? HL7 data is crucial to the healthcare industry, and the ability to extract meaningful insights from HL7 messages in real-time can help organizations improve patient outcomes, boost security, and save money.

ExtraHop's Application Inspection trigger editor.

Not all organizations need the same information from their HL7 messages, so ExtraHop makes it possible to create custom triggers to pull out the metrics that benefit your business most, whether you're a small healthcare clinic, a huge hospital network, or even an insurance provider.

The extensibility of the ExtraHop platform makes it simple to pull any piece of data out of an HL7 message and visualize it on a dashboard for comparison against other metrics. This post will walk you through a few concrete examples of how to pull specific pieces of info from an HL7 message.

Application Inspection Triggers Make It Easy to Parse HL7 Data

ExtraHop's unique Application Inspection Triggers (AI triggers) provide the framework to parse and extract valuable content from within an HL7 message.

First, let's start out at a high level by printing out an entire HL7 message. The code snippet below will grab the entire message off the wire and display it in the Runtime Log.

1. var msg = ""; 2. for (var i = 0; i < HL7.segments.length; i++) { 3. msg += HL7.segments[i].name + "|" + HL7.segments[i].fields.join("|") + "\n"; 4. } 5. log(msg);

Here's what each section of that code actually does:

  1. Initializes a variable called msg which will be used to gather up all the segments of the message.
  2. Loops through all segments of the message.
  3. Adds each segment to the msg variable separating each field with a "|" (the pipe character) and terminating the segment with a new line.
  4. The loop terminates once all segments have been added to the msg variable.
  5. The msg is then logged to output, seen on the Runtime Log.

Jump over to the Runtime Log tab to check it out. Be aware that as this trigger runs you'll be catching all HL7 messages so expect to see a bunch.

You should end up with something similar to the following:

MSH|^~\&amp;|EPICADT|DH|LABADT|DH|201301011226||ADT^A01|HL7MSG00001|P|2.3| EVN|A01|201301011223|| PID|||MRN12345^5^M11||APPLESEED^JOHN^A^III||19710101|M||C|1 CATALYZE STREET^^MADISON^WI^53005-1020|GL|(414)379-1212|(414)271-3434||S||MRN12345001^2^M10|123456789|987654^NC| NK1|1|APPLESEED^BARBARA^J|WIFE||||||NK^NEXT OF KIN PV1|1|I|2000^2012^01||||004777^GOOD^SIDNEY^J.|||SUR||||ADM|A0|

How To Pull Only Specific Message Types From Your HL7 Stream

Let's say you only wanted to see a specific message type? For example, maybe we want to examine ADT (Admit Discharge Transfer) messages.

1. if (HL7.msgType.indexOf("ADT") > -1) { 2. var msg = ""; 3. for (var i = 0; i < HL7.segments.length; i++) { 4. msg += HL7.segments[i].name + "|" + HL7.segments[i].fields.join("|") + "\n"; 5. } 6. log(msg); 7. }

Two additional lines are needed.

  • Line 1 initiates an if statement that searches for ADT in the msgType (the message type). We could have searched for any type of message here. We also could have narrowed it down to, say...ADT^A01, a patient admit.
  • Line 7 closes the if statement with }.

Parsing Specific Segments Within HL7 Messages

Let's take this one step deeper. Let's say that we want to find a specific segment within an ADT^A01 message. What if we want to examine the PID segment within the ADT^A01 message?

1. var msg = ""; 2. if (HL7.msgType.indexOf("ADT^A01") > -1) { 3. for (var i = 0; i < HL7.segments.length; i++) { 4. if (HL7.segments[i].name == "PID" ) { 5. msg += HL7.segments[i].name + "|" + HL7.segments[i].fields.join("|") + "\n"; 6. } 7. log(msg); 8. } 9. }

Again, two additional lines of code are needed. Line 4 adds in an if statement that seeks out all PID segment names and Line 6 closes the if statement.

Let's Get Specific: Pulling Patient Gender from Within the PID Segment of an HL7 Message

For our final trick, let's forget about the entire segment and instead pull out the patient gender field from within the PID segment.

Let's take a quick look at the PID segment from the example above. The segment is provided by ExtraHop, and the field we are looking for is at location 7.

HL7 Message Segment

Now that we're getting a bit deeper into the HL7 message let me take a minute to explain a few of the properties we're about to use. ExtraHop provides the segment as an array of objects where each object is of type {name: segment name, fields: Array of strings}. So, we first want to ensure that the name of the segment (HL7.segments[i].name) is PID and then we can go digging into the segments fields, specifically field 7 (HL7.segments[i].fields[7]). Remember that i is our looping variable.

Here's the code to pull out patient gender from the PID segment:

1. var msg = ""; 2. if (HL7.msgType.indexOf("ADT") > -1) { 3. for (var i = 0; i < HL7.segments.length; i++) { 4. if (HL7.segments[i].name == "PID" ) { 5. log(HL7.segments[i].fields[7]); 6. } 7. } 8. }

We've restructured the code snippet a bit. We've removed msg += HL7.segments[i].name + "|" + HL7.segments[i].fields.join("|") + "\n"; because we don't want to grab the entire message and we've also removed log(msg); because we don't want to print it out. Instead, we've added in log(HL7.segments[i].fields[7]); which grabs out the gender field.

Once you've got the hang of pulling any data you need out of HL7 messages, you can visualize that data in a dashboard and start getting valuable, easily-digested insights right away.

Here's an example where we used the Javascript string split() method to pull just the city name out of the address field in an HL7 message and graph the city and gender of the patients being admitted in real time.

Data extracted from HL7 message

Data extracted from HL7 message

Being able to pull out literally any piece of information from an HL7 message really opens up some interesting possibilities.

Video Walkthrough: Parsing HL7 Messages

If you want a detailed walkthrough of how to implement the HL7 message parsing techniques explained in this post, check out the video below:

We Can't Wait To See How You Use Real-Time HL7 Analytics

We would love to hear how you utilize this. Are there interesting use cases you develop in your environment? Or maybe you need some assistance? Feel free to share your stories or look for suggestions in the ExtraHop Forums.

Work in healthcare IT? Read 5 Ways Wire Data Analytics Enables Real-Time Healthcare Systems

Experience RevealX NDR for Yourself

Schedule a demo