task
Prefect task for CSV report generation.
Uses pure functions from steps.csv_report.functions for all DataFrame
transformations.
Module
Functions
csv_report_task
def csv_report_task( datasource: BaseSource, config: CSVReportConfig, csv_report_df: pandas.core.frame.DataFrame, filenames: list[str], task_id: str, ga_metrics: dict[str, GAMetricsWithFovea | None] | CacheAccessor | None = None, ehr_patient_data: CacheAccessor | None = None, encryption_key: bytes | None = None, sorting_columns: Optional[list[str]] = None,) ‑> CSVReportResult:Generate CSV report using composable pure functions.
Adapts to the datasource grain. For a FileSystemIterableSource the report's
demographic/source columns come from get_data_for_files (keyed by filename)
and the eligibility projection is merged on ORIGINAL_FILENAME_METADATA_COLUMN.
For any other datasource (the EHR grain) the demographics live on the EHR
patient frame criteria_matching matched against — not the null datasource —
so they are sourced from ehr_patient_data and the projection is merged on
EHR_BITFOUNT_PATIENT_ID_COL.
Arguments
datasource: The datasource providing source data for the report.config: CSV report configuration (includestrial_nameand therename_columnsmap).csv_report_df: DataFrame with metrics/results to report on. Typicallytabulate_criteria_outcomes's eligibility projection, keyed by the grain's merge column.filenames: List of file IDs being reported.task_id: Task run ID.ga_metrics: Optional GA metrics, re-assembled into columns (e.g. distance from fovea) that GA-metric-dependent CSV extensions consume. Either an in-memory{filename: GAMetricsWithFovea | None}map (same-phase producer) or thega_calculation.cacheaccessor (when GA calculation ran in the background);Nonewhen the flow has no GA-metrics producer. Only meaningful on the file-system grain.ehr_patient_data: The EHR patient frame to source demographics from on the non-file-system grain (the same tablecriteria_matchingmatched against). Ignored for aFileSystemIterableSource.encryption_key: Optional encryption key for encrypted CSV output.sorting_columns: Optional columns to sort the final CSV by.
Returns CSVReportResult indicating success.