Coverage for src/lumen/fhir/params.py: 100%
17 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-08-31 18:46 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-08-31 18:46 +0000
1"""
2This file defines structure representations and data types for FHIR search parameters.
3It exports definitions like SearchParamDef and types used for indexing and parsing.
4"""
6from __future__ import annotations
8from dataclasses import dataclass
9from typing import Literal
11SearchParamType = Literal[
12 "string", "token", "date", "reference", "quantity", "number", "composite", "geo"
13]
15# Component types supported inside a composite search parameter (MVP: the two
16# kinds actually used by R4B composite SearchParameters with 2 components,
17# e.g. Observation-combo-code-value-quantity, conformance-context-type-value).
18CompositeComponentType = Literal["token", "quantity"]
21@dataclass(frozen=True)
22class CompositeComponent:
23 """One component of a composite search parameter (``SearchParameter.component``).
25 ``expression`` is relative to each occurrence of the composite's own base
26 path (e.g. relative to a single ``Observation.component`` entry, not the
27 whole resource).
28 """
30 type: CompositeComponentType
31 expression: str
34@dataclass(frozen=True)
35class SearchParamDef:
36 name: str
37 type: SearchParamType # internal index type — picks the spidx_* table
38 paths: list[str] # FHIRPath expressions (composite: base/grouping paths)
39 definition: str = "" # canonical URL of the SearchParameter resource
40 # FHIR-declared type for CapabilityStatement output (e.g. "uri"), when it
41 # differs from the internal index type (e.g. "uri" indexes as "token").
42 # None means the declared type equals ``type``.
43 declared_type: str | None = None
44 # Set only when type == "composite": exactly 2 components, first always
45 # "token" and second either "token" or "quantity" (MVP scope).
46 components: tuple[CompositeComponent, ...] | None = None