Packages
hl7v2
3.3.0
3.10.1
3.9.0
3.8.0
3.7.0
3.6.0
3.5.0
3.4.0
3.3.6
3.3.5
3.3.4
3.3.3
3.3.2
3.3.1
3.3.0
3.2.0
3.1.1
3.1.0
3.0.2
3.0.1
3.0.0
2.11.0
2.10.0
2.9.1
2.9.0
2.8.2
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.4.0
2.3.0
2.2.0
2.1.3
2.1.2
2.1.1
2.1.0
1.4.6
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.0
0.6.0
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.1.0
Pure Elixir HL7 v2.x toolkit — schema-driven parsing, typed segments, message builder, MLLP transport
Current section
Files
Jump to
Current section
Files
lib/hl7v2/conformance/fixtures.ex
defmodule HL7v2.Conformance.Fixtures do
@moduledoc """
Runtime helper that computes conformance fixture corpus statistics from
the on-disk fixture directory.
This exists as a single source of truth for fixture coverage numbers
reported in docs, CHANGELOG, and `mix hl7v2.coverage` — so the published
counts cannot drift from actual evidence on disk.
"""
@fixture_dir Path.expand("../../../test/fixtures/conformance", __DIR__)
@total_official 186
@type coverage :: %{
files: non_neg_integer(),
canonical: non_neg_integer(),
total_official: non_neg_integer(),
pct: float()
}
@doc """
Returns a map summarizing the conformance fixture corpus.
- `:files` — number of `.hl7` fixture files on disk
- `:canonical` — number of unique canonical message structures covered
- `:total_official` — 186 (HL7 v2.5.1 official structures)
- `:pct` — canonical / total_official as a percentage, rounded to 1 decimal
"""
@spec coverage() :: coverage()
def coverage do
files = list_fixtures()
canonical = unique_canonical_structures(files)
pct = Float.round(length(canonical) / @total_official * 100, 1)
%{
files: length(files),
canonical: length(canonical),
total_official: @total_official,
pct: pct
}
end
@doc """
Returns the sorted list of fixture filenames on disk.
"""
@spec list_fixtures() :: [binary()]
def list_fixtures do
case File.ls(@fixture_dir) do
{:ok, entries} ->
entries
|> Enum.filter(&String.ends_with?(&1, ".hl7"))
|> Enum.sort()
_ ->
[]
end
end
@doc """
Returns the sorted list of unique canonical structures covered by the
on-disk fixture corpus.
"""
@spec unique_canonical_structures([binary()]) :: [binary()]
def unique_canonical_structures(files \\ list_fixtures()) do
files
|> Enum.map(&canonical_for_file/1)
|> Enum.reject(&is_nil/1)
|> Enum.uniq()
|> Enum.sort()
end
defp canonical_for_file(file) do
path = Path.join(@fixture_dir, file)
with {:ok, wire} <- File.read(path),
{:ok, msg} <- HL7v2.parse(String.replace(wire, "\n", "\r"), mode: :typed) do
msh = hd(msg.segments)
type = msh.message_type
HL7v2.MessageDefinition.canonical_structure(type.message_code, type.trigger_event)
else
_ -> nil
end
end
end