Skip to content

Commit

Permalink
Merge branch 'main' into mah_issues
Browse files Browse the repository at this point in the history
  • Loading branch information
martaalcalde committed Oct 9, 2024
2 parents c7829da + 4f2016c commit 3ae1f89
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Eunomia/*
inst/doc
/doc/
/Meta/
tests/testthat/UntitledR.R
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ Imports:
CDMConnector (>= 1.3.0),
cli,
clock,
CohortCharacteristics,
CohortConstructor,
CohortCharacteristics (>= 0.3.0),
CohortConstructor (>= 0.3.1),
dplyr,
ggplot2,
omock (>= 0.3.0),
omopgenerics (>= 0.3.1),
PatientProfiles,
PatientProfiles (>= 1.2.0),
purrr,
rlang,
stringr,
Expand Down
6 changes: 4 additions & 2 deletions R/summariseRecordCount.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,15 @@ splitIncidenceBetweenIntervals <- function(cdm, omopTable, date, strata){

createSummarisedResultRecordCount <- function(result, sex, ageGroup, omopTable, omopTableName, unit, unitInterval){

PatientProfiles::summariseResult(
result <- PatientProfiles::summariseResult(
result,
strata = getStrataList(sex, ageGroup),
includeOverallStrata = TRUE,
estimates = "count",
counts = FALSE
) |>
)

result |>
dplyr::filter(!.data$variable_name %in% c("sex", "age_group")) |>
dplyr::mutate("variable_name" = "incidence_records") |>
dplyr::mutate(
Expand Down
69 changes: 36 additions & 33 deletions tests/testthat/test-summariseRecordCount.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,39 +150,42 @@ test_that("summariseRecordCount() ageGroup argument works", {
dplyr::pull("estimate_value")
expect_equal(x,y)

expect_no_error(t <- summariseRecordCount(cdm, "condition_occurrence",
ageGroup = list("<=20" = c(0,20), "21 to 40" = c(21,40), "41 to 60" = c(41,60), ">60" = c(61, Inf))))
x <- t |>
dplyr::select("strata_level", "variable_level", "estimate_value") |>
dplyr::filter(strata_level == "<=20" & variable_level == "1920-01-01 to 1920-12-31") |>
dplyr::summarise(n = sum(as.numeric(estimate_value))) |>
dplyr::pull("n")
y <- cdm$condition_occurrence |>
dplyr::inner_join(cdm[["person"]] |> dplyr::select("person_id"), by = "person_id") |>
PatientProfiles::addAgeQuery(indexDate = "condition_start_date", ageGroup = list("<=20" = c(0,20))) |>
dplyr::filter(age_group == "<=20") |>
dplyr::filter(clock::get_year(condition_start_date) == "1920") |>
dplyr::summarise(n = dplyr::n()) |>
dplyr::pull("n") |> as.numeric()
expect_equal(x,y)


expect_no_error(t <- summariseRecordCount(cdm, "condition_occurrence",
ageGroup = list("<=20" = c(0,20), "21 to 40" = c(21,40), "41 to 60" = c(41,60))))
x <- t |>
dplyr::select("strata_level", "variable_level", "estimate_value") |>
dplyr::filter(strata_level == "<=20" & variable_level == "1920-01-01 to 1920-12-31") |>
dplyr::summarise(n = sum(as.numeric(estimate_value))) |>
dplyr::pull("n")
y <- cdm$condition_occurrence |>
dplyr::inner_join(cdm[["person"]] |> dplyr::select("person_id"), by = "person_id") |>
PatientProfiles::addAgeQuery(indexDate = "condition_start_date", ageGroup = list("<=20" = c(0,20))) |>
dplyr::filter(age_group == "<=20") |>
dplyr::filter(clock::get_year(condition_start_date) == "1920") |>
dplyr::summarise(n = dplyr::n()) |>
dplyr::pull("n") |> as.numeric()
expect_equal(x,y)

# Uncomment this tests when PP issue has been solved:
# https://github.com/darwin-eu-dev/PatientProfiles/issues/706

# expect_no_error(t <- summariseRecordCount(cdm, "condition_occurrence",
# ageGroup = list("<=20" = c(0,20), "21 to 40" = c(21,40), "41 to 60" = c(41,60), ">60" = c(61, Inf))))
# x <- t |>
# dplyr::select("strata_level", "variable_level", "estimate_value") |>
# dplyr::filter(strata_level == "<=20" & variable_level == "1920-01-01 to 1920-12-31") |>
# dplyr::summarise(n = sum(as.numeric(estimate_value))) |>
# dplyr::pull("n")
# y <- cdm$condition_occurrence |>
# dplyr::inner_join(cdm[["person"]] |> dplyr::select("person_id"), by = "person_id") |>
# PatientProfiles::addAgeQuery(indexDate = "condition_start_date", ageGroup = list("<=20" = c(0,20))) |>
# dplyr::filter(age_group == "<=20") |>
# dplyr::filter(clock::get_year(condition_start_date) == "1920") |>
# dplyr::summarise(n = dplyr::n()) |>
# dplyr::pull("n") |> as.numeric()
# expect_equal(x,y)


# expect_no_error(t <- summariseRecordCount(cdm, "condition_occurrence",
# ageGroup = list("<=20" = c(0,20), "21 to 40" = c(21,40), "41 to 60" = c(41,60))))
# x <- t |>
# dplyr::select("strata_level", "variable_level", "estimate_value") |>
# dplyr::filter(strata_level == "<=20" & variable_level == "1920-01-01 to 1920-12-31") |>
# dplyr::summarise(n = sum(as.numeric(estimate_value))) |>
# dplyr::pull("n") |> as.numeric()
# x
# y <- cdm$condition_occurrence |>
# dplyr::inner_join(cdm[["person"]] |> dplyr::select("person_id"), by = "person_id") |>
# PatientProfiles::addAgeQuery(indexDate = "condition_start_date", ageGroup = list("<=20" = c(0,20))) |>
# dplyr::filter(age_group == "<=20") |>
# dplyr::filter(clock::get_year(condition_start_date) == "1920") |>
# dplyr::summarise(n = dplyr::n()) |>
# dplyr::pull("n") |> as.numeric()
# expect_equal(x,y)

PatientProfiles::mockDisconnect(cdm = cdm)
})
Expand Down

0 comments on commit 3ae1f89

Please sign in to comment.