Skip to content

Commit

Permalink
Merge pull request #225 from OHDSI/dev_cc
Browse files Browse the repository at this point in the history
creates tables for summariseMissingData and summariseAllConceptCount
  • Loading branch information
martaalcalde authored Nov 12, 2024
2 parents cc0bf1b + 438494a commit e5d68a1
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ export(plotInObservation)
export(plotObservationPeriod)
export(plotRecordCount)
export(settings)
export(summariseAllConceptCounts)
export(summariseClinicalRecords)
export(summariseConceptCounts)
export(summariseInObservation)
export(summariseMissingData)
export(summariseObservationPeriod)
export(summariseOmopSnapshot)
export(summariseRecordCount)
export(suppress)
export(tableAllConceptCounts)
export(tableClinicalRecords)
export(tableMissingData)
export(tableObservationPeriod)
export(tableOmopSnapshot)
importFrom(dplyr,"%>%")
Expand Down
4 changes: 4 additions & 0 deletions R/summariseAllConceptCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ my_getStrataList <- function(sex = FALSE, ageGroup = NULL, year = FALSE){
return(strata)
}


checkFeasibility <- function(omopTable, tableName, conceptId){

if (omopgenerics::isTableEmpty(omopTable)){
Expand All @@ -37,6 +38,7 @@ checkFeasibility <- function(omopTable, tableName, conceptId){
}
return(TRUE)
}

#' Summarise concept use in patient-level data
#'
#' @param cdm A cdm object
Expand Down Expand Up @@ -74,6 +76,7 @@ summariseAllConceptCounts <- function(cdm,




omopTable <- cdm[[table]] |>
dplyr::ungroup()

Expand Down Expand Up @@ -143,6 +146,7 @@ summariseAllConceptCounts <- function(cdm,
result<- result |>
dplyr::mutate("omop_table" = table,
"variable_level" = as.character(.data[[conceptId]])) |>

dplyr::select(-dplyr::all_of(conceptId))
return(result)
})
Expand Down
14 changes: 7 additions & 7 deletions R/summariseMissingData.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#' @param col A character vector of column names to check for missing values.
#' If `NULL`, all columns in the specified tables are checked. Default is `NULL`.
#' @param sex TRUE or FALSE. If TRUE code use will be summarised by sex.
#' @param year TRUE or FALSE. If TRUE code use will be summarised by year.
#' @param ageGroup A list of ageGroup vectors of length two. Code use will be
#' thus summarised by age groups.
#' @return A summarised_result object with results overall and, if specified, by
#' strata.
#' @export

summariseMissingData <- function(cdm,
omopTableName,
col = NULL,
Expand Down Expand Up @@ -66,8 +66,8 @@ summariseMissingData <- function(cdm,
stratified_result |>
dplyr::group_by(dplyr::across(dplyr::all_of(g))) |>
dplyr::summarise(
na_count = sum(na_count, na.rm = TRUE),
total_count = sum(total_count, na.rm = TRUE),
na_count = sum(.data$na_count, na.rm = TRUE),
total_count = sum(.data$total_count, na.rm = TRUE),
colName = c,
.groups = "drop"
) |>
Expand All @@ -94,11 +94,11 @@ summariseMissingData <- function(cdm,
purrr::reduce(dplyr::union)|>
dplyr::mutate(dplyr::across(dplyr::all_of(strata), ~ dplyr::coalesce(., "overall")))|>
dplyr::mutate(
na_count = as.double(na_count), # Cast na_count to double
na_percentage = as.double(na_percentage)
na_count = as.double(.data$na_count), # Cast na_count to double
na_percentage = as.double(.data$na_percentage)
)|>
tidyr::pivot_longer(
cols = c(na_count, na_percentage),
cols = c(.data$na_count, .data$na_percentage),
names_to = "estimate_name",
values_to = "estimate_value"
)
Expand All @@ -118,7 +118,7 @@ summariseMissingData <- function(cdm,
"variable_level" = NA_character_
) |>
dplyr::rename("variable_name" = "colName") |>
dplyr::select(!c(total_count))
dplyr::select(!c(.data$total_count))

settings <- dplyr::tibble(
result_id = unique(sr$result_id),
Expand Down
45 changes: 45 additions & 0 deletions R/tableAllConceptCounts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#' Create a visual table from a summariseAllConceptCounts() result.
#' @param result A summarised_result object.
#' @param type Type of formatting output table, either "gt" or "flextable".
#' @return A gt or flextable object with the summarised data.
#' @export
#'
#'
tableAllConceptCounts <- function(result,
type = "gt") {
# initial checks
omopgenerics::validateResultArgument(result)
omopgenerics::assertChoice(type, choicesTables())

# subset to result_type of interest
result <- result |>
visOmopResults::filterSettings(
.data$result_type == "summarise_all_concept_counts")

# check if it is empty
if (nrow(result) == 0) {
warnEmpty("summarise_all_concept_counts")
return(emptyTable(type))
}

estimate_names <- result |>
dplyr::distinct(.data$estimate_name) |>
dplyr::pull()
estimateName <- c()
if ("record_count" %in% estimate_names) {
estimateName <- c(estimateName, "N records" = "<record_count>")
}
if ("person_count" %in% estimate_names) {
estimateName <- c(estimateName, "N persons" = "<person_count>")
}

result |>
formatColumn(c("variable_name", "variable_level")) |>
visOmopResults::visOmopTable(
type = type,
estimateName = estimateName,
header = c("cdm_name"),
rename = c("Database name" = "cdm_name"),
groupColumn = c("omop_table", visOmopResults::strataColumns(result))
)
}
36 changes: 36 additions & 0 deletions R/tableMissingData.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' Create a visual table from a summariseMissingData() result.
#' @param result A summarised_result object.
#' @param type Type of formatting output table, either "gt" or "flextable".
#' @return A gt or flextable object with the summarised data.
#' @export
#'
#'
tableMissingData <- function(result,
type = "gt") {
# initial checks
omopgenerics::validateResultArgument(result)
omopgenerics::assertChoice(type, choicesTables())

# subset to result_type of interest
result <- result |>
visOmopResults::filterSettings(
.data$result_type == "summarise_missing_data")

# check if it is empty
if (nrow(result) == 0) {
warnEmpty("summarise_missing_data")
return(emptyTable(type))
}

result |>
formatColumn(c("variable_name", "variable_level")) |>
visOmopResults::visOmopTable(
type = type,
estimateName = c(
"N (%)" = "<na_percentage> (%)",
"N" = "<na_count>"),
header = c("cdm_name"),
rename = c("Database name" = "cdm_name"),
groupColumn = c("omop_table", visOmopResults::strataColumns(result))
)
}
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ reference:
- tableClinicalRecords
- summariseRecordCount
- plotRecordCount
- summariseMissingData
- tableMissingData
- subtitle: Observation Periods
desc: Summarise and plot the observation period table in the OMOP Common Data Model
- contents:
Expand All @@ -28,6 +30,8 @@ reference:
- contents:
- summariseConceptCounts
- plotConceptCounts
- summariseAllConceptCounts
- tableAllConceptCounts
- subtitle: Mock Database
desc: Create a mock database to test the OmopSketch package
- contents:
Expand Down
2 changes: 1 addition & 1 deletion man/OmopSketch-package.Rd

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

38 changes: 38 additions & 0 deletions man/summariseAllConceptCounts.Rd

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

38 changes: 38 additions & 0 deletions man/summariseMissingData.Rd

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

19 changes: 19 additions & 0 deletions man/tableAllConceptCounts.Rd

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

19 changes: 19 additions & 0 deletions man/tableMissingData.Rd

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

2 changes: 2 additions & 0 deletions tests/testthat/test-summariseMissingData.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ test_that("summariseMissingData() works", {
expect_no_error(x<-summariseMissingData(cdm, "visit_occurrence"))
expect_no_error(summariseMissingData(cdm, "condition_occurrence"))
expect_no_error(summariseMissingData(cdm, "drug_exposure"))

expect_no_error(summariseMissingData(cdm, "procedure_occurrence", year = TRUE))
expect_warning(summariseMissingData(cdm, "device_exposure"))
expect_no_error(z<-summariseMissingData(cdm, "measurement"))
expect_no_error(s<-summariseMissingData(cdm, "observation"))

expect_warning(summariseMissingData(cdm, "death"))


Expand Down

0 comments on commit e5d68a1

Please sign in to comment.