Skip to content

Commit

Permalink
added cppac reports
Browse files Browse the repository at this point in the history
  • Loading branch information
pydemull committed Jun 9, 2022
1 parent 4f8657e commit f06d40b
Show file tree
Hide file tree
Showing 7 changed files with 555 additions and 25 deletions.
182 changes: 177 additions & 5 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -4212,6 +4212,8 @@ app_server <- function(input, output, session) {
shinyjs::hide("get_cppac_summary_fr")
shinyjs::hide("get_dppac_summary_en")
shinyjs::hide("get_dppac_summary_fr")
shinyjs::hide("report_en_cppac")
shinyjs::hide("report_fr_cppac")

if(nrow(results_list()$df_with_computed_metrics) >=1) {
shinyjs::show("ExpDataset")
Expand All @@ -4234,6 +4236,19 @@ app_server <- function(input, output, session) {
}

})

observe({
if(nrow(tab_cppac_summary_en()) >= 1) {
shinyjs::show("report_en_cppac")
}
})

observe({
if(nrow(tab_cppac_summary_fr()) >= 1) {
shinyjs::show("report_fr_cppac")
}

})


###################
Expand Down Expand Up @@ -4291,11 +4306,11 @@ app_server <- function(input, output, session) {
}
)

###################
# Generating report ----
###################
####################
# Generating reports ----
####################

# Generating report EN
# Generating general report EN
output$report_en <- downloadHandler(


Expand Down Expand Up @@ -4365,7 +4380,7 @@ app_server <- function(input, output, session) {
}
)

# Generating report FR
# Generating general report FR
output$report_fr <- downloadHandler(


Expand Down Expand Up @@ -4434,6 +4449,163 @@ app_server <- function(input, output, session) {

}
)

# Generating C-PPAC report EN
output$report_en_cppac <- downloadHandler(


filename = "report_cppac.pdf",
content = function(file) {


withProgress(message = 'Please wait...', {

report <- system.file("report", "report_en_cppac.Rmd", package = "activAnalyzer")

# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed). Code retrieved from https://shiny.rstudio.com/articles/generating-reports.html.
tempReport <- file.path(tempdir(), "report_en_cppac.Rmd")
file.copy(report, tempReport, overwrite = TRUE)

# Set up parameters to pass to Rmd document
params <- list(
assessor_name = input$assessor_name,
assessor_surname = input$assessor_surname,
patient_name = input$patient_name,
patient_surname = input$patient_surname,
sex = input$sex,
age = input$age,
weight = input$weight,
start_date = attributes(file())$startdatetime,
end_date = attributes(file())$stopdatetime,
device = attributes(file())$devicename,
position = input$position,
side = input$side,
sampling_rate = attributes(file())$`original sample rate`,
filter = attributes(file())$filter,
epoch = as.numeric(input$to_epoch),
start_day_analysis = input$start_day_analysis,
end_day_analysis = input$end_day_analysis,
axis_weartime = input$axis_weartime,
frame_size = input$frame_size,
allowanceFrame_size = input$allowanceFrame_size,
streamFrame_size = input$streamFrame_size,
equation_mets = input$equation_mets,
bmr_kcal_d = bmr_kcal_d(),
axis_sed = results_list()$axis_sed_chosen_name,
axis_mvpa = results_list()$axis_mvpa_chosen_name,
sed_cutpoint = results_list()$sed_cutpoint_chosen,
mpa_cutpoint = results_list()$mpa_cutpoint_chosen,
vpa_cutpoint = results_list()$vpa_cutpoint_chosen,
minimum_wear_time_for_analysis = input$minimum_wear_time_for_analysis,
results_by_day = results_list()$results_by_day,
results_summary_means = results_summary_means(),
results_summary_medians = results_summary_medians(),
cppac_table = tab_cppac_summary_en(),
cppac_diff_raw = sum(tab_cppac_summary_en()$"Difficulty score", na.rm = TRUE),
cppac_amount_raw = sum(tab_cppac_summary_en()$"Amount score", na.rm = TRUE),
cppac_total_raw = sum(tab_cppac_summary_en()$"Difficulty score", na.rm = TRUE) + sum(tab_cppac_summary_en()$"Amount score", na.rm = TRUE),
cppac_diff_rasch = rasch_transform(x = sum(tab_cppac_summary_en()$"Difficulty score", na.rm = TRUE), quest = "C-PPAC", score = "difficulty"),
cppac_amount_rasch = rasch_transform(x = sum(tab_cppac_summary_en()$"Amount score", na.rm = TRUE), quest = "C-PPAC", score = "quantity"),
cppac_total_rasch = round((rasch_transform(x = sum(tab_cppac_summary_en()$"Difficulty score", na.rm = TRUE), quest = "C-PPAC", score = "difficulty") +
rasch_transform(x = sum(tab_cppac_summary_en()$"Amount score", na.rm = TRUE), quest = "C-PPAC", score = "quantity")) / 2, 1),

rendered_by_shiny = TRUE
)

# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app). Code retrieved from https://shiny.rstudio.com/articles/generating-reports.html.
out <- rmarkdown::render(tempReport,
params = params,
envir = new.env(parent = globalenv())
)
out <- file.rename(out, file)

})

}
)

# Generating C-PPAC report FR
output$report_fr_cppac <- downloadHandler(


filename = "rapport_cppac.pdf",
content = function(file) {


withProgress(message = 'Please wait...', {

report <- system.file("report", "report_fr_cppac.Rmd", package = "activAnalyzer")

# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed). Code retrieved from https://shiny.rstudio.com/articles/generating-reports.html.
tempReport <- file.path(tempdir(), "report_fr_cppac.Rmd")
file.copy(report, tempReport, overwrite = TRUE)

# Set up parameters to pass to Rmd document
params <- list(
assessor_name = input$assessor_name,
assessor_surname = input$assessor_surname,
patient_name = input$patient_name,
patient_surname = input$patient_surname,
sex = input$sex,
age = input$age,
weight = input$weight,
start_date = attributes(file())$startdatetime,
end_date = attributes(file())$stopdatetime,
device = attributes(file())$devicename,
position = input$position,
side = input$side,
sampling_rate = attributes(file())$`original sample rate`,
filter = attributes(file())$filter,
epoch = as.numeric(input$to_epoch),
start_day_analysis = input$start_day_analysis,
end_day_analysis = input$end_day_analysis,
axis_weartime = input$axis_weartime,
frame_size = input$frame_size,
allowanceFrame_size = input$allowanceFrame_size,
streamFrame_size = input$streamFrame_size,
equation_mets = input$equation_mets,
bmr_kcal_d = bmr_kcal_d(),
axis_sed = results_list()$axis_sed_chosen_name,
axis_mvpa = results_list()$axis_mvpa_chosen_name,
sed_cutpoint = results_list()$sed_cutpoint_chosen,
mpa_cutpoint = results_list()$mpa_cutpoint_chosen,
vpa_cutpoint = results_list()$vpa_cutpoint_chosen,
minimum_wear_time_for_analysis = input$minimum_wear_time_for_analysis,
results_by_day = results_list()$results_by_day,
results_summary_means = results_summary_means(),
results_summary_medians = results_summary_medians(),
cppac_table = tab_cppac_summary_fr(),
cppac_diff_raw = sum(tab_cppac_summary_fr()$"Score de difficult\xc3\xa9", na.rm = TRUE),
cppac_amount_raw = sum(tab_cppac_summary_fr()$"Score de quantit\xc3\xa9", na.rm = TRUE),
cppac_total_raw = sum(tab_cppac_summary_fr()$"Score de difficult\xc3\xa9", na.rm = TRUE) + sum(tab_cppac_summary_fr()$"Score de quantit\xc3\xa9", na.rm = TRUE),
cppac_diff_rasch = rasch_transform(x = sum(tab_cppac_summary_fr()$"Score de difficult\xc3\xa9", na.rm = TRUE), quest = "C-PPAC", score = "difficulty"),
cppac_amount_rasch = rasch_transform(x = sum(tab_cppac_summary_fr()$"Score de quantit\xc3\xa9", na.rm = TRUE), quest = "C-PPAC", score = "quantity"),
cppac_total_rasch = round((rasch_transform(x = sum(tab_cppac_summary_fr()$"Score de difficult\xc3\xa9", na.rm = TRUE), quest = "C-PPAC", score = "difficulty") +
rasch_transform(x = sum(tab_cppac_summary_fr()$"Score de quantit\xc3\xa9", na.rm = TRUE), quest = "C-PPAC", score = "quantity")) / 2, 1),


rendered_by_shiny = TRUE
)

# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app). Code retrieved from https://shiny.rstudio.com/articles/generating-reports.html.
out <- rmarkdown::render(tempReport,
params = params,
envir = new.env(parent = globalenv())
)
out <- file.rename(out, file)

})

}
)

#######################################################
# Switching from accelerometer panel to PROactive panel
Expand Down
25 changes: 19 additions & 6 deletions R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ app_ui <- function(request) {
tags$style(".main-header {vertical-align: middle;}"),
tags$style(".main-header .logo {vertical-align: middle;}")
),
title = span(img(src="www/favicon.png", width = 30), "activAnalyzer 0.4.1"), titleWidth = 237
title = span(img(src="www/favicon.png", width = 30), "activAnalyzer 1.0.0"), titleWidth = 237
),
shinydashboardPlus::dashboardSidebar(
tags$style(HTML(".sidebar-menu li a {font-size: 17px;}")),
Expand Down Expand Up @@ -789,7 +789,7 @@ app_ui <- function(request) {
),
),
fluidRow(
column(12,
column(1,
shiny::actionButton("get_cppac_summary_en", "Results / Update", class = "btn-validate"),
h3("")
),
Expand All @@ -809,10 +809,17 @@ app_ui <- function(request) {
h4(""),
shinydashboard::valueBoxOutput("infoBox_cppac_en_total_diff_rasch"),
shinydashboard::valueBoxOutput("infoBox_cppac_en_total_amount_rasch"),
shinydashboard::valueBoxOutput("infoBox_cppac_en_total_all_rasch")
shinydashboard::valueBoxOutput("infoBox_cppac_en_total_all_rasch"),
),

),
fluidRow(
column(2,
h4(""),
h4(""),
downloadButton("report_en_cppac", "Generate C-PPAC report (EN) (.pdf)", class = "btn-report")
)
)

), # End of tabPanel

Expand Down Expand Up @@ -2167,8 +2174,8 @@ app_ui <- function(request) {
),
),
fluidRow(
column(12,
shiny::actionButton("get_cppac_summary_fr", "R\u00e9ssulats / Actualiser", class = "btn-validate"),
column(1,
shiny::actionButton("get_cppac_summary_fr", "R\u00e9sulats / Actualiser", class = "btn-validate"),
h3("")
),
),
Expand All @@ -2188,7 +2195,13 @@ app_ui <- function(request) {
shinydashboard::valueBoxOutput("infoBox_cppac_fr_total_amount_rasch"),
shinydashboard::valueBoxOutput("infoBox_cppac_fr_total_all_rasch")
),

),
fluidRow(
column(4,
h4(""),
h4(""),
downloadButton("report_fr_cppac", "Générer le rapport du C-PPAC (.pdf)", class = "btn-report")
)
),
), # End of tabPanel

Expand Down
12 changes: 6 additions & 6 deletions inst/report/report_en.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ options("scipen"=100, "digits"=4)

**Patient:** `r params$patient_surname` `r params$patient_name` | **Date:** `r Sys.Date()` | **Assessor:** `r params$assessor_surname` `r params$assessor_name`

**Age:** `r params$age` yr | **Sex:** `r params$sex` | **Weight:** `r params$weight` kg | **Measurement period:** `r format(params$start_date, "%Y-%m-%d %H:%M:%S")` to `r format(params$end_date, "%Y-%m-%d %H:%M:%S")` | **Estimated Basal Metabolic Rate (BMR):** `r format(round(params$bmr_kcal_d, 2), nsmall = 2)` kcal/day (Estimation based on Henry equations [2005, doi: 10.1079/PHN2005801].)
**Age:** `r params$age` yr | **Sex:** `r params$sex` | **Weight:** `r params$weight` kg | **Measurement period:** `r format(params$start_date, "%Y-%m-%d %H:%M:%S")` to `r format(params$end_date, "%Y-%m-%d %H:%M:%S")` | **Estimated Basal Metabolic Rate (BMR):** `r format(round(params$bmr_kcal_d, 2), nsmall = 2)` kcal/day (Estimation based on Henry equations [2005, doi: 10.1079/PHN2005801])

**Device:** `r params$device` | **Position:** `r params$position` | **Side:** `r params$side` | **Sampling rate:** `r params$sampling_rate` Hz | **Filter:** `r params$filter`.
**Device:** `r params$device` | **Position:** `r params$position` | **Side:** `r params$side` | **Sampling rate:** `r params$sampling_rate` Hz | **Filter:** `r params$filter`

**Epoch:** `r params$epoch` s | **Nonwear time:** Based on `r params$axis_weartime`, interval of `r params$frame_size` min with zero count for nonwear time detection, interval of `r params$allowanceFrame_size` min with nonzero counts allowed during a nonwear period, interval of `r params$streamFrame_size` min with zero count around detected activity to confirm nonwear time | **MET equation:** `r params$equation_mets` | **Axis used for PA intensity categorization:** `r params$axis_mvpa` | **Cut-points:** <`r params$sed_cutpoint` counts/min for SED, $\geqslant$ `r params$mpa_cutpoint` counts/min for MPA, $\geqslant$ `r params$vpa_cutpoint` counts/min for VPA.
**Epoch:** `r params$epoch` s | **Nonwear time:** Based on `r params$axis_weartime`, interval of `r params$frame_size` min with zero count for nonwear time detection, interval of `r params$allowanceFrame_size` min with nonzero counts allowed during a nonwear period, interval of `r params$streamFrame_size` min with zero count around detected activity to confirm nonwear time | **MET equation:** `r params$equation_mets` | **Axis used for PA intensity categorization:** `r params$axis_mvpa` | **Cut-points:** <`r params$sed_cutpoint` counts/min for SED, $\geqslant$ `r params$mpa_cutpoint` counts/min for MPA, $\geqslant$ `r params$vpa_cutpoint` counts/min for VPA

**Period of the day considered to count wear time:** from `r params$start_day_analysis` to `r params$end_day_analysis`.
**Period of the day considered to count wear time:** from `r params$start_day_analysis` to `r params$end_day_analysis`

**Minimum number of hours with wear time to validate a day**: `r params$minimum_wear_time_for_analysis` hours.
**Minimum number of hours with wear time to validate a day:** `r params$minimum_wear_time_for_analysis` hours

**Abbreviations:** SED = sedentary, LPA = light physical activity, MPA = moderate physical activity, VPA = vigorous physical activity, MVPA = moderate-to-vigorous physical activity, PAL = physical activity level.
**Abbreviations:** SED = sedentary, LPA = light physical activity, MPA = moderate physical activity, VPA = vigorous physical activity, MVPA = moderate-to-vigorous physical activity, PAL = physical activity level


# Results
Expand Down
Loading

0 comments on commit f06d40b

Please sign in to comment.