Skip to content

Commit

Permalink
Merge pull request #243 from OHDSI/issue_242
Browse files Browse the repository at this point in the history
Issue 242
  • Loading branch information
catalamarti authored Dec 2, 2024
2 parents 9023c2f + 064f65d commit 24bcfb2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
5 changes: 3 additions & 2 deletions R/summariseClinicalRecords.R
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,11 @@ summaryData <- function(x, denominator, strata, cdm) {
}

formatResults <- function(x, variableName, variableLevel, denominator, strata) {

attr(denominator, "settings")$strata <- paste(unique(unlist(strata)), collapse = " &&& ")
denominator <- denominator |>
dplyr::select("strata_name", "strata_level", "denominator" = "estimate_value") |>
visOmopResults::splitStrata()
dplyr::filter(.data$strata_name != "overall") |>
omopgenerics::splitStrata()

strataCols <- unique(unlist(strata))

Expand Down
4 changes: 2 additions & 2 deletions R/summariseObservationPeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ addOrdinalLevels <- function(x) {
xx <- suppressWarnings(as.integer(x$id))
desena <- (floor(xx/10)) %% 10
unitat <- xx %% 10
val <- rep("overall", length(xx))
val <- rep("overall_", length(xx))
id0 <- !is.na(xx)
val[id0] <- paste0(xx[id0], "th")
id <- id0 & desena != 1L & unitat == 1L
Expand Down Expand Up @@ -162,7 +162,7 @@ arrangeSr <- function(x, estimates) {

order <- dplyr::tibble(
"variable_name" = c("number records"),
"group_level" = "overall",
"group_level" = "overall_",
"strata_level" = "overall",
"estimate_name" = "count"
) |>
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-summariseConceptCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_that("summarise code use - eunomia", {
time_interval == "1909-01-01 to 1909-12-31",
group_level == "acetiminophen") |>
dplyr::pull("estimate_value"),
as.character(NA)
"-"
)

# check is a summarised result
Expand Down
30 changes: 24 additions & 6 deletions tests/testthat/test-summariseObservationPeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test_that("check summariseObservationPeriod works", {
# counts
expect_identical(resAll$estimate_value[resAll$variable_name == "number records"], "8")
x <- dplyr::tibble(
group_level = c("overall", "1st", "2nd", "3rd"),
group_level = c("overall_", "1st", "2nd", "3rd"),
variable_name = "number subjects",
estimate_value = c("4", "4", "3", "1"))
expect_identical(nrow(x), resAll |> dplyr::inner_join(x, by = colnames(x)) |> nrow())
Expand All @@ -88,21 +88,39 @@ test_that("check summariseObservationPeriod works", {
dplyr::filter(variable_name == "duration in days", estimate_name == "mean") |>
dplyr::pull("estimate_value"),
as.character(c(
mean(c(20, 6, 113, 144, 18, 9, 29, 276)), mean(c(20, 18, 9, 276)),
mean(c(6, 29, 144)), 113
mean(c(20, 18, 9, 276)),
mean(c(6, 29, 144)), 113, mean(c(20, 6, 113, 144, 18, 9, 29, 276))
))
)
# when it will be group_level = "overall"
# expect_identical(
# resAll |>
# dplyr::filter(variable_name == "duration in days", estimate_name == "mean") |>
# dplyr::pull("estimate_value"),
# as.character(c(
# mean(c(20, 6, 113, 144, 18, 9, 29, 276)), mean(c(20, 18, 9, 276)),
# mean(c(6, 29, 144)), 113
# ))
# )

# days to next observation period
expect_identical(
resAll |>
dplyr::filter(variable_name == "days to next observation period", estimate_name == "mean") |>
dplyr::pull("estimate_value"),
as.character(c(
mean(c(5, 32, 136, 26)), mean(c(5, 32, 136)), 26, NA
mean(c(5, 32, 136)), 26, NA, mean(c(5, 32, 136, 26))
))
)

# when it will be group_level="overall"
# expect_identical(
# resAll |>
# dplyr::filter(variable_name == "days to next observation period", estimate_name == "mean") |>
# dplyr::pull("estimate_value"),
# as.character(c(
# mean(c(5, 32, 136, 26)), mean(c(5, 32, 136)), 26, NA
# ))
# )
# duration - density
xx <- resAllD |>
dplyr::filter(variable_name == "duration in days", !is.na(variable_level)) |>
Expand Down Expand Up @@ -144,7 +162,7 @@ test_that("check summariseObservationPeriod works", {
# counts
expect_identical(resOne$estimate_value[resOne$variable_name == "number records"], "4")
x <- dplyr::tibble(
group_level = c("overall", "1st"),
group_level = c("overall_", "1st"),
variable_name = "number subjects",
estimate_value = c("4", "4"))
expect_identical(nrow(x), resOne |> dplyr::inner_join(x, by = colnames(x)) |> nrow())
Expand Down

0 comments on commit 24bcfb2

Please sign in to comment.