# `HL7v2.Conformance.Fixtures`
[🔗](https://github.com/Balneario-de-Cofrentes/hl7v2/blob/v3.10.1/lib/hl7v2/conformance/fixtures.ex#L1)

Conformance fixture corpus statistics.

The canonical structure list and fixture filenames are **frozen at compile
time** by walking the fixture directory and extracting MSH-9 from each wire
file. This means:

- `coverage/0`, `list_fixtures/0`, and `unique_canonical_structures/0` return
  compile-time-frozen results with no runtime disk access. The fixture files
  ship inside the Hex package, and CI verifies the tarball fixture count
  matches the frozen list.
- Changing any fixture file triggers recompilation via `@external_resource`.
- Canonical resolution uses the same fallback logic as
  `HL7v2.Validation` — if the trigger-specific structure is unregistered,
  the bare message_code is tried before giving up. This correctly reports
  `ACK` for `ACK^A01^ACK_A01`, not the unregistered `ACK_A01`.

This module is the single source of truth for fixture corpus counts
reported in docs, CHANGELOG, and `mix hl7v2.coverage`.

# `coverage`

```elixir
@type coverage() :: %{
  files: non_neg_integer(),
  canonical: non_neg_integer(),
  total_official: non_neg_integer(),
  pct: float()
}
```

# `check_freshness`

```elixir
@spec check_freshness(keyword()) ::
  :ok | {:stale, keyword()} | {:error, :fixture_dir_unavailable}
```

Compares the compile-time-frozen fixture list against the current on-disk
state of the fixture directory.

Returns:

- `:ok` — frozen list matches on-disk state
- `{:stale, on_disk_only: [...], frozen_only: [...]}` — drift detected
- `{:error, :fixture_dir_unavailable}` — the fixture directory does not
  exist or is unreadable (e.g. the corpus was not shipped in a Hex
  artifact). As of v3.3.3 the corpus ships in the Hex package, so a
  missing directory is itself a release-surface regression and is
  reported loudly by default.

Options for dependency injection in tests and opt-out for edge cases:

- `:dir` — override the directory to compare against (default: compile-time
  `@fixture_dir`)
- `:frozen` — override the frozen list (default: compile-time `@fixtures`)
- `:allow_missing` — when `true`, return `:ok` instead of
  `{:error, :fixture_dir_unavailable}` when the directory is not
  readable. Default: `false`.

# `coverage`

```elixir
@spec coverage() :: coverage()
```

Returns a map summarizing the conformance fixture corpus.

- `:files` — number of `.hl7` fixture files
- `: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

# `families`

```elixir
@spec families() :: [binary()]
```

Returns the sorted list of message family prefixes covered by the corpus
(e.g. `"ADT"`, `"ORU"`, `"MFN"`). Derived from canonical structure names.

# `list_fixtures`

```elixir
@spec list_fixtures() :: [binary()]
```

Returns the sorted list of fixture filenames included in the corpus.

# `unique_canonical_structures`

```elixir
@spec unique_canonical_structures([binary()]) :: [binary()]
```

Returns the sorted deduplicated list of canonical message structures
covered by the corpus. Uses the same alias fallback as validation, so
`ACK^A01^ACK_A01` resolves to the registered `ACK` structure rather than
the unregistered `ACK_A01`.

The `files` argument is ignored and kept for backwards compatibility —
the result is frozen at compile time regardless of input.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
