Conformance Profiles¶
Parser¶
- hl7types.profiles.parser.parse_tables(path)¶
Parse a table file into a mapping of table ID to allowed codes.
- hl7types.profiles.parser.parse_profile(path)¶
Parse an HL7 v2 conformance profile XML file into a
ProfileConstraintsobject.- Parameters:
path (str or Path) – Path to the conformance profile XML file.
- Returns:
The full tree of segment and field constraints defined in the profile, along with metadata such as HL7 version, message type, and event type.
- Return type:
ProfileConstraints
- Raises:
ValueError – If the file does not contain a valid
HL7v2xStaticDefelement.
Builder¶
- hl7types.profiles.builder.make_constrained_segment(base_cls, constraint, tables=None)¶
Return a Pydantic subclass of
base_clsthat enforces the given constraint.Fields marked
R(required) are made non-optional. Fields markedX(not used) are set toNone. String fields havemax_lengthapplied where a length is defined, and anAfterValidatoris added for any field whose table ID is present intables. If no overrides are needed the originalbase_clsis returned unchanged.- Parameters:
base_cls (type[HL7Model]) – The standard generated segment class to constrain.
constraint (SegmentConstraint) – The field-level constraints parsed from the conformance profile.
tables (dict[str, set[str]], optional) – Mapping of table ID to permitted codes. Only tables present in this dict are enforced.
- Returns:
A constrained subclass, or
base_clsif no constraints apply.- Return type:
type[HL7Model]
- hl7types.profiles.builder.build_registry_from_profile(profile, registry, *, version=None, tables=None)¶
Walk a parsed conformance profile and register constrained segment classes.
For each segment in the profile that has field-level constraints worth enforcing, a Pydantic subclass of the standard generated segment is created and registered in
registryunder the segment’s three-letter name. Segments with no enforceable constraints are left as-is.- Parameters:
profile (ProfileConstraints) – A parsed conformance profile, as returned by
parse_profile.registry (HL7Registry) – The registry to populate. Constrained classes are registered with
override=True, so protected segments such asMSHcan be constrained if the profile defines rules for them.version (str, optional) – HL7 version string to use when importing segment classes. Defaults to the version declared in the profile.
tables (dict[str, set[str]], optional) – Mapping of table ID to permitted codes, as returned by
parse_tables. Only tables present here are enforced.