HL7v2.Validation.Structural (HL7v2 v3.10.1)

Copy Markdown View Source

Positional structural validation against HL7 v2.5.1 abstract message definitions.

Validates segment ordering, group structure, and cardinality by walking the actual segment stream against the structure AST in order — a state-machine approach that correctly handles:

  • Segments in multiple groups — ROL can appear in PATIENT, VISIT, PROCEDURE, INSURANCE; each group consumes its own occurrences
  • Repeating groups — each repetition independently validates required children (e.g., ADT_A39 PATIENT group needs PID+MRG per occurrence)
  • Positional ordering — violations are detected naturally because the walk is sequential
  • Cardinality — non-repeating segments/groups consumed at most once

Modes

  • :lenient (default) — unexpected segments are warnings, missing required segments are errors
  • :strict — all structural violations are errors

Usage

structure = HL7v2.Standard.MessageStructure.get("ORU_R01")
segment_ids = ["MSH", "PID", "OBR", "OBX", "NTE"]
errors = HL7v2.Validation.Structural.validate(structure, segment_ids)

Summary

Functions

Validates a list of segment IDs against a message structure definition.

Types

error()

@type error() :: %{
  level: :error | :warning,
  location: binary(),
  field: atom() | nil,
  message: binary()
}

Functions

validate(map, segment_ids, opts \\ [])

Validates a list of segment IDs against a message structure definition.

Returns a list of errors/warnings (empty list = valid).