v1
patient_level_eligibility step, v1 — canonical aliases.
Module
Submodules
- bitfount.steps.patient_level_eligibility.v1.config - Config for the patient_level_eligibility step (v1).
- bitfount.steps.patient_level_eligibility.v1.functions - Pure helpers for the patient_level_eligibility step.
- bitfount.steps.patient_level_eligibility.v1.result - Result for the patient_level_eligibility step (v1).
- bitfount.steps.patient_level_eligibility.v1.task - Prefect task for the patient_level_eligibility step.
Functions
task_fn
def task_fn( evaluations: list[CriteriaEvaluation], cache: CacheProtocol, task_hash: str, project_id: str, config: PatientLevelEligibilityConfig | None = None, ehr_patient_data: CacheAccessor | None = None, run_id: str | None = None,) ‑> PatientLevelEligibilityResult:Compute + persist each patient's EHR verdict and identity rows.
Arguments
evaluations: Per-rowCriteriaEvaluations fromcriteria_matching; one representative evaluation per patient is used (patient-level criteria and identity are constant across a patient's scans).cache: The pod background cache to write to.task_hash: Partition key; a config change lands in a fresh partition.project_id: The trial (project) ID (a runtime param).config: Optional step config (trial display name); nothing in it is persisted by this step.ehr_patient_data: Optional EHR cache accessor for patient identity (ehr_patient_id, name, MRNs) and for theehr_retrieved_atcolumn (the EHR row's ownprocessed_at, so a served-but-stale row reports its true age rather than this run's time); when absent, identity falls back to the evaluation'sSubjectIdentityand no retrieval time is recorded.run_id: Optional provenance run ID.
Returns
PatientLevelEligibilityResult with the number of
patient_level_eligibility rows written and a cache accessor scoped
to this task_hash.
Raises
ValueError: Ifproject_idis not supplied.
Classes
Config
class Config(**data: Any):Config for the patient_level_eligibility step.
Arguments
trial_name: Optional display name for the trial, stored for the UI.
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.
Result
class Result(**data: Any):Result of a patient_level_eligibility task.
records_stored reports how many patient_level_eligibility rows were persisted;
cache exposes the CacheAccessor over them for the downstream reduce step.
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.
Ancestors
Variables
- static
model_config
cache : CacheAccessor | None- Return theCacheAccessorfor reading this result in a DAG pipeline.
-
records : pandas.core.frame.DataFrame- Retrieve this result's rows as a DataFrame.The DataFrame is fetched from the cache on each access — it is not stored in the result object, allowing lazy access to large datasets without materialising them in memory until needed.
Returns: A
pandas.DataFramewith one row per cached record.Raises: RuntimeError: If no accessor is attached (e.g. the result was serialised across a Prefect task boundary). In a DAG pipeline use
<step_name>.cacheinstead.
Static methods
from_accessor
def from_accessor( accessor: CacheAccessor, *, records_stored: int | None = None,) ‑> Self:Inherited from:
CacheBackedResult.from_accessor :
Build a result carrying accessor, in one call rather than two.
_accessor is a PrivateAttr, so it cannot be passed to the
constructor and every producer would otherwise construct the result and
then reach in to attach the accessor. That two-step is the shape this
replaces.
Arguments
accessor: TheCacheAccessorbacking<step>.cache, scoped to the partition this result stands for.records_stored: Rows this result stands for. Defaults toaccessor.count()— the whole partition — which is what a step that persisted nothing this run reports. A step that wrote rows passes what it wrote; see the field's docstring for why the two are not interchangeable.
Returns An instance of the calling subclass, with the accessor attached.
Methods
model_post_init
def model_post_init(self: BaseModel, context: Any, /) ‑> None:Inherited from:
CacheBackedResult.model_post_init :
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.