Skip to content

Commit

Permalink
Merge branch 'release/4.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dermatologist committed Jul 11, 2024
2 parents eb4f37a + b95f9ff commit 6448554
Show file tree
Hide file tree
Showing 19 changed files with 469 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# .coveragerc to control coverage.py
[run]
branch = True
source = pyomop
source = src.pyomop
# omit = bad_file.py

[paths]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout Latest Commit
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Generate changelog
uses: charmixer/auto-changelog-action@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2.3.1
uses: actions/setup-python@v5.0.0
with:
python-version: '3.10.13'
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2.3.1
uses: actions/setup-python@v5.0.0
with:
python-version: '3.10.13'
- name: Install dependencies
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 15
env:
CI: true
timeout-minutes: 10
strategy:
max-parallel: 4
matrix:
python-version: [3.10.13]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.3.1
uses: actions/setup-python@v5.0.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # caching pip dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python Test
name: Tox Test

on:
push:
Expand All @@ -9,18 +9,19 @@ jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 12
strategy:
max-parallel: 4
matrix:
python-version: [3.10.13]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.3.1
uses: actions/setup-python@v5.0.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # caching pip dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [Unreleased](https://github.com/dermatologist/pyomop/tree/HEAD)

[Full Changelog](https://github.com/dermatologist/pyomop/compare/4.2.0...HEAD)

**Closed issues:**

- Google Cloud Platform Compatibility [\#9](https://github.com/dermatologist/pyomop/issues/9)

## [4.2.0](https://github.com/dermatologist/pyomop/tree/4.2.0) (2023-11-19)

[Full Changelog](https://github.com/dermatologist/pyomop/compare/4.1.0...4.2.0)

## [4.1.0](https://github.com/dermatologist/pyomop/tree/4.1.0) (2023-11-19)

[Full Changelog](https://github.com/dermatologist/pyomop/compare/4.0.0...4.1.0)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@

### [Documentation](https://dermatologist.github.io/pyomop/)

## UPDATE
Recently added support for **LLM based natural language queries** of OMOP CDM databases using [llama-index](examples/llm_example.py). Please install the llm extras as follows. Please be cognizant of the privacy issues with publically hosted LLMs. Any feedback will be highly appreciated. [See usage](examples/llm_example.py)!

```
git clone https://github.com/dermatologist/pyomop.git@develop
cd pyomop
pip install pyomop[llm]
```
[See usage](examples/llm_example.py).

## Description

The [OHSDI](https://www.ohdsi.org/) 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.](https://github.com/OHDSI/QueryLibrary)
Expand Down
16 changes: 7 additions & 9 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ babel==2.9.1
# via sphinx
backports-entry-points-selectable==1.1.0
# via virtualenv
certifi==2022.12.7
certifi==2023.7.22
# via requests
charset-normalizer==2.0.6
# via requests
commonmark==0.9.1
# via recommonmark
coverage[toml]==5.5
# via
# coverage
# pytest-cov
# via pytest-cov
distlib==0.3.2
# via virtualenv
docutils==0.17.1
Expand All @@ -38,7 +36,7 @@ imagesize==1.2.0
# via sphinx
iniconfig==1.1.1
# via pytest
jinja2==3.0.1
jinja2==3.1.4
# via sphinx
markupsafe==2.0.1
# via jinja2
Expand All @@ -58,7 +56,7 @@ py==1.10.0
# via
# pytest
# tox
pygments==2.10.0
pygments==2.15.0
# via sphinx
pyparsing==2.4.7
# via packaging
Expand All @@ -68,13 +66,13 @@ pytest==6.2.5
# pytest-cov
pytest-cov==3.0.0
# via -r dev-requirements.in
pytz==2023.3.post1
pytz==2024.1
# via
# -c requirements.txt
# babel
recommonmark==0.7.1
# via -r dev-requirements.in
requests==2.26.0
requests==2.32.2
# via sphinx
setuptools-scm==6.3.2
# via -r dev-requirements.in
Expand Down Expand Up @@ -110,7 +108,7 @@ tomli==1.2.1
# via setuptools-scm
tox==3.24.5
# via -r dev-requirements.in
urllib3==1.26.6
urllib3==1.26.19
# via requests
virtualenv==20.8.0
# via tox
Expand Down
60 changes: 60 additions & 0 deletions examples/llm_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Example of using LLMs with PyOMOP
git clone https://github.com/dermatologist/pyomop.git@develop
cd pyomop
pip install -e .[llm]
"""

from pyomop import CdmEngineFactory, Cohort, metadata, CdmLLMQuery, CDMDatabase
import datetime
import asyncio
# Import any LLMs that llama_index supports and you have access to
# Require OpenAI API key to use OpenAI LLMs
from llama_index.llms import Vertex

async def main():
# Create a sqllite database by default
# You can also connect to an existing CDM database using the CdmEngineFactory
cdm = CdmEngineFactory()
# Postgres example below (db='mysql' also supported)
# cdm = CdmEngineFactory(db='pgsql', host='', port=5432,
# user='', pw='',
# name='', schema='cdm6')

engine = cdm.engine
# Create Tables if required
await cdm.init_models(metadata)

async with cdm.session() as session:
async with session.begin():

# Adding a cohort just for the example (not required if you have a OMOP CDM database)
session.add(Cohort(cohort_definition_id=2, subject_id=100,
cohort_end_date=datetime.datetime.now(),
cohort_start_date=datetime.datetime.now()))
await session.commit()

# Use any LLM that llama_index supports
llm = Vertex(
model="chat-bison",
)
# Include tables that you want to query
sql_database = CDMDatabase(engine, include_tables=[
"cohort",
])
query_engine = CdmLLMQuery(sql_database, llm=llm)
# Try any complex query.
response = query_engine.query("Show each in table cohort with a subject id of 100?")
print(response)
"""
| cohort_id | subject_id | cohort_name |
|---|---|---|
| 1 | 100 | Math |
"""
# Close session
await session.close()
await engine.dispose()

# Run the main function
asyncio.run(main())
22 changes: 12 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
#
# pip-compile
#
aiosqlite==0.19.0
aiosqlite==0.20.0
# via pyomop (setup.py)
click==8.1.7
# via pyomop (setup.py)
greenlet==3.0.1
greenlet==3.0.3
# via sqlalchemy
numpy==1.26.2
numpy==2.0.0
# via pandas
pandas==2.1.3
pandas==2.2.2
# via pyomop (setup.py)
python-dateutil==2.8.2
python-dateutil==2.9.0.post0
# via pandas
pytz==2023.3.post1
pytz==2024.1
# via pandas
six==1.16.0
# via python-dateutil
sqlalchemy==2.0.23
sqlalchemy==2.0.31
# via pyomop (setup.py)
typing-extensions==4.8.0
# via sqlalchemy
tzdata==2023.3
typing-extensions==4.12.2
# via
# aiosqlite
# sqlalchemy
tzdata==2024.1
# via pandas
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ exclude =
# `pip install pyomop[PDF]` like:
# PDF = ReportLab; RXP
# Add here test requirements (semicolon/line-separated)
llm =
llama-index
langchain==0.0.350
overrides

testing =
pytest
pytest-cov
Expand Down
8 changes: 7 additions & 1 deletion src/pyomop/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import sys

import logging
_logger = logging.getLogger(__name__)
from .engine_factory import CdmEngineFactory
from .cdm6_tables import metadata
from .vocabulary import CdmVocabulary
from .vector import CdmVector
try:
from .llm_query import CdmLLMQuery
from .llm_engine import CDMDatabase
except ImportError:
_logger.warn("LLM is not installed. Please install LLM with pip install pyomop[llm] to use this package.")

from .cdm6_tables import AttributeDefinition
from .cdm6_tables import CareSite
Expand Down
Loading

0 comments on commit 6448554

Please sign in to comment.