Skip to main content
# Data Models SQLAlchemy

[![Circle CI](https://circleci.com/gh/chop-dbhi/data-models-sqlalchemy/tree/master.svg?style=svg)](https://circleci.com/gh/chop-dbhi/data-models-sqlalchemy/tree/master)

SQLAlchemy models and DDL and ERD generation for chop-dbhi/data-models style JSON endpoints.

Web service available at http://dmsa.a0b.io/

## SQLAlchemy Models

In your shell, hopefully within a virtualenv:

```sh
pip install dmsa
```

In python:

```python
from dmsa.omop.v5.models import Base

for tbl in Base.metadata.sorted_tables():
print tbl.name
```

Or:

```python
from dmsa.pedsnet.v2.models import Person, VisitPayer

print VisitPayer.columns
```

These models are dynamically generated at runtime from JSON endpoints provided by chop-dbhi/data-models-service, which reads data stored in chop-dbhi/data-models. It should be simple to add modules for any additional data models that become available, but the currently provided ones are:

- **OMOP V4** at `omop.v4.models`
- **OMOP V5** at `omop.v5.models`
- **PEDSnet V1** at `pedsnet.v1.models`
- **PEDSnet V2** at `pedsnet.v2.models`
- **i2b2 V1.7** at `i2b2.v1_7.models`
- **i2b2 PEDSnet V2** at `i2b2.pedsnet.v2.models`
- **PCORnet V1** at `pcornet.v1.models`
- **PCORnet V2** at `pcornet.v2.models`
- **PCORnet V3** at `pcornet.v3.models`

## DDL and ERD Generation

Use of the included Dockerfile is highly recommended to avoid installing DBMS and graphing specific system requirements.

The following DBMS dialects are supported when generating DDL:

- **PostgreSQL** called as `postgresql`
- **MySQL** called as `mysql`
- **MS SQL Server** called as `mssql`
- **Oracle** called as `oracle`

### With Docker:

Retrieve the image:

```sh
docker pull dbhi/data-models-sqlalchemy
```

Usage for DDL generation:

```sh
docker run --rm dbhi/data-models-sqlalchemy ddl -h
```

Generate OMOP V5 creation DDL for Oracle:

```sh
docker run --rm dbhi/data-models-sqlalchemy ddl omop v5 oracle
```

Generate OMOP V5 drop DDL for Oracle:

```sh
docker run --rm dbhi/data-models-sqlalchemy ddl -d omop v5 oracle
```

Generate OMOP V5 data deletion DML for Oracle:

```sh
docker run --rm dbhi/data-models-sqlalchemy ddl -x omop v5 oracle
```

Usage for ERD generation:

```sh
docker run --rm dbhi/data-models-sqlalchemy erd -h
```

Generate i2b2 PEDSnet V2 ERD (the image will land at `./erd/i2b2_pedsnet_v2_erd.png`):

```sh
docker run --rm -v $(pwd)/erd:/erd dbhi/data-models-sqlalchemy erd i2b2_pedsnet v2 /erd/i2b2_pedsnet_v2_erd.png
```

The `graphviz` graphing package supports a number of other output formats, listed here (link pending), which are interpreted from the passed extension.

### Without Docker:

Install the system requirements (see Dockerfile for details):

- **Python 2.7**
- `graphviz` for ERD generation
- Oracle `instantclient-basic` and `-sdk` and `libaio1` for Oracle DDL generation
- `libpq-dev` for PostgreSQL DDL generation
- `unixodbc-dev` for MS SQL Server DDL generation

Install the python requirements, hopefully within a virtualenv (see Dockerfile for details):

```sh
pip install cx-Oracle # for Oracle DDL generation
pip install psycopg2 # for PostgreSQL DDL generation
pip install PyMySQL # for MySQL DDL generation
pip install pyodbc # for MS SQL Server DDL generation
```

Install the data-models-sqlalchemy python package:

```sh
pip install dmsa
```

Usage for DDL generation:

```sh
dmsa ddl -h
```

Generate OMOP V5 creation DDL for Oracle:

```sh
dmsa ddl omop v5 oracle
```

Generate OMOP V5 drop DDL for Oracle:

```sh
dmsa ddl -d omop v5 oracle
```

Generate OMOP V5 data deletion DML for Oracle:

```sh
dmsa ddl -x omop v5 oracle
```

Usage for ERD generation:

```sh
dmsa erd -h
```

Generate i2b2 PEDSnet V2 ERD (the image will land at `./erd/i2b2_pedsnet_v2_erd.png`):

```sh
mkdir erd
dmsa erd i2b2_pedsnet v2 ./erd/i2b2_pedsnet_v2_erd.png
```

## Web Service

The web service uses a simple Flask debug server for now. It exposes the following endpoints:

- Creation DDL at `/<model>/<version>/ddl/<dialect>/`
- Creation DDL for only `table`, `constraint`, or `index` elements at `/<model>/<version>/ddl/<dialect>/<elements>`
- Drop DDL at `/<model>/<version>/drop/<dialect>/`
- Drop DDL for only `table`, `constraint`, or `index` elements at `/<model>/<version>/drop/<dialect>/<elements>`
- Data deletion DML at `/<model>/<version>/delete/<dialect>/`
- ERDs at `/<model>/<version>/erd/`

### With Docker:

Usage:

```sh
docker run dbhi/data-models-sqlalchemy start -h
```

Run:

```sh
docker run dbhi/data-models-sqlalchemy # Uses Dockerfile defaults of 0.0.0.0:80
```

### Without Docker:

Install Flask:

```sh
pip install Flask
```

Usage:

```sh
dmsa start -h
```

Run:

```sh
dmsa start # Uses Flask defaults of 127.0.0.1:5000
```

Metadata

Release files for dmsa 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dmsa 0.5.1
File Size Uploaded
dmsa-0.5.1.tar.gz 11.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dmsa 0.5.1
File Interpreter ABI Platform
dmsa-0.5.1-py2.7.egg Legacy Egg format - - Details
dmsa-0.5.1-py2-none-any.whl Python 2 none any Details

Total release size: 56.1 kB

Release files / dmsa-0.5.1.tar.gz

Download URL dmsa-0.5.1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2078ca5b06e9493ad26574f78c9a0630186db742485ad0c64ab0a826423dad55
BLAKE2b-256 checksum
How to use checksums
f5a47f960e2bc4a58ce62dc65f9b42a96bb6a7989a187ccfd28a9bd284ca2a6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / dmsa-0.5.1-py2.7.egg

Download URL dmsa-0.5.1-py2.7.egg
Size 27.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
7c445e79b3626b97c71cb918273e833d7e79fa0c573b403968e975745236b381
BLAKE2b-256 checksum
How to use checksums
20a3c9ca5f443347e7eb8127da1dcc98fe500b17d4e1bf4a18bc7e27ef59e817
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / dmsa-0.5.1-py2-none-any.whl

Download URL dmsa-0.5.1-py2-none-any.whl
Size 16.8 kB
Tags Python 2
SHA-256 checksum
How to use checksums
0bcfe935c276473d25438daa14fb9eb6c97dabd9afccbd6f4ad392aa6f1947fa
BLAKE2b-256 checksum
How to use checksums
794c4684b00e2e5b04345b3cc76aed0f889b3bea8689f7170703a0b2d0f0f24e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.5.8

3 release files

0.5.7

3 release files

0.5.6

3 release files

0.5.4

3 release files

This release

0.5.1 This release

3 release files

0.4.4

3 release files

0.3

2 release files

0.2

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page