Skip to main content

task

Prefect task for pre-computing EHR data during the background flow.

Extracts patient demographic and code data from the EHR datasource and persists the combined records to the ehr_data cache table. Two modes are supported, selected via EHRQueryConfig.mode:

"filename" (default) Patients are resolved from imaging file metadata (name + DOB columns on the datasource).

"patient_id_cache" Patients are resolved by ID streamed from a cache accessor wired in via the step's inputs: block — typically the output of ehr_patient_lister.

Module

Functions

ehr_criteria_query_task

def ehr_criteria_query_task(    ehr_data_resource: EHRDataResource | None,    cache: CacheProtocol,    task_hash: str,    config: EHRQueryConfig | None = None,    datasource: BaseSource | None = None,    filenames: list[str] | None = None,    patient_ids: CacheAccessor | None = None,)> EHRQueryResult:

Extract and cache EHR data for the current run.

Arguments

  • ehr_data_resource: Configured EHR resource (NextGen or FHIR R4).
  • cache: Cache backend to write ehr_data rows to.
  • task_hash: Hash identifying the current task run; written into every row so re-runs upsert via session.merge.
  • config: Step config. config.mode selects between filename-driven and patient-ID-cache-driven lookups, config.fetch_appointments controls whether appointment and encounter history is fetched, and config.observation_codes/config.observation_categories fetch coded Observations matching those codes/categories (merged and deduplicated when both are set). If neither is set, every core FHIR observation-category (ALL_OBSERVATION_CATEGORIES) is fetched by default — see EHRQueryConfig's docstring. When config itself is None the defaults are used so existing programmatic callers do not have to pass one.
  • datasource: Imaging datasource. Required in "filename" mode.
  • filenames: Imaging file IDs to process. Required in "filename" mode.
  • patient_ids: Cache accessor over the ehr_patient_ids table (typically wired from ehr_patient_lister.cache in the YAML). Required in "patient_id_cache" mode.