# `HL7v2.Standard.Tables`
[🔗](https://github.com/Balneario-de-Cofrentes/hl7v2/blob/v3.10.1/lib/hl7v2/standard/tables.ex#L1)

HL7 v2.5.1 coded-value tables.

Provides lookup and validation for the most commonly used HL7-defined tables
referenced by typed segments in this library. Each table is a map of
`code => description` drawn from the HL7 v2.5.1 specification.

Table validation is opt-in. Call `HL7v2.validate(msg, validate_tables: true)`
to enable coded-value checking during message validation.

## Examples

    iex> HL7v2.Standard.Tables.valid?(1, "F")
    true

    iex> HL7v2.Standard.Tables.valid?(1, "ZZ")
    false

    iex> HL7v2.Standard.Tables.validate(8, "AA")
    :ok

    iex> HL7v2.Standard.Tables.validate(8, "XX")
    {:error, "invalid code \"XX\" for table 0008 (Acknowledgment Code)"}

# `get`

```elixir
@spec get(non_neg_integer()) ::
  %{name: String.t(), codes: %{required(String.t()) =&gt; String.t()}} | nil
```

Returns the table map for the given table ID, or `nil` if undefined.

The table ID is an integer (e.g., `1` for Table 0001).

## Examples

    iex> table = HL7v2.Standard.Tables.get(1)
    iex> table.name
    "Administrative Sex"

    iex> HL7v2.Standard.Tables.get(9999)
    nil

# `table_ids`

```elixir
@spec table_ids() :: [non_neg_integer()]
```

Returns a sorted list of all defined table IDs.

## Examples

    iex> ids = HL7v2.Standard.Tables.table_ids()
    iex> 1 in ids
    true

    iex> ids = HL7v2.Standard.Tables.table_ids()
    iex> ids == Enum.sort(ids)
    true

# `valid?`

```elixir
@spec valid?(non_neg_integer(), String.t()) :: boolean()
```

Returns `true` if `code` is a valid value in the given table.

Returns `false` for unknown table IDs.

## Examples

    iex> HL7v2.Standard.Tables.valid?(1, "F")
    true

    iex> HL7v2.Standard.Tables.valid?(1, "ZZ")
    false

    iex> HL7v2.Standard.Tables.valid?(9999, "X")
    false

# `validate`

```elixir
@spec validate(non_neg_integer(), String.t()) :: :ok | {:error, String.t()}
```

Validates `code` against the given table.

Returns `:ok` if the code is valid, or `{:error, message}` with a
human-readable description if invalid.

Returns `:ok` for unknown table IDs (cannot validate what is not defined).

## Examples

    iex> HL7v2.Standard.Tables.validate(8, "AA")
    :ok

    iex> HL7v2.Standard.Tables.validate(8, "XX")
    {:error, "invalid code \"XX\" for table 0008 (Acknowledgment Code)"}

    iex> HL7v2.Standard.Tables.validate(9999, "X")
    :ok

---

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