Skip to content

Commit

Permalink
basic html report w/ smells
Browse files Browse the repository at this point in the history
ref #5
  • Loading branch information
wibeasley committed Dec 29, 2021
1 parent b7ee90a commit 8a338c7
Show file tree
Hide file tree
Showing 5 changed files with 811 additions and 89 deletions.
2 changes: 2 additions & 0 deletions R/execute-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#'
#' execute_checks(ds_pt_event, checks)
#'
#' saveRDS(execute_checks(ds_pt_event, checks), "inst/derived/biochemical.rds")
#'
#' @export
execute_checks <- function (ds, checks) {
checkmate::assert_data_frame(ds)
Expand Down
138 changes: 49 additions & 89 deletions for-developers/sandbox/report-1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,108 +59,68 @@ requireNamespace("DT")

<!-- Load the datasets. -->
```{r load-data, echo=echo_chunks, results='show', message=FALSE}
checks <- readRDS(system.file("derived/biochemical.rds", package = "trawler"))
```

<!-- Tweak the datasets. -->
```{r tweak-data, echo=echo_chunks, results='show', message=TRUE}
```

```{r groom-rules, echo=echo_chunks, results='show', message=TRUE}
```

```{r groom-smells, echo=echo_chunks, results='show', message=TRUE}
```

Set Up {.tabset .tabset-fade}
=============================

Instructions
-----------------------------

1. Work through each line in the table to discover & correct entry mistakes in the database. Be aware that a single mistake may manifest in multiple rows; fixing one value may clear several rows.
1. Click the `record id` value in a row to be taken to the participant's Event Grid in REDCap (*i.e.*, the 'stop light page').
1. Double-check that your manual corrections in REDCap are reflected in `r checks$path_output_rule`. Be careful not to move this file to somewhere unsafe.
1. To help discover the dataflow and problematic location, use the
* project's [codebook](`r checks$redcap_codebook`) in REDCap,
* [validator-1-arch](`r checks$github_link_arch`) file, and
* [validator-1](`r checks$github_link_report`) report.
1. If you create a new rule or smell check, make sure the error message won't reveal any PHI.

Execute Rules
-----------------------------
```{r execute-rules, echo=echo_chunks, message=TRUE, results='asis'}
```

Execute Smells
-----------------------------
```{r execute-smells, echo=echo_chunks, message=TRUE, results='asis'}
```

Inactive Rules
-----------------------------

`r nrow(ds_rule_inactive)` rules are defined, but disabled for this report:

```{r echo=echo_chunks, results='asis'}
# glue::collapse(paste0("1. ", ds_rule_inactive$check_name), sep="; \n", last=", and \n")
ds_rule_inactive |>
glue::glue_data("1. {check_name};")
```

Inactive Smells
-----------------------------

`r nrow(ds_smell_inactive)` smells are defined, but disabled for this report:

```{r echo=echo_chunks, results='asis'}
ds_smell_inactive |>
glue::glue_data("1. {check_name};")
# if( nrow(ds_smell_inactive) == 0L ) {
# cat("* *no smells are disabled*.")
# } else {
# glue::collapse(paste0("1. ", ds_smell_inactive$smell_name), sep="; \n", last=", and \n")
# }
```

Rules {.tabset .tabset-fade}
=============================

A *rule* is very exact. Each record is examined, and determined if it passes each specific rule.

Rule Detail
-----------------------------
```{r table-rule-detail, echo=echo_chunks, message=TRUE}
```

Rule Summary
-----------------------------
```{r table-rule-summary, echo=echo_chunks, message=TRUE}
```

Smells {.tabset .tabset-fade}
=============================

A *smell* test won't validate a given record (like the rules above), but it will make sure the dataset overall smells correct.
A *smell* test won't validate a specific record (like the rules below), but it will make sure the dataset overall smells correct.

Smell Summary
-----------------------------
```{r table-smell-summary, echo=echo_chunks, message=TRUE}
```

Termination {.tabset .tabset-fade}
=============================

### Save To Disk

```{r verify-values, echo=echo_chunks, message=TRUE}
```

```{r specify-columns-to-upload, echo=echo_chunks, message=TRUE}
```
palette_summary <- list(warm = "#fde0ef", hot = "#f1b6da", header = "#555") #http://colrd.com/palette/18841/
ds_smell_result_pretty <-
checks$smells |>
dplyr::transmute(
check_name = gsub("_", " ", check_name),
priority, # = wrap_violation(n, priority),
description,
boundaries = sprintf(.data$bounds_template, .data$bound_lower, .data$bound_upper),
value = sprintf(.data$value_template , .data$value),
pass
# n
) |>
dplyr::arrange(priority, check_name)
ds_smell_result_pretty |>
knitr::kable(
col.names = c("Smell Name", "Priority", "Proportion of...", "Legal Boundaries", "Value", "Pass"),
align = "lrllrl",
escape = FALSE,
format = "html"
) |>
kableExtra::kable_styling(
bootstrap_options = c("hover", "condensed", "responsive"), #"striped",
full_width = FALSE,
position = "left"
) |>
kableExtra::row_spec(
row = 0,
bold = T,
color = "white",
background = palette_summary$header
) |>
kableExtra::row_spec(
row = seq_len(nrow(ds_smell_result_pretty)),
color = "#555"
) |>
kableExtra::row_spec(
row = which(!ds_smell_result_pretty$pass & ds_smell_result_pretty$priority == 1L),
bold = T,
background = palette_summary$hot
) |>
kableExtra::row_spec(
row = which(!ds_smell_result_pretty$pass & ds_smell_result_pretty$priority >= 2L),
bold = T,
background = palette_summary$warm
)
```{r save-to-disk, echo=echo_chunks, message=TRUE}
```


<!-- The footer that's common to all reports. -->
<!-- ```{r, child = "analysis/common/footer-1.Rmd"}``` -->
608 changes: 608 additions & 0 deletions for-developers/sandbox/report-1.html

Large diffs are not rendered by default.

152 changes: 152 additions & 0 deletions for-developers/sandbox/report-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
title: REDCapR Validator Example 1 # Change this value for new validators.
date: "Date: 2021-12-29 17:04:01"
output:
html_document:
keep_md: yes
toc: yes
toc_float: true
number_sections: true
# css: ../analysis/common/styles-1.css
---


<!-- Set the working directory to the repository's base directory; this assumes the report is nested inside of three directories.-->


<!-- Set the report-wide options, and point to the external code file. -->


<!-- Load 'sourced' R files. Suppress the output when loading packages. -->


<!-- Load any global functions and variables declared in the R file. Suppress the output. -->


<!-- Declare any global functions specific to a Rmd output. Suppress the output. -->


<!-- Load the datasets. -->


<!-- Tweak the datasets. -->



Smells {.tabset .tabset-fade}
=============================

A *smell* test won't validate a specific record (like the rules below), but it will make sure the dataset overall smells correct.

Smell Summary
-----------------------------
<table class="table table-hover table-condensed table-responsive" style="width: auto !important; ">
<thead>
<tr>
<th style="text-align:left;font-weight: bold;color: white !important;background-color: #555 !important;"> Smell Name </th>
<th style="text-align:right;font-weight: bold;color: white !important;background-color: #555 !important;"> Priority </th>
<th style="text-align:left;font-weight: bold;color: white !important;background-color: #555 !important;"> Proportion of... </th>
<th style="text-align:left;font-weight: bold;color: white !important;background-color: #555 !important;"> Legal Boundaries </th>
<th style="text-align:right;font-weight: bold;color: white !important;background-color: #555 !important;"> Value </th>
<th style="text-align:left;font-weight: bold;color: white !important;background-color: #555 !important;"> Pass </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> average bmi at baseline </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> Average BMI is between 18 and 24 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> [18.00, 24.00] </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 24.8500 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> FALSE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;"> average serum ferritin levels at baseline </td>
<td style="text-align:right;color: #555 !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;"> Mean serum ferritin levels are in the recommended range of &gt; 500ng/dl-1200ng/dl </td>
<td style="text-align:left;color: #555 !important;"> [501, 1200] </td>
<td style="text-align:right;color: #555 !important;"> 589.12 </td>
<td style="text-align:left;color: #555 !important;"> TRUE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;"> definitive diagnosis </td>
<td style="text-align:right;color: #555 !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;"> A 100 percent of study participants were diagnosed with malnutrition associated with Chronic Renal Disease </td>
<td style="text-align:left;color: #555 !important;"> [1.00, 1.00] </td>
<td style="text-align:right;color: #555 !important;"> 1.0000 </td>
<td style="text-align:left;color: #555 !important;"> TRUE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;"> dialysis adequacy </td>
<td style="text-align:right;color: #555 !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;"> Normal range for Kt/V values are between 1.2 and 5 </td>
<td style="text-align:left;color: #555 !important;"> [1.20, 5.00] </td>
<td style="text-align:right;color: #555 !important;"> 1.9167 </td>
<td style="text-align:left;color: #555 !important;"> TRUE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;"> mean age </td>
<td style="text-align:right;color: #555 !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;"> Mean age of participants is between 18 years to 20 years </td>
<td style="text-align:left;color: #555 !important;"> [20.00, 80.00] </td>
<td style="text-align:right;color: #555 !important;"> 44.3889 </td>
<td style="text-align:left;color: #555 !important;"> TRUE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;"> mean serum cholesterol levels at baseline </td>
<td style="text-align:right;color: #555 !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;"> Average Cholesterol levels range is between 100mg/dl-140mg/dl at baseline level </td>
<td style="text-align:left;color: #555 !important;"> [100.00, 140.00] </td>
<td style="text-align:right;color: #555 !important;"> 134.1176 </td>
<td style="text-align:left;color: #555 !important;"> TRUE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> mean serum creatinine level at baseline </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> Mean serum creatinine levels at baseline are between 3mg/dl and 15mg/dl </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> [3.00, 15.00] </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 23.1687 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> FALSE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> mean serum prealbumin level at baseline </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> Mean serum pre-albumin levels at baseline are between 31mg/dl and 39mg/dl </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> [32.00, 39.00] </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 23.6667 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> FALSE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> normalized protein catabolic rate </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> Average Normalized Protein Catabolic Rate is &lt; 1.2g/kg/day </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> [0.00, 0.12] </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 0.9313 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> FALSE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;"> nutritional counseling </td>
<td style="text-align:right;color: #555 !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;"> Most patients agreed to receiving nutritional counseling </td>
<td style="text-align:left;color: #555 !important;"> [0.85, 0.99] </td>
<td style="text-align:right;color: #555 !important;"> 0.8889 </td>
<td style="text-align:left;color: #555 !important;"> TRUE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> proportion female participants </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> Proportion female participants is half the participants till study conclusion </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> [0.50, 0.50] </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 0.4444 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> FALSE </td>
</tr>
<tr>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> proportion male participants </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 1 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> Proportion male participants is half the participants till study conclusion </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> [0.50, 0.50] </td>
<td style="text-align:right;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> 0.5556 </td>
<td style="text-align:left;color: #555 !important;font-weight: bold;background-color: #f1b6da !important;"> FALSE </td>
</tr>
</tbody>
</table>
Binary file added inst/derived/biochemical.rds
Binary file not shown.

0 comments on commit 8a338c7

Please sign in to comment.