Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
Spayralbe committed Mar 21, 2024
1 parent 56c89c3 commit 01ee144
Show file tree
Hide file tree
Showing 67 changed files with 11,205 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
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.
-->
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
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
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## v0.1.0
First release.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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 [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`.
47 changes: 47 additions & 0 deletions noxfile.py
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")
1,037 changes: 1,037 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions pyproject.toml
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.0"


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

[lint]
select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# 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"]
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
33 changes: 33 additions & 0 deletions src/omop_cdm/constants.py
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",
}
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 01ee144

Please sign in to comment.