LSchuster.HL7MessageProcessor 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package LSchuster.HL7MessageProcessor --version 1.0.4
                    
NuGet\Install-Package LSchuster.HL7MessageProcessor -Version 1.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LSchuster.HL7MessageProcessor" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LSchuster.HL7MessageProcessor" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="LSchuster.HL7MessageProcessor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LSchuster.HL7MessageProcessor --version 1.0.4
                    
#r "nuget: LSchuster.HL7MessageProcessor, 1.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LSchuster.HL7MessageProcessor@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LSchuster.HL7MessageProcessor&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=LSchuster.HL7MessageProcessor&version=1.0.4
                    
Install as a Cake Tool

HL7 .Net Message Processor

LSCH.HL7MessageProcessor is a .NET library for parsing and working with HL7 v2.x messages. It provides structured access to message headers and values without mutating the input string, making it suitable for read-only inspection, validation, and routing scenarios.

Features

  • ๐Ÿ” Deep field access by segment name and component indices
  • ๐Ÿงฉ Immutable HL7ReadonlyMessage wrapper
  • โœ… HL7-compliant header parsing (MSH segment)
  • ๐Ÿงช Tested with xUnit and FluentAssertions
  • โš™๏ธ Optimized for performance with ReadOnlySpan<char>

Install via NuGet

dotnet add package LSchuster.HL7MessageProcessor

Or via NuGet Package Manager:

Install-Package LSchuster.HL7MessageProcessor

Quick Start

using LSCH.HL7MessageProcessor;

// Read the HL7 message from a file
var rawMessage = File.ReadAllText("some-message.hl7");
var hl7 = new HL7ReadonlyMessage(rawMessage);

// Access message header data
var sendingApp = hl7.Header.SendingApplication;
var messageDate = hl7.Header.ParsedDateTime;

// Read a specific field
string patientId = hl7.GetValue("PID", 3, 1); // Segment: PID, Field 3, Component 1

// Read a specific field from multiple segments
IReadOnlyList<string> values = hl7.GetValues("OBR", 4, 2); // Segment: OBR, Field 4, Component 2

// Check if the message is structurally valid
bool isValid = hl7.IsValid();

// Check if it's an ACK message
bool isAck = hl7.IsAcknowledgment();
Console.WriteLine($"Is ACK? {isAck}");

// Generate an acknowledgment
if (!isAck && isValid)
{
    var ack = hl7.GenerateAcknowledgement(
        switchSenderAndReceiver: true,
        acknowledgmentCode: "CR", // "CA" for success, "AE"/"AR"/"CR"/"CE" for errors
        errorMessage: "Missing required field: PID-5"
    );

    string ackRaw = ack.ToString();
    Console.WriteLine("Generated ACK:\n" + ackRaw);
}

Testing

The library includes a dedicated xUnit test project that uses real HL7 sample messages. Tests verify structural parsing, header field correctness, and field access methods.

Run tests locally:

dotnet test

Project Structure

src/
  HL7MessageProcessor/             # Library project
test/
  HL7MessageProcessor.Tests/      # xUnit test project
  โ””โ”€โ”€ TestData/                   # Contains sample .hl7 files

License

This project is licensed under the MIT License.

Author

GitHub @LSchuster

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 227 5/7/2025
1.0.6 210 5/7/2025
1.0.5 197 5/6/2025
1.0.4 202 5/6/2025
1.0.3 199 5/6/2025
1.0.2 205 5/4/2025
1.0.1 126 5/3/2025
1.0.0 128 5/3/2025