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

HL7 v2.5.1 abstract message structure definitions.

Each message structure is defined as a tree of segments and groups with
cardinality constraints, following the HL7 v2.5.1 abstract message definitions.

## Structure AST

Each node is one of:

- `{:segment, id, optionality}` — a single segment occurrence
- `{:segment, id, optionality, :repeating}` — a repeating segment
- `{:group, name, optionality, children}` — a segment group (single)
- `{:group, name, optionality, :repeating, children}` — a repeating group

Where:
- `id` is an atom like `:MSH`, `:PID`, `:PV1`
- `name` is a group name atom like `:PATIENT`, `:VISIT`, `:ORDER`
- `optionality` is `:required` or `:optional`
- `children` is a list of nested nodes

222 structure definitions covering all 186 official v2.5.1 abstract message
structures plus aliases and response variants. Run `mix hl7v2.gen_docs` to
regenerate reference documentation from these definitions.

Source: HL7 v2.5.1 abstract message definitions via
https://www.hl7.eu/HL7v2x/v251/hl7v251msgstruct.htm and
https://hl7-definition.caristix.com/v2/HL7v2.5.1/TriggerEvents

# `structure`

```elixir
@type structure() :: %{
  name: binary(),
  description: binary(),
  nodes: [structure_node()]
}
```

# `structure_node`

```elixir
@type structure_node() ::
  {:segment, atom(), :required | :optional}
  | {:segment, atom(), :required | :optional, :repeating}
  | {:group, atom(), :required | :optional, [structure_node()]}
  | {:group, atom(), :required | :optional, :repeating, [structure_node()]}
```

# `count`

```elixir
@spec count() :: non_neg_integer()
```

Returns the count of defined structures.

# `get`

```elixir
@spec get(binary()) :: structure() | nil
```

Returns the structure definition for a message structure name, or nil.

# `names`

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

Returns all defined structure names.

# `required_segments`

```elixir
@spec required_segments(structure()) :: [atom()]
```

Extracts the flat list of required segment IDs from a structure definition.

This is the bridge to the current presence-only validation: it walks the
structure tree and collects all required segment IDs, ignoring group nesting.

---

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