diff --git a/R/summariseClinicalRecords.R b/R/summariseClinicalRecords.R index d855a7d..699ad6f 100644 --- a/R/summariseClinicalRecords.R +++ b/R/summariseClinicalRecords.R @@ -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)) diff --git a/R/summariseObservationPeriod.R b/R/summariseObservationPeriod.R index 7b81fb4..f193731 100644 --- a/R/summariseObservationPeriod.R +++ b/R/summariseObservationPeriod.R @@ -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 @@ -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" ) |> diff --git a/tests/testthat/test-summariseConceptCounts.R b/tests/testthat/test-summariseConceptCounts.R index 6d9fc16..0158080 100644 --- a/tests/testthat/test-summariseConceptCounts.R +++ b/tests/testthat/test-summariseConceptCounts.R @@ -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 diff --git a/tests/testthat/test-summariseObservationPeriod.R b/tests/testthat/test-summariseObservationPeriod.R index 50b8ea8..fe737c3 100644 --- a/tests/testthat/test-summariseObservationPeriod.R +++ b/tests/testthat/test-summariseObservationPeriod.R @@ -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()) @@ -88,10 +88,20 @@ 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( @@ -99,10 +109,18 @@ test_that("check summariseObservationPeriod works", { 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)) |> @@ -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())