Skip to main content

model

Pydantic record for the ehr_data cache table (v9).

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 | bool | datetime.datetime | dict[str, str] | list[dict[str, typing.Any]]]] | None
  • static country : str | None
  • static deceased : bool | 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 practitioner_name : 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 | bool | 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.

Each value is the ehr_data column it fills, minus the _json suffix, with one exception: BCVA_DOCUMENTS names no column of its own. It is a sub-source of observation_codes, the patient's documents, whose visual acuity readings land in that column beside the observations searched for there. It has its own state because the column can answer while the documents did not, and a reader of acuity has to know that.

Variables​

  • static ALLERGY_CODES
  • static BCVA_DOCUMENTS
  • static CONDITION_CODES
  • static DEVICE_CODES
  • static MEDICATION_CODES
  • static NEXT_APPOINTMENT
  • static OBSERVATION_CODES
  • static PRACTITIONER_NAME
  • static PREVIOUS_APPOINTMENTS
  • static PREVIOUS_ENCOUNTERS
  • static PROCEDURE_CODES

FetchState​

class FetchState(*args, **kwds):

Why a fetched source produced no value of its own this run.

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".

The two failure states are read by different callers, and the split is what lets each act correctly. The criteria select UNSUPPORTED only, to stop waiting on a column that can never fill. ehr_query's fetch skip (fresh_ehr_data_patient_ids) selects UNAVAILABLE and not UNSUPPORTED, to re-query a patient whose row is blank for a reason that may resolve — without re-querying one whose backend will answer the same way for ever. A row whose only such source is BCVA_DOCUMENTS is re-queried once it is a day old rather than on the next run (_CCD_RETRY_AFTER in the store), since a CCD failure is often deterministic and the re-query re-runs the patient's whole record.

CARRIED_FORWARD is the one state whose source holds a value: the fetch failed this run, and the value is the last answer an earlier run stored (carry_forward_ccd_acuity in bitfount.steps.ehr_query.functions). A reader selecting UNAVAILABLE or UNSUPPORTED does not select it, so the criteria read the source as answered; the fetch skip re-queries it as it does UNAVAILABLE, a day bound included.

Variables​

  • static CARRIED_FORWARD
  • static NOT_ATTEMPTED
  • static UNAVAILABLE
  • static UNSUPPORTED