TypeSchema: precompute derived slice facts and refine the slicing model - #207
Draft
ryukzak wants to merge 9 commits into
Draft
TypeSchema: precompute derived slice facts and refine the slicing model#207ryukzak wants to merge 9 commits into
ryukzak wants to merge 9 commits into
Conversation
FieldSlice gains effectiveRequired, constrainedChoice, autoStub and resourceType, populated once at snapshot build. The TS and Python writers consume them instead of re-deriving the same semantics per language, which removes duplicated collectors and fixes two divergences that duplication had already produced: - Python auto-stubbed required slices that need user data beyond the discriminator match (e.g. US Core race/ethnicity text slices) — extension profiles now keep 'extension' as an optional create() param populated via sub-extension setters, mirroring the TS Raw type; - validateSliceFields no longer requires choice-declaration base names (phantom 'value' key that never exists in FHIR JSON) inside slices.
FieldSlice.match becomes { kind: "value" | "type", value } — the runtime
discriminator values keep their shape under 'value', while 'kind' states
whether they are fixed/pattern discriminator values or a resource-type
discriminator. Empty matches are no longer stored, so consumers test presence
instead of key-counting. Generated output is unchanged.
…ield flatProfile previously replaced the whole inherited FieldSlicing when a child profile restated slicing on the same field. Now the child refines it: its header and same-name slices win, inherited slices survive.
…extension-slice ownership explicit Extension-style slices carry their discriminator value as schema.url and their cardinality on the slice schema (fhirschema convention); buildSlicing now recovers both, so the slicing map has no degenerate entries. Writers replace the accidental skip (missing match) with an explicit rule: on resource-based profiles, extension/modifierExtension slices are owned by the ProfileExtension mechanism; on Extension-based profiles the slice machinery keeps generating the sub-extension slice API as before. Generated output is unchanged.
…N schema
Adds field-slicing/field-slice/slice-match/slice-discriminator definitions —
including the snapshot-time derived facts (effectiveRequired,
constrainedChoice, autoStub, resourceType) — attaches the schema-level
'slicing' map next to 'fields', and updates 'reference' to the
{ resource, profiles } shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second PR of the slice-refactor sequence started in #203.
Derived slice facts
FieldSlicegains four derived facts, computed once at snapshot build (enrichSlicein the index):effectiveRequired(required − match keys − choice-declaration base names),constrainedChoice(the single narrowed choice variant),autoStub(stub-eligible with just the discriminator match),resourceType(matched resource type of type-discriminated slices).tsIndex.constrainedChoicecalls, two divergent resource-type extractors) are deleted.validateSliceFields/validate_slice_fieldsno longer require choice-declaration base names — a phantom key ("value") that never exists in FHIR JSON and could only false-fail;extensionas an optionalcreate()param populated via sub-extension setters, mirroring the TSRawtype.effectiveRequiredbut still blockautoStub.Slicing model refinements
matchbecomes a discriminatedSliceMatchunion:{ kind: "value" | "type", value }; empty matches are no longer stored, so consumers test presence instead of key-counting.{ url }match is recovered fromschema.urland cardinality from the slice schema (fhirschema convention) — no more degenerate slicing entries. Writers replace the accidental skip (missing match) with an explicit ownership rule: on resource-based profilesextension/modifierExtensionslices belong to the ProfileExtension mechanism; Extension-based profiles keep their sub-extension slice API.flatProfile(leaf header and same-name slices win, inherited slices survive) instead of replacing it wholesale.docs/type-schema.schema.jsondocuments the slicing model (incl. derived facts) and thereference: { resource, profiles }shape from TypeSchema/TS/PY: resolve reference targets to base resources, keep profile expectations separately #201.Example of the enriched serialized slice (BP component):
Generated output changes are limited to the two bug fixes (US Core race/ethnicity/tribal extension profiles, TS + Python); everything else is byte-identical.