Skip to content

Commit

Permalink
Merge pull request #396 from OHDSI/match_description
Browse files Browse the repository at this point in the history
match description
  • Loading branch information
edward-burn authored Dec 8, 2024
2 parents 2436a12 + 40c0fa2 commit 173ed7e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
22 changes: 9 additions & 13 deletions R/matchCohorts.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
#' @description
#' `matchCohorts()` generate a new cohort matched to individuals in an
#' existing cohort. Individuals can be matched based on year of birth and sex.
#' Matching is done at the record level, so if individuals have multiple
#' cohort entries they can be matched to different individuals for each of their
#' records.
#'
#' Two new cohorts will be created when matching. The first is those
#' cohort entries which were matched ("_sampled" is added to the original
#' cohort name for this cohort). The other is the matches found from the
#' database population ("_matched" is added to the original cohort name
#' for this cohort).
#'
#' @inheritParams cohortDoc
#' @inheritParams cohortIdSubsetDoc
Expand Down Expand Up @@ -48,19 +57,6 @@ matchCohorts <- function(cohort,
omopgenerics::assertLogical(matchSex, length = 1)
omopgenerics::assertLogical(matchYearOfBirth, length = 1)

# Check if there are repeated people within the cohort
y <- cohort |>
dplyr::filter(.data$cohort_definition_id %in% cohortId) |>
dplyr::group_by(.data$cohort_definition_id, .data$subject_id) |>
dplyr::filter(dplyr::n() >= 2) |>
dplyr::ungroup() |>
dplyr::tally() |>
dplyr::pull()
if (y != 0) {
cli::cli_warn(
"Multiple records per person detected. The matchCohorts() function is designed to operate under the assumption that there is only one record per person within each cohort. If this assumption is not met, each record will be treated independently. As a result, the same individual may be matched multiple times, leading to inconsistent and potentially misleading results."
)
}

# table prefix
tablePrefix <- omopgenerics::tmpPrefix()
Expand Down
2 changes: 1 addition & 1 deletion R/measurementCohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ measurementCohort <- function(cdm,

if (ud > 0) {
cli::cli_inform(
c("x" = "{.strong {ud}} concept{?s} excluded because don't correspond to the `Measurement` domain.")
c("x" = "{.strong {ud}} concept{?s} excluded because they don't correspond to the `Measurement` domain.")
)
}

Expand Down
9 changes: 9 additions & 0 deletions man/matchCohorts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions tests/testthat/test-matchCohorts.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ test_that("matchCohorts runs without errors", {

# expect warnings
cdm <- mockCohortConstructor(nPerson = 1000)
expect_warning(matchCohorts(cohort = cdm$cohort1,
name = "new_cohort"))

PatientProfiles::mockDisconnect(cdm)
})
Expand Down

0 comments on commit 173ed7e

Please sign in to comment.