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:

  1. a patients query that selects only female patients
  2. 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
  3. 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.

  1. In the Queries screen create a new query called “Female Patients”, and click this query to edit it.
_images/empty_query_design_screen.png
  1. 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.
_images/example_patient_output_columns.png
  1. 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.
_images/example_patient_with_filter.png

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.

  1. In the Queries screen create a new query called “Admissions Female Patients”, and click this query to edit it.
_images/empty_query_design_screen_admissions.png
  1. In the Input Tables pane, select the public.admissions table and drag this table to the Output Columns pane.
  2. 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
  3. 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:
_images/example_admissions_location_filter.png
  1. 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”
_images/example_admissions_location_and_patients_filter_selected.png _images/example_admissions_location_and_patients_filter.png

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.

  1. In the Queries screen create a new query called “Labitems Female Emergency Room Patients”, and click this query to edit it.
  2. 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.
_images/example_labitems_output_columns.png
  1. 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”
  2. 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:

_images/example_labitems_output_columns_after_filtering.png