-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
11,426 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!--- | ||
Thank you for your soon-to-be pull request. Before you submit this, please | ||
double check to make sure that you've added an entry to CHANGELOG.md. | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Ruff | ||
on: [push, pull_request] | ||
jobs: | ||
ruff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
- name: Install nox | ||
run: pip install nox | ||
- name: Run ruff linter via nox session | ||
run: nox -s lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This workflow will install Python dependencies, run tests with a range of Python versions | ||
|
||
name: tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
python-version: [ | ||
'3.8', | ||
'3.9', | ||
'3.10', | ||
'3.11', | ||
'3.12', | ||
] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
- name: Install package and dependencies | ||
run: poetry install | ||
- name: Test with pytest | ||
run: poetry run pytest -vs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.3.2 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
args: [ --fix ] | ||
# Run the formatter. | ||
- id: ruff-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Changelog | ||
|
||
## v0.1.0 | ||
First release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# omop-cdm | ||
|
||
Python SQLAlchemy table definitions of the [OHDSI OMOP CDM](https://ohdsi.github.io/CommonDataModel/). | ||
|
||
## Installation | ||
|
||
omop-cdm requires Python >= 3.8. | ||
|
||
Install from PyPI: | ||
```shell | ||
pip install omop-cdm | ||
``` | ||
|
||
## Usage | ||
|
||
See [User documentation](docs/README.md) | ||
|
||
## Supported databases | ||
The omop-cdm table definitions are tested to be compatible with PostgreSQL. | ||
|
||
Though not officially supported, omop-cdm doesn't use postgres-specific features | ||
of SQLAlchemy, so it can likely be used for other database types as well. | ||
|
||
## CDM versions | ||
omop-cdm contains table defintions for the following CDM versions: | ||
- CDM 5.4 | ||
- CDM 5.3.1 | ||
- CDM 6.0.0 ([not recommended](https://ohdsi.github.io/CommonDataModel/cdm60.html#NOTE_ABOUT_CDM_v60)) | ||
|
||
## Development | ||
|
||
### Setup steps | ||
|
||
- Make sure [Poetry](https://python-poetry.org/docs/#installation) is installed. | ||
- Install the project and dependencies via `poetry install`. | ||
- Set up the pre-commit hook scripts via `poetry run pre-commit install`. | ||
|
||
### Nox sessions | ||
|
||
Several developer actions (e.g. run tests, code format, lint) are available | ||
via [nox](https://nox.thea.codes/en/stable/) sessions. | ||
For a complete list, run: | ||
```shell | ||
nox --list | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import nox # type: ignore | ||
|
||
nox.options.sessions = [ | ||
"tests", | ||
"lint", | ||
] | ||
|
||
python = [ | ||
"3.8", | ||
"3.9", | ||
"3.10", | ||
"3.11", | ||
"3.12", | ||
] | ||
|
||
|
||
@nox.session(python=python) | ||
def tests(session: nox.Session): | ||
"""Run test suite.""" | ||
session.run("poetry", "install", external=True) | ||
session.run("pytest", "--cov=src") | ||
session.notify("coverage") | ||
|
||
|
||
@nox.session | ||
def coverage(session: nox.Session): | ||
"""Generate pytest code coverage report.""" | ||
session.run("coverage", "report", "--show-missing") | ||
|
||
|
||
@nox.session(reuse_venv=True, name="format") | ||
def format_all(session: nox.Session): | ||
"""Format codebase with ruff.""" | ||
session.run("poetry", "install", "--only", "dev", external=True) | ||
session.run("ruff", "format") | ||
# format imports according to isort via ruff check | ||
session.run("ruff", "check", "--select", "I", "--fix") | ||
|
||
|
||
@nox.session(reuse_venv=True) | ||
def lint(session: nox.Session): | ||
"""Run ruff linter.""" | ||
session.run("poetry", "install", "--only", "dev", external=True) | ||
# Run the ruff linter | ||
session.run("ruff", "check") | ||
# Check if any code requires formatting via ruff format | ||
session.run("ruff", "format", "--diff") |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[tool.poetry] | ||
name = "omop-cdm" | ||
version = "0.1.0" | ||
description = "SQLAlchemy ORM of the OHDSI OMOP CDM" | ||
authors = [ | ||
"Spayralbe <[email protected]>", | ||
] | ||
readme = "README.md" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
sqlalchemy = "^2.0.4" | ||
|
||
|
||
[tool.poetry.group.dev.dependencies] | ||
nox = "^2024.3.2" | ||
ruff = "^0.3.2" | ||
pre-commit = "^3.5.0" | ||
|
||
[tool.poetry.group.test.dependencies] | ||
pytest = "^8.1.1" | ||
pytest-cov = "^4.1.0" | ||
testcontainers = {version = ">=3.7.1", extras = ["postgres"]} | ||
psycopg2-binary = "^2.9.9" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
|
||
[tool.pytest.ini_options] | ||
addopts = "--import-mode=importlib" | ||
pythonpath = [ | ||
".", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
src = ["src", "."] | ||
|
||
[lint] | ||
select = [ | ||
# pycodestyle | ||
"E", "W", | ||
# Pyflakes | ||
"F", | ||
# pyupgrade | ||
"UP", | ||
# flake8-bugbear | ||
"B", | ||
# flake8-simplify | ||
"SIM", | ||
# flake8-builtins | ||
"A", | ||
# flake8-return | ||
"RET", | ||
# flake8-pytest-style | ||
"PT", | ||
# flake8-use-pathlib | ||
"PTH", | ||
# flake8-self | ||
"SLF", | ||
# flake8-comprehensions | ||
"C4", | ||
# Ruff-specific rules | ||
"RUF", | ||
# isort | ||
"I", | ||
] | ||
|
||
[lint.isort] | ||
known-first-party = ["omop_cdm"] | ||
|
||
# Ignore import violations in all `__init__.py` files | ||
[lint.per-file-ignores] | ||
"__init__.py" = ["E402", "F401"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from omop_cdm.constants import NAMING_CONVENTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Module containing the placeholder schema names as used in the ORM.""" | ||
|
||
# These are the placeholder schema names as used in the ORM table | ||
# definitions. They will be replaced with actual schema names at runtime | ||
# by providing a schema_translate_map to your SQLAlchemy engine. | ||
VOCAB_SCHEMA = "vocabulary_schema" | ||
CDM_SCHEMA = "cdm_schema" | ||
|
||
# Some often used foreign keys are added as variables for convenience. | ||
FK_CONCEPT_ID = f"{VOCAB_SCHEMA}.concept.concept_id" | ||
FK_VOCABULARY_ID = f"{VOCAB_SCHEMA}.vocabulary.vocabulary_id" | ||
FK_DOMAIN_ID = f"{VOCAB_SCHEMA}.domain.domain_id" | ||
FK_CONCEPT_CLASS_ID = f"{VOCAB_SCHEMA}.concept_class.concept_class_id" | ||
FK_PERSON_ID = f"{CDM_SCHEMA}.person.person_id" | ||
FK_VISIT_OCCURRENCE_ID = f"{CDM_SCHEMA}.visit_occurrence.visit_occurrence_id" | ||
FK_VISIT_DETAIL_ID = f"{CDM_SCHEMA}.visit_detail.visit_detail_id" | ||
FK_PROVIDER_ID = f"{CDM_SCHEMA}.provider.provider_id" | ||
FK_CARE_SITE_ID = f"{CDM_SCHEMA}.care_site.care_site_id" | ||
FK_LOCATION_ID = f"{CDM_SCHEMA}.location.location_id" | ||
|
||
# This object should be used to set the naming_convention parameter of | ||
# the SQLAlchemy MetaData object. Using it makes sure that the naming of | ||
# constraints and indexes is deterministic and not left up to the DBMS. | ||
# It's also needed when dropping these, as SQLAlchemy requires that | ||
# they have a name for them to be dropped. See: | ||
# https://docs.sqlalchemy.org/en/20/core/constraints.html#configuring-constraint-naming-conventions | ||
NAMING_CONVENTION = { | ||
"ix": "ix_%(table_name)s_%(column_0_N_name)s", | ||
"uq": "uq_%(table_name)s_%(column_0_name)s", | ||
"ck": "ck_%(table_name)s_%(constraint_name)s", | ||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", | ||
"pk": "pk_%(table_name)s", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
OMOP CDM Version 5.3.1. | ||
Generated from OMOP CDM release 5.3.1 using sqlacodegen 3.0.0rc5. | ||
DDL from https://github.com/OHDSI/CommonDataModel/tree/v5.3.1. | ||
Deviations from standard model | ||
Removed | ||
attribute_definition | ||
cohort_attribute | ||
Added | ||
stem_table | ||
source_to_concept_map_version | ||
Updated | ||
source_to_concept_map | ||
source_code from VARCHAR(50) --> VARCHAR(1000) | ||
If using a separate vocab schema, STCM is created in the CDM schema | ||
""" | ||
|
||
from omop_cdm.dynamic.cdm531.clinical_data import ( | ||
BaseConditionOccurrenceCdm531, | ||
BaseDeathCdm531, | ||
BaseDeviceExposureCdm531, | ||
BaseDrugExposureCdm531, | ||
BaseFactRelationshipCdm531, | ||
BaseMeasurementCdm531, | ||
BaseNoteCdm531, | ||
BaseNoteNlpCdm531, | ||
BaseObservationCdm531, | ||
BaseObservationPeriodCdm531, | ||
BasePersonCdm531, | ||
BaseProcedureOccurrenceCdm531, | ||
BaseSpecimenCdm531, | ||
BaseStemTableCdm531, | ||
BaseVisitDetailCdm531, | ||
BaseVisitOccurrenceCdm531, | ||
) | ||
from omop_cdm.dynamic.cdm531.derived_elements import ( | ||
BaseConditionEraCdm531, | ||
BaseDoseEraCdm531, | ||
BaseDrugEraCdm531, | ||
) | ||
from omop_cdm.dynamic.cdm531.health_economics import ( | ||
BaseCostCdm531, | ||
BasePayerPlanPeriodCdm531, | ||
) | ||
from omop_cdm.dynamic.cdm531.health_system_data import ( | ||
BaseCareSiteCdm531, | ||
BaseLocationCdm531, | ||
BaseProviderCdm531, | ||
) | ||
from omop_cdm.dynamic.cdm531.metadata import ( | ||
BaseCdmSourceCdm531, | ||
BaseMetadataCdm531, | ||
) | ||
from omop_cdm.dynamic.cdm531.vocabularies import ( | ||
BaseConceptAncestorCdm531, | ||
BaseConceptCdm531, | ||
BaseConceptClassCdm531, | ||
BaseConceptRelationshipCdm531, | ||
BaseConceptSynonymCdm531, | ||
BaseDomainCdm531, | ||
BaseDrugStrengthCdm531, | ||
BaseRelationshipCdm531, | ||
BaseSourceToConceptMapCdm531, | ||
BaseSourceToConceptMapVersionCdm531, | ||
BaseVocabularyCdm531, | ||
) |
Oops, something went wrong.