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
Functions
@spec validate(HL7v2.Standard.MessageStructure.structure(), [binary()], keyword()) :: [error()]
Validates a list of segment IDs against a message structure definition.
Returns a list of errors/warnings (empty list = valid).