HL7v2 Metric Device

HL7v2 Metric Device

This device provides an easy way to track HL7v2 message properties and visualize these via Prometheus and Grafana.

By default, Connexion includes some HL7v2 information as part of built-in metrics. For example, the connexion_queue_message_count metric provides queue-level message counts which include the message type. If your channel is processing HL7v2 messages, then the exposed metric includes the value from MSH-9.

image-20241107-160924.png
Built-in metric connection_queue_message_count

If you wish to create metrics based on other HL7v2 fields, then you can utilize the HL7 Metrics Device, or, use a custom code device (refer to the metrics tutorials).

Let’s look at a simple scenario where you wish to track the Sending Facility values.

Position of this device within the channel is important, as metrics are calculated when the message passes through the device. For example, if you wish to accurately track the time a message is received, the device should go before the first queue. If you with to track updated message values, the device should be placed after any transforms.

In this example, we’re going to track the distribution of messages by MSH-4 (Sending Facility) and create both pie and line charts. Let’s assume the following channel, which receives messages over a network.

 

image-20241107-174657.png
Sample channel with the metric device before the queue

We want our device to track the value from MSH-4 (sending facility). To do this, add a new line item by clicking the Add Metric button:

image-20241107-175236.png

Next, double-click in the Name column and enter SendingFacility. This is the label used in Prometheus/Grafana. Next, enter the HL7 path into the Expression column.

image-20241107-175657.png
The Prometheus query showing Name matching the value entered into the device’s Name column.

Ensure the HL7v2 metric is enabled, and run some messages through the test channel.

image-20241107-175952.png

You should be able to visit Grafana and create the following visualizations:

image-20241107-200728.png
Line chart: rate(connexion_hl7_message_metrics{Name="SendingFacility"}[$__rate_interval])

The line chart shows the rate messages are received (by Sending Facility / MSH-4), and the pie chart shows the proportion of messages from each Sending Facility.

Now let’s add another metric based on the contents of OBRsegments. For this sample, add another metric with the following settings:

image-20241107-201600.png
Expose OBR-24.4.1 for ORU messages

Duplicate the visualizations done previously, and update the Name to Diagnostic. Running some sample messages through produces the following visualizations:

image-20241107-202518.png

We now have charts for both Sending Facility (MSH-4) and Diagnostic Type (OBR-24.1). However, what if we want to create a visualization which shows the Diagnostic Type by Sending Facility? For example, show a visualization for Diagnostic Type based on Sending Facility. To accomplish this, we need to update our configuration and change the Type column for the Sending Facility row.

image-20241107-203736.png

Metric Type

Value: The result of the Expression will be in stored in the Value label. Example: connexion_hl7_message_metrics{Name="SendingFacility",Value="UCHC"}

Label: The result of the Expression will be stored as a new label with name Name=Expression. Example: connexion_hl7_message_metrics{Name="Diagnostic", SendingFacility="EPIC"}

In Grafana, you can now create queries which filter based on any additional labels you’ve defined:

image-20241107-233348.png

You could also leverage Grafana’s variables feature to create a drop-down list which let’s users choose which Sending Facility to view:

image-20241107-234251.png