Skip to main content

model

Pydantic record for the ehr_data cache table (v7).

Classes

EHRDataRecord

class EHRDataRecord(**data: Any):

Stored EHR data record for a single patient.

The background flow extracts patient demographic and code data from the EHR datasource and stores it here. The interactive flow applies code filters against the stored diagnosis_codes, condition_codes, and procedure_codes lists to determine EHR eligibility.

file_ids_json holds all imaging file IDs associated with this patient in the batch. Multiple files for the same patient are accumulated into the list before the row is written, so no file ID is ever silently overwritten. It is None for EHR-only tasks that have no associated imaging files.

error is non-None when EHR extraction failed for this patient.

run_id is the UUID of the run that produced this record (for provenance).

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Variables

  • static allergy_codes_json : list[typing.Any] | None
  • static bitfount_patient_id : str
  • static cell_numbers : list[str]
  • static condition_codes_json : list[dict[str, str | None | datetime.datetime | dict[str, str] | list[dict[str, typing.Any]]]] | None
  • static country : str | None
  • static device_codes_json : list[typing.Any] | None
  • static ehr_patient_id : str
  • static emails : list[str]
  • static error : str | None
  • static family_name : str | None
  • static fetch_states_json : dict[str, str] | None
  • static file_ids_json : list[str] | None
  • static gender : str | None
  • static given_name : str | None
  • static home_numbers : list[str]
  • static mailing_address : str | None
  • static medical_record_number : list[str] | None
  • static medication_codes_json : list[typing.Any] | None
  • static model_config
  • static next_appointment : str | None
  • static patient_id : str | None
  • static patient_metadata_json : dict[str, typing.Any] | None
  • static postal_code : str | None
  • static previous_appointments_json : list[typing.Any] | None
  • static previous_encounters_json : list[typing.Any] | None
  • static procedure_codes_json : list[dict[str, str | None | datetime.datetime | dict[str, str] | list[dict[str, typing.Any]]]] | None
  • static row_number : int | None
  • static run_id : str | None
  • static task_hash : str

EHRFetchedSource

class EHRFetchedSource(*args, **kwds):

One fetched source, at the grain of the ehr_data column it fills.

Names the source only; what happened to it is the FetchState stored against it in EHRDataRecord.fetch_states_json.

Column grain rather than FetchGroup grain because the group is too coarse to answer the reader's question: FetchGroup.APPOINTMENTS spans three fetches, and a group whose appointments leg answered reports no failure reason at all even when its encounters leg can never answer.

Members are added as readers need to tell one absent column from another — a source's absence from this enum means no reader has needed to ask about it, not that it is always retrievable.

Variables

  • static PREVIOUS_APPOINTMENTS
  • static PREVIOUS_ENCOUNTERS

FetchState

class FetchState(*args, **kwds):

Why a fetched source produced no value, where a bare NULL cannot say.

A NULL list column means "not retrieved", which readers resolve as UNKNOWN. That is right for a fetch that failed this run and wrong for one the backend structurally cannot serve: the latter is NULL on every run for every patient, so a reader that waits for it to fill waits forever. appointment_history_filter is the case that forced the distinction — it counts list-valued history columns to decide whether the history it judged was complete, and downgrades a FAIL to UNKNOWN when it was not, so a permanently-NULL encounters column left that criterion unable to exclude anybody on a backend with no Encounter endpoint.

A source that answered has no entry at all, so the absence of a state is the success case and a reader must treat a missing key as "answered".

Variables

  • static NOT_ATTEMPTED
  • static UNAVAILABLE
  • static UNSUPPORTED