During a project, it's often necessary to work on a subset of the patient population from a dataset: this is what patient groups enable.
We'll see how to:
- Create a patient group
- Add patients to this group
- Remove patients
This is the multi-page printable view of this section. Click here to print.
During a project, it's often necessary to work on a subset of the patient population from a dataset: this is what patient groups enable.
We'll see how to:
To create a patient group (or subset), go to the Patient Groups page. For this, you need to have loaded a project. Then click on the “Patient Groups” icon from the menu at the top of the page, to the right of the loaded project name.
You’ll arrive at the project’s patient groups page.
A patient group is a subset of a dataset, but it depends on a project. If two projects use the same dataset, they won’t share the same datasets.
An “All patients” group is created by default when creating a project.
To create a patient group, click on the “+” icon on the left side of the screen.
Choose a name, then click “Add”. For this example, we’ll create a group containing patients over 50 years old.
Click on the group you just created: you’ll arrive at the selected group’s page.
On the right side of the screen, you have two tabs:
To add patients to a subset, we use the add_patients_to_subset
function.
This function takes these two arguments:
patients
: a numeric vector containing the IDs of patients to addsubset_id
: the ID of the group to which patients will be added (by default the ID of the selected group, modifying this argument is useful in plugins particularly)When creating a patient group, the code allowing to add all patients to the group is created.
This code will be executed if the user presses the button to execute the code, or if the group is selected from the project (and if it doesn’t already contain patients).
We’ll modify this code to add patients over 50 years old.
Let’s use the code to create a column containing patient ages, from the tutorial on usual OMOP queries.
d$visit_occurrence %>%
dplyr::left_join(
d$person %>% dplyr::select(person_id, birth_datetime),
by = "person_id"
) %>%
dplyr::collect() %>%
dplyr::mutate(
age = round(as.numeric(difftime(visit_start_datetime, birth_datetime, units = "days")) / 365.25, 1)
)
The code editor of the selected group allows testing the code. We’ll extract the IDs of patients with an age greater than 50 years. For now, we’ll comment out the add_patients_to_subset
function.
d$visit_occurrence %>%
dplyr::left_join(
d$person %>% dplyr::select(person_id, birth_datetime),
by = "person_id"
) %>%
dplyr::collect() %>%
dplyr::mutate(
age = round(as.numeric(difftime(visit_start_datetime, birth_datetime, units = "days")) / 365.25, 1)
) %>%
dplyr::filter(age > 50) %>%
dplyr::distinct(person_id) %>%
dplyr::pull()
Our code works, so we can store these IDs in a variable and then integrate it into the add_patients_to_subset
function.
patients <-
d$visit_occurrence %>%
dplyr::left_join(
d$person %>% dplyr::select(person_id, birth_datetime),
by = "person_id"
) %>%
dplyr::collect() %>%
dplyr::mutate(
age = round(as.numeric(difftime(visit_start_datetime, birth_datetime, units = "days")) / 365.25, 1)
) %>%
dplyr::filter(age > 50) %>%
dplyr::distinct(person_id) %>%
dplyr::pull()
add_patients_to_subset(patients = patients)
A message indicates that the patients have been successfully added to the group.
Note that here we added patients to the group, but it’s also possible to filter:
visit_occurrence
column to the patients
variablevisit_detail
column to the patients
variable
Graphical Interface
There is no graphical interface yet, which would be very useful for filtering patients on certain characteristics (age, sex, length of stay, hospitalization dates, presence of concepts such as diagnoses or treatments).
This graphical interface will be developed in the next version.
To remove patients from a group, you need to use the remove_patients_from_subset
function, which works like add_patients_to_subset
, with the same arguments: patients
and subset_id
.
We could, for example, after adding all patients to the group, remove those with an age less than or equal to 50 years.
It would be interesting to create an Individual Data plugin allowing patient exclusion with one or more exclusion criteria, created by the user.
We could imagine that this plugin removes patients from the “Included patients” group, and adds them to the “Excluded patients” group.
To do this, it would be enough to use the functions add_patients_to_subset
and remove_patients_from_subset
from the plugin.
How to retrieve the ID of patient groups? Thanks to the m$subsets
variable.
All that’s left is to create the plugin!
We've seen how to create patient groups, and how to add and remove patients from a group.
A graphical interface will soon be developed to facilitate adding and removing patients.
We'll subsequently focus on more technical LinkR functionalities, namely:
If you don't wish to explore these functionalities, you only need to read the chapters related to content sharing: