Skip to main content

schema

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

Declares its own local Base (isolated MetaData) carrying the shared nullable tags JSON column, so a future v2/ 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.

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

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]
  • 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]