task
Prefect task priming the EHR serving layer 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, in the same two modes v1
supports (see EHRQueryConfig.mode).
What differs from v1 is what happens when the EHR cannot be reached. v1 is a
gate: it raises, and because the step is step 1 of a sequential step loop
(flows/dag/executor.py) nothing downstream runs — no inference, no
calculations, no criteria_matching, no pointer flip. v3 is a primer instead:
it stores whatever it did fetch, reports how the run went on its result, and
returns a real cache accessor either way, so downstream steps read this run's
rows where they exist and earlier runs' rows where they do not.
Best-effort behaviour is unconditional here rather than a config flag, because
_semantic_config hashes every config field including defaults
(flows/dag/hashing.py): adding a flag would move the ehr_query partition for
every template using the config, including the one that keeps fail-fast on v2
and whose ehr_data cache must survive. Which template gets which behaviour is
answered by the version in the YAML.
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:Prime the EHR cache for the current run, without failing the run.
Arguments
ehr_data_resource: Configured EHR resource (NextGen or FHIR R4).Nonemeans no EHR reached this pod's DAG setup: the run continues, nothing is queried, and the result reportsEHRRunOutcome.NOT_CONFIGURED.cache: Cache backend to writeehr_datarows to.task_hash: Hash identifying the current task run; written into every row so re-runs upsert viasession.merge.config: Step config.config.modeselects between filename-driven and patient-ID-cache-driven lookups,config.fetch_appointmentscontrols whether appointment and encounter history is fetched, andconfig.observation_codes/config.observation_categoriesfetch coded Observations matching those codes/categories (merged and deduplicated when both are set). If neither is set, every core FHIR observation-category is fetched by default — seeEHRQueryConfig.fetch_options. Whenconfigitself isNonethe 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 theehr_patient_idstable (typically wired fromehr_patient_lister.cachein the YAML). Required in"patient_id_cache"mode.
Returns
The step result, always carrying a CacheAccessor over this run's
ehr_data partition — including when no row was stored, since an
unwired accessor costs criteria_matching its EHR columns
entirely, and EHR criteria then read as scan evidence with
provenance unknown rather than as UNKNOWN EHR evidence.
Raises
ValueError: Ifconfig.modeis not one this step supports, or the mode's required inputs are missing. A misconfigured step is not an EHR outage.