outcomes
Evaluates the eligibility filters into one CriteriaEvaluation per row.
build_criterion_outcomes runs every filter on every row and records each
outcome with its provenance, unit and target column. A filter that raises
gives an unknown outcome (_error_outcome). build_subject_identity reads
the patient, scan, scan date, eye, name and MRNs of a row.
Module
Functions
build_criterion_outcomes
def build_criterion_outcomes( df: pd.DataFrame, filters: list[ColumnFilter | MethodFilter], column_provenance: Mapping[str, CriterionProvenance], catalog: Mapping[str, FieldSpec] | None = None, column_status: Mapping[str, str] | None = None,) ‑> list[CriteriaEvaluation]:Build one CriteriaEvaluation per df row from the eligibility filters.
Resolves each ColumnFilter's target column once (constant across rows), then
evaluates every filter per row into a CriterionOutcome. Each outcome's
provenance is stamped from column_provenance keyed by the filter's
resolved target column — the source axis, distinct from the filter's grain.
A filter that reads more than one source column overrides that per row. The
observation filter spans OBSERVATIONS_COLUMN and
SUPPLIED_OBSERVATIONS_COLUMN, whose provenances differ, so no single
filter-level column describes it and the constant resolves to UNKNOWN for
every row. Such a filter reports CriterionOutcome.matched_column — the
column that determined that row's verdict — and it is preferred here.
Single-column filters set it to None and keep the constant.
Its unit is stamped from the target column's catalogued FieldSpec, or
for a column the catalog has no unit for, from its CSV header
(COLUMN_HEADER_UNITS), so the unit travels with the evidence the API
serves rather than being knowable only from a display column name. Its
display_name comes from COLUMN_DISPLAY_NAMES, for the column the row's
verdict read.
Self-contained — does not require apply_inclusion_filters to have run.
Arguments
df: The assembled feature DataFrame (values + identity columns).filters: The eligibility filters (frombuild_eligibility_filters).column_provenance: Source-column →CriterionProvenancemap built at frame assembly; a column absent from it resolves toUNKNOWN.catalog: The aggregated{name: FieldSpec}field catalog units are read from. Optional: without it a unit comes from the CSV header only.column_status: Each scan metric column, mapped to the column that holds its analysis's status for each scan. Anunknownoutcome on such a column says why the analysis has no value, when the status tells (see_scan_unknown_reason).
Returns
A list aligned to df row order, one CriteriaEvaluation each.
build_subject_identity
def build_subject_identity(row: pd.Series[Any]) ‑> SubjectIdentity:Build the SubjectIdentity for one row from its identity columns.
All fields are read from columns criteria_matching already assembled.
scan_id/study_date/laterality are None when absent (the EHR grain).
A patient-ID column holding no value gives None, and so does one holding
the empty string: the two mean the same thing, and keeping both would leave
consumers guarding against either. first_present already maps a null
(including the pd.NA that generate_bitfount_patient_id writes for a name
it will not key) to None, so the or None here only folds in the empty
string.
Arguments
row: The df row.
Returns
The row's SubjectIdentity.