There are (at least) two other .Net HL7 libraries that are well known in the community:
- NHapi is ridiculously fully featured, use it and love it if you want strongly typed spec compliant messages.
- HL7-V2 has a nice design ethos and is much lighter than NHapi, but has many years of legacy code and forked history, interesting coding standards and
netstandard2.0
back compat to worry about. As a previous contributor to this library you may see similarities :)
These are both fantastic libraries, with different trade-offs, and I've used both successfully in production in the past.
This library aims for the simplicity of HL7-V2, while being strictly modern .Net, and as lean as we can make it! It is not intended to be the one HL7 library to rule them all!
It is currently focused on reading messages, not building/writing them, and it makes no attempt to validate messages against the spec.
It aims provides a set of tools for your toolkit, rather than being a fully integrated all-in-one framework, and rewards sparse access to the message structure. If you need every single field in the message, one of the other libraries may be a better fit, or maybe not.
There's a set of benchmarks in the Benchmarks directory, but the TL;DR is that it's very fast, and very low allocation:
To parse a fully featured message and query some data:
| Method | Mean | Ratio | Gen0 | Gen1 | Allocated | Alloc Ratio |
|------------- |-----------:|-------:|--------:|--------:|----------:|------------:|
| FastHl7 | 1.620 us | 1.00 | 0.0153 | - | 288 B | 1.00 |
| Hl7V2 | 25.401 us | 15.68 | 7.4463 | 1.2817 | 128696 B | 446.86 |
| NHapi_Parser | 172.307 us | 106.38 | 29.2969 | 12.6953 | 518875 B | 1,801.65 |
As noted over there it's difficult to do a truly apples-apples comparisons of some features, but if you think a benchmark is unfair/misleading then please submit a PR to make it better!
Pretty simple:
-
Add a reference to the FastHl7 Nuget package
-
Create a message from a string (or other
ReadOnlySpan<char>
:-
using FastHl7; var message = Message.Parse(hl7MessageString);
-
-
Query segments, fields etc:
-
var patientFirstName = message.Query("PID.5.2");
-
-
There are helpers for date time conversions/de-escaping special chars:
-
var dobText = message.Query("PID.7"); var dobAsDate = dobText.AsDate();
-
var noteText = message.Query("NTE.3"); var unescapedNote = noteText.Unescape();
-
There's an example of a high-performance MLLP listener (server) in the samples directory.
-
Create a message
-
Support for Components (
^
) -
and Sub-Components (
&
) -
Support for Repeating fields (
~
) -
Querying (this whole space needs some cleaning up)
- Allow fetch of segments by index
- Allow fetch of segments by name/ordinal (
message.GetSegment("PID")
)- Allow fetch of segments by name/ordinal with index (
message.GetSegment("PID(2)")
) for repeating segments - Allow fetch of segments by name/ordinal with index and field (
message.QueryValue("PID(2).4")
?) We don't know whether to return a Field, Segment, Component etc, so just theReadOnlySpan<char>
?....
- Allow fetch of segments by name/ordinal with index (
- Allow fetch of fields by index (
pid.GetField(4)
) - Query by path (
message.Query("NK1(2).4.1")
or similar)
-
Samples:
- MLLP listener that actually consumes and processes messages to prove out API
-
Low-alloc DateTime conversion helpers
-
Support MEL.ILogger for places we swallow exceptions etc??
-
Nuget when vaguely ready
-
Escape sequences for delimiter chars (https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=EHL72_escape_sequences)
- Hex char support via Hex Encoding (0xA2) (https://web.archive.org/web/20160422163547/https://corepointhealth.com/resource-center/hl7-resources/hl7-escape-sequences)
- Unicode char support via Html Encoding (
¢
) (https://hl7.org.au/archive/hl7v2wg/1278287.html#Appendix1ParsingHL7v2(Informative)-8Unicodecharacters)- (Leaving for the caller for now, just use
WebUtility.HtmlDecode
)
- (Leaving for the caller for now, just use
-
Support for efficiently building messages (maybe)