Skip to main content

task

Prefect task for the patient_level_eligibility step.

The patient-grain step. Evaluates each patient's patient-level criteria from criteria_matching's structured evaluations and persists a per-patient verdict to the patient_level_eligibility table (one row per patient, partitioned by task_hash), and — in the same per-patient pass — writes the patients identity rows from the EHR cache (falling back to the evaluation's SubjectIdentity). The patient_eligibility reduce step combines this verdict with the per-scan rollup from scan_eligibility.

EHR is the primary (but optional) source of patient-level criteria and identity: ehr_patient_data may be absent, in which case identity falls back to the scan's DICOM-derived SubjectIdentity, and scan-provenance patient-grain criteria (e.g. DICOM age) still flow through. This is why the step is wired into EHR-free templates (e.g. patient_eligibility_scan_only_v9) — patient_eligibility needs its per-patient row and this step is the sole writer of the patients identity table.

Module

Functions

patient_level_eligibility_task

def patient_level_eligibility_task(    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-row CriteriaEvaluations from criteria_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 the ehr_retrieved_at column (the EHR row's own processed_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's SubjectIdentity and 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: If project_id is not supplied.