Skip to content

Commit

Permalink
Merge pull request #214 from OHDSI/mah_concept
Browse files Browse the repository at this point in the history
Fix concept argument
  • Loading branch information
martaalcalde authored Oct 21, 2024
2 parents 5749f1a + 5b1c161 commit b575776
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/summariseConceptCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#' results
#'
#' PatientProfiles::mockDisconnect(cdm)
#'
#' }
summariseConceptCounts <- function(cdm,
conceptId,
Expand Down Expand Up @@ -176,12 +177,19 @@ getCodeUse <- function(x,
}

if(!"number subjects" %in% c(countBy)){records <- records |> dplyr::select(-"person_id")}
if(concept){
group <- list("standard_concept_id")
}else{
group <- list()
records <- records |>
dplyr::mutate("standard_concept_name" = !!names(x))
}

cc <- records |>
# dplyr::collect() |> # https://github.com/darwin-eu-dev/PatientProfiles/issues/706
PatientProfiles::summariseResult(strata = strata,
variable = "standard_concept_name",
group = "standard_concept_id",
group = group,
includeOverallGroup = TRUE,
includeOverallStrata = TRUE,
counts = TRUE,
Expand Down
1 change: 1 addition & 0 deletions man/summariseConceptCounts.Rd

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

38 changes: 38 additions & 0 deletions tests/testthat/test-summariseConceptCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,43 @@ test_that("summarise code use - eunomia", {
dplyr::tally() %>%
dplyr::pull("n"))

results1 <- summariseConceptCounts(cdm = cdm,
conceptId = cs,
interval = "years",
concept = FALSE,
sex = TRUE,
ageGroup = list(c(0,17),
c(18,65),
c(66, 100)))

expect_true(results1$additional_level |> unique() |> length() == 1)
expect_equal(
results1 |>
dplyr::filter(variable_name == "Number records") |>
dplyr::arrange(dplyr::across(dplyr::everything())),
results |>
dplyr::filter(variable_name == "Number records", additional_name == "overall") |>
dplyr::arrange(dplyr::across(dplyr::everything()))
)
expect_true(results1 |>
dplyr::filter(variable_name == "Number subjects",
group_level == "acetiminophen",
variable_level == "1909-01-01 to 1909-12-31",
strata_level == "0 to 17") |>
dplyr::pull("estimate_value") |>
as.numeric() ==
cdm$drug_exposure %>%
dplyr::filter(drug_concept_id %in% acetiminophen) %>%
PatientProfiles::addAge(indexDate = "drug_exposure_start_date") %>%
PatientProfiles::addSex() %>%
dplyr::filter(age >= "0", age <= "17", clock::get_year(drug_exposure_start_date) == 1909) |>
dplyr::select("person_id") %>%
dplyr::distinct() %>%
dplyr::tally() %>%
dplyr::pull("n"))
expect_true(results1$group_level |> unique() |> length() == 2)
expect_true(results1$additional_name |> unique() |> length() == 1)

results <- summariseConceptCounts(list("acetiminophen" = acetiminophen),
cdm = cdm, countBy = "person",
interval = "years",
Expand All @@ -178,6 +215,7 @@ test_that("summarise code use - eunomia", {
expect_true(nrow(results %>%
dplyr::filter(variable_name == "Number records")) == 0)


results <- summariseConceptCounts(list("acetiminophen" = acetiminophen),
cdm = cdm, countBy = "record",
interval = "years",
Expand Down

0 comments on commit b575776

Please sign in to comment.