Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
Spayralbe committed Mar 18, 2024
1 parent 56c89c3 commit fcb5647
Show file tree
Hide file tree
Showing 51 changed files with 7,350 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
32 changes: 32 additions & 0 deletions .github/workflows/python-package.yml
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
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# OMOP-CDM

Python SQLAlchemy table definitions of the [OHDSI OMOP CDM](https://ohdsi.github.io/CommonDataModel/).

## Installation

Install from PyPI:
```shell
pip install omop-cdm
```

## Usage
TODO:
See [User documentation](docs/index.md)

## Development

### Setup steps

Make sure the following tooling is installed:
- [Poetry](https://python-poetry.org/docs/#installation)
- [pre-commit](https://pre-commit.com/#install)

Install the project and dependencies via `poetry install`.

Then set up the git hook scripts via `pre-commit install`.
26 changes: 26 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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):
session.run("poetry", "install", external=True)
session.run("pytest")


@nox.session(python="3.12")
def lint(session):
session.run("poetry", "install", external=True)
session.run("ruff", "check")
802 changes: 802 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[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.0"


[tool.poetry.group.test.dependencies]
testcontainers-postgres = "^0.0.1rc1"
pytest = "^8.1.1"
nox = "^2024.3.2"
ruff = "^0.3.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


[tool.pytest.ini_options]
addopts = "--import-mode=importlib"
pythonpath = [
".",
]

# Ignore import violations in all `__init__.py` files
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402", "F401"]
1 change: 1 addition & 0 deletions src/omop_cdm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from omop_cdm.constants import NAMING_CONVENTION
34 changes: 34 additions & 0 deletions src/omop_cdm/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Module containing the placeholder schema names as used in the ORM."""

# These are the placeholder schema names as used in the ORM table
# definitions and as keys in the schema_translate_map.
# Actual schema names will be different at runtime, as determined by the
# provided parameters in the config.yml file.
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",
}
29 changes: 29 additions & 0 deletions src/omop_cdm/dynamic/cdm531/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
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
"""
Loading

0 comments on commit fcb5647

Please sign in to comment.