HL7 v2.x version utilities.
Pure helpers for normalizing, comparing, and gating on HL7 version strings.
This module is intentionally lightweight and side-effect free. It is the foundation for future version-aware validation rules — callers can use it today to detect, normalize, and compare versions, even though no validation rule yet branches on version.
Supported range
The library targets HL7 v2.3 through v2.8 inclusive. supported?/1 returns
true for any canonical version that falls within that range.
Examples
iex> HL7v2.Standard.Version.normalize("v2.5.1")
"2.5.1"
iex> HL7v2.Standard.Version.compare("2.5", "2.7")
:lt
iex> HL7v2.Standard.Version.at_least?("2.7", "2.5")
true
iex> HL7v2.Standard.Version.supported?("2.5.1")
true
Summary
Functions
Returns true when version is greater than or equal to target.
Compares two HL7 version strings, returning :lt, :eq, or :gt.
Normalizes an HL7 version string to its canonical form.
Returns true when the given version is within the library's supported
range (HL7 v2.3 through v2.8 inclusive).
Functions
Returns true when version is greater than or equal to target.
Examples
iex> HL7v2.Standard.Version.at_least?("2.7", "2.5")
true
iex> HL7v2.Standard.Version.at_least?("2.5.1", "2.5.1")
true
iex> HL7v2.Standard.Version.at_least?("2.5", "2.7")
false
Compares two HL7 version strings, returning :lt, :eq, or :gt.
Inputs are normalized first via normalize/1. Missing trailing components
are treated as 0, so "2.5" and "2.5.0" compare equal.
Raises ArgumentError if either input is not a recognizable version.
Examples
iex> HL7v2.Standard.Version.compare("2.5", "2.7")
:lt
iex> HL7v2.Standard.Version.compare("2.7", "2.5.1")
:gt
iex> HL7v2.Standard.Version.compare("2.5", "2.5.0")
:eq
iex> HL7v2.Standard.Version.compare("v2.5.1", "2.5.1")
:eq
Normalizes an HL7 version string to its canonical form.
Strips an optional v/V prefix and surrounding whitespace, and validates
that the result looks like a dotted numeric version (e.g. 2, 2.5,
2.5.1). Returns the canonical string on success, or nil for nil,
empty, or unrecognized inputs.
Examples
iex> HL7v2.Standard.Version.normalize("2.5.1")
"2.5.1"
iex> HL7v2.Standard.Version.normalize("v2.7")
"2.7"
iex> HL7v2.Standard.Version.normalize(" V2.5 ")
"2.5"
iex> HL7v2.Standard.Version.normalize(nil)
nil
iex> HL7v2.Standard.Version.normalize("garbage")
nil
Returns true when the given version is within the library's supported
range (HL7 v2.3 through v2.8 inclusive).
Inputs are normalized first. Unparseable, missing, or out-of-range versions
return false.
Examples
iex> HL7v2.Standard.Version.supported?("2.5.1")
true
iex> HL7v2.Standard.Version.supported?("2.3")
true
iex> HL7v2.Standard.Version.supported?("2.8")
true
iex> HL7v2.Standard.Version.supported?("2.2")
false
iex> HL7v2.Standard.Version.supported?("3.0")
false
iex> HL7v2.Standard.Version.supported?(nil)
false