3. Example queries¶
The process outlined in the example queries below shows how a user can build a dataset consisting of a number of distinct tables. The tables are created step-by-step, starting with a basic selection of patients. This first query is further used in queries that select distinct aspects of the selected patients. All queries are based on the MIMIC dataset.
Starting with the MIMIC dataset, we will create the following queries:
a patients query that selects only female patients
an admissions query that selects only those hospital admissions where (a) the patient is part of the result of the first query (so only female patients), and (b) the patient was admitted to/in the emergency room
a labitems query that selects all labitems for the the admissions of the second query (female patients that were admitted to/in the emergency room)
3.1. Patients query¶
As a first step we create a query that selects only female patients in MIMIC.
In the Queries screen create a new query called “Female Patients”, and click this query to edit it.
In the Input Tables pane, select the public.patients table and drag this table to the Output Columns pane. The result will look like the screenshot below.
In the Input Tables pane, expand the public.patients table, drag the “gender” attribute and drop it this attribute the Filter Conditions pane, fill in ‘F’ (Female) in the input field. The result is a query that selects only female patients.
3.2. Admissions query¶
As a second step, we create a query that selects tha admissions for the female patients we just selected and a filter to it, to select only those patients that were admitted to the Emergency Room.
In the Queries screen create a new query called “Admissions Female Patients”, and click this query to edit it.
In the Input Tables pane, select the public.admissions table and drag this table to the Output Columns pane.
On second thoughts, we don’t need every column of the admissions table in our result, so we delete the following columns (by clicking the <delete> button next to the column name in the Output Columns pane):
public.admissions.row_id
public.admissions.edregtime
public.admissions.edtimeout
We add a filter to only select the admissions where the admission location is the Emergency Room:
drag the admission_location attribute from the public.admissions table to the Filter Conditions pane
type “EMERGENCY ROOM ADMIT” in the value textbox (besides the operator box that defaults to “equal”), or, type “EMERGENCY ROOM” and pick the “begins with” operator to get to the same result
the filter will be applied to the table:
Finally, we add a filter that uses the “Patients query” to select only the female patients:
drag the subject_id attribute from the public.admissions column to the Filter Conditions pane
in the operator listbox change “equal” to “in dataset”
in the value textbox select “Female Patients public.patients.subject_id”
These steps result in a query that selects all admission data from the female patients that were admitted to the Emergy Room.
3.3. Labitems query¶
Next we create a query that select all labevents that are linked to the admissions and (female) patients selected in the former two queries. What we also do is link the labitems table to its domain table d_labitems, to make the data more intelligible.
In the Queries screen create a new query called “Labitems Female Emergency Room Patients”, and click this query to edit it.
In the Input Tables pane, select the public.labevents table and drag this table to the Output Columns pane. The result will look like the screenshot below.
We add a filter that uses the Admissions query to only select the labitems linked to female patients that were admitted to/in the Emergency room.
drag hadm_id attribute of the public.labevents table to the Filter Conditions pane
in the operator listbox change “equal” to “in dataset”
in the value textbox select “Admissions Female Patients public.admissions.hadm_id”
In the MIMIC dataset we can retrieve the meaning of the records in the labevents table from its domain table d_labevents, so the next step is to select this table and drop it in the Output Columns pane. The tables will be auto-joined. To make the output simpler, delete the following columns (by clicking the <delete> button next to the column name in the Output Columns pane):
public.d_labitems.itemid
public.d_labitems.row_id
public.labevents.row_id
public_labevents.itemid
A screenshot of the result of this query: