From 8955f049fefd093cb506456f9313263a79894cd1 Mon Sep 17 00:00:00 2001 From: Marta Alcalde-Herraiz Date: Sat, 4 May 2024 17:37:01 +0100 Subject: [PATCH] Update matchCohorts.R --- R/matchCohorts.R | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/R/matchCohorts.R b/R/matchCohorts.R index b4d68f7f..ca8519f8 100644 --- a/R/matchCohorts.R +++ b/R/matchCohorts.R @@ -473,14 +473,20 @@ observationControl <- function(x) { x |> dplyr::select(-"cohort_start_date", -"cohort_end_date") |> dplyr::rename("cohort_start_date" = "index_date") |> - PatientProfiles::addFutureObservation( - futureObservationName = "cohort_end_date", futureObservationType = "date" + dplyr::inner_join( + cdm$observation_period |> + dplyr::select( + "subject_id" = "person_id", + "observation_period_start_date", + "cohort_end_date" = "observation_period_end_date" + ), + by = "subject_id" ) |> - dplyr::filter(!is.na(.data$cohort_end_date)) |> - dplyr::select( - "cohort_definition_id", "subject_id", "cohort_start_date", - "cohort_end_date", "cluster_id" + dplyr::filter( + .data$cohort_start_date <= .data$cohort_end_date & + .data$cohort_start_date >= .data$observation_period_start_date ) |> + dplyr::select(-"observation_period_start_date") |> dplyr::compute(name = tableName(x), temporary = FALSE) |> omopgenerics::recordCohortAttrition( reason = "Exclude individuals not in observation"