kids-first / kf-model-omop

💡 Kids First OMOP Common Data Model Experimentation
Apache License 2.0
1 stars 0 forks source link

Kids First OMOP CommonDataModel

Experimentation with the OMOP CommonDataModel https://github.com/OHDSI/CommonDataModel/wiki

Getting Started - Users

Install

pip install -e git+https://github.com/kids-first/kf-model-omop.git#egg=kf-model-omop
export OMOP_CONFIG=development

Load Data

Generate a Python module with starter code needed to connect to the db and load data in using the OMOP SQLAlchemy models.

kfmodel code-template

Will generate something like this:

from kf_model_omop.model.models import *
from kf_model_omop.factory import scoped_session

# Use the context managed session to interact with DB
with scoped_session() as session:
    # Test load
    loc = Location(city='Philadelphia')

    session.add(loc)
    session.commit()

    assert session.query(Location).count() == 1

Use a Local OMOP database

Create and start new Postgres Docker container

* Note that increasing the max size of the Postgres write ahead log (max_wal_size) is needed to optimize bulk loading the standard vocabulary.

docker container run -d -p 5432:5432 --name=omop-pg postgres:10
docker exec omop-pg psql -U postgres -c "alter system set max_wal_size = '10GB';"
docker container omop-pg restart

Create and initialize the OMOP database

* This takes approximately 1 to 1.5 hours

Create tables, primary keys and constraints and populate the database with the OMOP standard vocabulary.

kfmodel create-omop --with_standard_vocab

Reset the max_wal_size

docker exec omop-pg psql -U postgres -c "alter system set max_wal_size = default;"

Use a Remote OMOP database

If you'd like to use the CLI with a remote Postgres database, configure the following environment variables:


Getting Started - Developers

Setup dev environment

Get code

git clone git@github.com:kids-first/kf-model-omop.git
cd kf-model-omop

Create virtual env

python3 -m venv venv
source ./venv/bin/activate

Install

Install min dependencies and CLI

pip install -e .

Install docs dependencies (needed to generate ERD)

pip install -r doc-requirements.txt

Test

Follow steps above to create and start a Dockerized Postgres container

Then create the test database:

docker container exec omop-pg psql -U postgres -c "CREATE DATABASE test;"

Install dependencies and run tests

pip install -r dev-requirements.txt
python -m pytest tests