Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom check in seprate package. #401

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions R/executeDqChecks.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#' @param tableCheckThresholdLoc The location of the threshold file for evaluating the table checks. If not specified the default thresholds will be applied.
#' @param fieldCheckThresholdLoc The location of the threshold file for evaluating the field checks. If not specified the default thresholds will be applied.
#' @param conceptCheckThresholdLoc The location of the threshold file for evaluating the concept checks. If not specified the default thresholds will be applied.
#' @param systemFileNamespace The name of the package where the check are stored. If not specified the default `DataQualityDashboard` namespace will be applied.
#'
#' @return If sqlOnly = FALSE, a list object of results
#'
Expand Down Expand Up @@ -77,7 +78,8 @@ executeDqChecks <- function(connectionDetails,
cdmVersion = "5.3",
tableCheckThresholdLoc = "default",
fieldCheckThresholdLoc = "default",
conceptCheckThresholdLoc = "default") {
conceptCheckThresholdLoc = "default",
systemFileNamespace = "DataQualityDashboard") {
# Check input -------------------------------------------------------------------------------------------------------------------
if (!("connectionDetails" %in% class(connectionDetails))){
stop("connectionDetails must be an object of class 'connectionDetails'.")
Expand Down Expand Up @@ -165,24 +167,25 @@ executeDqChecks <- function(connectionDetails,
file = system.file(
"csv",
sprintf("OMOP_CDMv%s_Check_Descriptions.csv", cdmVersion),
package = "DataQualityDashboard"
package = systemFileNamespace
),
stringsAsFactors = FALSE
)

tableChecks <- .readThresholdFile(
checkThresholdLoc = tableCheckThresholdLoc,
defaultLoc = sprintf("OMOP_CDMv%s_Table_Level.csv", cdmVersion)
defaultLoc = sprintf("OMOP_CDMv%s_Table_Level.csv", cdmVersion),
systemFileNamespace
)

fieldChecks <- .readThresholdFile(
checkThresholdLoc = fieldCheckThresholdLoc,
defaultLoc = sprintf("OMOP_CDMv%s_Field_Level.csv", cdmVersion)
defaultLoc = sprintf("OMOP_CDMv%s_Field_Level.csv", cdmVersion, systemFileNamespace)
)

conceptChecks <- .readThresholdFile(
checkThresholdLoc = conceptCheckThresholdLoc,
defaultLoc = sprintf("OMOP_CDMv%s_Concept_Level.csv", cdmVersion)
defaultLoc = sprintf("OMOP_CDMv%s_Concept_Level.csv", cdmVersion, systemFileNamespace)
)

# ensure we use only checks that are intended to be run -----------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions R/listChecks.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
#' @param tableCheckThresholdLoc The location of the threshold file for evaluating the table checks. If not specified the default thresholds will be applied.
#' @param fieldCheckThresholdLoc The location of the threshold file for evaluating the field checks. If not specified the default thresholds will be applied.
#' @param conceptCheckThresholdLoc The location of the threshold file for evaluating the concept checks. If not specified the default thresholds will be applied.
#'
#' @param systemFileNamespace The name of the package where the check are stored. If not specified the default `DataQualityDashboard` namespace will be applied.
#'
#' @export
listDqChecks <- function(cdmVersion = "5.3", tableCheckThresholdLoc = "default", fieldCheckThresholdLoc = "default",conceptCheckThresholdLoc = "default") {
listDqChecks <- function(cdmVersion = "5.3", tableCheckThresholdLoc = "default", fieldCheckThresholdLoc = "default",conceptCheckThresholdLoc = "default", systemFileNamespace = "DataQualityDashboard") {
dqChecks <- {}
dqChecks$checkDescriptions <-
read.csv(system.file(
"csv",
sprintf("OMOP_CDMv%s_Check_Descriptions.csv", cdmVersion),
package = "DataQualityDashboard"
package = systemFileNamespace
),
stringsAsFactors = FALSE)

Expand All @@ -45,7 +45,7 @@ listDqChecks <- function(cdmVersion = "5.3", tableCheckThresholdLoc = "default",
system.file(
"csv",
sprintf("OMOP_CDMv%s_Table_Level.csv", cdmVersion),
package = "DataQualityDashboard"
package = systemFileNamespace
),
stringsAsFactors = FALSE,
na.strings = c(" ", "")
Expand All @@ -64,7 +64,7 @@ listDqChecks <- function(cdmVersion = "5.3", tableCheckThresholdLoc = "default",
system.file(
"csv",
sprintf("OMOP_CDMv%s_Field_Level.csv", cdmVersion),
package = "DataQualityDashboard"
package = systemFileNamespace
),
stringsAsFactors = FALSE,
na.strings = c(" ", "")
Expand All @@ -83,7 +83,7 @@ listDqChecks <- function(cdmVersion = "5.3", tableCheckThresholdLoc = "default",
system.file(
"csv",
sprintf("OMOP_CDMv%s_Concept_Level.csv", cdmVersion),
package = "DataQualityDashboard"
package = systemFileNamespace
),
stringsAsFactors = FALSE,
na.strings = c(" ", "")
Expand Down
12 changes: 7 additions & 5 deletions R/reEvaluateThresholds.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#' @param fieldCheckThresholdLoc The location of the threshold file for evaluating the field checks. If not specified the default thresholds will be applied.
#' @param conceptCheckThresholdLoc The location of the threshold file for evaluating the concept checks. If not specified the default thresholds will be applied.
#' @param cdmVersion The CDM version to target for the data source. By default, 5.3 is used.
#'
#' @param systemFileNamespace The name of the package where the check are stored. If not specified the default `DataQualityDashboard` namespace will be applied.
#'
#' @export

reEvaluateThresholds <- function(jsonFilePath,
Expand All @@ -36,7 +37,8 @@ reEvaluateThresholds <- function(jsonFilePath,
tableCheckThresholdLoc = "default",
fieldCheckThresholdLoc = "default",
conceptCheckThresholdLoc = "default",
cdmVersion = '5.3') {
cdmVersion = '5.3',
systemFileNamespace = "DataQualityDashboard") {
# Read in results to data frame --------------------------------------
dqdResults <- jsonlite::read_json(path = jsonFilePath)

Expand All @@ -47,10 +49,10 @@ reEvaluateThresholds <- function(jsonFilePath,
df <- do.call(plyr::rbind.fill, df)

# Read in new thresholds ----------------------------------------------
tableChecks <- .readThresholdFile(tableCheckThresholdLoc, defaultLoc = sprintf("OMOP_CDMv%s_Table_Level.csv", cdmVersion))
fieldChecks <- .readThresholdFile(fieldCheckThresholdLoc, defaultLoc = sprintf("OMOP_CDMv%s_Field_Level.csv", cdmVersion))
tableChecks <- .readThresholdFile(tableCheckThresholdLoc, defaultLoc = sprintf("OMOP_CDMv%s_Table_Level.csv", cdmVersion), systemFileNamespace)
fieldChecks <- .readThresholdFile(fieldCheckThresholdLoc, defaultLoc = sprintf("OMOP_CDMv%s_Field_Level.csv", cdmVersion), systemFileNamespace)
fieldChecks$cdmFieldName <- toupper(fieldChecks$cdmFieldName) # Uppercase in results, lowercase in threshold files
conceptChecks <- .readThresholdFile(conceptCheckThresholdLoc, defaultLoc = sprintf("OMOP_CDMv%s_Concept_Level.csv", cdmVersion))
conceptChecks <- .readThresholdFile(conceptCheckThresholdLoc, defaultLoc = sprintf("OMOP_CDMv%s_Concept_Level.csv", cdmVersion), systemFileNamespace)
conceptChecks$cdmFieldName <- toupper(conceptChecks$cdmFieldName)

newCheckResults <- .evaluateThresholds(df, tableChecks, fieldChecks, conceptChecks)
Expand Down
4 changes: 2 additions & 2 deletions R/readThresholdFile.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.readThresholdFile <- function(checkThresholdLoc, defaultLoc) {
.readThresholdFile <- function(checkThresholdLoc, defaultLoc, systemFileNamespace = "DataQualityDashboard") {
if (checkThresholdLoc == "default") {
result <- read.csv(
file = system.file(
"csv",
defaultLoc,
package = "DataQualityDashboard"
package = systemFileNamespace
),
stringsAsFactors = FALSE,
na.strings = c(" ","")
Expand Down
4 changes: 3 additions & 1 deletion R/runCheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
setNames(check[c], c)
})

packageName <- if(!is.null(checkDescription$packageName)) checkDescription$packageName else "DataQualityDashboard"

params <- c(list(dbms = connectionDetails$dbms),
list(sqlFilename = checkDescription$sqlFile),
list(packageName = "DataQualityDashboard"),
list(packageName = packageName),
list(warnOnMissingParameters = FALSE),
list(cdmDatabaseSchema = cdmDatabaseSchema),
list(cohortDatabaseSchema = cohortDatabaseSchema),
Expand Down
14 changes: 8 additions & 6 deletions extras/execution.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@
#' @param tableCheckThresholdLoc The location of the threshold file for evaluating the table checks. If not specified the default thresholds will be applied.
#' @param fieldCheckThresholdLoc The location of the threshold file for evaluating the field checks. If not specified the default thresholds will be applied.
#' @param conceptCheckThresholdLoc The location of the threshold file for evaluating the concept checks. If not specified the default thresholds will be applied.
#'
#' @param systemFileNamespace The name of the package where the check are stored. If not specified the default `DataQualityDashboard` namespace will be applied.
#'
#' @return If sqlOnly = FALSE, a list object of results
#'
#' @importFrom magrittr %>%
Expand Down Expand Up @@ -192,7 +193,8 @@ executeDqChecks <- function(connectionDetails,
cdmVersion = "5.3.1",
tableCheckThresholdLoc = "default",
fieldCheckThresholdLoc = "default",
conceptCheckThresholdLoc = "default") {
conceptCheckThresholdLoc = "default",
systemFileNamespace = "DataQualityDashboard") {
# Check input -------------------------------------------------------------------------------------------------------------------
if (!("connectionDetails" %in% class(connectionDetails))){
stop("connectionDetails must be an object of class 'connectionDetails'.")
Expand Down Expand Up @@ -277,25 +279,25 @@ executeDqChecks <- function(connectionDetails,
startTime <- Sys.time()

checkDescriptionsDf <- read.csv(system.file("csv", sprintf("OMOP_CDMv%s_Check_Descriptions.csv", cdmVersion),
package = "DataQualityDashboard"),
package = systemFileNamespace),
stringsAsFactors = FALSE)


if (tableCheckThresholdLoc == "default"){
tableChecks <- read.csv(system.file("csv", sprintf("OMOP_CDMv%s_Table_Level.csv", cdmVersion),
package = "DataQualityDashboard"),
package = systemFileNamespace),
stringsAsFactors = FALSE, na.strings = c(" ",""))} else {tableChecks <- read.csv(tableCheckThresholdLoc,
stringsAsFactors = FALSE, na.strings = c(" ",""))}

if (fieldCheckThresholdLoc == "default"){
fieldChecks <- read.csv(system.file("csv", sprintf("OMOP_CDMv%s_Field_Level.csv", cdmVersion),
package = "DataQualityDashboard"),
package = systemFileNamespace),
stringsAsFactors = FALSE, na.strings = c(" ",""))} else {fieldChecks <- read.csv(fieldCheckThresholdLoc,
stringsAsFactors = FALSE, na.strings = c(" ",""))}

if (conceptCheckThresholdLoc == "default"){
conceptChecks <- read.csv(system.file("csv", sprintf("OMOP_CDMv%s_Concept_Level.csv", cdmVersion),
package = "DataQualityDashboard"),
package = systemFileNamespace),
stringsAsFactors = FALSE, na.strings = c(" ",""))} else {conceptChecks <- read.csv(conceptCheckThresholdLoc,
stringsAsFactors = FALSE, na.strings = c(" ",""))}

Expand Down
Loading