write("Export death data for monitoring", stderr())

Death data quality checks

dropped_cols <- c("start",
                  "duration",
                  "device_id",
                  "sys_submit_id",
                  "uuid")
dropped_cols_day0 <- c(dropped_cols,
                       "start_time",
                       "end",
                       "end_time",
                       "submission_date",
                       "fid_ra",
                       "district_ra",
                       "district",
                       "facility",
                       "location",
                       "location_lvl1",
                       "location_lvl2",
                       "location_lvl3",
                       "location_lvl4",
                       "physical_fu_instructions",
                       "cg_common_name",
                       "latitude",
                       "longitude",
                       "altitude",
                       "gps_accuracy",
                       "start_contact",
                       "ra_name",
                       "cg_fs_name",
                       "cg_ls_name",
                       "phone_nb",
                       "phone_nb2",
                       "phone_nb3",
                       "cmty_contact",
                       "fs_name",
                       "ms_name",
                       "ls_name",
                       "mother_fs_name",
                       "mother_ls_name",
                       "child_hf_id",
                       "fid_from_main_device",
                       "facility_name_from_main_device",
                       "fid_from_device",
                       "facility_name",
                       "fid_discrepancy",
                       "t_screening_start",
                       "dob_knwn",
                       "ymdob",
                       "ymob",
                       "yob",
                       "prev_enrl",
                       "prev_id",
                       "prev_hf_name_card",
                       "prev_hf_id_cg",
                       "prev_hf_name_cg",
                       "date_prev",
                       "enrl_days_cg",
                       "enrl_days_card",
                       "repeat_consult",
                       "form_version")
dropped_cols_fu <- c(dropped_cols,
                     "main_cg",
                     "district",
                     "hf_name",
                     "rhf_loc_name",
                     "rhf_name",
                     "rhf_oth",
                     "na.rm",
                     "window",
                     "days",
                     "rhf_loc_oth",
                     "form_version")
dropped_cols_day7 <- c(dropped_cols_fu,
                       "date_day0",
                       "qual_ok",
                       "cure_day7",
                       "fid",
                       "first_attempt",
                       "respondent",
                       "respondent_oth",
                       "respondent_ok",
                       "valid_phone",
                       "phone_off")
dropped_cols_day28 <- c(dropped_cols_fu,
                        "date_day0",
                        "cure_day28",
                        "fid",
                        "rhf_loc_oth",
                        "call_ok")
dropped_cols_hosp <- c(dropped_cols,
                       "sex",
                       "rhf_name",
                       "date_enrol",
                       "dob_knwn_hf",
                       "rhf_name_hosp",
                       "dob_knwn_hf",
                       "date_visit_cg")

Export death data reported at Day 7

allday7_deaths <- raw_successday7fu_data %>%
  dplyr::filter(status_day7 == 3 | fu_type == 3)
if (nrow(allday7_deaths) > 0) {
  allday7_deaths <- pivot_duplicates_to_columns(allday7_deaths)
}
locked_day7fu_deaths <- day7fu_data %>%
  dplyr::filter(status_day7 == 3 | fu_type == 3)

# Remove the columns `dropped_cols` from the exported data frame
locked_day7fu_deaths <- locked_day7fu_deaths[,!(names(locked_day7fu_deaths) %in% dropped_cols_day7)]
allday7_deaths <- raw_successday7fu_data %>%
  dplyr::filter(status_day7 == 3)
if (nrow(allday7_deaths) > 0) {
  allday7_deaths <- pivot_duplicates_to_columns(allday7_deaths)
}
locked_day7fu_deaths <- day7fu_data %>%
  dplyr::filter(status_day7 == 3)
timci::dataset_export(allday7_deaths,
                      "14",
                      "timci_day7_death_data",
                      rctls_dir,
                      "Raw Day 7 death data")
timci::dataset_export(locked_day7fu_deaths,
                      "14",
                      "timci_day7_death_data",
                      locked_db_dir,
                      "Cleaned Day 7 death data")

Export death data reported at Day 28

allday28_deaths <- raw_successday28fu_data %>%
  dplyr::filter(status_day28 == 3)
if (nrow(allday28_deaths) > 0) {
  allday28_deaths <- pivot_duplicates_to_columns(allday28_deaths)
}
locked_day28fu_deaths <- day28fu_data %>%
  dplyr::filter(status_day28 == 3)

# Remove the columns `dropped_cols` from the exported data frame
locked_day28fu_deaths <- locked_day28fu_deaths[,!(names(locked_day28fu_deaths) %in% dropped_cols_day28)]
timci::dataset_export(allday28_deaths,
                      "15",
                      "timci_day28_death_data",
                      rctls_dir,
                      "Raw Day 28 death data")
timci::dataset_export(locked_day28fu_deaths,
                      "15",
                      "timci_day28_death_data",
                      locked_db_dir,
                      "Cleaned Day 28 death data")

Combined death data

all_deaths <- NULL
all_deaths <- allday7_deaths %>%
  merge(allday28_deaths,
        by = 'child_id',
        all = TRUE) %>%
  merge(allday0_data,
        by = 'child_id',
        all.x = TRUE) %>%
  merge(hospit_data,
        by = 'child_id',
        all.x = TRUE)
all_deaths <- allday7_deaths %>%
  merge(allday0_data,
        by = 'child_id',
        all.x = TRUE) %>%
  merge(hospit_data,
        by = 'child_id',
        all.x = TRUE)
timci::dataset_export(all_deaths,
                      "16",
                      "timci_all_death_data",
                      rctls_dir,
                      "Raw all death data")
# Remove the columns `dropped_cols` from the exported data frame
day0_data_subset <- allday0_data[,!(names(allday0_data) %in% dropped_cols_day0)]
hospit_data_subset <- hospit_data[,!(names(hospit_data) %in% dropped_cols_hosp)]
locked_all_deaths <- locked_day7fu_deaths %>%
  merge(locked_day28fu_deaths,
        by = 'child_id',
        all = TRUE,
        suffixes = c("_day7","_day28"))
locked_all_deaths <- day0_data_subset %>%
  merge(locked_all_deaths,
        by = 'child_id',
        all.y = TRUE) %>%
  merge(hospit_data_subset,
        by = 'child_id',
        all.x = TRUE,
        suffixes = c("","_hosp"))
locked_all_deaths <- locked_all_deaths %>%
  dplyr::relocate(child_id) %>%
  dplyr::relocate(fid,
                  .after = child_id)
locked_all_deaths <- locked_all_deaths %>%
  dplyr::mutate(month_day0 = lubridate::month(date_visit, label = TRUE)) %>%
  dplyr::mutate(days_diff_day0_day7 = as.Date(date_call_day7) - as.Date(date_visit)) %>%
  dplyr::mutate(days_diff_day0_day28 = as.Date(date_call_day28) - as.Date(date_visit)) %>%
  dplyr::mutate(days_diff_day0_hosp_s7 = as.Date(date_hosp_day7) - as.Date(date_visit)) %>%
  dplyr::mutate(days_diff_day0_hosp_s28 = as.Date(date_hosp_day28) - as.Date(date_visit)) %>%
  dplyr::mutate(days_diff_day0_hosp_sh = as.Date(date_visit_rhf) - as.Date(date_visit)) %>%
  dplyr::mutate(days_diff_day0_death_s7 = as.Date(date_death_day7) - as.Date(date_visit)) %>%
  dplyr::mutate(days_diff_day0_death_s28 = as.Date(date_death_day28) - as.Date(date_visit)) %>%
  dplyr::mutate(days_diff_day0_death_sh = as.Date(date_death) - as.Date(date_visit)) %>%
  dplyr::mutate(age_days_day0 = as.Date(date_visit) - as.Date(dob)) %>%
  dplyr::mutate(age_days_death_s7 = as.Date(date_death_day7) - as.Date(dob)) %>%
  dplyr::mutate(age_days_death_s28 = as.Date(date_death_day28) - as.Date(dob)) %>%
  dplyr::mutate(age_days_death_sh = as.Date(date_death) - as.Date(dob)) %>%
  dplyr::mutate(days_diff_day0_discharge_sh = as.Date(date_discharge) - as.Date(date_visit))
locked_all_deaths <- locked_all_deaths %>%
  dplyr::relocate(month_day0,
                  age_days_day0,
                  days_diff_day0_day7,
                  days_diff_day0_day28,
                  days_diff_day0_hosp_s7,
                  days_diff_day0_hosp_s28,
                  days_diff_day0_hosp_sh,
                  days_diff_day0_death_s7,
                  days_diff_day0_death_s28,
                  days_diff_day0_death_sh,
                  age_days_death_s7,
                  age_days_death_s28,
                  age_days_death_sh,
                  .after = fid)
# Remove date columns used for day difference calculation
dropped_cols <- c("dob")
locked_all_deaths <- locked_all_deaths[,!(names(locked_all_deaths) %in% dropped_cols)]
# Commented on 10 Oct 2022 to answer VĂ¢nia's request
# Remove date columns used for day difference calculation
# dropped_cols <- c("date_visit",
#                   "date_call_day7",
#                   "date_hosp_day7",
#                   "date_death_day7",
#                   "date_call_day28",
#                   "date_hosp_day28",
#                   "date_death_day28",
#                   "date_visit_rhf",
#                   "date_death",
#                   "date_discharge")
# locked_all_deaths <- locked_all_deaths[,!(names(locked_all_deaths) %in% dropped_cols)]

Inconsistent date of death

Data export

timci::dataset_export(locked_all_deaths,
                      "16",
                      "timci_all_death_data",
                      locked_db_dir,
                      "Cleaned all death data")


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