Experimentation with the OMOP CommonDataModel https://github.com/OHDSI/CommonDataModel/wiki
pip install -e git+https://github.com/kids-first/kf-model-omop.git#egg=kf-model-omop
export OMOP_CONFIG=development
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
See kf_model_omop./model/models.py
for more details on the ORM models.
See https://docs.sqlalchemy.org/en/latest/orm/tutorial.html for more info on how to use the models to interact with the database.
Note that the SQLAlchemy models are autogenerated and have not been thoroughly unit tested since they are autogenerated and there are a lot of them. If you see or experience a bug while loading data, please submit an issue or a PR for it.
* 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
* 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;"
If you'd like to use the CLI with a remote Postgres database, configure the following environment variables:
PG_HOST
- the host postgres is running onPG_PORT
- the port postgres is listening onPG_NAME
- the name of the database in postgresPG_USER
- the postgres user to connect withPG_PASS
- the password of the userGet 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 min dependencies and CLI
pip install -e .
Install docs dependencies (needed to generate ERD)
pip install -r doc-requirements.txt
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