Skip to content

Typing

OMOP Alchemy exposes a set of Protocols and typed containers for code that needs to interact with CDM classes without coupling to specific ORM implementations.

These live in two modules:

Module Contents
omop_alchemy.cdm.base.typing Runtime-checkable Protocols for structural checking
omop_alchemy.cdm.model.typing Typed row containers

Protocols (cdm.base.typing)

HasConceptId

Satisfied by any object with an integer concept_id attribute.

Bases: Protocol

concept_id instance-attribute

concept_id: int

HasPersonId

Satisfied by any object with an integer person_id attribute.

Bases: Protocol

person_id instance-attribute

person_id: int

HasEpisodeId

Satisfied by any object with an integer episode_id attribute.

Bases: Protocol

episode_id instance-attribute

episode_id: int

DomainSemanticTable

Structural protocol for CDM ORM classes that participate in domain validation. A class satisfies this protocol if it has __tablename__, __mapper__, __expected_domains__, and a collect_domain_rules() classmethod.

Bases: Protocol

__expected_domains__ class-attribute

__expected_domains__: dict[str, ExpectedDomain]

__mapper__ class-attribute

__mapper__: DeclarativeMeta

__tablename__ class-attribute

__tablename__: str

collect_domain_rules classmethod

collect_domain_rules() -> list[DomainRule]

ClinicalEvent (Protocol)

Minimal protocol for ORM rows that represent a clinical event — a concept, a person, a start date, and an optional end date. Used as the structural contract for domain-level utilities that operate across multiple CDM tables.

Note

The concrete mixin of the same name lives in omop_alchemy.cdm.handlers.timeline.event_timeline. The Protocol here is the structural interface; the mixin there is the implementation.

Bases: Protocol

__tablename__ instance-attribute

__tablename__: str

concept_id instance-attribute

concept_id: int

end_date instance-attribute

end_date: Optional[date]

event_id instance-attribute

event_id: int

person_id instance-attribute

person_id: int

start_date instance-attribute

start_date: date

type_concept_id instance-attribute

type_concept_id: int

visit_detail_id instance-attribute

visit_detail_id: Optional[int]

visit_occurrence_id instance-attribute

visit_occurrence_id: Optional[int]

ConceptResolver

Protocol for objects that can look up whether a set of concept IDs are standard.

Bases: Protocol


Typed row containers (cdm.model.typing)

ConceptRow

A frozen dataclass representing the core fields of a concept lookup row. Used where a lightweight, hashable concept record is preferable to a full ORM object.

concept_class_id instance-attribute

concept_class_id: str | None

concept_code instance-attribute

concept_code: str

concept_id instance-attribute

concept_id: int

concept_name instance-attribute

concept_name: str

domain_id instance-attribute

domain_id: str | None

standard_concept instance-attribute

standard_concept: str | None

vocabulary_id instance-attribute

vocabulary_id: str | None