diff --git a/R/matchCohorts.R b/R/matchCohorts.R index b399d2c2..64ab83a0 100644 --- a/R/matchCohorts.R +++ b/R/matchCohorts.R @@ -128,6 +128,8 @@ matchCohorts <- function(cohort, ) |> dplyr::left_join( settings(cdm[[target]]) |> + dplyr::mutate( + "cohort_name" = paste0(.data$cohort_name, "_matched")) |> dplyr::select("cohort_definition_id", "target_cohort_name" = "cohort_name"), by = "cohort_definition_id" ) |> @@ -149,6 +151,8 @@ matchCohorts <- function(cohort, omopgenerics::newCohortTable( cohortSetRef = settings(cdm[[target]]) |> dplyr::select("cohort_definition_id", "cohort_name") |> + dplyr::mutate( + "cohort_name" = paste0(.data$cohort_name, "_matched")) |> dplyr::mutate( "target_table_name" = omopgenerics::tableName(cohort), "target_cohort_id" = .data$cohort_definition_id, @@ -208,7 +212,7 @@ getNewCohort <- function(cohort, cohortId, control) { dplyr::relocate(dplyr::all_of(omopgenerics::cohortColumns("cohort"))) |> omopgenerics::newCohortTable( cohortSetRef = settings(cohort) |> - dplyr::mutate("cohort_name" = paste0(.data$cohort_name, "_matched")), + dplyr::mutate("cohort_name" = paste0("matched_to_", .data$cohort_name)), cohortAttritionRef = dplyr::tibble( "cohort_definition_id" = as.integer(cohortId), "number_records" = controls |> dplyr::tally() |> dplyr::pull() |> as.integer(), diff --git a/tests/testthat/test-matchCohorts.R b/tests/testthat/test-matchCohorts.R index a7446ef4..4d519fc2 100644 --- a/tests/testthat/test-matchCohorts.R +++ b/tests/testthat/test-matchCohorts.R @@ -236,7 +236,7 @@ test_that("test exactMatchingCohort with a ratio bigger than 1", { cdm[["new_cohort"]] %>% cohortCount() |> dplyr::filter(.data$cohort_definition_id %in% omopgenerics::getCohortId( - cdm$new_cohort, "cohort_1" + cdm$new_cohort, "cohort_1_matched" )) %>% dplyr::pull("number_subjects") |> sum() == 2 @@ -245,7 +245,7 @@ test_that("test exactMatchingCohort with a ratio bigger than 1", { cdm[["new_cohort"]] %>% cohortCount() |> dplyr::filter(.data$cohort_definition_id %in% omopgenerics::getCohortId( - cdm$new_cohort, "cohort_1_matched" + cdm$new_cohort, "matched_to_cohort_1" )) %>% dplyr::pull("number_subjects") |> sum() == 8 @@ -254,7 +254,7 @@ test_that("test exactMatchingCohort with a ratio bigger than 1", { cdm[["new_cohort"]] %>% cohortCount() |> dplyr::filter(.data$cohort_definition_id %in% omopgenerics::getCohortId( - cdm$new_cohort, "cohort_2" + cdm$new_cohort, "cohort_2_matched" )) %>% dplyr::pull("number_subjects") |> sum() == 2 @@ -263,7 +263,7 @@ test_that("test exactMatchingCohort with a ratio bigger than 1", { cdm[["new_cohort"]] %>% cohortCount() |> dplyr::filter(.data$cohort_definition_id %in% omopgenerics::getCohortId( - cdm$new_cohort, "cohort_2_matched" + cdm$new_cohort, "matched_to_cohort_2" )) %>% dplyr::pull("number_subjects") |> sum() == 8