HL7lite 2.0.0-rc.1

This is a prerelease version of HL7lite.
dotnet add package HL7lite --version 2.0.0-rc.1
                    
NuGet\Install-Package HL7lite -Version 2.0.0-rc.1
                    
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="HL7lite" Version="2.0.0-rc.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HL7lite" Version="2.0.0-rc.1" />
                    
Directory.Packages.props
<PackageReference Include="HL7lite" />
                    
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 HL7lite --version 2.0.0-rc.1
                    
#r "nuget: HL7lite, 2.0.0-rc.1"
                    
#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 HL7lite@2.0.0-rc.1
                    
#: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=HL7lite&version=2.0.0-rc.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=HL7lite&version=2.0.0-rc.1&prerelease
                    
Install as a Cake Tool

HL7lite

Simple, lightweight HL7 v2.x parsing and manipulation for .NET

Quick Start

using HL7lite;
using HL7lite.Fluent;

// Parse a message
var hl7String = @"MSH|^~\&|SENDER|FACILITY|RECEIVER|FACILITY|20240101120000||ADT^A01|123456|P|2.5
PID|||12345||Doe^John^Middle||19800315|M|||123 Main St^Apt 4B^City^ST^12345";
var result = hl7String.TryParse();
if (!result.IsSuccess) {
    Console.WriteLine($"Parse failed: {result.ErrorMessage}");
    return;
}
var message = result.Message;

// Access fields using the Fluent API
var patientName = message.PID[5][1].Value;        // "Doe"
var dateOfBirth = message.PID[7].Value;           // "19800315"

// Modify values with fluent chaining
message.PID[5].SetComponents("Smith", "Jane", "Marie")
    .Field(7).Set("19850315")
    .Field(8).Set("M")
    .Field(13).Repetitions.Add("555-1234")
                          .Add("555-5678");

// Create new segments with fluent building
var obx = message.Segments("OBX").Add()
    .Field(1).Set("1")
    .Field(2).Set("NM")
    .Field(3).Set("GLUCOSE")
    .Field(5).Set("120");

Key Features

  • 🎯 Modern Fluent API - Intuitive, chainable methods for message manipulation
  • 🛡️ Never Throws - Returns empty values instead of throwing exceptions
  • 🔧 Auto-creation - Automatically creates missing segments and fields
  • High Performance - Efficient parsing without schema validation overhead
  • 📦 Zero Dependencies - Lightweight with minimal footprint

Fluent API Examples

Reading Values

// Simple field access
string patientId = message.PID[3].Value;

// Component access
string lastName = message.PID[5][1].Value;
string firstName = message.PID[5][2].Value;

// Safe access (never throws)
string value = message.ZZZ[999].Value;  // Returns empty string if segment doesn't exist

// Field repetitions
string firstId = message.PID[3].Repetition(1).Value;
string secondId = message.PID[3].Repetition(2).Value;

Setting Values

// Set field value
message.PID[3].Set("12345");

// Set with components
message.PID[5].SetComponents("Smith", "John", "M");

// Add field repetitions with chaining
message.PID[13].Repetitions.Add("555-1234")
                           .Add("555-5678");

// Pure navigation with method chaining
message.PID[5].SetComponents("Johnson", "Robert")
    .Field(7).Set("19850315")
    .Field(8).Set("M")
    .Field(11).SetComponents("123 Main St", "Boston", "MA");

Working with Segments

// Add segments with fluent building
var dg1 = message.Segments("DG1").Add()
    .Field(1).Set("1")
    .Field(3).SetComponents("I10", "Essential Hypertension")
    .Field(6).Set("F");

// Query segments with LINQ
var diagnoses = message.Segments("DG1")
    .Where(d => d[6].Value == "F")
    .Select(d => d[3][2].Value);

// Create complete message from scratch
var newMessage = FluentMessage.Create();
newMessage.CreateMSH
    .Sender("HIS", "HOSPITAL")
    .Receiver("LAB", "LABORATORY")
    .MessageType("ADT^A01")
    .AutoControlId()
    .Build();

newMessage.Segments("PID").Add()
    .Field(3).Set("12345")
    .Field(5).SetComponents("Smith", "John", "M")
    .Field(7).Set("19850315");

Path-based Access

// Get values using path syntax
string value = message.Path("PID.5.1").Value;

// Set values using paths
message.Path("PID.5.1").Set("Smith");
message.Path("OBX.5").Set("120");

// Safe encoding - Set() automatically handles special characters
message.Path("PID.5").Set("Smith & Jones Law Firm");  // & automatically encoded
message.Path("OBX.5").Set("https://lab.com/result?id=123&type=CBC");  // & in URL encoded

// Conditional path operations
message.Path("PID.6").SetIf("MAIDEN", hasMiddleName);

Documentation & Support

License

MIT License - see https://github.com/domibies/HL7lite/blob/master/LICENSE.txt

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 is compatible.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0-rc.1 447 7/24/2025
1.2.0 340 7/20/2024
1.1.6 9,510 7/1/2022
1.1.5 1,135 5/23/2022
1.1.4 1,558 11/20/2021
1.1.3 419 11/2/2021
1.1.2 862 5/27/2021
1.1.1 488 4/29/2021
1.0.0 461 4/2/2021