For building complex constructs on top of the omop-alchemy library.
Project description
omop-constructs
omop-constructs is a small library for building reusable, composable analytical constructs on top of OMOP CDM using SQLAlchemy.
It sits “above” low-level OMOP table models (from omop-alchemy) and semantic definitions (from omop-semantics), and provides a way to package up common query patterns, mappings, and derived views into reusable units.
In practice, this means you can define things like:
- tumour staging logic (T/N/M, group stage),
- clinical modifiers (grade, laterality, size),
- condition + modifier joins,
- episode-linked phenotypes,
- reusable materialized views or query fragments,
and then reuse them consistently across:
- analytics code,
- cohort definitions,
- ETL / feature engineering,
- dashboards and reports.
What problem does this solve?
When working with OMOP in real research settings, you often end up re-implementing the same patterns:
- joining measurements or observations back to conditions,
- resolving multiple staging systems (clinical vs pathological),
- preferring “best available” records (earliest, latest, ranked),
- materialising complex derived tables for performance,
- wiring together multiple OMOP tables into analysis-ready shapes.
These patterns are:
- non-trivial SQL,
- project-specific but reusable,
- and easy to drift or fork across notebooks, pipelines, and services.
omop-constructs gives you a place to define these patterns once, as explicit, testable Python objects built on SQLAlchemy, and then reuse them anywhere you use OMOP.
Think of it as a library of semantic query building blocks for OMOP.
Relationship to other libraries
-
omop-alchemy
Provides the canonical, typed SQLAlchemy models for OMOP CDM tables. -
omop-semantics
Defines which concepts, groups, and roles mean what in your domain (e.g. staging, modifiers). -
omop-constructs
Uses both of the above to build higher-level analytical constructs, such as:- derived views,
- reusable joins,
- staged phenotype tables,
- canonical query fragments.
In short:
omop-alchemy defines the schema
omop-semantics defines the meaning
omop-constructs defines the reusable analytical shapes
Core ideas
-
Composable query building blocks
Encapsulate common SQL patterns as reusable Python objects. -
SQLAlchemy-first
Constructs are normal SQLAlchemyselect()expressions, subqueries, and ORM-mapped views. -
Reusable analytical units
Package complex mappings (e.g. staging logic) once and reuse them across contexts. -
Materialized view support
Support for defining derived tables and materialized views for performance and stability. -
Semantics-aware
Integrates with omop-semantics concept registries and lookups, rather than hard-coding concept IDs.
Example use case (high level)
A typical construct might:
- take OMOP
Measurementrows representing staging concepts, - classify them into T, N, M, and group stage using semantic lookups,
- rank multiple records per condition to select the “best” stage,
- expose the result as a materialized view that can be joined back to
Condition_Occurrence.
This allows downstream code to work with a clean, analysis-ready table like:
“conditions with resolved TNM stage and modifiers”
without re-implementing the logic every time.
Typical workflow
-
Define semantic lookups
Useomop-semanticsto define which concepts represent staging, grading, laterality, etc. -
Build constructs
Use SQLAlchemy andomop-alchemymodels to define reusable queries and derived views. -
Materialize or compose
Optionally materialize complex constructs into views or tables for performance. -
Reuse everywhere
Import the same construct into analytics notebooks, ETL jobs, or services.
When should you use this?
Use omop-constructs if you:
- repeatedly write and share complex OMOP joins and mappings,
- need consistent, reusable phenotype or feature definitions,
- want complex logic to live in one place that is versionable and extensible,
- are building analytics pipelines or research platforms on OMOP,
- care about making your analytical layer explicit and testable.
Design goals
- Declarative, explicit constructs
- SQLAlchemy-native
- No hidden execution or side effects
- Easy to test in isolation
- Compatible with materialized views and derived tables
- Portable across PostgreSQL, SQLite, and other SQLAlchemy backends
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file omop_constructs-0.2.12.tar.gz.
File metadata
- Download URL: omop_constructs-0.2.12.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
019957079ad499916d91ed71fb4f6bed9aba988f525ec0fa62096c59d0f5e9e7
|
|
| MD5 |
5210780abbf6dcb275aa06f4665a84ef
|
|
| BLAKE2b-256 |
a730591ba856c00309bcae986bcd0db7b0ab351b33e4be246483ee36fd7347c3
|
Provenance
The following attestation bundles were made for omop_constructs-0.2.12.tar.gz:
Publisher:
py_pi.yml on AustralianCancerDataNetwork/omop-constructs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
omop_constructs-0.2.12.tar.gz -
Subject digest:
019957079ad499916d91ed71fb4f6bed9aba988f525ec0fa62096c59d0f5e9e7 - Sigstore transparency entry: 984680809
- Sigstore integration time:
-
Permalink:
AustralianCancerDataNetwork/omop-constructs@ca506fd3d1dc0c55c12ff27992e3e8b418f87816 -
Branch / Tag:
refs/tags/0.2.12 - Owner: https://github.com/AustralianCancerDataNetwork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
py_pi.yml@ca506fd3d1dc0c55c12ff27992e3e8b418f87816 -
Trigger Event:
release
-
Statement type:
File details
Details for the file omop_constructs-0.2.12-py3-none-any.whl.
File metadata
- Download URL: omop_constructs-0.2.12-py3-none-any.whl
- Upload date:
- Size: 34.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d090de73d0528c438a744f83dd27ef019a00083cb30b1f6bad0ddb80b286fd0a
|
|
| MD5 |
34036fae9b0791d068f39a844ade639e
|
|
| BLAKE2b-256 |
55cc70b4f60b351a6341a2876d05f237f89a6b338d202ef4e01c5b2b3006c270
|
Provenance
The following attestation bundles were made for omop_constructs-0.2.12-py3-none-any.whl:
Publisher:
py_pi.yml on AustralianCancerDataNetwork/omop-constructs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
omop_constructs-0.2.12-py3-none-any.whl -
Subject digest:
d090de73d0528c438a744f83dd27ef019a00083cb30b1f6bad0ddb80b286fd0a - Sigstore transparency entry: 984680811
- Sigstore integration time:
-
Permalink:
AustralianCancerDataNetwork/omop-constructs@ca506fd3d1dc0c55c12ff27992e3e8b418f87816 -
Branch / Tag:
refs/tags/0.2.12 - Owner: https://github.com/AustralianCancerDataNetwork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
py_pi.yml@ca506fd3d1dc0c55c12ff27992e3e8b418f87816 -
Trigger Event:
release
-
Statement type: