task
Prefect task for the inclusion-criteria matching step.
Calls the pure functions in steps.criteria_matching to determine
which scans meet the clinical trial eligibility criteria.
Module
Functions
criteria_matching_task
def criteria_matching_task( datasource: BaseSource, config: CriteriaMatchConfig, *, scan_metrics: list[dict[str, typing.Any]] | None = None, patient_data: list[CacheAccessor] | None = None, filenames: Optional[list[str]] = None, ga_metrics: dict[str, GAMetricsWithFovea | None] | CacheAccessor | None = None, fluid_metrics: dict[str, FluidVolumeMetrics | None] | CacheAccessor | None = None, cst_metrics: dict[str, CSTMetrics | None] | CacheAccessor | None = None, gcc_metrics: dict[str, GCCMetrics | None] | CacheAccessor | None = None, lesion_metrics: dict[str, LesionMetrics | None] | CacheAccessor | None = None, ehr_patient_data: CacheAccessor | None = None, enrichment_data: CacheAccessor | None = None,) ‑> CriteriaMatchResult:Apply inclusion criteria and return eligibility results.
Inputs are two expandable channels: scan_metrics (a list of
{"metrics": ..., "metrics_type": ...} sources, one per scan-derived
metrics producer) and patient_data (a list of CacheAccessors, one per
patient-data producer). The legacy scalar ga_metrics / fluid_metrics /
cst_metrics / gcc_metrics / ehr_patient_data are still accepted and
coerced into single-element channel lists by _coerce_channels (an
explicit scan_metrics/patient_data channel list wins over any of the
scalars). Each scalar metrics kwarg accepts either an in-memory
{filename: metrics | None} dict or a CacheAccessor (e.g. a
cache-backed step's wired .cache); a non-dict value is rebuilt into the
dict via its typed *_metrics_from_cache wrapper.
The task adapts to the datasource:
- For a
FileSystemIterableSourcethe scan data is loaded withget_data_for_files(usingfilenames);patient_dataandscan_metricsare joined onto it by bitfount patient id /ORIGINAL_FILENAME_METADATA_COLUMNrespectively, when supplied. - For any other datasource the data is not loaded from the source. The
single
patient_datasource's frame is the table to match against andfilenamesis unused; more than onepatient_datasource raises aValueError, since merging multiple patient-grain sources by bitfount patient id is only supported on a file-system datasource.scan_metricsare only meaningful for file-system sources, so any supplied here are ignored (and a warning is logged).
scan_metrics is optional. If it is omitted (or ignored) while the config
still specifies GA-derived filters, a warning is logged because those
filters cannot be evaluated (their columns will be absent).
A field catalog is built from every wired scan_metrics source's
field_specs() and passed to build_eligibility_filters so generic
column_criteria grains resolve correctly. Any column_criteria column
that neither the catalog nor the assembled frame has is logged as a
warning — never raised, since column_criteria is a best-effort escape
hatch. (Pathology-biomarker max_<label>_probability columns are only
added to the catalog when a GA-derived scan_metrics source is wired —
see _build_catalog — so a column_criteria targeting one of those
triggers this warning on a GA-less run, since the column is genuinely
never produced.)
Arguments
datasource: The data source to match criteria against.config: The criteria-matching configuration.scan_metrics: The expandablescan_metricschannel; see above.patient_data: The expandablepatient_datachannel; see above.filenames: Filenames to load scan data for, on aFileSystemIterableSource; unused otherwise.ga_metrics: Legacy scalar GA metrics, coerced intoscan_metrics; see above.fluid_metrics: Legacy scalar fluid-volume metrics, coerced intoscan_metrics; see above.cst_metrics: Legacy scalar CST metrics, coerced intoscan_metrics; see above.gcc_metrics: Legacy scalar GCC metrics, coerced intoscan_metrics; see above.lesion_metrics: Metrics for lesion size, coerced intoscan_metrics; see above.ehr_patient_data: Legacy scalar EHR accessor, coerced intopatient_data; see above.enrichment_data: Thepatient_enrichmentstep's cache, rebuilt into a patient-grain frame and merged by bitfount patient id to contribute the supplied observations column, which observation criteria read alongside the EHR one. Optional;Noneleaves every frame untouched.
Returns
The CriteriaMatchResult with one CriteriaEvaluation per row.