From cffe30dbfb8319888f51da7ea267b2a398566fb2 Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Wed, 25 Sep 2024 08:28:26 +0100 Subject: [PATCH] new names closes #329 --- R/matchCohorts.R | 6 +++++- tests/testthat/test-matchCohorts.R | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) 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