device
Criteria on a patient's devices (FHIR Device).
The device leaf (DeviceCriterion): a device of a matching code or text is
recorded for the patient, for example an implanted pacemaker. The records are
read from the device column of the EHR data.
Module
Functions
device_leaf_filter
def device_leaf_filter( criterion: DeviceCriterion, ctx: FilterBuildContext,) ‑> MethodFilter:Build a MethodFilter for a DeviceCriterion criteria_tree leaf.
A device's code lives in exactly one place (its own type), so the code
arm filters on that alone. criterion.text adds a second arm matching
the strings that name the device. The two are AND-ed, each
skipped when unconfigured. A criterion configuring neither is rejected
at validation, so an entry can never match by default.
It reads against the fixed DEVICES_COLUMN.
Arguments
criterion: The leaf to compile.ctx: What the filter builders share; unused here.
Returns
A MethodFilter degrading to unknown when DEVICES_COLUMN is
absent from the row, or the row's cell is unreadable.
Classes
DeviceCriterion
class DeviceCriterion(**data: Any):An EHR device record, matched by its own type code or its text.
FHIR R4 Device (https://hl7.org/fhir/R4/device.html) carries no field
meaning "when this became relevant to the patient" (only
manufactureDate/expirationDate, neither clinical) — unlike every
other code-addressed leaf, this one has no date_range at all, not
merely an unset one. selector is declared fresh here rather than
inherited and narrowed: a mutable pydantic field's type must stay
invariant across a class hierarchy, so narrowing an inherited field in a
subclass is unsound and pyrefly rejects it
(bad-override-mutable-attribute). Declaring it fresh here instead
excludes "latest"/"earliest" (neither can select a "most recent"
entry with no date to order by) and "all" (a poor fit for trial
criteria — a patient's devices are typically unrelated to each other,
e.g. a pacemaker and a hip implant — and mathematically identical to
"any" here regardless, since with no secondary per-entry check both
reduce to "at least one candidate").
text matches the strings that name the device — its code_text and
each codings[].display — rather than its code, and applies whether or
not the device is coded. Given alone it is an alternative to code;
given alongside one it narrows that match rather than widening it.
It exists because for some backends a device has no code to match at all. NextGen builds a device record from the FDA GUDID catalogue, which carries no SNOMED CT concept, so its devices are named by a Global Medical Device Nomenclature term and coded not at all — a code-only criterion can never match one. GMDN is a controlled vocabulary of device types, so matching its terms is closer to matching a code than free text usually is.
code is optional here, as on AllergyCriterion and for the same
reason: a text-only criterion has to be expressible, and for a
GUDID-sourced device it is the only expressible one. Supplying neither
is rejected — a leaf narrowed only by selector would count devices of
any kind, which is not a question trial criteria ask. When both are
given they are additional restrictions, not alternatives: an entry must
match both.
Arguments
node: Discriminator identifying this as adevice-typecriteria_treenode.code: As_BareCodeAddressedLeaf.code; omit it for a text-only criterion.text: Free text matched against the strings naming the device, glob-capable the same waycodeis (e.g."*intraocular lens*"), or a list of alternatives. Matched case-insensitively, unlikecode, since the casing of a device name depends on which backend answered. Matched against the whole string, so a bare"intraocular lens"does not match"Anterior-chamber intraocular lens, pseudophakic"— wrap it in*to match within. Searched acrosscode_textand everycodings[].display; see_code_text_candidates.selector:"any", or aCountSelectorrequiring at leastNqualifying devices (see above for why"all"/"latest"/"earliest"are excluded).
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Variables
- static
criterion_noun : ClassVar[str]
- static
model_config
- static
node : Literal['device']
- static
selector : Literal['any'] | CountSelector
Methods
model_post_init
def model_post_init(self: BaseModel, context: Any, /) ‑> None:This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that's what pydantic-core passes when calling it.
Arguments
self: The BaseModel instance.context: The context.