Skip to main content

schema

SQLAlchemy ORM for the patients identity cache table (v3).

Declares its own local Base (isolated MetaData) carrying the shared nullable tags JSON column, so each version can coexist without a __tablename__ collision. One row per Bitfount patient ID, independent of trial/criteria. name is always present (a component of the Bitfount patient ID); ehr_patient_id is NULL for non-EHR flows.

v2 adds name_raw and name_provenance to v1: the unparsed string name was rendered from, and what kind of source that was. The table is not partitioned, so every run that reaches a patient writes the same row and something has to decide which name it keeps; name_provenance is that something, and name_raw is what lets a parsing fix re-render an already-stored name.

v3 adds practitioner_name, the patient's associated medical practitioner as the EHR reports it, served for display only.

Cache encryption is removed: name, ehr_patient_id and mrns are all stored plaintext, which lets the patient-data API run case-insensitive substring search and name ordering directly in SQL (encrypted values used a random nonce, so they were opaque to LIKE/ORDER BY).

Migration: these columns used to be EncryptedString/EncryptedJSON, so an existing cache may hold enc:v1: ciphertext. They now use the Migrating* decorators, which store plaintext on write and decrypt a legacy enc:v1: value on read — so reads stay correct through the change. name/ehr_patient_id become searchable only once rewritten to plaintext, which the one-time cache.migrations.convert_encrypted_to_plaintext migration does at startup (or that happens the next time the row is upserted).

Classes​

Base​

class Base(**kwargs: Any):

Local declarative base for patients v3.

Owns an isolated MetaData and carries the shared nullable tags JSON column that every ORM in this version inherits.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance's class are allowed. These could be, for example, any mapped columns or relationships.

Subclasses​

Variables​

  • static metadata
  • static registry
  • static tags : sqlalchemy.orm.base.Mapped[dict[str, typing.Any] | None]

Patient​

class Patient(**kwargs):

SQLAlchemy model for the patients identity table.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance's class are allowed. These could be, for example, any mapped columns or relationships.

Variables​

  • bitfount_patient_id : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • ehr_patient_id : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • mrns : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • name : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • name_provenance : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • name_raw : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • practitioner_name : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • processed_at : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • run_id : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • tags : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]
  • task_hash : Union[sqlalchemy.orm.attributes.InstrumentedAttribute[+_T_co], +_T_co]