RISE_FJ/T1_child_sampling/O3_T1_FJ_data_check.R

#DATA CHECKS FOR DAILY/WEEKLY REPORT

# THINGS TO CHECK

# what return visits are needed

#how many visits to each settlement
table (child.merge$today, child.merge$settlement_barcode) #1 settlements so far
table (feces.merge$today, feces.merge$settlement_barcode) #1 settlements so far

# 1	Completed survey; no return visit required
# 2	Completed survey; return visit required for at least one child
# 3	Incomplete survey
# 4	Child exceeded age cut-off of 5 years old
# 5	No one home
# 6	No one available to complete the survey
# 7	Previously consented but refused to participate in the survey
# 8	No previous consent and did not want to consent today.
# -77	Other
table (child$survey_status, child$caregiver_present)

# 1	Yes, parent/guardian/caregiver is at home with their child and ready for child sample collection
# 2	Yes, parent/guardian/caregiver is at home, but NOT ready for child sample collection
# 3	Yes, parent/guardian/caregiver is at home, but does not want to participate in child sample collection
# 4	No, parent/guardian/caregiver is NOT at home
# 5	No one at home
# 6	House is vacant
table (child$survey_status, child$home_yn, useNA="always") # add useNA so you can see all responses


# *****************
# *****************
# FECES CHECKS

#are there any duplicate barcodes?
table(duplicated(feces.merge$barcode)) #no duplicates! 314 barcodes
table(feces$feces_sample_yn, exclude = NULL) # 141 visits with no sample pick up (0); #259 with samples (1)
x <- feces.merge %>% #samples per house
  select (settlement_barcode, extract_house_no, feces_sample_yn, barcode) %>%
  group_by(settlement_barcode, extract_house_no) %>%
  summarize (count = n())
summary(x$count) #up to 4 samples per house
rm(x)


# 1. feces kits handed out vs. collected
feces.kits <- child.merge %>%
  select (settlement_barcode, extract_house_no, feces, today) %>%
  rename (feces.kits = feces,
          date.handout = today) %>%
  filter (!is.na(feces.kits)) #remove any NA values

feces.recd <- feces.merge %>%
  select (settlement_barcode, extract_house_no, barcode, today) %>%
  rename (feces.recd = barcode,
          date.pickup = today) %>%
  filter (!is.na(feces.recd))

feces.compare <- full_join (feces.kits, feces.recd,
                            by = c("settlement_barcode" = "settlement_barcode",
                                   "extract_house_no" = "extract_house_no",
                                   "feces.kits" = "feces.recd"))
table(duplicated(feces.compare$feces.kits)) #1 duplicates in barcodes
feces.compare[duplicated(feces.compare$feces.kits),] #only  duplicates, excluding NA
#this returns the duplicates: -



feces.compare_final <- full_join (feces.compare, feces.compare, by = "feces.kits") %>%
                   filter (extract_house_no.x != extract_house_no.y & is.na(date.pickup.x)) %>%
                   rename (Site_Out = settlement_barcode.x,
                           Site_In = settlement_barcode.y,
                           House_Out = extract_house_no.x,
                           House_In = extract_house_no.y,
                           Date_Out = date.handout.x,
                           Date_Collected = date.pickup.y) %>%
                   mutate (House_In = ifelse(is.na(Date_Collected), NA, House_In),
                           Site_In = ifelse(is.na(Date_Collected), NA, Site_In)) %>%
                   select (feces.kits, Site_Out, House_Out, Date_Out, Site_In, House_In, Date_Collected)

#use this list to check for feces kits that have not been picked up:
# write_csv(feces.compare, path = "Z:/Data Files/Data Files Objective 3/Reports/Child Sampling/feces.compare.csv")
rm(feces.kits, feces.recd)


#COUNT TOTAL NUMBER OF VISITS FOR FECES COLLECTION
#summarising data by child - # visits to each house and # samples
# visits must be on different days (so if more than one on same day = 1 visit)
# The no_visits_feces count is not correct... need to use nrow(feces) to get
# number of feces visits for now - Jeff F - 12/10/2019
visits_feces <- full_join (feces, feces.sample, by = c("KEY" = "PARENT_KEY")) %>%
  mutate (barcode = ifelse (is.na(barcode_feces), barcode_feces_text, barcode_feces)) %>%
  mutate (barcode_yes = ifelse (!is.na(barcode), 1, 0)) %>%
  group_by(settlement_barcode, extract_house_no, today) %>%
  summarise (test = n(),
             no_samples = sum(barcode_yes, na.rm = TRUE)) %>% #note - there are quite a few re-visits on the same day
  group_by(settlement_barcode, extract_house_no) %>%
  summarise(no_visits_feces = n(),
            no_samples = sum(no_samples))

visits_feces_summ <- visits_feces %>%
  group_by (settlement_barcode) %>%
  summarise(no_visits_feces = sum (no_visits_feces, na.rm = TRUE),
            no_samples = sum (no_samples, na.rm = TRUE)) %>%
  mutate (test = 1)
visits_feces_summ2 <- visits_feces_summ %>%    #add totals
  group_by (test) %>%
  summarise (no_visits_feces = sum (no_visits_feces, na.rm = TRUE),
             no_samples = sum (no_samples, na.rm = TRUE)) %>%
  rename (settlement_barcode = test) %>%
  mutate (settlement_barcode = "Totals")
visits_feces_summ$test <- NULL
visits_feces_summary <- rbind (visits_feces_summ, visits_feces_summ2)
rm(visits_feces_summ, visits_feces_summ2)
# write_csv(visits_feces_summary, path = "S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/2. ID/3/20190225_child sampling/3. ID/2. Data/4. reports/visits_feces_summary.csv")

# NUMBER OF KITS HANDED OUT
feces.kits <- child.merge %>%
  select (settlement_barcode, extract_house_no, feces, today) %>%
  mutate (no.feces.kits = ifelse(!is.na(feces), 1, 0)) %>%
  group_by(settlement_barcode, extract_house_no, today) %>%
  summarise (no.feces.kits = sum(no.feces.kits, na.rm = TRUE)) %>%
  group_by(settlement_barcode, extract_house_no) %>%
  summarise(no.feces.kits = sum(no.feces.kits, na.rm = TRUE))

feces.kits_summ <- feces.kits %>%
  group_by(settlement_barcode) %>%
  summarise(no.feces.kits = sum(no.feces.kits, na.rm = TRUE)) %>%
  mutate (test = 1)
feces.kits_summ2 <- feces.kits_summ %>%    #add totals
  group_by (test) %>%
  summarise (no.feces.kits = sum(no.feces.kits, na.rm = TRUE)) %>%
  rename (settlement_barcode = test) %>%
  mutate (settlement_barcode = "Totals")
feces.kits_summ$test <- NULL
feces.kits_summary <- rbind (feces.kits_summ, feces.kits_summ2)
rm(feces.kits_summ, feces.kits_summ2)

feces.summary <- full_join (feces.kits_summary, visits_feces_summary,
                            by = c("settlement_barcode" = "settlement_barcode"))
rm(feces.kits_summary, visits_feces_summary)
# write_csv(visits_feces_summary, path = "S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/2. ID/3/20190225_child sampling/3. ID/2. Data/4. reports/visits_feces_summary.csv")


# *****************
# *****************
#CHECK CONSENTS
#check household consent
hhd.consent.check <- child %>%
  select (settlement_barcode, extract_house_no, hhd_id_no, new_consent_yn1, hhd_name, 
          child_name_first, respondent_name_first,
          signedyn_pl, study_pl, surveys_pl,
          signed_form1, consent1_1, consent1_3) %>%
  filter (!is.na(hhd_id_no)) %>%
  mutate (need.consent = ifelse((signedyn_pl == "no" | is.na(signedyn_pl)
                                 | study_pl == "no" | is.na(study_pl)
                                 | surveys_pl == "no" | is.na(surveys_pl)), 1, 0)) %>%
  filter (need.consent == 1)  %>%  #only those that need consent
  mutate (consent.error = ifelse ((signed_form1 != 1 | consent1_1 != "yes" | consent1_3 != "yes"), 1, 0)) %>% 
  filter (is.na(consent.error) | consent.error==1)

# Newtown #76 (is this Dike Manasa?), 81 (is this Sunia Bolavatu?), 134 (is this Suliana Rokoura?)Wailea #21 (is this Luisa Biu Vakaloloma?), 58 (is this Joana Berwick?), 82 (is this Sera Turuva?) 
# Wainidinu #7 (is this Ilikimi Sirino Baisagale?)


#check CHILD consents -
child.consent.check <- child %>%
  select (settlement_barcode, extract_house_no, hhd_id_no, today, child_name, child_dob,
          child.signed.yn_pl, feces_pl, blood_pl, height_pl,
          child_signed_yn,  blood_yn, height_yn1,
          consent_new2, consent_new3,
          survey_check2, height_check2, blood_check2) %>%
  filter (!is.na(hhd_id_no)) %>%
  mutate (need.consent = ifelse((child.signed.yn_pl == "no" | is.na(child.signed.yn_pl)
                                 | blood_pl == "no" | is.na(blood_pl)
                                 | height_pl == "no" | is.na(height_pl)), 1, 0)) %>%
  filter (need.consent == 1)  %>%  #only those that need consent
  mutate (consent.error = ifelse (((child_signed_yn!="yes" & (blood_check2==1 | height_check2==1)) |
                                     (blood_yn !="yes" & blood_check2==1) |
                                     (height_yn1 !="yes" & height_check2==1)), 1, 0)) %>% 
  filter (is.na(consent.error) | consent.error==1)

#added by Fiona on 10 Oct 2019 to cross check child consents
#added by Jeff on 17 Oct 2019 to check if the name was in child_name_text to cross check child consents
child.consent.check2 <- child %>%
  select (settlement_barcode, extract_house_no, hhd_id_no, today,
          child_name_text, child_name, child_dob,
          child.signed.yn_pl, feces_pl, blood_pl, height_pl,
          consent_no_prev1, consent_new2, consent_new3,
          child_signed_yn,  blood_yn, height_yn1, cough,
          survey_check2, feces_check2, height_check2, blood_check2,
          consent3_2, consent3_3) %>%
  filter (!is.na(hhd_id_no)) %>%
  separate(child_name, sep = "([\\(])", c("name", "delete")) %>%
  mutate(name = str_trim(name))
child.consent.check3 <- left_join(child.consent.check2, child_consent_list_all,
                                  by = c("settlement_barcode"= "settlement",
                                         "extract_house_no" = "house.no",
                                         "name" = "child.name")) %>%
  filter (is.na(child.signed.yn_pl) | is.na(consent3_2) | is.na(consent3_3) |
            consent3_2 == "no" | consent3_3 == "no") %>%  #only those with no consent on record
  filter (is.na(guardian.name) | blood == "no" | height.weight == "no") %>% #remove those that did do consent
  filter (!is.na(cough) | !is.na(blood_check2) | !is.na(height_check2)) #keep those that did survey and sampling; these are the missing consents!!!!

child.consent.check4 <- child.consent.check3 %>% 
  filter(!is.na(child_name_text)) %>%
  select (settlement_barcode, extract_house_no, hhd_id_no, today,
          child_name_text, name, child_dob,
          child.signed.yn_pl, feces_pl, blood_pl, height_pl,
          consent_no_prev1, consent_new2, consent_new3,
          child_signed_yn,  blood_yn, height_yn1, cough,
          survey_check2, feces_check2, height_check2, blood_check2,
          consent3_2, consent3_3)
child.consent.check3 <- child.consent.check3 %>% 
  filter (is.na(child_name_text)) %>%
  select (-delete)
child.consent.check5 <- left_join(child.consent.check4, child_consent_list_all,
                                  by = c("settlement_barcode"= "settlement",
                                         "extract_house_no" = "house.no",
                                         "child_name_text" = "child.name")) %>%
  filter (is.na(child.signed.yn_pl) | is.na(consent3_2) | is.na(consent3_3) |
          consent3_2 == "no" | consent3_3 == "no") %>%  #only those with no consent on record
  filter (is.na(guardian.name) | blood == "no" | height.weight == "no") %>% #remove those that did do consent
  filter (!is.na(cough) | !is.na(blood_check2) | !is.na(height_check2)) #keep those that did survey and sampling; these are the missing consents!!!!

child.consent.check6 <- rbind(child.consent.check3, child.consent.check5)
child.consent.check_final <- child.consent.check6 %>%
  distinct(settlement_barcode, extract_house_no, name, .keep_all = TRUE)

rm(child.consent.check2, child.consent.check3, child.consent.check4, child.consent.check5, child.consent.check6)


#HOUSEHOLD CONSENT
hhd.consent.check <- child %>%
  filter (!is.na(hhd_id_no)) %>%
  select (settlement_barcode, extract_house_no, today, hhd_consent_yes) %>%
  filter (hhd_consent_yes!=1) #none - good


# *****************
# *****************
# CHILD SAMPLING:
#1) survey started but no child name = no child sampling

child.no.data <- child %>%
  select (settlement_barcode, extract_house_no, caregiver_present, child_name, today) %>%
  filter (is.na(child_name))
table(child.no.data$caregiver_present) #all with zero - which is correct; 2 with -66??
rm(child.no.data)


# check blood spots
blood.spot <- child.merge %>%
  select (settlement_barcode, extract_house_no, today, bloodspot, edta, serum) %>%
  filter (!is.na(bloodspot)) #316
#
# write_csv(blood.spot, path = "S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/2. ID/3/20190225_child sampling/3. ID/2. Data/4. reports/blood.spot.csv")
rm(blood.spot)


#summarising data by child - # visits
child_samples <- child %>%
  mutate (edta = ifelse (is.na(barcode_edta), barcode_edta_text, barcode_edta),
          serum = ifelse (is.na(barcode_serum), barcode_serum_text, barcode_serum),
          bloodspot = ifelse (is.na(barcode_bloodspot), barcode_bloodspot_text, barcode_bloodspot),
          feces = ifelse (is.na(feces_kit_barcode), feces_kit_barcode_note, feces_kit_barcode)) %>%
  mutate (edta = ifelse(edta_yn == 1 | edta_yn == 2, 1, 0),
          serum = ifelse(serum_yn == 1 | serum_yn == 2, 1, 0),
          blood_spot = ifelse(blood_spot_no > 0, 1, 0),
          gender = ifelse(gender_pl == 'male', 1, 0),
          diarrhea = ifelse(diarrhea1 == 1, 1, 0),
          doctor = ifelse(doctor_yn > 0, 1, 0),
          breastfed = ifelse(breastfed_3m_yn == 1, 1, 0),
          weight = ifelse(weight_avg > 0 , 1, 0),
          height = ifelse(height_avg > 0 , 1, 0),
          survey = ifelse(!is.na(cough), 1, 0),
          photo = ifelse(child_photo > 0, 1, 0),
          consented = ifelse(blood_check2 == 1, 1, 0),
          refused = ifelse(survey_status == 7, 1, 0)) %>%
  rename (settlement = settlement_barcode,
          house_no = extract_house_no) %>%
  group_by (settlement, house_no, child_name) %>%
  summarise (no_visits = n(),
             dob = max(child_dob, na.rm = TRUE),
             age = max((date("2019-10-01") - dob) / 365, na.rm = TRUE),
             gender = max(gender, na.rm = TRUE),
             diarrhea = max(diarrhea, na.rm = TRUE),
             doctor = max(doctor, na.rm = TRUE),
             breastfed = max(breastfed, na.rm = TRUE),
             edta = max(edta, na.rm = TRUE),
             serum = max(serum, na.rm = TRUE),
             blood_spot = max(blood_spot, na.rm = TRUE),
             weight = max(weight, na.rm = TRUE),
             height = max(height, na.rm = TRUE),
             survey = max(survey, na.rm = TRUE),
             photo = max(photo, na.rm = TRUE),
             consented = max(consented, na.rm = TRUE),
             refused = max(refused, na.rm = TRUE)) %>%
  mutate (edta = ifelse(is.infinite(edta), NA, edta),
          serum = ifelse(is.infinite(serum), NA, serum),
          blood_spot = ifelse(is.infinite(blood_spot), NA, blood_spot),
          weight = ifelse(is.infinite(weight), NA, weight),
          height = ifelse(is.infinite(height), NA, height),
          survey = ifelse(is.infinite(survey), NA, survey),
          age = ifelse(is.infinite(age), NA, age),
          diarrhea = ifelse(is.infinite(diarrhea), NA, diarrhea),
          doctor = ifelse(is.infinite(doctor), NA, doctor),
          breastfed = ifelse(is.infinite(breastfed), NA, breastfed),
          gender = ifelse(is.infinite(gender), NA, gender),
          photo = ifelse(is.infinite(photo), NA, photo),
          consented = ifelse(is.infinite(consented), NA, consented),
          refused = ifelse(is.infinite(refused), NA, refused)) #remove Inf


# write_csv(child_samples, path = "S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/2. ID/3/20190225_child sampling/3. ID/2. Data/4. reports/child_samples.csv")
#field supervisor needs to check every day with their list

child_samples2 <- child_samples %>%
  mutate (test = ifelse(!is.na(child_name), 1, 0), test2 = 1) %>%
  select (-child_name)

#summarising data by settlement
child_samples_summ <- child_samples2 %>%
  group_by(settlement) %>%
  summarise (no_visits = sum(no_visits, na.rm = TRUE),
             no_children = sum(test, na.rm = TRUE),
             edta = sum(edta, na.rm = TRUE),
             serum = sum(serum, na.rm = TRUE),
             blood_spot = sum(blood_spot, na.rm = TRUE),
             weight = sum(weight, na.rm = TRUE),
             height = sum(height, na.rm = TRUE),
             survey = sum(survey, na.rm = TRUE),
             photo = sum(photo, na.rm = TRUE),
             gender = mean(gender, na.rm = TRUE),
             diarrhea = sum(diarrhea, na.rm = TRUE),
             doctor = sum(doctor, na.rm = TRUE),
             breastfed = sum(breastfed, na.rm = TRUE),
             age = mean(age, na.rm = TRUE)) %>%
  mutate (test = 1)

child_samples_summ2 <- child_samples_summ %>%    #add totals
  group_by (test) %>%
  summarise (no_visits = sum(no_visits, na.rm = TRUE),
             no_children = sum(no_children, na.rm = TRUE),
             edta = sum(edta, na.rm = TRUE),
             serum = sum(serum, na.rm = TRUE),
             blood_spot = sum(blood_spot, na.rm = TRUE),
             weight = sum(weight, na.rm = TRUE),
             height = sum(height, na.rm = TRUE),
             survey = sum(survey, na.rm = TRUE),
             photo = sum(photo, na.rm = TRUE),
             gender = mean(gender, na.rm= TRUE),
             diarrhea = sum(diarrhea, na.rm = TRUE),
             doctor = sum(doctor, na.rm = TRUE),
             breastfed = sum(breastfed, na.rm = TRUE),
             age = mean(age, na.rm = TRUE)) %>%
  rename (settlement = test) %>%
  mutate (settlement = "Totals")
child_samples_summ$test <- NULL
child_samples_summary <- rbind (child_samples_summ, child_samples_summ2)
rm(child_samples_summ, child_samples_summ2)


child_sampling_summary <- full_join(child_samples_summary, feces.summary,
                                    by = c("settlement" = "settlement_barcode"))
# write_csv(child_sampling_summary, path = "S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/2. ID/3. Objectives/3/20190225_child sampling/3. ID/2. Data/4. reports/child_sampling_summary.csv")

# *****************
# *****************
# HEALTHCARE UTILIZATION

# child hospitalized, outpatient non-routine visits (not for vaccines),
# duration of hospitalization (histogram), number of children given antibiotics
healthcare1 <- child %>% filter (survey_check2 == 1) %>%
  group_by (settlement_barcode) %>%
  summarise ('Outpatient Visit' = noquote(paste0(sum(doctor_yn > 0, na.rm = TRUE), "/", sum (doctor_yn >= 0, na.rm = TRUE), " (", round(sum(doctor_yn > 0, na.rm = TRUE) / sum(doctor_yn >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             'Sick/Injured' = noquote(paste0(sum(doctor_sick == 1, na.rm = TRUE), "/", sum (doctor_sick >= 0, na.rm = TRUE), " (", round(sum(doctor_sick == 1, na.rm = TRUE) / sum(doctor_sick >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             Antibiotics = noquote(paste0(sum(doctor_antibiotics == 1, na.rm = TRUE), "/", sum (doctor_antibiotics >= 0, na.rm = TRUE), " (", round(sum(doctor_antibiotics == 1, na.rm = TRUE) / sum(doctor_antibiotics >= 0, na.rm = TRUE)*100, digits=1), "%", ")" ))) %>%
  rename (settlement = settlement_barcode)

healthcare2 <- child %>%
  mutate (test = 1) %>%
  select (-child_name)

healthcare3 <- healthcare2 %>%    #add totals
  group_by (test) %>%
  summarise ('Outpatient Visit' = noquote(paste0(sum(doctor_yn > 0, na.rm = TRUE), "/", sum (doctor_yn >= 0, na.rm = TRUE), " (", round(sum(doctor_yn > 0, na.rm = TRUE) / sum(doctor_yn >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             'Sick/Injured' = noquote(paste0(sum(doctor_sick == 1, na.rm = TRUE), "/", sum (doctor_sick >= 0, na.rm = TRUE), " (", round(sum(doctor_sick == 1, na.rm = TRUE) / sum(doctor_sick >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             Antibiotics = noquote(paste0(sum(doctor_antibiotics == 1, na.rm = TRUE), "/", sum (doctor_antibiotics >= 0, na.rm = TRUE), " (", round(sum(doctor_antibiotics == 1, na.rm = TRUE) / sum(doctor_antibiotics >= 0, na.rm = TRUE)*100, digits=1), "%", ")" ))) %>%
  rename (settlement = test) %>%
  mutate (settlement = "Totals")
healthcare1$test <- NULL
healthcare <- rbind (healthcare1, healthcare3)
rm(healthcare1, healthcare2, healthcare3)


hospital_visits <- child %>% filter (survey_check2 == 1) %>%
  mutate (visit1 = ifelse(doctor_yn == 1, 1, 0),
          visit2 = ifelse(doctor_yn == 2, 1, 0),
          visit3 = ifelse(doctor_yn == 3, 1, 0),
          visit4 = ifelse(doctor_yn == 4, 1, 0),
          visit5 = ifelse(doctor_yn == 5, 1, 0),
          visit6 = ifelse(doctor_yn == 6, 1, 0),
          visit7 = ifelse(doctor_yn == 7, 1, 0),
          visit8 = ifelse(doctor_yn == 8, 1, 0),
          visit9 = ifelse(doctor_yn == 9, 1, 0),
          visit10 = ifelse(doctor_yn >= 10, 1, 0)) %>%
  summarise('1 visit' = sum(visit1, na.rm = TRUE),
            '2 visits' = sum(visit2, na.rm = TRUE),
            '3 visits' = sum(visit3, na.rm = TRUE),
            '4 visits' = sum(visit4, na.rm = TRUE),
            '5 visits' = sum(visit5, na.rm = TRUE),
            '6 visits' = sum(visit6, na.rm = TRUE),
            '7 visits' = sum(visit7, na.rm = TRUE),
            '8 visits' = sum(visit8, na.rm = TRUE),
            '9 visits' = sum(visit9, na.rm = TRUE),
            '10 visits or more' = sum(visit10, na.rm = TRUE))

# *****************
# *****************
# BLOOD DRAW DATA

# Group on settlement to determine eligible population, who consented, who
# refused, who had blood drawn, and SST obtained - Jeff

child_sampling_summary3 <- child_samples2 %>%
  group_by (settlement) %>%
  summarise ('Eligible Population' = noquote(paste0(sum(age > 0.5 & age < 5, na.rm = TRUE), "/", sum(age > 0, na.rm = TRUE), " (", round(sum(age > 0.5 & age < 5, na.rm = TRUE) / sum(age > 0, na.rm = TRUE)*100, digits=1), "%", ")")),
             Consented = noquote(paste0(sum(age > 0.5 & age < 5 & consented == 1, na.rm = TRUE), "/", sum((age > 0.5 & age < 5) & consented == 0 | consented == 1, na.rm = TRUE), " (", round(sum(age > 0.5 & age < 5 & consented == 1, na.rm = TRUE) / sum((age > 0.5 & age < 5) & consented == 0 | consented == 1, na.rm = TRUE)*100, digits=1), "%", ")")),
             Withdrawal = noquote(paste0(sum(refused == 1, na.rm = TRUE), "/", sum(refused == 0 | refused == 1, na.rm = TRUE), " (", round(sum(refused == 1, na.rm = TRUE) / sum(refused == 0 | refused == 1, na.rm = TRUE)*100, digits=1), "%", ")")),
             'Successful Draw' = noquote(paste0(sum(edta == 1 | serum == 1 | blood_spot == 1, na.rm = TRUE), "/", sum(edta == 0 | edta == 1 | serum == 0 | serum == 1 | blood_spot == 0 | blood_spot == 1, na.rm = TRUE), " (", round(sum(edta == 1 | serum == 1 | blood_spot == 1, na.rm = TRUE) / sum(edta == 0 | edta == 1 | serum == 0 | serum == 1 | blood_spot == 0 | blood_spot == 1, na.rm = TRUE)*100, digits=1), "%", ")")),
             'SST Obtained' = noquote(paste0(round(sum(edta == 1 | serum == 1, na.rm = TRUE) / sum(edta == 0 | edta == 1 | serum == 0 | serum == 1, na.rm = TRUE)*100, digits=1), "%" )))

child_sampling_summary4 <- child_samples2 %>%    #add totals
  group_by (test2) %>%
  summarise ('Eligible Population' = noquote(paste0(sum(age > 0.5 & age < 5, na.rm = TRUE), "/", sum(age > 0, na.rm = TRUE), " (", round(sum(age > 0.5 & age < 5, na.rm = TRUE) / sum(age > 0, na.rm = TRUE)*100, digits=1), "%", ")")),
             Consented = noquote(paste0(sum(consented == 1, na.rm = TRUE), "/", sum(consented == 0 | consented == 1, na.rm = TRUE), " (", round(sum(consented == 1, na.rm = TRUE) / sum(consented == 0 | consented == 1, na.rm = TRUE)*100, digits=1), "%", ")")),
             Withdrawal = noquote(paste0(sum(refused == 1, na.rm = TRUE), "/", sum(refused == 0 | refused == 1, na.rm = TRUE), " (", round(sum(refused == 1, na.rm = TRUE) / sum(refused == 0 | refused == 1, na.rm = TRUE)*100, digits=1), "%", ")")),
             'Successful Draw' = noquote(paste0(sum(edta == 1 | serum == 1 | blood_spot == 1, na.rm = TRUE), "/", sum(edta == 0 | edta == 1 | serum == 0 | serum == 1 | blood_spot == 0 | blood_spot == 1, na.rm = TRUE), " (", round(sum(edta == 1 | serum == 1 | blood_spot == 1, na.rm = TRUE) / sum(edta == 0 | edta == 1 | serum == 0 | serum == 1 | blood_spot == 0 | blood_spot == 1, na.rm = TRUE)*100, digits=1), "%", ")")),
             'SST Obtained' = noquote(paste0(round(sum(edta == 1 | serum == 1, na.rm = TRUE) / sum(edta == 0 | edta == 1 | serum == 0 | serum == 1, na.rm = TRUE)*100, digits=1), "%" ))) %>%
  rename (settlement = test2) %>%
  mutate (settlement = "Totals")
child_sampling_summary3$test <- NULL
child_sampling_summary5 <- rbind (child_sampling_summary3, child_sampling_summary4)
rm(child_sampling_summary3, child_sampling_summary4)

# *****************
# *****************
# SYMPTOM DATA

# kids with diarrhea, fever, cough, shortness of breath, resulting in health
# care visit
# child survey - exposure data - Jeff F - 14/10/2019
# In the past 3 months has child swum or played in local water ways (swim_yn)
# In the past 7 days has child eaten any dirt/soil (dirt_yn)
sick_exposure1 <- child %>% filter (survey_check2 == 1) %>%
  group_by (settlement_barcode) %>%
  summarise (diarrhea = noquote(paste0(sum(diarrhea1 == 1, na.rm = TRUE), "/", sum (diarrhea1 >= 0, na.rm = TRUE), " (", round(sum(diarrhea1 == 1, na.rm = TRUE) / sum(diarrhea1 >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             cough = noquote(paste0(sum(cough == 1, na.rm = TRUE), "/", sum (cough >= 0, na.rm = TRUE), " (", round(sum(cough == 1, na.rm = TRUE) / sum(cough >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             breathing = noquote(paste0(sum(breathing == 1, na.rm = TRUE), "/", sum (breathing >= 0, na.rm = TRUE), " (", round(sum(breathing == 1, na.rm = TRUE) / sum(breathing >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             fever = noquote(paste0(sum(fever == 1, na.rm = TRUE), "/", sum (fever >= 0, na.rm = TRUE), " (", round(sum(fever == 1, na.rm = TRUE) / sum(fever >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             swimming = noquote(paste0(sum(swim_yn == 1, na.rm = TRUE), "/", sum (swim_yn >= 0, na.rm = TRUE), " (", round(sum(swim_yn == 1, na.rm = TRUE) / sum(swim_yn >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             dirt = noquote(paste0(sum(dirt_yn == 1, na.rm = TRUE), "/", sum (dirt_yn >= 0, na.rm = TRUE), " (", round(sum(dirt_yn == 1, na.rm = TRUE) / sum(dirt_yn >= 0, na.rm = TRUE)*100, digits=1), "%", ")" ))) %>%
  rename (settlement = settlement_barcode)

sick_exposure2 <- child %>%
  mutate (test = 1) %>%
  select (-child_name)

sick_exposure3 <- sick_exposure2 %>%    #add totals
  group_by (test) %>%
  summarise (diarrhea = noquote(paste0(sum(diarrhea1 == 1, na.rm = TRUE), "/", sum (diarrhea1 >= 0, na.rm = TRUE), " (", round(sum(diarrhea1 == 1, na.rm = TRUE) / sum(diarrhea1 >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             cough = noquote(paste0(sum(cough == 1, na.rm = TRUE), "/", sum (cough >= 0, na.rm = TRUE), " (", round(sum(cough == 1, na.rm = TRUE) / sum(cough >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             breathing = noquote(paste0(sum(breathing == 1, na.rm = TRUE), "/", sum (breathing >= 0, na.rm = TRUE), " (", round(sum(breathing == 1, na.rm = TRUE) / sum(breathing >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             fever = noquote(paste0(sum(fever == 1, na.rm = TRUE), "/", sum (fever >= 0, na.rm = TRUE), " (", round(sum(fever == 1, na.rm = TRUE) / sum(fever >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             swimming = noquote(paste0(sum(swim_yn == 1, na.rm = TRUE), "/", sum (swim_yn >= 0, na.rm = TRUE), " (", round(sum(swim_yn == 1, na.rm = TRUE) / sum(swim_yn >= 0, na.rm = TRUE)*100, digits=1), "%", ")" )),
             dirt = noquote(paste0(sum(dirt_yn == 1, na.rm = TRUE), "/", sum (dirt_yn >= 0, na.rm = TRUE), " (", round(sum(dirt_yn == 1, na.rm = TRUE) / sum(dirt_yn >= 0, na.rm = TRUE)*100, digits=1), "%", ")" ))) %>%
  rename (settlement = test) %>%
  mutate (settlement = "Totals")
sick_exposure1$test <- NULL
sick_exposure <- rbind (sick_exposure1, sick_exposure3)
rm(sick_exposure1, sick_exposure2, sick_exposure3)

symptoms <- child %>% filter (survey_check2 == 1) %>%
  mutate (diarrhea = ifelse (doctor_why_1 == 1, 1, 0),
          vomiting = ifelse (doctor_why_2 == 1, 1, 0),
          fever = ifelse (doctor_why_3 == 1, 1, 0),
          skin_infection = ifelse (doctor_why_4 == 1, 1, 0),
          breathing = ifelse (doctor_why_5 == 1, 1, 0),
          ear_throat = ifelse (doctor_why_6 == 1, 1, 0),
          not_eating = ifelse (doctor_why_7 == 1, 1, 0),
          injury = ifelse (doctor_why_8 == 1, 1, 0),
          other = ifelse (doctor_why__77 == 1, 1, 0),
          dont_know = ifelse (doctor_why__99 == 1, 1, 0),
          refused = ifelse (doctor_why__88 == 1, 1, 0),
          not_asked = ifelse (doctor_why__66 == 1, 1, 0)) %>%
  summarise (diarrhea = sum(diarrhea, na.rm = TRUE),
             vomiting = sum(vomiting, na.rm = TRUE),
             fever = sum(fever, na.rm = TRUE),
             skin_infection = sum(skin_infection, na.rm = TRUE),
             breathing = sum(breathing, na.rm = TRUE),
             ear_throat = sum(ear_throat, na.rm = TRUE),
             not_eating = sum(not_eating, na.rm = TRUE),
             injury = sum(injury, na.rm = TRUE),
             other = sum(other, na.rm = TRUE),
             dont_know = sum(dont_know, na.rm = TRUE),
             refused = sum(refused, na.rm = TRUE),
             not_asked = sum(not_asked, na.rm = TRUE))

# *****************
# *****************
# HEMOGLOBIN AND ZSCORES LEVELS

#Get Hemoglobin Levels for John - Jeff F - 16/10/2019
hemoglobin <- child %>% filter (blood_hb_yn == 1) %>%
  mutate (lessThanSeven = ifelse(blood_hb < 7, 1, 0),
          seven = ifelse((blood_hb >= 7 & blood_hb < 8), 1, 0),
          eight = ifelse((blood_hb >= 8 & blood_hb < 9), 1, 0),
          nine = ifelse((blood_hb >= 9 & blood_hb < 10), 1, 0),
          ten = ifelse((blood_hb >= 10 & blood_hb < 11), 1, 0),
          eleven = ifelse((blood_hb >= 11 & blood_hb < 12), 1, 0),
          twelve = ifelse((blood_hb >= 12 & blood_hb < 13), 1, 0),
          greaterThanThirteen = ifelse(blood_hb >= 13, 1, 0),) %>%
  summarise('<7' = sum(lessThanSeven, na.rm = TRUE),
            '7' = sum(seven, na.rm = TRUE),
            '8' = sum(eight, na.rm = TRUE),
            '9' = sum(nine, na.rm = TRUE),
            '10' = sum(ten, na.rm = TRUE),
            '11' = sum(eleven, na.rm = TRUE),
            '12' = sum(twelve, na.rm = TRUE),
            '>13' = sum(greaterThanThirteen, na.rm = TRUE))

#Get Zscores for children for John - Jeff F - 16/10/2019
zscores <- child %>% filter (!is.na(child$weight_avg) & !is.na(child$height_avg)) %>%
  mutate (age = (date("2019-10-01") - dob_pl) / 365,
         sex = ifelse(gender_pl == "male", 1, 2),
         feces = ifelse (is.na(feces_kit_barcode), feces_kit_barcode_note, feces_kit_barcode)) %>%
  select (settlement_barcode, extract_house_no, child_name, today, feces, age, sex, weight_avg, height_avg) %>%
  arrange (settlement_barcode, extract_house_no, desc(today))

zscores <- addWGSR(data = zscores,
                         sex = "sex",
                         firstPart = "weight_avg",
                         secondPart = "height_avg",
                         index = "wfh")

# remove duplicates - Jeff 31/10/2019
zscores <- distinct(zscores, settlement_barcode, extract_house_no, child_name, sex, .keep_all = TRUE)

zscores_histogram <- zscores %>%
  mutate (lessThanNegativeThree = ifelse(wfhz < -3, 1, 0),
          negative2 = ifelse((wfhz >= -3 & wfhz < -2), 1, 0),
          negative1 = ifelse((wfhz >= -2 & wfhz < -1), 1, 0),
          lessThan0 = ifelse((wfhz >= -1 & wfhz < 0), 1, 0),
          zero = ifelse((wfhz >= 0 & wfhz < 1), 1, 0),
          one = ifelse((wfhz >= 1 & wfhz < 2), 1, 0),
          two = ifelse((wfhz >= 2 & wfhz < 3), 1, 0),
          greaterThanThree = ifelse(wfhz >= 3, 1, 0),) %>%
  summarise('<-3' = sum(lessThanNegativeThree, na.rm = TRUE),
            '-2' = sum(negative2, na.rm = TRUE),
            '-1' = sum(negative1, na.rm = TRUE),
            '-0' = sum(lessThan0, na.rm = TRUE),
            '0' = sum(zero, na.rm = TRUE),
            '1' = sum(one, na.rm = TRUE),
            '2' = sum(two, na.rm = TRUE),
            '>3' = sum(greaterThanThree, na.rm = TRUE))
Monash-RISE/riseR documentation built on Dec. 11, 2019, 9:49 a.m.