Skip to content

Commit

Permalink
simplify columns
Browse files Browse the repository at this point in the history
ref #4
  • Loading branch information
wibeasley committed Dec 23, 2021
1 parent 6f1713f commit 9ad17eb
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 75 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Imports:
readr (>= 2.0),
rlang (>= 0.4.12),
tibble (>= 1.4.0),
tidyselect,
yaml
Suggests:
covr,
Expand Down
18 changes: 12 additions & 6 deletions R/execute-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ execute_checks <- function (ds, ds_smell) {

}

#' @importFrom rlang .data
execute_smells <- function (ds, ds_smell) {
checkmate::assert_data_frame(ds)
checkmate::assert_data_frame(ds_smell)
Expand All @@ -44,8 +45,8 @@ execute_smells <- function (ds, ds_smell) {
ds_smell |>
dplyr::mutate(
# f = purrr::invoke_map(function(x) eval(parse(text=x)), .data$equation),
smell_value = NA_real_,
smell_pass = NA
value = NA_real_,
pass = NA
)

# for( i in 1:14 ) {
Expand All @@ -62,16 +63,21 @@ execute_smells <- function (ds, ds_smell) {
})

tryCatch({
ds_smell_result$smell_value[i] <- f(ds)
ds_smell_result$value[i] <- f(ds)
}, error = function(e) {
stop("Problem executing the equation for smell `", ds_smell$check_name[i], "`.\n", e)
})

# ds_smell_result$smell_value[i] <- f[[i]](ds)
ds_smell_result$smell_pass[i] <- dplyr::between(ds_smell_result$smell_value[i], left = ds_smell_result$bound_lower[i], right = ds_smell_result$bound_upper[i])
ds_smell_result$pass[i] <- dplyr::between(ds_smell_result$value[i], left = ds_smell_result$bound_lower[i], right = ds_smell_result$bound_upper[i])
}

message(nrow(ds_smell_result), " smells have been sniffed ", sum(!ds_smell_result$smell_pass), " violation(s) were found.\n")
message(nrow(ds_smell_result), " smells have been sniffed ", sum(!ds_smell_result$pass), " violation(s) were found.\n")

ds_smell_result
ds_smell_result |>
dplyr::select(
.data$check_name,
.data$pass,
tidyselect::everything()
)
}
16 changes: 8 additions & 8 deletions R/load-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ load_smells <- function (checks) {
ds_smell <-
checks$smells |>
purrr::map_df(tibble::as_tibble) |>
dplyr::filter(.data$smell_active) |>
dplyr::filter(.data$active) |>
dplyr::mutate(
debug = dplyr::coalesce(.data$debug, FALSE),
)

ds_smell_inactive <-
checks$smells |>
purrr::map_df(tibble::as_tibble) |>
dplyr::filter(!.data$smell_active)
dplyr::filter(!.data$active)

testit::assert("The count of distinct rule columns (in the yaml checks file) should be 10.", ncol(ds_smell) == 10L)
testit::assert( # dput(colnames(ds_smell))
"The smell columns (in the yaml checks file) should be correct.",
colnames(ds_smell) == c("check_name", "description", "priority", "smell_active", "debug", "bound_lower", "bound_upper", "bounds_template", "value_template", "equation")
colnames(ds_smell) == c("check_name", "description", "priority", "active", "debug", "bound_lower", "bound_upper", "bounds_template", "value_template", "equation")
)

ds_smell <-
Expand All @@ -56,7 +56,7 @@ load_smells <- function (checks) {
checkmate::assert_character(ds_smell$check_name , any.missing=F , pattern="^.{4,99}$" , unique=T)
checkmate::assert_character(ds_smell$description , any.missing=F , pattern="^.{4,255}$" , unique=T)
checkmate::assert_integer( ds_smell$priority , any.missing=F , lower=1, upper=5 )
checkmate::assert_logical( ds_smell$smell_active , any.missing=F )
checkmate::assert_logical( ds_smell$active , any.missing=F )
checkmate::assert_logical( ds_smell$debug , any.missing=F )
checkmate::assert_numeric( ds_smell$bound_lower , any.missing=F )
checkmate::assert_numeric( ds_smell$bound_upper , any.missing=F )
Expand All @@ -78,20 +78,20 @@ load_rules <- function (checks) {
checks$rules |>
purrr::map_df(tibble::as_tibble) |>
# dplyr::rename(check_name = name) |>
dplyr::filter(.data$test_active) |>
dplyr::filter(.data$active) |>
dplyr::mutate(
debug = dplyr::coalesce(.data$debug, FALSE),
)

ds_rule_inactive <-
checks$rules |>
purrr::map_df(tibble::as_tibble) |>
dplyr::filter(!.data$test_active)
dplyr::filter(!.data$active)

#testit::assert("The count of distinct rule columns (in the yaml checks file) should be 7.", ncol(ds_rule) == 10L)
testit::assert( # dput(colnames(ds_rule))
"The rule columns (in the yaml checks file) should be correct.",
colnames(ds_rule) == c("check_name", "error_message", "priority", "test_active", "debug", "instrument", "passing_test")
colnames(ds_rule) == c("check_name", "error_message", "priority", "active", "debug", "instrument", "passing_test")
)
# table(ds_rule$check_name)
# table(ds_rule$error_message)
Expand All @@ -101,7 +101,7 @@ load_rules <- function (checks) {
checkmate::assert_character(ds_rule$check_name , any.missing=F , pattern="^.{4,99}$" , unique=T)
checkmate::assert_character(ds_rule$error_message , any.missing=F , pattern="^.{4,255}$" , unique=T)
checkmate::assert_integer( ds_rule$priority , any.missing=F , lower=1, upper=5 )
checkmate::assert_logical( ds_rule$test_active , any.missing=F )
checkmate::assert_logical( ds_rule$active , any.missing=F )
checkmate::assert_logical( ds_rule$debug , any.missing=F )
checkmate::assert_character(ds_rule$instrument , any.missing=F , pattern="^.{2,255}$" )
checkmate::assert_character(ds_rule$passing_test , any.missing=F , pattern="^.{5,}$" , unique=T)
Expand Down
54 changes: 27 additions & 27 deletions inst/checks/checks-biochemical.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ default:
- check_name : proportion_female_participants
description : Proportion female participants is half the participants till study conclusion
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : .5
bound_upper : .5
Expand All @@ -31,7 +31,7 @@ default:
- check_name : proportion_male_participants
description : Proportion male participants is half the participants till study conclusion
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : .5
bound_upper : .5
Expand All @@ -44,7 +44,7 @@ default:
- check_name : mean_age
description : Mean age of participants is between 18 years to 20 years
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : 20
bound_upper : 80
Expand All @@ -57,7 +57,7 @@ default:
- check_name : mean_serum_prealbumin_level_at_baseline
description : Mean serum pre-albumin levels at baseline are between 31mg/dl and 39mg/dl
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : 32
bound_upper : 39
Expand All @@ -70,7 +70,7 @@ default:
- check_name : mean_serum_creatinine_level_at_baseline
description : Mean serum creatinine levels at baseline are between 3mg/dl and 15mg/dl
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : 3
bound_upper : 15
Expand All @@ -83,7 +83,7 @@ default:
- check_name : average_bmi_at_baseline
description : Average BMI is between 18 and 24
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : 18
bound_upper : 24
Expand All @@ -96,7 +96,7 @@ default:
- check_name : mean_serum_cholesterol_levels_at_baseline
description : Average Cholesterol levels range is between 100mg/dl-140mg/dl at baseline level
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : 100
bound_upper : 140
Expand All @@ -109,7 +109,7 @@ default:
- check_name : dialysis_adequacy
description : Normal range for Kt/V values are between 1.2 and 5
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : 1.2
bound_upper : 5
Expand All @@ -122,7 +122,7 @@ default:
- check_name : average_serum_ferritin_levels_at_baseline
description : Mean serum ferritin levels are in the recommended range of > 500ng/dl-1200ng/dl
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : 501
bound_upper : 1200
Expand All @@ -135,7 +135,7 @@ default:
- check_name : nutritional_counseling
description : Most patients agreed to receiving nutritional counseling
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : .85
bound_upper : .99
Expand All @@ -148,7 +148,7 @@ default:
- check_name : definitive_diagnosis
description : A 100 percent of study participants were diagnosed with malnutrition associated with Chronic Renal Disease
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : 1.0
bound_upper : 1.0
Expand All @@ -161,7 +161,7 @@ default:
- check_name : normalized_protein_catabolic_rate
description : Average Normalized Protein Catabolic Rate is < 1.2g/kg/day
priority : 1
smell_active : TRUE
active : TRUE
debug : FALSE
bound_lower : 0
bound_upper : 0.12
Expand All @@ -175,7 +175,7 @@ default:
- check_name : baseline_prealbumin_levels
error_message : "Serum pre-albumin level of all enrolled patients do not meet the study criterion" # Tranferrin level <100 indicates severe protein-energy malnutrition
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : baseline_data # At baseline the study is enrolling malnurished patients or patients with chronic renal failure
passing_test : |
Expand All @@ -189,7 +189,7 @@ default:
- check_name : missing_serum_marker_levels
error_message : "Relevant nutritional serum markers are missing" # All these parameters together, should not be missing
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : baseline_data
passing_test : |
Expand All @@ -203,7 +203,7 @@ default:
- check_name : serum_prealbumin_levels_1
error_message : "Baseline prealbumin levels are not missing however levels were not carefully monitored in the subsequent visit"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : baseline_data, visit_lab_date
passing_test : |
Expand All @@ -218,7 +218,7 @@ default:
- check_name : serum_prealbumin_levels_2
error_message : "Baseline prealbumin levels and pre-albumin levels during the 1st visit are not missing however levels in the next reading are missing"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : baseline_data, visit_lab_date, visit_blood_workup
passing_test : |
Expand All @@ -233,7 +233,7 @@ default:
- check_name : serum_prealbumin_levels_completion_data
error_message : "Baseline prealbumin levels are not missing however readings are not carefully monitored at completion"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : baseline_data, visit_lab_date, visit_blood_workup, completion_date
passing_test : |
Expand All @@ -249,7 +249,7 @@ default:
- check_name : serum_prealbumin_levels_expectations
error_message : "serum prealbumin levels are not missing however subsequent readings did not come as expected"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : baseline_data, visit_lab_date, visit_blood_workup, completion_date
passing_test : |
Expand All @@ -265,7 +265,7 @@ default:
- check_name : pre_albumin_levels
error_message : "pre_albumin levels are not improving"
priority : 1
test_active : FALSE
active : FALSE
debug : FALSE
instrument : visit_lab_date
passing_test : |
Expand All @@ -281,7 +281,7 @@ default:
- check_name : baseline_first_visit_lab_parameters
error_message : "Serum prealbumin levels are low and protein intake at baseline is less than optimal"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : baseline_data, visit_lab_data
passing_test : |
Expand All @@ -297,7 +297,7 @@ default:
- check_name : daily_first_visit_lab_and_workup_parameters
error_message : "In-addition to baseline & visit lab protein parameters, blood work-up npcr levels are also low"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : baseline_data, patient_morale_questionnaire
passing_test : |
Expand All @@ -314,7 +314,7 @@ default:
- check_name : daily_protein_intake
error_message : "npcr levels in study have not improved as intended"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : baseline_data, patient_morale_questionnaire
passing_test : |
Expand All @@ -332,7 +332,7 @@ default:
- check_name : hospitalization_reason
error_message : "Patient was hospitalized but reason and the date of hospitalization is missing"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : completion_project_questionnaire
passing_test : |
Expand All @@ -346,7 +346,7 @@ default:
- check_name : optimal_daily_protein_intake
error_message : "Daily protein intake is optimal but one of the nutritional marker is not within the normal range"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : completion_project_questionnaire, completion_data
passing_test : |
Expand All @@ -360,7 +360,7 @@ default:
- check_name : recommended_npcr_range
error_message : "NPCR values are not within the recommended range at completion"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : completion_data # At baseline the study is enrolling malnurished patients or patients with chronic renal failure
passing_test : |
Expand All @@ -370,7 +370,7 @@ default:
- check_name : npcr
error_message : "NPCR at completion is missing"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : completion_data
passing_test : |
Expand All @@ -385,7 +385,7 @@ default:
- check_name : npcr_comparison # Showing improvement in nutritional status
error_message : "NPCR at completion is not greater than npcr at baseline"
priority : 1
test_active : TRUE
active : TRUE
debug : FALSE
instrument : completion_data
passing_test : |
Expand Down
Loading

0 comments on commit 9ad17eb

Please sign in to comment.