Project Description
A command line application to retrieve specific elements from HL7 v2.x files. Designed to query multiple HL7 files to validate specific field values.
HL7Query is a simple command line app to retrieve HL7 v2.x segments, fields or components/sub components from file based HL7 messages. This was written to assist validation of specific fields when dealing with a large sample of HL7 messages. The results are written to the console, allowing further manipulation via Powershell cmdlets etc. HL7Query can be run against a single file or a directory containing multiple HL7 v2.x files.

Optionally, the results can be restricted to unique values only. This assists validation of code sets used in the messages interrogated.

If querying a directory of files, the query can be restricted to specific message triggers. See below for examples.

Repeating fields and segments are supported.

Running HL7Query
HL7Query.exe <filename> <HL7Element> [-IgnoreWarnings] [-ListFilenames] [-Unique] [-Filter <HL7Element>=<Value>]

<filename> is the path to a single HL7 file, or a folder containing multiple HL7 files

<HL7Element> identifes the HL7 element to return. Formatted as <Segment>-[Field].[Component].[SubComponent]. Segment is the 3 letter segment code. Field, Component and SubComponent are identified by number. e.g 'PID' or 'PID-3' or or 'PID-3.1' or 'PID-3.1.1'

[-IgnoreWarnings | -I] is an optional switch to suppress warnings when a segment, field, component or
sub component is not present in the message.

[-ListFilenames | -L] is an optional switch list the file name the values were obtained from.

[-Unique | -U] display unique results only. If -ListFileNames is also supplied it will be ignored.
Warnings will also be suppressed.

[-Filter <HL7Element>=<Value> | -F HL7Element>=<Value>] Only search messages where the <HL7Element> matches the <Value> specified.
e.g. '-Filter MSH-9=ADT^A01' will only search messages with a trigger of 'ADT^A01'
If <HL7Element> identifies multiple items in a file (ie repeating segments or fields) all repeats will be checked for a match. You can specify a specif repeat number if needed. e.g 'PID-3[2]=E1234567' will
only examine the second repeat of PID-3. The filter allows exact matches only. If a value isn't provided (e.g. 'PV1-19=', it will match empty or missing HL7Elements.

HL7Query.exe c:\HL7Files\ PID-3.1 -ListFilenames -Filter MSH-9=ADT^A08

HL7Query.exe c:\HL7Files\MDM_D4923.txt TXA-2

HL7Query.exe c:\HL7Files\ PID-42.1.1 -Unique "}

The following example illustrates piping the output into the Powershell 'Group-Object' cmdlet to report on the number of unique occurrences of the results returned.
.\HL7Query.exe 'E:\Samples' MSH-9.2 | Group-Object | Format-Table Count,Name
     Count       Name
     -----       ------
       307        A31
         2        A27
        43        A28
         7        A04
        37        A03
         4        A05
        43        A14
        71        A01
       171        A08
         3        A02
         5        A60
         2        A11
         1        A38

Related Projects
You may be interested in HL7Listener This will listen on a TCP port and save any MLLP framed HL7 messages received to disk, allowing offline analysis to be done with HL7Query.

Last edited May 30, 2015 at 7:00 AM by RobHolme, version 30