\newpage

Day 28 follow-up

n_day28fu_rate <- round(100 * n_completed_day28fu/n_due_day28fu, prec)
cat(paste0("The valid Day 28 follow-up period is **", day28_wmin, "** to **", day28_wmax, "** days.\n\n"))
if (n_due_day28fu > 0) {
  cat(paste0("**", n_due_day28fu, "** participants should have completed their Day 28 follow-up.\n\n"))
  cat(paste0("**", n_completed_day28fu, "** participants (", n_day28fu_rate, "%) completed their Day 28 follow-up."))
}
if (!is.null(raw_day28fu_data)) {
  if (nrow(raw_day28fu_data) > 1) {
    day28fu_data <- timci::format_day28_data(raw_day28fu_data)[[1]]
    day28fu_data <- day28fu_data %>%
      dplyr::mutate(days = as.Date(date_call) - as.Date(date_day0), na.rm = TRUE)

    all <- data.frame(day28fu_data)

    day28_call_ss <- list(
      "District" = list(
        "Successful call" = ~qwraps2::n_perc(cg_reached == 1, prec, na_rm = TRUE),
        "Valid time window" = ~qwraps2::n_perc(cg_reached == 1 & (days >= day28_wmin) & (days <= day28_wmax), prec, na_rm = TRUE)
        )
    )
    out <- format_summary_table(all, day28_call_ss, district)
    out %>% 
      kableExtra::kbl(booktabs = TRUE,
                      longtable = TRUE,
                      linesep = "") %>% 
      kableExtra::kable_styling(latex_options = c("HOLD_position", "repeat_header"), font_size = table_fs) %>%
      kableExtra::row_spec(0, bold = TRUE) %>%
      kableExtra::row_spec(1, color = total_row_ft2, background = total_row_bg2, bold = TRUE) %>%
      kableExtra::row_spec(1:(nrow(out)/2) * 2, background = striped_row_bg)
  }
}

Weekly calls

if (!is.null(raw_day28fu_data)) {
  if(length(raw_day28fu_data) > 0 & nrow(raw_day28fu_data) > 1){

  }
}

Number of submissions during the last 30 days

if (!is.null(raw_day28fu_data)) {
  if (nrow(raw_day28fu_data) > 1) {
    plot(timci::generate_day_bar_plot(raw_day28fu_data$date,
                                      as.Date(Sys.Date() - w),
                                      as.Date(Sys.Date() + 1),
                                      ylbl = submission_str,
                                      date_vec_ref = as.Date(as.Date(baseline_data$date_visit) + 28)))
  } else {
    cat('0 submissions since the start of the study.\n\n')
  }
} else{
  cat('0 submissions since the start of the study.\n\n')
}

Calendar heatmap

if (!is.null(raw_day28fu_data)) {
  if (nrow(raw_day28fu_data) > 1) {
    timci::generate_calendar_heatmap2(raw_day28fu_data,
                                      date,
                                      legendtitle = "Number of day 28 follow-up phone calls")
  } else{
    cat('N/A\n\n')
  }
} else{
  cat('N/A\n\n')
}

Completed follow-ups

succ_day28fu_data <- merge(x = succ_day28fu_data,
                           y = params$research_facilities[, c("facility_id", "facility_name")],
                           by.x = 'fid',
                           by.y = 'facility_id',
                           all = FALSE)
all <- data.frame(succ_day28fu_data)
day28_outcome_ss <- list(
  "summary" = list(
    "Before day 28" = ~qwraps2::n_perc(days <= 27, prec, na_rm = TRUE),
    "Day 28-32" = ~qwraps2::n_perc(days >= 28 & days <= 32, prec, na_rm = TRUE),
    "Above day 32" = ~qwraps2::n_perc(days > 32, prec, na_rm = TRUE),
    "Median" = ~qwraps2::median_iqr(days, na_rm = TRUE)
    )
  )
out <- format_summary_table(all, day28_outcome_ss, facility_name) 
out %>% 
  kableExtra::kbl(booktabs = TRUE,
                  longtable = TRUE,
                  linesep = "") %>% 
  kableExtra::kable_styling(latex_options = c("HOLD_position", "repeat_header"), font_size = table_fs) %>%
  kableExtra::row_spec(0, bold = TRUE) %>%
  # kableExtra::column_spec(2, color = ifelse(as.numeric(gsub("\\(([^()]*)%\\)|.", "\\1", x = out[, 1], perl = TRUE)) > 0,
  #                                           "red",
  #                                           "black")) %>%
  kableExtra::row_spec(1, color = total_row_ft2, background = total_row_bg2, bold = TRUE) %>%
  kableExtra::row_spec(1:(nrow(out)/2) * 2, background = striped_row_bg) %>%
  kableExtra::footnote(general = "Mean and inner quartile range (IQR) are represented by the format \\\\textit{median (Q1, Q3)}.",
                       escape = FALSE)
all <- data.frame(succ_day28fu_data) %>% 
  mutate(hf_visit_day28 = 1 * ((hf_visit_day28_no_day7 == 1) | (hf_visit_day28_after_day7 == 1)))
all$cure_day28[is.na(all$cure_day28)] <- 0
all$all_hf_visit_day28 <- ifelse(all$status_day28 == 2 | (all$status_day28 != 2 & all$hf_visit_day28 == 1 & all$hf_visit_type == hospit_value), 1, 0)
all$admission[is.na(all$admission)] <- 0
day28_outcome_ss <- list(
  "summary" = list(
    "Cure" = ~qwraps2::n_perc(cure_day28 == 1 | cure_day28 == 2, prec, na_rm = TRUE),
    "Death" = ~qwraps2::n_perc(status_day28 == 3, prec, na_rm = TRUE),
    "Higher level visit" = ~qwraps2::n_perc(all_hf_visit_day28 == 1, prec, na_rm = TRUE),
    "Admission" = ~qwraps2::n_perc(admission == 1, prec, na_rm = TRUE)
    )
  )
out <- format_summary_table(all, day28_outcome_ss, facility_name) 
out %>% 
  kableExtra::kbl(booktabs = TRUE,
                  longtable = TRUE,
                  linesep = "") %>% 
  kableExtra::kable_styling(latex_options = c("HOLD_position", "repeat_header"), font_size = table_fs) %>%
  kableExtra::row_spec(0, bold = TRUE) %>%
  # kableExtra::column_spec(3, color = ifelse(as.numeric(gsub("\\(([^()]*)%\\)|.", "\\1", x = out[, 2], perl = TRUE)) > 0,
  #                                           "red",
  #                                           "black")) %>%
  # kableExtra::column_spec(4, color = ifelse(as.numeric(gsub("\\(([^()]*)%\\)|.", "\\1", x = out[, 3], perl = TRUE)) > 0,
  #                                           "red",
  #                                           "black")) %>%
  kableExtra::row_spec(1, color = total_row_ft2, background = total_row_bg2, bold = TRUE) %>%
  kableExtra::row_spec(1:(nrow(out)/2) * 2, background = striped_row_bg)


SwissTPH/timci documentation built on April 11, 2024, 8:31 a.m.