LSchuster.HL7MessageProcessor
1.0.7
dotnet add package LSchuster.HL7MessageProcessor --version 1.0.7
NuGet\Install-Package LSchuster.HL7MessageProcessor -Version 1.0.7
<PackageReference Include="LSchuster.HL7MessageProcessor" Version="1.0.7" />
<PackageVersion Include="LSchuster.HL7MessageProcessor" Version="1.0.7" />
<PackageReference Include="LSchuster.HL7MessageProcessor" />
paket add LSchuster.HL7MessageProcessor --version 1.0.7
#r "nuget: LSchuster.HL7MessageProcessor, 1.0.7"
#:package LSchuster.HL7MessageProcessor@1.0.7
#addin nuget:?package=LSchuster.HL7MessageProcessor&version=1.0.7
#tool nuget:?package=LSchuster.HL7MessageProcessor&version=1.0.7
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
HL7ReadonlyMessagewrapper - ๐ Mutable transformations with
HL7TransformableMessagefor editing HL7 content - โ HL7-compliant header parsing (MSH segment)
- ๐งพ Automatic ACK generation (CA, AE, AR, CR, CE) with error message support
- ๐งช 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;
// Load an HL7 message
var rawMessage = File.ReadAllText("some-message.hl7");
// Create a readonly HL7 message wrapper
var hl7 = new HL7ReadonlyMessage(rawMessage);
// โ
Access message header fields
var sendingApp = hl7.Header.SendingApplication;
var messageDate = hl7.Header.ParsedDateTime;
// โ
Extract a single field value (e.g., PID-3.1)
string patientId = hl7.GetValue("PID", 3, 1);
// โ
Extract values across repeated segments (e.g., OBR-4.2 from all OBRs)
IReadOnlyList<string> values = hl7.GetValues("OBR", 4, 2);
// โ
Use HL7 field path notation (e.g., "OBR-4.2", "PID-5.1.2")
string id = hl7.GetValue("PID-3.1");
IReadOnlyList<string> lipidTestCodes = hl7.GetValues("OBR-4.1");
// โ
Validate structural correctness
bool isValid = hl7.IsValid();
// โ
Detect if the message is an HL7 acknowledgment
bool isAck = hl7.IsAcknowledgment();
Console.WriteLine($"Is ACK? {isAck}");
// โ
Generate an ACK in response
if (!isAck && isValid)
{
var ack = hl7.GenerateAcknowledgement(
switchSenderAndReceiver: true,
acknowledgmentCode: "AE", // "CA" = Accept, "AE" = App Error, "AR" = App Reject, etc.
errorMessage: "Missing required field: PID-5"
);
string ackRaw = ack.ToString();
Console.WriteLine("Generated ACK:\n" + ackRaw);
}
โ๏ธ Modify the HL7 Message (Transformable)
// Use HL7TransformableMessage for write access
var transformable = new HL7TransformableMessage(rawMessage);
// Redact patient name (e.g., PID-5)
transformable.SetValue("PID", "REDACTED", 5);
// Remove all NTE segments
transformable.RemoveSegments("NTE");
// Add a custom Z-segment
transformable.AddSegment("ZBX", "Custom|Value|Here");
// Get the updated HL7 message
string updatedMessage = transformable.ToString();
File.WriteAllText("transformed.hl7", updatedMessage);
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.
Links
Author
| Product | Versions 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. |
-
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.