Skip to content

Commit 6fc8f75

Browse files
committed
add transpiled versions of mimic-iii concepts
1 parent 7113e25 commit 6fc8f75

104 files changed

Lines changed: 17620 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

mimic-iii/concepts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ for dialect in postgres duckdb; do
2828
--destination_dialect "${dialect}" \
2929
--derived_schema mimiciii_derived \
3030
--schema_map mimiciii_clinical=mimiciii,mimiciii_notes=mimiciii \
31-
--exclude cookbook other-languages functions pivot/pivoted_oasis.sql
31+
--exclude cookbook functions
3232
done
3333
```
3434

35-
Source tables are referenced via the `mimiciii` schema (the schema created by the [buildmimic](../buildmimic) scripts), and the derived concepts are created in the `mimiciii_derived` schema. `pivot/pivoted_oasis.sql` is excluded from transpilation as it is not currently runnable on any engine.
35+
Source tables are referenced via the `mimiciii` schema (the schema created by the [buildmimic](../buildmimic) scripts), and the derived concepts are created in the `mimiciii_derived` schema.
3636

3737
Continuous integration rebuilds both dialects against the [MIMIC-III demo](https://physionet.org/content/mimiciii-demo/1.4/) on every approved pull request and verifies that the PostgreSQL and DuckDB results are identical.
3838

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# DuckDB concepts (MIMIC-III)
2+
3+
This folder contains scripts to generate useful abstractions of raw MIMIC-III data ("concepts") in [DuckDB](https://duckdb.org/).
4+
Almost all of these scripts were generated automatically from the BigQuery SQL dialect using the [sqlglot](https://github.com/tobymao/sqlglot) package.
5+
If you would like to contribute a correction, do not make it here. Instead, make your correction in the [concepts folder](/mimic-iii/concepts/) using the BigQuery SQL syntax, and regenerate this folder as described in that folder's [README](/mimic-iii/concepts/README.md).
6+
7+
One file is hand-written for DuckDB and has no BigQuery source: [diagnosis/ccs_multi_dx.sql](diagnosis/ccs_multi_dx.sql) loads the ICD-9 to CCS mapping from [diagnosis/ccs_multi_dx.csv.gz](diagnosis/ccs_multi_dx.csv.gz).
8+
9+
## Using these concepts
10+
11+
The scripts assume the MIMIC-III data have been loaded into a `mimiciii` schema of the DuckDB database, and create the concept tables in the `mimiciii_derived` schema. For example, to load the data with the standard DDL:
12+
13+
```sh
14+
duckdb mimic3.db -c "CREATE SCHEMA mimiciii; CREATE SCHEMA mimiciii_derived;"
15+
# create the tables in the mimiciii schema and COPY each table's CSV into it,
16+
# e.g. using mimic-iii/buildmimic/duckdb/duckdb_add_tables.sql after USE mimiciii;
17+
```
18+
19+
The `duckdb.sql` file calls all the concepts in the correct order and outputs them to the `mimiciii_derived` schema.
20+
You should connect to your DuckDB database file and run this file from this folder (the paths are relative):
21+
22+
```sh
23+
cd mimic-iii/concepts_duckdb
24+
duckdb /path/to/mimic3.db -c ".read duckdb.sql"
25+
```
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY.
2+
DROP TABLE IF EXISTS mimiciii_derived.code_status; CREATE TABLE mimiciii_derived.code_status AS
3+
WITH t1 AS (
4+
SELECT
5+
icustay_id,
6+
charttime,
7+
value,
8+
ROW_NUMBER() OVER (PARTITION BY icustay_id ORDER BY charttime NULLS FIRST) AS rnfirst,
9+
ROW_NUMBER() OVER (PARTITION BY icustay_id ORDER BY charttime DESC) AS rnlast,
10+
CASE WHEN value IN ('Full Code', 'Full code') THEN 1 ELSE 0 END AS fullcode,
11+
CASE WHEN value IN ('Comfort Measures', 'Comfort measures only') THEN 1 ELSE 0 END AS cmo,
12+
CASE WHEN value = 'CPR Not Indicate' THEN 1 ELSE 0 END AS dncpr,
13+
CASE
14+
WHEN value IN ('Do Not Intubate', 'DNI (do not intubate)', 'DNR / DNI')
15+
THEN 1
16+
ELSE 0
17+
END AS dni,
18+
CASE
19+
WHEN value IN ('Do Not Resuscita', 'DNR (do not resuscitate)', 'DNR / DNI')
20+
THEN 1
21+
ELSE 0
22+
END AS dnr
23+
FROM mimiciii.chartevents
24+
WHERE
25+
itemid IN (128, 223758)
26+
AND NOT value IS NULL
27+
AND value <> 'Other/Remarks'
28+
AND (
29+
error IS NULL OR error = 0
30+
)
31+
)
32+
SELECT
33+
ie.subject_id,
34+
ie.hadm_id,
35+
ie.icustay_id,
36+
MAX(CASE WHEN rnfirst = 1 THEN t1.fullcode ELSE NULL END) AS fullcode_first,
37+
MAX(CASE WHEN rnfirst = 1 THEN t1.cmo ELSE NULL END) AS cmo_first,
38+
MAX(CASE WHEN rnfirst = 1 THEN t1.dnr ELSE NULL END) AS dnr_first,
39+
MAX(CASE WHEN rnfirst = 1 THEN t1.dni ELSE NULL END) AS dni_first,
40+
MAX(CASE WHEN rnfirst = 1 THEN t1.dncpr ELSE NULL END) AS dncpr_first,
41+
MAX(CASE WHEN rnlast = 1 THEN t1.fullcode ELSE NULL END) AS fullcode_last,
42+
MAX(CASE WHEN rnlast = 1 THEN t1.cmo ELSE NULL END) AS cmo_last,
43+
MAX(CASE WHEN rnlast = 1 THEN t1.dnr ELSE NULL END) AS dnr_last,
44+
MAX(CASE WHEN rnlast = 1 THEN t1.dni ELSE NULL END) AS dni_last,
45+
MAX(CASE WHEN rnlast = 1 THEN t1.dncpr ELSE NULL END) AS DNCPR_last,
46+
MAX(t1.fullcode) AS fullcode,
47+
MAX(t1.cmo) AS cmo,
48+
MAX(t1.dnr) AS dnr,
49+
MAX(t1.dni) AS dni,
50+
MAX(t1.dncpr) AS dncpr,
51+
MIN(CASE WHEN t1.dnr = 1 THEN t1.charttime ELSE NULL END) AS dnr_first_charttime,
52+
MIN(CASE WHEN t1.dni = 1 THEN t1.charttime ELSE NULL END) AS dni_first_charttime,
53+
MIN(CASE WHEN t1.dncpr = 1 THEN t1.charttime ELSE NULL END) AS dncpr_first_charttime,
54+
MIN(CASE WHEN t1.cmo = 1 THEN t1.charttime ELSE NULL END) AS timecmo_chart
55+
FROM mimiciii.icustays AS ie
56+
LEFT JOIN t1
57+
ON ie.icustay_id = t1.icustay_id
58+
GROUP BY
59+
ie.subject_id,
60+
ie.hadm_id,
61+
ie.icustay_id,
62+
ie.intime

0 commit comments

Comments
 (0)