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

Canonical message structure mappings and validation dispatch.

Maps HL7v2 trigger events to their canonical message structures (e.g.,
ADT^A04 → ADT_A01) and dispatches structural validation to
`HL7v2.Standard.MessageStructure` and `HL7v2.Validation.Structural`.

# `canonical_structure`

```elixir
@spec canonical_structure(binary(), binary()) :: binary()
```

Returns the canonical message structure for a message code and trigger event.

Many HL7v2 trigger events share the same abstract message definition. For
example, ADT^A04, ADT^A08, and ADT^A13 all use the ADT_A01 structure.

Falls back to `"CODE_EVENT"` when no canonical mapping exists.

## Examples

    iex> HL7v2.MessageDefinition.canonical_structure("ADT", "A28")
    "ADT_A05"

    iex> HL7v2.MessageDefinition.canonical_structure("ADT", "A01")
    "ADT_A01"

    iex> HL7v2.MessageDefinition.canonical_structure("ZZZ", "Z01")
    "ZZZ_Z01"

# `validate_structure`

```elixir
@spec validate_structure(binary() | nil, [binary()]) :: :ok | {:error, [map()]}
```

Validates segment presence/structure against the message definition.

Delegates to `HL7v2.Validation.Structural` for structures with group-aware
definitions. Returns a warning for unknown structures.

---

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