diff --git a/R/executeDqChecks.R b/R/executeDqChecks.R index b5a1ea67..d52a9dd9 100644 --- a/R/executeDqChecks.R +++ b/R/executeDqChecks.R @@ -35,6 +35,7 @@ #' @param writeToCsv Boolean to indicate if the check results will be written to a csv file. Default is FALSE #' @param csvFile (OPTIONAL) CSV file to write results #' @param checkLevels Choose which DQ check levels to execute. Default is all 3 (TABLE, FIELD, CONCEPT) +#' @param checkSeverity Choose which DQ check severity levels to execute. Default is all 3 (fatal, convention, characterization) #' @param checkNames (OPTIONAL) Choose which check names to execute. Names can be found in inst/csv/OMOP_CDM_v[cdmVersion]_Check_Descriptions.csv. Note that "cdmTable", "cdmField" and "measureValueCompleteness" are always executed. #' @param cohortDefinitionId The cohort definition id for the cohort you wish to run the DQD on. The package assumes a standard OHDSI cohort table #' with the fields cohort_definition_id and subject_id. @@ -77,6 +78,7 @@ executeDqChecks <- function(connectionDetails, csvFile = "", checkLevels = c("TABLE", "FIELD", "CONCEPT"), checkNames = c(), + checkSeverity = c("fatal", "convention", "characterization"), cohortDefinitionId = c(), cohortDatabaseSchema = resultsDatabaseSchema, cohortTableName = "cohort", @@ -110,7 +112,14 @@ executeDqChecks <- function(connectionDetails, You passed in ', paste(checkLevels, collapse = ", ")) } - stopifnot(is.null(checkNames) | is.character(checkNames), is.null(tablesToExclude) | is.character(tablesToExclude)) + if (!all(checkSeverity %in% c("fatal", "convention", "characterization"))) { + stop('checkSeverity argument must be a subset of c("fatal", "convention", "characterization"). + You passed in ', paste(checkSeverity, collapse = ", ")) + } + + stopifnot(is.null(checkNames) | is.character(checkNames), + is.character(checkSeverity), + is.null(tablesToExclude) | is.character(tablesToExclude)) stopifnot(is.character(cdmVersion)) # Warning if check names for determining NA is missing @@ -241,6 +250,7 @@ executeDqChecks <- function(connectionDetails, })] checkDescriptionsDf <- checkDescriptionsDf[checkDescriptionsDf$checkLevel %in% checkLevels & + checkDescriptionsDf$severity %in% checkSeverity & checkDescriptionsDf$evaluationFilter != "" & checkDescriptionsDf$sqlFile != "" & checkDescriptionsDf$checkName %in% checksToInclude, ] diff --git a/man/executeDqChecks.Rd b/man/executeDqChecks.Rd index 0b7b5f7f..5bd72f35 100644 --- a/man/executeDqChecks.Rd +++ b/man/executeDqChecks.Rd @@ -23,6 +23,7 @@ executeDqChecks( csvFile = "", checkLevels = c("TABLE", "FIELD", "CONCEPT"), checkNames = c(), + checkSeverity = c("fatal", "convention", "characterization"), cohortDefinitionId = c(), cohortDatabaseSchema = resultsDatabaseSchema, cohortTableName = "cohort", @@ -71,6 +72,8 @@ executeDqChecks( \item{checkNames}{(OPTIONAL) Choose which check names to execute. Names can be found in inst/csv/OMOP_CDM_v[cdmVersion]_Check_Descriptions.csv. Note that "cdmTable", "cdmField" and "measureValueCompleteness" are always executed.} +\item{checkSeverity}{Choose which DQ check severity levels to execute. Default is all 3 (fatal, convention, characterization)} + \item{cohortDefinitionId}{The cohort definition id for the cohort you wish to run the DQD on. The package assumes a standard OHDSI cohort table with the fields cohort_definition_id and subject_id.} diff --git a/tests/testthat/test-executeDqChecks.R b/tests/testthat/test-executeDqChecks.R index c02227d2..daecf76b 100644 --- a/tests/testthat/test-executeDqChecks.R +++ b/tests/testthat/test-executeDqChecks.R @@ -375,3 +375,24 @@ test_that("Execute checks on Synthea/Eunomia to test new variable executionTimeS ) expect_true(is.numeric(results$executionTimeSeconds)) }) + + +test_that("checkNames are filtered by checkSeverity", { + outputFolder <- tempfile("dqd_") + on.exit(unlink(outputFolder, recursive = TRUE)) + + results <- executeDqChecks( + connectionDetails = connectionDetailsEunomia, + cdmDatabaseSchema = cdmDatabaseSchemaEunomia, + resultsDatabaseSchema = resultsDatabaseSchemaEunomia, + cdmSourceName = "Eunomia", + checkSeverity = "fatal", + outputFolder = outputFolder, + writeToTable = F + ) + + expectedCheckNames <- c("cdmTable", "cdmField", "isRequired", "cdmDatatype", + "isPrimaryKey", "isForeignKey") + expect_true(all(results$CheckResults$checkName %in% expectedCheckNames)) +}) + diff --git a/vignettes/DataQualityDashboard.rmd b/vignettes/DataQualityDashboard.rmd index 6c45fa10..00654f40 100644 --- a/vignettes/DataQualityDashboard.rmd +++ b/vignettes/DataQualityDashboard.rmd @@ -101,6 +101,9 @@ checkLevels <- c("TABLE", "FIELD", "CONCEPT") # which DQ checks to run? ------------------------------------ checkNames <- c() # Names can be found in inst/csv/OMOP_CDM_v5.3_Check_Descriptions.csv +# which DQ severity levels to run? ---------------------------- +checkSeverity <- c("fatal", "convention", "characterization") + # want to EXCLUDE a pre-specified list of checks? run the following code: # # checksToExclude <- c() # Names of check types to exclude from your DQD run @@ -129,6 +132,7 @@ DataQualityDashboard::executeDqChecks(connectionDetails = connectionDetails, writeToCsv = writeToCsv, csvFile = csvFile, checkLevels = checkLevels, + checkSeverity = checkSeverity, tablesToExclude = tablesToExclude, checkNames = checkNames)