diff --git a/DESCRIPTION b/DESCRIPTION index 2380e90..9699fbc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: OmopSketch Title: Characterise Tables of an OMOP Common Data Model Instance -Version: 0.1.2 +Version: 0.1.1 Authors@R: c( person( "Marta", "Alcalde-Herraiz", @@ -15,6 +15,10 @@ Authors@R: c( "Elin", "Rowlands", email = "elin.rowlands@ndorms.ox.ac.uk", role = c("aut"), comment = c(ORCID = "0009-0005-5166-0417") ), + person( + "Cecilia", "Campanile", email = "cecilia.campanile@ndorms.ox.ac.uk", + role = c("aut"), comment = c(ORCID = "0009-0007-6629-4661") + ), person( "Edward", "Burn", email = "edward.burn@ndorms.ox.ac.uk", role = c("aut"), comment = c(ORCID = "0000-0002-9286-1128") @@ -71,4 +75,4 @@ URL: https://OHDSI.github.io/OmopSketch/ BugReports: https://github.com/OHDSI/OmopSketch/issues VignetteBuilder: knitr Remotes: - darwin-eu-dev/omopgenerics@mah_vl + darwin-eu-dev/omopgenerics diff --git a/R/plotConceptCounts.R b/R/plotConceptCounts.R index f92326c..ae0b2b0 100644 --- a/R/plotConceptCounts.R +++ b/R/plotConceptCounts.R @@ -23,7 +23,7 @@ #' #' result |> #' filter(variable_name == "Number subjects") |> -#' plotConceptCounts(facet = "codelist_name", colour = "codelist_name") +#' plotConceptCounts(facet = "codelist_name", colour = "standard_concept_name") #' #' PatientProfiles::mockDisconnect(cdm) #' } @@ -35,9 +35,7 @@ plotConceptCounts <- function(result, # subset to results of interest result <- result |> - visOmopResults::filterSettings(.data$result_type == "summarise_concept_counts") |> - dplyr::mutate(variable_level = gsub(" to.*","",.data$variable_level)) |> - dplyr::mutate(variable_level = gsub("-01$","",.data$variable_level)) + visOmopResults::filterSettings(.data$result_type == "summarise_concept_counts") if (nrow(result) == 0) { cli::cli_abort(c("!" = "No records found with result_type == summarise_concept_counts")) @@ -52,12 +50,14 @@ plotConceptCounts <- function(result, )) } + result1 <- result |> visOmopResults::splitAdditional() # Detect if there are several time intervals - if(length(unique(result$variable_level)) > 1 ){ + if("time_interval" %in% colnames(result1)){ # Line plot where each concept is a different line - p <- result |> - dplyr::filter(.data$variable_level != "overall") |> - visOmopResults::scatterPlot(x = "variable_level", + p <- result1 |> + dplyr::filter(.data$time_interval != "overall") |> + visOmopResults::uniteAdditional(cols = c("time_interval", "standard_concept_name", "standard_concept_id", "source_concept_name", "source_concept_id", "domain_id")) |> + visOmopResults::scatterPlot(x = "time_interval", y = "count", line = TRUE, point = TRUE, @@ -66,11 +66,20 @@ plotConceptCounts <- function(result, facet = facet, colour = colour) }else{ - p <- result |> - visOmopResults::barPlot(x = "standard_concept_name", - y = "count", - facet = facet, - colour = colour) + + if("standard_concept_name" %in% colnames(result1)){ + p <- result |> + visOmopResults::barPlot(x = "standard_concept_name", + y = "count", + facet = facet, + colour = colour) + }else{ + p <- result |> + visOmopResults::barPlot(x = "codelist_name", + y = "count", + facet = facet, + colour = colour) + } + p <- p + ggplot2::labs( x = "Concept name" ) diff --git a/R/plotRecordCount.R b/R/plotRecordCount.R index f8b902e..221cb4b 100644 --- a/R/plotRecordCount.R +++ b/R/plotRecordCount.R @@ -57,13 +57,13 @@ plotRecordCount <- function(result, ) }else{ p <- result |> - visOmopResults::barPlot(x = "additional_level", + visOmopResults::barPlot(x = "variable_name", y = "count", facet = facet, colour = colour) + ggplot2::labs( y = "Count", - x = "Number records" + x = "" ) } p diff --git a/R/summariseConceptCounts.R b/R/summariseConceptCounts.R index 20a1cee..e6ea43a 100644 --- a/R/summariseConceptCounts.R +++ b/R/summariseConceptCounts.R @@ -186,7 +186,6 @@ getCodeUse <- function(x, } cc <- records |> - # dplyr::collect() |> # https://github.com/darwin-eu-dev/PatientProfiles/issues/706 PatientProfiles::summariseResult(strata = strata, variable = "standard_concept_name", group = group, @@ -211,7 +210,10 @@ getCodeUse <- function(x, if(interval != "overall"){ cc <- cc |> visOmopResults::splitStrata() |> - dplyr::mutate(variable_level = .data$interval_group) |> + dplyr::mutate("additional_level" = dplyr::if_else(.data$interval_group == "overall", .data$additional_level, paste0(.data$interval_group, " &&& ", .data$additional_level))) |> + dplyr::mutate("additional_name" = dplyr::if_else(.data$interval_group == "overall", .data$additional_name, paste0("time_interval &&& ", .data$additional_name))) |> + dplyr::mutate("additional_level" = gsub(" &&& overall$", "", .data$additional_level)) |> + dplyr::mutate("additional_name" = gsub(" &&& overall$", "", .data$additional_name)) |> visOmopResults::uniteStrata(unique(unlist(strata))[unique(unlist(strata)) != "interval_group"]) |> dplyr::select(-"interval_group") } diff --git a/R/summariseInObservation.R b/R/summariseInObservation.R index e52d6b8..bc0e2a5 100644 --- a/R/summariseInObservation.R +++ b/R/summariseInObservation.R @@ -338,7 +338,7 @@ addSexOverall <- function(result, sex){ dplyr::group_by(.data$age_group, .data$additional_level, .data$variable_name) |> dplyr::summarise(estimate_value = sum(.data$estimate_value, na.rm = TRUE), .groups = "drop") |> dplyr::mutate(sex = "overall", - additional_name = dplyr::if_else(additional_level == "overall", "overall", "time_interval")) + additional_name = dplyr::if_else(.data$additional_level == "overall", "overall", "time_interval")) ) } return(result) diff --git a/R/summariseRecordCount.R b/R/summariseRecordCount.R index 8c82fb4..c5cb0f2 100644 --- a/R/summariseRecordCount.R +++ b/R/summariseRecordCount.R @@ -255,7 +255,7 @@ createSummarisedResultRecordCount <- function(result, strata, omopTable, omopTab result <- result |> visOmopResults::splitStrata() |> dplyr::mutate(additional_level = .data$interval_group) |> - dplyr::mutate(additional_name = dplyr::if_else(additional_level == "overall", "overall", "time_interval")) |> + dplyr::mutate(additional_name = dplyr::if_else(.data$additional_level == "overall", "overall", "time_interval")) |> visOmopResults::uniteStrata(unique(unlist(strata))[unique(unlist(strata)) != "interval_group"]) |> dplyr::select(-"interval_group") } diff --git a/man/OmopSketch-package.Rd b/man/OmopSketch-package.Rd index 0bc315f..459a2b9 100644 --- a/man/OmopSketch-package.Rd +++ b/man/OmopSketch-package.Rd @@ -25,6 +25,7 @@ Authors: \itemize{ \item Kim Lopez-Guell \email{kim.lopez@spc.ox.ac.uk} (\href{https://orcid.org/0000-0002-8462-8668}{ORCID}) \item Elin Rowlands \email{elin.rowlands@ndorms.ox.ac.uk} (\href{https://orcid.org/0009-0005-5166-0417}{ORCID}) + \item Cecilia Campanile \email{cecilia.campanile@ndorms.ox.ac.uk} \item Edward Burn \email{edward.burn@ndorms.ox.ac.uk} (\href{https://orcid.org/0000-0002-9286-1128}{ORCID}) \item MartĂ­ CatalĂ  \email{marti.catalasabate@ndorms.ox.ac.uk} (\href{https://orcid.org/0000-0003-3308-9905}{ORCID}) } diff --git a/man/plotConceptCounts.Rd b/man/plotConceptCounts.Rd index 63492a7..2492a3d 100644 --- a/man/plotConceptCounts.Rd +++ b/man/plotConceptCounts.Rd @@ -37,7 +37,7 @@ result <- cdm |> result |> filter(variable_name == "Number subjects") |> - plotConceptCounts(facet = "codelist_name", colour = "codelist_name") + plotConceptCounts(facet = "codelist_name", colour = "standard_concept_name") PatientProfiles::mockDisconnect(cdm) } diff --git a/tests/testthat/test-summariseConceptCounts.R b/tests/testthat/test-summariseConceptCounts.R index 6486e28..6e63e46 100644 --- a/tests/testthat/test-summariseConceptCounts.R +++ b/tests/testthat/test-summariseConceptCounts.R @@ -1,6 +1,6 @@ test_that("summarise code use - eunomia", { skip_on_cran() - cdm <- cdmEunomia() + cdm <- cdmEunomia() acetiminophen <- c(1125315, 1127433, 40229134, 40231925, 40162522, 19133768, 1127078) poliovirus_vaccine <- c(40213160) @@ -10,6 +10,8 @@ test_that("summarise code use - eunomia", { results <- summariseConceptCounts(cdm = cdm, conceptId = cs, interval = "years", + countBy = c("record", "person"), + concept = TRUE, sex = TRUE, ageGroup = list(c(0,17), c(18,65), @@ -23,12 +25,15 @@ test_that("summarise code use - eunomia", { # min cell counts: expect_equal( omopgenerics::suppress(results, 5) |> + visOmopResults::splitAdditional() |> dplyr::filter( - variable_name == "overall", - strata_level == "1909-01-01 to 1909-12-31", + strata_level == "overall", + variable_name == "Number records", + standard_concept_id == "overall", + time_interval == "1909-01-01 to 1909-12-31", group_level == "acetiminophen") |> dplyr::pull("estimate_value"), - as.character() + as.character(NA) ) # check is a summarised result @@ -38,13 +43,12 @@ test_that("summarise code use - eunomia", { # overall record count expect_true(results %>% - dplyr::filter(group_name == "codelist_name" & - strata_name == "overall" & - strata_level == "overall" & - variable_level == "overall" & - group_level == "acetiminophen" & - variable_name == "Number records", - additional_name == "overall") %>% + dplyr::filter(group_name == "codelist_name", + strata_name == "overall", + strata_level == "overall", + additional_level == "overall", + group_level == "acetiminophen", + variable_name == "Number records") %>% dplyr::pull("estimate_value") |> as.numeric() == cdm$drug_exposure %>% @@ -58,7 +62,6 @@ test_that("summarise code use - eunomia", { dplyr::filter(group_name == "codelist_name" & strata_name == "overall" & strata_level == "overall" & - variable_level == "overall" & group_level == "acetiminophen" & variable_name == "Number subjects", additional_name == "overall") %>% @@ -74,12 +77,13 @@ test_that("summarise code use - eunomia", { # by year # overall record count expect_true(results %>% + visOmopResults::splitAdditional() |> dplyr::filter(group_name == "codelist_name" & strata_name == "overall" & - variable_level == "2008-01-01 to 2008-12-31" & + time_interval == "2008-01-01 to 2008-12-31" & group_level == "acetiminophen" & variable_name == "Number records", - additional_name == "overall") %>% + standard_concept_name == "overall") %>% dplyr::pull("estimate_value") |> as.numeric() == cdm$drug_exposure %>% @@ -90,12 +94,13 @@ test_that("summarise code use - eunomia", { # overall person count expect_true(results %>% + visOmopResults::splitAdditional() |> dplyr::filter(group_name == "codelist_name" & strata_name == "overall" & - variable_level == "2008-01-01 to 2008-12-31" & + time_interval == "2008-01-01 to 2008-12-31" & group_level == "acetiminophen" & variable_name == "Number subjects", - additional_name == "overall") %>% + standard_concept_name == "overall") %>% dplyr::pull("estimate_value") |> as.numeric() == cdm$drug_exposure %>% @@ -112,7 +117,6 @@ test_that("summarise code use - eunomia", { dplyr::filter(group_name == "codelist_name" & strata_name == "sex" & strata_level == "Male" & - variable_level == "overall" & group_level == "acetiminophen" & variable_name == "Number records" & additional_name == "overall") %>% @@ -129,7 +133,6 @@ test_that("summarise code use - eunomia", { dplyr::filter(group_name == "codelist_name" & strata_name == "age_group &&& sex" & strata_level == "18 to 65 &&& Male" & - variable_level == "overall" & group_level == "acetiminophen" & variable_name == "Number records", additional_name == "overall") %>% @@ -150,7 +153,6 @@ test_that("summarise code use - eunomia", { dplyr::filter(group_name == "codelist_name" & strata_name == "age_group &&& sex" & strata_level == "18 to 65 &&& Male" & - variable_level == "overall" & group_level == "acetiminophen" & variable_name == "Number subjects", additional_name == "overall") %>% @@ -177,33 +179,35 @@ test_that("summarise code use - eunomia", { c(18,65), c(66, 100))) - expect_true(results1$additional_level |> unique() |> length() == 1) expect_equal( results1 |> + visOmopResults::splitAdditional() |> dplyr::filter(variable_name == "Number records") |> dplyr::arrange(dplyr::across(dplyr::everything())), results |> - dplyr::filter(variable_name == "Number records", additional_name == "overall") |> + visOmopResults::splitAdditional() |> + dplyr::filter(variable_name == "Number records", standard_concept_name == "overall") |> + dplyr::select(-c(starts_with("standard_"), starts_with("source_"), "domain_id")) |> 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")) + visOmopResults::splitAdditional() |> + dplyr::filter(variable_name == "Number subjects", + group_level == "acetiminophen", + time_interval == "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",