Skip to main content

assembly

Builds the eligibility filters from a criteria-matching config.

build_eligibility_filters turns the flat config fields and the criteria_tree leaves into filters, with the builders of each domain module. apply_inclusion_filters applies them to a frame.

Module​

Functions​

apply_inclusion_filters​

def apply_inclusion_filters(    df: pd.DataFrame, filters: list[ColumnFilter | MethodFilter],) ‑> pandas.core.frame.DataFrame:

Apply a list of eligibility filters to df.

Runs each filter in turn (every filter appends its own eligibility / exclusion-reason columns), then trims the joined reason string.

Arguments

  • df: The assembled feature frame. A FILTER_FAILED_REASON_COLUMN is seeded when absent so every row carries a reason string.
  • filters: The eligibility filters to apply, in order.

Returns The same frame with each filter's eligibility/reason columns added and the aggregate reason column stripped of stray separators.

Extracted from BaseGATrialInclusionWorkerAlgorithmSingleEye._filter_by_criteria.

build_eligibility_filters​

def build_eligibility_filters(    config: CriteriaMatchConfig,    catalog: dict[str, FieldSpec] | None = None,    column_provenance: Mapping[str, CriterionProvenance] | None = None,    reference_date: date | None = None,) ‑> list[ColumnFilter | MethodFilter]:

Build the eligibility filter list from a criteria-matching config.

Every criterion is expressed as a filter so that eligibility (and its failure reasons) can be derived from a single pass over the data. A bound left as None contributes no filter, and an empty/None code list contributes no filter.

Bounds notes:

  • GA area / largest GA lesion: exclusive (> lower, < upper).
  • CNV: eligible only when strictly below the threshold (<).
  • Patient age: inclusive (>= lower, <= upper), per clinical protocol.
  • Distance from fovea: inclusive (>= lower, <= upper).
  • exclude_foveal_ga: when set, excludes rows whose lesion sits exactly at the fovea centre (distance == 0).

Inclusion code lists make a patient eligible when any one code matches; exclusion code lists make a patient ineligible when any one code matches.

Arguments

  • config: The criteria-matching config.
  • catalog: The aggregated field catalog used to resolve a generic column_criteria grain, or None for an empty catalog.
  • column_provenance: Source-column → provenance map, used as the last-resort grain source for a column_criteria column the catalog does not carry (an EHR column resolves to PATIENT). None/absent columns fall through to the SCAN default.
  • reference_date: The date every dated criterion counts from, or None for today in UTC.

warn_on_missing_appointment_columns​

def warn_on_missing_appointment_columns(    config: CriteriaMatchConfig, frame: pd.DataFrame,) ‑> None:

Warn when appointment criteria are configured but no data reached them.

fetch_appointments lives on the ehr_query step's config, while the appointment-history criteria live on this step's config, so nothing else cross-checks them. A modeller who configures appointment_history, current_patient_months, and/or an AppointmentWindowCriterion criteria_tree leaf while the ehr_query step ran without fetch_appointments gets NULL appointment columns for every patient — every one of those criteria evaluates to unknown for every row, and since matches_all requires PASS, no row can be eligible. This surfaces that misconfiguration explicitly.

Absent columns alone do not detect it. SqliteCacheAccessor.to_dataframe builds its column list from the ORM's mapped attributes, so every ehr_data column is in the frame whenever a patient_data source is wired, however empty. The fetch_appointments: false case therefore shows up as columns that are present and entirely NULL, which is what the second check below looks for; the missing-column check still catches a run with no EHR source at all.

Arguments

  • config: The criteria-matching config.
  • frame: The assembled match frame.