You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mimic-iii/concepts/README.md
+17-59Lines changed: 17 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,76 +10,34 @@ You can read about cloud access to MIMIC-III, including via Google BigQuery, on
10
10
The rest of this README describes:
11
11
12
12
*[Generating the concepts in BigQuery](#generating-the-concepts-in-bigquery)
13
-
*[Generating the concepts in PostgreSQL (\*nix/Mac OS X)](#generating-the-concepts-in-postgresql-nix-mac-os-x)
14
-
*[Generating the concepts in PostgreSQL (Windows)](#generating-the-concepts-in-postgresql-windows)
13
+
*[Generating the concepts in PostgreSQL](#generating-the-concepts-in-postgresql)
15
14
16
15
## Generating the concepts in BigQuery
17
16
18
17
You do not need to generate the concepts if you are using BigQuery! They have already been generated for you. If you have access to MIMIC-III on BigQuery, look under `physionet-data.mimic_derived`. If you would like to generate the concepts again, for example on your own dataset, you must modify the `TARGET_DATASET` variable within the [make-concepts.sh](/concepts/make-concepts.sh) script. The script assumes you have installed and configured the [Google Cloud SDK](https://cloud.google.com/sdk/docs/install).
19
18
20
-
## Generating the concepts in PostgreSQL (\*nix/Mac OS X)
19
+
## Generating the concepts in PostgreSQL
20
+
21
+
### Quickstart
22
+
23
+
Go to the [concepts_postgres](../concepts_postgres) folder, run the [postgres-functions.sql](../concepts_postgres/postgres-make-concepts.sql) and [postgres-make-concepts.sql](../concepts_postgres/postgres-make-concepts.sql) scripts, in that order.
24
+
25
+
### In more detail
21
26
22
27
While the SQL scripts here are written in BigQuery's Standard SQL syntax, there are many BigQuery specific functions which do not carry over to PostgreSQL. Nevertheless, with only a few changes, the scripts can be made compatible. In order to generate the concepts on a PostgreSQL database, one must:
23
28
24
29
* create postgres functions which emulate BigQuery functions
25
30
* modify SQL scripts for incompatible syntax
26
31
* run the modified SQL scripts and direct the output into tables in the PostgreSQL database
27
32
28
-
This can be done as follows:
29
-
30
-
1. Open a terminal in the `concepts` folder.
31
-
2. Run [postgres-functions.sql](postgres-functions.sql).
32
-
* e.g. `psql -f postgres-functions.sql`
33
-
* This script creates functions which emulate BigQuery syntax.
34
-
3. Run [postgres_make_concepts.sh](postgres_make_concepts.sh).
35
-
* e.g. `bash postgres_make_concepts.sh`
36
-
* This file runs the scripts after applying a few regular expressions which convert table references and date calculations appropriately.
37
-
* This file generates all concepts on the `public` schema.
38
-
* Exporting DBCONNEXTRA before calling this script will add this to the
will add these settings to all of the psql calls. (Note that "dbname"
42
-
and "search_path" do not need to be set.)
43
-
44
-
If you do not have access to a PostgreSQL database with MIMIC, you can read more about building the data within one in the [buildmimic/postgres](https://github.com/MIT-LCP/mimic-code/tree/main/mimic-iii/buildmimic/postgres) folder.
45
-
46
-
## Generating the concepts in PostgreSQL (Windows)
47
-
48
-
On Windows, it is a bit more complex to generate the concepts in the PostgreSQL database. The approach relies on using \*nix command line tools which are not available by default in a Windows installation. Instead, we have adapted the script into a `.bat` file which relies on the Windows Subsystem for Linux in order to run the shell commands. The steps are:
49
-
50
-
1. Install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
51
-
* If you don't have a preference, follow the steps to install a Ubuntu system. The bat file was tested with Ubuntu, though the commands should work with any flavor of \*nix since we rely on the utils rather than the kernel.
52
-
2. Verify you can use the wsl.exe utilities in command prompt.
53
-
* Go to run and type `cmd`, or type "command prompt" in the search.
54
-
* Run `wsl.exe echo "hi"` - this should print out `hi` back to you
55
-
3. Change to your local folder where these concepts are stored
56
-
* e.g. `cd C:\Tools\mimic-code-master\concepts`
57
-
4. Modify the .bat file: update the `CONNSTR` and `PSQL_PATH` variables.
58
-
* Replace `INSERT_PASSWORD_HERE` in `CONNSTR` with your password; or remove it if you have a `.pgpass` file or other form of authentication. If you have a different username or database location, be sure to update those as well.
59
-
* Change `PSQL_PATH` to point to your `psql.exe` file. It is currently set to the default location for a PostgreSQL 13 installation.
60
-
5. Run the .bat file
61
-
* In the command prompt, type `postgres_make_concepts_windows.bat`
62
-
63
-
The script echos the commands and the outputs as they run. If it is running successfully, you should see a `SELECT` statement after each command, with the number of rows generated in the table.
64
-
65
-
### Can I just do the above manually without WSL?
66
-
67
-
Of course! And this might be more informative.
68
-
69
-
First, generate the necessary functions as above, by running `postgres-functions.sql` in the SQL shell.
70
-
Once that's done, you need to do the following text replacements in all the SQL files:
71
-
72
-
1. Replace ````physionet-data.mimiciii_clinical.<table_name>````, ````physionet-data.mimiciii_derived.<table_name>```` , and ````physionet-data.mimiciii_notes.<table_name>```` with just `<table_name>`.
73
-
* This is done by the `REGEX_SCHEMA` variable in the `postgres_make_concepts.sh` script.
74
-
* Ideally you should set your search path with `set search_path to public,mimiciii;`. This will create the concepts on `public`, and read data from `mimiciii`. This distinction isn't strictly necessary, but many find it useful.
75
-
2. Replace `DATETIME_DIFF(date1, date2, DATE_PART)` with `DATETIME_DIFF(date1, date2, 'DATE_PART')`.
76
-
* This adds single quotes around any `DATE_PART`, which is required by PostgreSQL.
77
-
* This is done by the `REGEX_DATETIME_DIFF ` variable in the `postgres_make_concepts.sh` script.
78
-
3. Add a create table statement at the top of the file, e.g. if the file is named `echo_data.sql`, add `CREATE TABLE echo_data AS` at the top of the file.
79
-
* This is done by the `echo` calls in the shell script.
80
-
4. Run each file individually in the order specified by the make concepts script.
81
-
82
-
The above steps replicate what is done in the shell script (postgres_make_concepts.sh).
33
+
The bash script [convert_mimiciii_concepts_bq_to_psql.sh](/convert_mimiciii_concepts_bq_to_psql.sh) has done most of this for you. To generate concepts in PostgreSQL, simply go to the [concepts_postgres](../concepts_postgres) folder and run:
34
+
35
+
```sh
36
+
\i postgres-functions.sql
37
+
\i postgres-make-concepts.sql
38
+
```
39
+
40
+
You can also read more about building the data within PostgreSQL in the [buildmimic/postgres](https://github.com/MIT-LCP/mimic-code/tree/main/mimic-iii/buildmimic/postgres) folder.
83
41
84
42
## List of concepts
85
43
@@ -190,4 +148,4 @@ Useful snippets of SQL implementing common functions. For example, the `auroc.sq
190
148
191
149
## other-languages
192
150
193
-
Scripts in flavours of SQL which are not necessarily compatible with PostgreSQL.
151
+
Scripts in flavours of SQL which are not compatible with BigQuery/PostgreSQL.
0 commit comments