OMOP CDM utils in Python
Project description
pyomop
OMOP CDM utils. This repo may be similar to @jbadger3's inspectomop, but this is not a fork.
Description
The OHSDI OMOP Common Data Model allows for the systematic analysis of healthcare observational databases. This is a python library to use the CDM v6 compliant databases using SQLAlchemy as the ORM. pyomop also supports converting query results to a pandas dataframe (see below) for use in machine learning pipelines. See some useful SQL Queries here.
Support
- Postgres
- MySQL
- SqLite
- More to follow..
Installation
pip install pyomop
Usage
from pyomop import CdmEngineFactory, CdmVocabulary, CdmVector, Cohort, Vocabulary, metadata
from sqlalchemy.sql import select
import datetime
cdm = CdmEngineFactory() # Creates SQLite database by default
# Postgres example (db='mysql' also supported)
# cdm = CdmEngineFactory(db='pgsql', host='', port=5432,
# user='', pw='',
# name='', schema='cdm6')
engine = cdm.engine
# Create Tables if required
metadata.create_all(engine)
# Create vocabulary if required
vocab = CdmVocabulary(cdm)
# vocab.create_vocab('/path/to/csv/files') # Uncomment to load vocabulary csv files
# SQLAlchemy as ORM
session = cdm.session
session.add(Cohort(cohort_definition_id=2, subject_id=100,
cohort_end_date=datetime.datetime.now(),
cohort_start_date=datetime.datetime.now()))
session.commit()
result = session.query(Cohort).all()
for row in result:
print(row)
# Convert result to a pandas dataframe
vec = CdmVector()
vec.result = result
print(vec.df.dtypes)
# Execute a query and convert it to dataframe
vec.sql_df(cdm, 'TEST') # TEST is defined in sqldict.py
print(vec.df.dtypes) # vec.df is a pandas dataframe
# OR
vec.sql_df(cdm, query='SELECT * from cohort')
print(vec.df.dtypes) # vec.df is a pandas dataframe
command-line usage
pyomop -help
Contributors
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
pyomop-3.0.0-py2.py3-none-any.whl
(22.9 kB
view hashes)
Close
Hashes for pyomop-3.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32bb87234c4dbe1d73c86094f2b977a625e56a20599b90a1061fcef8152fe533 |
|
MD5 | 88c591a2b9a0c56a93e02bafcf301572 |
|
BLAKE2b-256 | a91b040540a36de3d5fa6834281b6d11cfd6aa2e67ffcb000ca7f89abedd658d |