Skip to main content

Module search_param_cardinality

Module search_param_cardinality 

Source
Expand description

Resolving a search parameter’s FHIRPath expression against the StructureDefinition snapshots, to learn whether it can yield more than one value.

A parameter that yields at most one value can be stored as a scalar column, which is what lets an index answer an ordered comparison, a prefix match or a sort. One that can yield more cannot.

The answer is given per (parameter, resource type), because most shared base parameters are a union with one branch per type — AllergyIntolerance.patient | … | Observation.subject.where(resolve() is Patient) | … — and a resource only ever takes its own branch. Judging the union as a whole would let one repeating branch (DocumentReference’s encounter) deny a column to every other type.

Each branch is reduced to a plain dotted path — Patient.birthDate, Patient.name.family — and resolved against the schema, so the answer is exact and needs no sample data. A where() filter is dropped from the path, because a filter can only remove values; an ofType() or as cast narrows the leaf to the cast’s type. Anything else — an index accessor, a function the walk cannot see through — leaves the branch unanswered, and the parameter repeating for that type.

Note what this deliberately does not answer. Cardinality is the count of values the expression selects, not the count of index entries they become: Observation.code selects one CodeableConcept, which fans out to one token per coding. Callers have to combine repeats with the leaf type’s fan-out, which is why [ResolvedPath::leaf_type] is reported alongside.

Structs§

ResolvedPath
SnapshotIndex
The snapshots a path is resolved against, keyed by the type they define.

Enums§

PathAnalysis
What walking a path against the snapshots established.

Constants§

FANNING_OUT_TYPES
Datatypes whose conversion to index values emits more than one entry for a single value, so a path that selects exactly one of them still produces several index entries.

Functions§

analyze_path
Walks a plain dotted path through the snapshots, segment by segment.
generate_lookup
Emits the Rust source for the compiled lookup table.
is_single_valued_for
Whether a parameter produces at most one index entry for a resource of type base.
load_definitions
Reads every StructureDefinition under the given files or directories, following the same JSON-file walk the other generators use. Bundles are unwrapped, so a profiles-resources.min.json can be passed directly.
load_search_parameters
Reads every SearchParameter under the given files or directories.