Skip to main content

OMOP CDM utils in Python

Project description

pyomop

Libraries.io SourceRank forthebadge made-with-python PyPI download total Build

Documentation

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.

Installation (stable)

pip install pyomop

Installation (current)

  • git clone this repository and:
pip install -e .

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

Troubleshoot

  • sqlalchemy > 1.4 may not work. See issue #6. Please downgrade sqlalchemy untill issue #6 is fixed.
pip install sqlalchemy==1.3.24

Other utils

Want to convert FHIR to pandas data frame? Try fhiry

Use the same functions in .NET and Golang!

Support

  • Postgres
  • MySQL
  • SqLite
  • More to follow..

Give us a star ⭐️

If you find this project useful, give us a star. It helps others discover the project.

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

If you're not sure about the file name format, learn more about wheel file names.

pyomop-3.2.0-py2.py3-none-any.whl (23.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pyomop-3.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pyomop-3.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pyomop-3.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d66665550048a8300aaeb8a7c5eed2a727fcc5b4028bd863ee2fb0d71c2512fa
MD5 cdd30869eafcf969288b0223ac6e99fc
BLAKE2b-256 32ff060294268499fa110190daafca213abd90ad7143e0689562399b89c30060

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page