Combine and check data from all countries for internal purposes. NOT FOR CIRCULATION.

For each moduel, update the following code chunks:
1. Confirm and select the latest file in import_chartbooks
2. Only for french chartbooks, open chartbook in excel and manually change the purple tab's name to English. see import_chartbooks_check_sheets.
3. Update dflist: import_chartbooks_checkmore AND import_chartbooks_append

Code is saved in the sharepoint: "*/BANICA, Sorin - HSA unit/3 Country implementation & learning/1 HFAs for COVID-19/HFA database/"

(Summary data last updated: 2021-08-31 12:47:08)

1.Check file and worksheet names

1.1. Check file names and use the latest one

path<-"C:/Users/YoonJoung Choi/World Health Organization/BANICA, Sorin - HSA unit/3 Country implementation & learning/1 HFAs for COVID-19/"
chartbooks<-"/Chartbooks"

setwd(paste0(path,"AFRO/Ghana/Round1",chartbooks))
dir()     

[1] "Archive"
[2] "GH_Community_Chartbook.xlsx"
[3] "Ghana_CEHS_Chartbook.xlsx"
[4] "Ghana_COVID19HospitalReadiness_Chartbook.xlsx" [5] "Re Need Help.msg"

setwd(paste0(path,"AFRO/Cameroun/Round1",chartbooks))
dir()     

[1] "Archive"
[2] "CMR_CEHS_Chartbook_21July2021.xlsx"
[3] "CMR_CEHS_Chartbook_30July2021.xlsx"
[4] "CMR_Community_Chartbook21July2021.xlsx"
[5] "CMR_WHO_COVID19HospitalReadiness_Chartbook_21July2021.xlsx" [6] "CMR_WHO_COVID19HospitalReadiness_Chartbook_30July2021.xlsx" [7] "Copy of CMR_Community_Chartbook30July2021.xlsx"

setwd(paste0(path,"AFRO/Kenya/Round1",chartbooks))
dir()     

[1] "Archive" "KEN_CEHS_Chartbook_R1.xlsx"
[3] "KEN_Community_Chartbook_R1.xlsx" "KEN_Hospital_Chartbook_R1.xlsx"

setwd(paste0(path,"AFRO/Kenya/Round2",chartbooks))
dir()     

[1] "Archive"
[2] "KEN_CEHS_Chartbook_R2_JK_01062021 (Jamlick).xlsx"
[3] "KEN_COVID_CEHS_HFA_Chartbook_R2_27_05_2021A.xlsx"
[4] "KEN_Hospital_Chartbook_R2_26_05_2021_JK_(Jamlick).xlsx"
[5] "Re_ EXT Re_ checking in - latest Round 2 chartbooks and introduction.msg" [6] "Trend analysis variables 12062121_.xlsx"

setwd(paste0(path,"EURO/Ukraine/Round1",chartbooks))
dir()   

[1] "WHO_CEHS_chartbook_UKRAINE_R1_v7_20210525.xlsx"

#setwd(paste0(path,"AFRO/Zambia"))
setwd(paste0(path,"AFRO/Zambia/chartbook"))
dir()   

[1] "archive"
[2] "WHO_CEHS_Zambia_Chartbook_Final_20082021.xlsx"
[3] "Zambia_WHO_COVID19HospitalReadiness_Chartbook_20082021.xlsx"

1.2. Check sheet names for non-English ones

Note: R Knitr cannot handle French. Change the purple tab name to "Indicator estimate data."

excel_sheets(paste0(path,"AFRO/Ghana/Round1",chartbooks,
                    "/Ghana_CEHS_Chartbook.xlsx"))

excel_sheets(paste0(path,"AFRO/Cameroun/Round1",chartbooks,
                    "/Archive/CMR_CEHS_Chartbook_20July21.xlsx"))
#But, need to runt this first because of the conflict issue between dplyr and plyr, which messes up rename.... 
#SEE: https://stackoverflow.com/questions/30562819/error-message-when-running-simple-rename-function-in-r/31833572

library(conflicted)
#rename
conflict_prefer("rename", "dplyr")
conflict_prefer("mutate", "dplyr")
conflict_prefer("filter", "dplyr")

2.C19CM

2.1. Import group 1 country/survey chartbooks

#https://freshbiostats.wordpress.com/2012/12/21/handling-many-data-frames-in-r/

tempCMRR1<-read_excel((paste0(path,"AFRO/Cameroun/Round1",chartbooks, "/CMR_WHO_COVID19HospitalReadiness_Chartbook_21July2021.xlsx")), 
                         #sheet = "Donn?es_estimations_indicateurs")
                         sheet = "Indicator estimate data")

tempGHAR1<-read_excel((paste0(path,"AFRO/Ghana/Round1",chartbooks, "/Ghana_COVID19HospitalReadiness_Chartbook.xlsx")), 
                         sheet = "Indicator estimate data")

tempKENR1<-read_excel((paste0(path,"AFRO/Kenya/Round1",chartbooks,
                          "/KEN_Hospital_Chartbook_R1.xlsx")), 
                         sheet = "Indicator estimate data")

tempKENR2<-read_excel((paste0(path,"AFRO/Kenya/Round2",chartbooks, "/KEN_Hospital_Chartbook_R2_26_05_2021_JK_(Jamlick).xlsx")), 
                         sheet = "Indicator estimate data")

tempZAMR1<-read_excel((paste0(path,"AFRO/Zambia/chartbook", "/Zambia_WHO_COVID19HospitalReadiness_Chartbook_20082021.xlsx")), 
                         sheet = "Indicator estimate data")

2.2. Inspect group 1 country/survey chartbooks

dflist <- list(tempCMRR1, tempGHAR1, tempKENR1, tempKENR2, tempZAMR1)

lapply(dflist, dim)
lapply(dflist, function(df) table(df$country) )

2.3. Prepare further for select individual surveys that changed indicator names

# Ghane: fix naming convention from *__02 to *__002  
    
tempGHAR1%>%select(grep("__", names(tempGHAR1)))%>%colnames() 
        
    tempGHAR1%>%
        select(grep("__", names(tempGHAR1)), 
               -grep("__00", names(tempGHAR1)),
               -grep("reason", names(tempGHAR1)))%>%
        colnames()  
    
    varlist0<-tempGHAR1%>%
        select(grep("__", names(tempGHAR1)), 
               -grep("__00", names(tempGHAR1)),
               -grep("reason", names(tempGHAR1)))%>%
        colnames() 
    varlist1<-tempGHAR1%>%
        select(grep("__1", names(tempGHAR1)), 
               -grep("__00", names(tempGHAR1)),
               -grep("reason", names(tempGHAR1)))%>%
        colnames() 
    varlist2<-tempGHAR1%>%
        select(grep("__2", names(tempGHAR1)), 
               -grep("__00", names(tempGHAR1)),
               -grep("reason", names(tempGHAR1)))%>%
        colnames()     
    varlistreasons<-tempGHAR1%>%
        select(grep("malfunction_reason__", names(tempGHAR1)))%>%
        colnames()        

    
    newnames0<-gsub('__0', '__00', varlist0)
    newnames1<-gsub('__1', '__01', varlist1)
    newnames2<-gsub('__2', '__02', varlist2)
    newnamesreasons<-gsub('reason__', 'reason__00', varlistreasons)
    
    tempGHAR1<-tempGHAR1%>%
        rename_at(vars(varlist0), ~ newnames0)%>%
        rename_at(vars(varlist1), ~ newnames1)%>%
        rename_at(vars(varlist2), ~ newnames2)%>%
        rename_at(vars(varlistreasons), ~ newnamesreasons)
    
#tempGHAR1%>%select(grep("__", names(tempGHAR1)))%>%colnames() 
tempKENR1<-tempKENR1%>%
    rename(
        xoffsitetime_1 = xtesttime_1, 
        xoffsitetime_2 = xtesttime_2, 
        xoffsitetime_3 = xtesttime_3
        )    
tempKENR2<-tempKENR2%>%
    rename(
        xoffsitetime_1 = xtesttime_1, 
        xoffsitetime_2 = xtesttime_2, 
        xoffsitetime_3 = xtesttime_3,
        xoffsitetime_4 = xtesttime_4
        )    

# Kenya R2: changes var names for covid vaccine section 

    varlist0<-tempKENR2%>%
        select(grep("xcov_training", names(tempKENR2)))%>%
        colnames()  
    varlist1<-tempKENR2%>%
        select(grep("xvac_type_prov_", names(tempKENR2)), 
               -grep("xvac_type_prov_av_", names(tempKENR2)))%>%
        colnames() 
    varlist2<-tempKENR2%>%
        select(grep("xvac_type_prov_av_", names(tempKENR2)))%>%
        colnames()     
 
    newnames0<-gsub('xcov_training_0', 'xcovax_train__0', varlist0)
    newnames1<-gsub('xvac_type_prov_0', 'xcovax_offer__0', varlist1)
    newnames2<-gsub('xvac_type_prov_av_0', 'xcovax_offerav__0', varlist2)

    tempKENR2<-tempKENR2%>%
        rename_at(vars(varlist0), ~ newnames0)%>%
        rename_at(vars(varlist1), ~ newnames1)%>%
        rename_at(vars(varlist2), ~ newnames2)
    
tempKENR2%>%select(grep("xcovax", names(tempKENR2)))%>%colnames() 
tempZAMR1<-tempZAMR1%>%
    rename(
        #incorrectly named, although the 4th sub-question was dropped
        xsafe__004 = xsafe__triage
        )   

2.4. Rename indicators ending with sub-question numbers with more friendly names. See "Template for indicators.xlsx" in the share point.

dflist <- list(tempKENR1, tempKENR2, tempCMRR1, tempGHAR1, tempZAMR1)

for(df in dflist) {
    table<-table(df$country)
    list<-df%>%select(starts_with("xsafe"))%>%colnames()
    
    print(table)
    print(list)
}
tempKENR1<- tempKENR1%>%
    rename(
        
        xdrug__ampicillin    =  xdrug__003   , 
        xdrug__ceftriaxone   =  xdrug__002   , 
        xdrug__azithromycin  =  xdrug__004   , 
        xdrug__dexamethasone     =  xdrug__009   , 
        xdrug__heparin   =  xdrug__008   , 
        xdrug__morphine  =  xdrug__007   , 
        xdrug__haloperidol   =  xdrug__006   , 
        xdrug__epinephrine   =  xdrug__001   , 
        xdrug__saline    =  xdrug__010   , 
        xdrug__cistracurium  =  xdrug__005   , 
                            
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__syringe     =  xsupply__001     , 
        xsupply__gauze   =  xsupply__003     , 
        xsuuply__chlorexidine    =  xsupply__004     , 
        xsupply__chlorine    =  xsupply__005     ,  
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
                
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
        xppe_all__mask_cloth     =  xppe_allsome__006    , 
                    
        xipcitem__soap   =  xipcitem__001    , 
        xipcitem__sanitizer  =  xipcitem__006    , 
        xipcitem__biobag     =  xipcitem__002    , 
        xipcitem__boxes  =  xipcitem__003    , 
        xipcitem__bodybags   =  xipcitem__004    , 
        xipcitem__handwash   =  xipcitem__005    , 
                    
        xspcmitem__transport     =  xspcmitem__001   , 
        xspcmitem__swab  =  xspcmitem__002   , 
                    
        xoffsitetime_24hours     =  xoffsitetime_1   , 
        xoffsitetime_2days   =  xoffsitetime_2   , 
        xoffsitetime_3days   =  xoffsitetime_3   , 
                    
        xequip_anyfunction__xray     =  xequip_anyfunction__001  , 
        xequip_anyfunction__oximeters    =  xequip_anyfunction__002  , 
        xequip_anyfunction__vicu     =  xequip_anyfunction__003  , 
        xequip_anyfunction__vnoninv  =  xequip_anyfunction__004  , 
                    
        xequip_allfunction__xray     =  xequip_allfunction__001  , 
        xequip_allfunction__oximeters    =  xequip_allfunction__002  , 
        xequip_allfunction__vicu     =  xequip_allfunction__003  , 
        xequip_allfunction__vnoninv  =  xequip_allfunction__004  , 
                    
        #xequip_anymalfunction__vicu     =  xequip_anymalfunction__003   , 
        #xequip_anymalfunction__vnoninv  =  xequip_anymalfunction__004   , 
                    
        xequip_malfunction_reason__inst  =  xequip_malfunction_reason__001   , 
        xequip_malfunction_reason__cons  =  xequip_malfunction_reason__003   , 
        xequip_malfunction_reason__staff     =  xequip_malfunction_reason__004   , 
        xequip_malfunction_reason__funds     =  xequip_malfunction_reason__005   , 
        #xequip_malfunction_reason__other    =  xequip_malfunction_reason__006   , 
        xequip_malfunction_reason__train     =  xequip_malfunction_reason__002   
    )
tempKENR2<- tempKENR2%>%
    rename(
        xdrug__ampicillin    =  xdrug__003   , 
        xdrug__ceftriaxone   =  xdrug__002   , 
        xdrug__azithromycin  =  xdrug__004   , 
        xdrug__dexamethasone     =  xdrug__009   , 
        xdrug__heparin   =  xdrug__008   , 
        xdrug__morphine  =  xdrug__007   , 
        xdrug__haloperidol   =  xdrug__006   , 
        xdrug__epinephrine   =  xdrug__001   , 
        xdrug__saline    =  xdrug__010   , 
        xdrug__cistracurium  =  xdrug__005   , 
                    
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__syringe     =  xsupply__001     , 
        xsupply__gauze   =  xsupply__003     , 
        xsuuply__chlorexidine    =  xsupply__004     , 
        xsupply__chlorine    =  xsupply__005     , 
        
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
                    
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
                    
        xipcitem__soap   =  xipcitem__001    , 
        xipcitem__sanitizer  =  xipcitem__006    , 
        xipcitem__biobag     =  xipcitem__002    , 
        xipcitem__boxes  =  xipcitem__003    , 
        xipcitem__bodybags   =  xipcitem__004    , 
        xipcitem__handwash   =  xipcitem__005    , 
        
        xppe_maskdispose__redbin     =  xppe_maskdispose__001    , 
        xppe_maskdispose__yellowbin  =  xppe_maskdispose__002    , 
        xppe_maskdispose__blackbin   =  xppe_maskdispose__003    , 
        xppe_maskdispose__landfill   =  xppe_maskdispose__004    , 
        xppe_maskdispose__incinerate     =  xppe_maskdispose__005    , 
        xppe_coveralldispose__redbin     =  xppe_coveralldispose__001    , 
        xppe_coveralldispose__yellowbin  =  xppe_coveralldispose__002    , 
        xppe_coveralldispose__blackbin   =  xppe_coveralldispose__003    , 
        xppe_coveralldispose__landfill   =  xppe_coveralldispose__004    , 
        xppe_coveralldispose__incerate   =  xppe_coveralldispose__005    , 
                    
        #xspcmitem__transport    =  xspcmitem__001   , 
        #xspcmitem__swab     =  xspcmitem__002   , 
                    
        xoffsitetime_24hours     =  xoffsitetime_1   , 
        xoffsitetime_2days   =  xoffsitetime_2   , 
        xoffsitetime_3days   =  xoffsitetime_3   , 
        xoffsitetime_3daysplus   =  xoffsitetime_4   , 
                    
        xequip_anyfunction__xray     =  xequip_anyfunction__001  , 
        xequip_anyfunction__oximeters    =  xequip_anyfunction__002  , 
        xequip_anyfunction__vicu     =  xequip_anyfunction__003  , 
        xequip_anyfunction__vnoninv  =  xequip_anyfunction__004  , 
                    
        xequip_allfunction__xray     =  xequip_allfunction__001  , 
        xequip_allfunction__oximeters    =  xequip_allfunction__002  , 
                    
        xequip_anymalfunction__vicu  =  xequip_anymalfunction__003   , 
        xequip_anymalfunction__vnoninv   =  xequip_anymalfunction__004   , 
                    
        xequip_malfunction_reason__inst  =  xequip_malfunction_reason__001   , 
        xequip_malfunction_reason__cons  =  xequip_malfunction_reason__003   , 
        xequip_malfunction_reason__staff     =  xequip_malfunction_reason__004   , 
        xequip_malfunction_reason__funds     =  xequip_malfunction_reason__005   , 
        #xequip_malfunction_reason__other    =  xequip_malfunction_reason__006   , 
        xequip_malfunction_reason__train     =  xequip_malfunction_reason__002   , 
                
        xcovax_offer__pfizer     =   xcovax_offer__001   , 
        xcovax_offerav__pfizer   =   xcovax_offerav__001     , 
        xcovax_offer__moderna    =   xcovax_offer__002   , 
        xcovax_offerav__moderna  =   xcovax_offerav__002     , 
        xcovax_offer__astra  =   xcovax_offer__003   , 
        xcovax_offerav__astra    =   xcovax_offerav__003     , 
        xcovax_offer__jj     =   xcovax_offer__004   , 
        xcovax_offerav__jj   =   xcovax_offerav__004     , 
        xcovax_offer__sputnik    =   xcovax_offer__005   , 
        xcovax_offerav__sputnik  =   xcovax_offerav__005     , 
        
        xcovax_train__storage    =   xcovax_train__002   , 
        xcovax_train__admin  =   xcovax_train__003   , 
        xcovax_train__manage_adverse     =   xcovax_train__004   , 
        xcovax_train__report_adverse     =   xcovax_train__005   , 
        xcovax_train__setup  =  xcovax_train__001    , 
        xcovax_train__waste  =  xcovax_train__006    , 
        xcovax_train__ipc    =  xcovax_train__007    , 
        xcovax_train__target     =  xcovax_train__008    , 
        xcovax_train__data   =  xcovax_train__009    , 
        
        xcold_storage__2_8   =  xcold_storage_001    , 
        xcold_storage__lt20  =  xcold_storage_002    , 
        xcold_storage__lt70  =  xcold_storage_003    
    )
tempCMRR1<- tempCMRR1%>%
    rename(
        xtraining__ipc   =  xtraining__001   , 
        xtraining__ppe   =  xtraining__002   , 
        xtraining__triage    =  xtraining__003   , 
        xtraining__emerg     =  xtraining__005   , 
        xtraining__mental    =  xtraining__006   , 
        xtraining__ss_ipc    =  xtraining__007   , 
        xtraining__ss_ppe    =  xtraining__008   , 
        xtraining__ss_c19cm  =  xtraining__009   , 
        xtraining__c19cm     =  xtraining__004   , 
        
        xdrug__chlorine  =  xdrug__002   , 
        xdrug__paracetamol   =  xdrug__010   , 
        xdrug__ampicillin    =  xdrug__005   , 
        xdrug__ceftriaxone   =  xdrug__004   , 
        xdrug__azithromycin  =  xdrug__006   , 
        xdrug__dexamethasone     =  xdrug__011   , 
        xdrug__heparin   =  xdrug__012   , 
        xdrug__rocuronium    =  xdrug__007   , 
        xdrug__morphine  =  xdrug__009   , 
        xdrug__haloperidol   =  xdrug__008   , 
        xdrug__epinephrine   =  xdrug__003   , 
        xdrug__saline    =  xdrug__013   , 
        xdrug__oxygen    =  xdrug__014   , 
        xrdrug__chlorhex     =  xdrug__001   , 
        
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__syringe     =  xsupply__001     , 
        xsupply__gauze   =  xsupply__003     , 
                
        xsafe__entrance_screening    =  xsafe__001   , 
        xsafe__staff_entrance    =  xsafe__002   , 
        xsafe__sep_room  =  xsafe__003   , 
        xsafe__triage_c19    =  xsafe__triage    , 
        xsafe__isolatareas   =  xsafe__isolation     , 
        xsafe__distancing    =  xsafe__006   , 
        xsafe__hygiene_instructions  =  xsafe__007   , 
        xsafe__hygiene_stations  =  xsafe__008   , 
        xsafe__ppe   =  xsafe__009   , 
        xsafe__cleaning  =  xsafe__010   , 
                    
        xguideline__screening    =  xguideline__001  , 
        xguideline__c19_manage   =  xguideline__002  , 
        xguideline__c19_surveillance     =  xguideline__003  , 
        xguideline__deadbody     =  xguideline__004  , 
        xguideline__waste    =  xguideline__005  , 
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
                    
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
        
        xipcitem__soap   =  xipcitem__001    , 
        xipcitem__sanitizer  =  xipcitem__002    , 
        xipcitem__biobag     =  xipcitem__003    , 
        xipcitem__boxes  =  xipcitem__004    , 
        xipcitem__bodybags   =  xipcitem__005    ,
                    
        xspcmitem__transport     =  xspcmitem__001   , 
        xspcmitem__swab  =  xspcmitem__002   , 
                    
        xoffsitetime_24hours     =  xoffsitetime_1   , 
        xoffsitetime_2days   =  xoffsitetime_2   , 
        xoffsitetime_3days   =  xoffsitetime_3   , 
        xoffsitetime_7days   =  xoffsitetime_7   , 
                    
        xequip_anyfunction__xray     =  xequip_anyfunction__001  , 
        xequip_anyfunction__oximeters    =  xequip_anyfunction__002  , 
        xequip_anyfunction__vicu     =  xequip_anyfunction__003  , 
        xequip_anyfunction__vnoninv  =  xequip_anyfunction__004  , 
                    
        xequip_allfunction__xray     =  xequip_allfunction__001  , 
        xequip_allfunction__oximeters    =  xequip_allfunction__002  , 
        xequip_allfunction__vicu     =  xequip_allfunction__003  , 
        xequip_allfunction__vnoninv  =  xequip_allfunction__004  , 
                    
        xequip_anymalfunction__vicu  =  xequip_anymalfunction__003   , 
        xequip_anymalfunction__vnoninv   =  xequip_anymalfunction__004   , 
                    
        xequip_malfunction_reason__inst  =  xequip_malfunction_reason__001   , 
        xequip_malfunction_reason__cons  =  xequip_malfunction_reason__002   , 
        xequip_malfunction_reason__staff     =  xequip_malfunction_reason__003   , 
        xequip_malfunction_reason__funds     =  xequip_malfunction_reason__004   , 
        xequip_malfunction_reason__power     =  xequip_malfunction_reason__005   
        #xequip_malfunction_reason__other    =  xequip_malfunction_reason__006   
                
    )
tempGHAR1<- tempGHAR1%>%
    rename(
        xtraining__ipc   =  xtraining__001   , 
        xtraining__ppe   =  xtraining__002   , 
        xtraining__triage    =  xtraining__003   , 
        xtraining__emerg     =  xtraining__004   , 
        xtraining__remote    =  xtraining__005   , 
        xtraining__mental    =  xtraining__006   , 
        xtraining__ss_ipc    =  xtraining__007   , 
        xtraining__ss_ppe    =  xtraining__008   , 
        xtraining__ss_c19cm  =  xtraining__009   , 
        
        xdrug__chlorine  =  xdrug__002   , 
        xdrug__paracetamol   =  xdrug__010   , 
        xdrug__ampicillin    =  xdrug__005   , 
        xdrug__ceftriaxone   =  xdrug__004   , 
        xdrug__azithromycin  =  xdrug__006   , 
        xdrug__dexamethasone     =  xdrug__011   , 
        xdrug__tocilizumab   =  xdrug__023   , 
        xdrug__heparin   =  xdrug__012   , 
        xdrug__rocuronium    =  xdrug__007   , 
        xdrug__morphine  =  xdrug__009   , 
        xdrug__haloperidol   =  xdrug__008   , 
        xdrug__epinephrine   =  xdrug__003   , 
        xdrug__saline    =  xdrug__013   , 
        xdrug__oxygen    =  xdrug__014   , 
        xrdrug__chlorhex     =  xdrug__001   , 
        xdrug__hydroxychloroquine    =  xdrug__015   , 
        xdrug__chloroquinephosphate  =  xdrug__016   , 
        xdrug__doxycycline   =  xdrug__017   , 
        xdrug__methylprednisolone    =  xdrug__018   , 
        xdrug__prednisolone  =  xdrug__019   , 
        xdrug__enoxaparin    =  xdrug__020   , 
        xdrug__dalteparin    =  xdrug__021   , 
        xdrug__rivaroxaban   =  xdrug__022   , 
        xdrug__remdesivir    =  xdrug__024   , 
                
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__syringe     =  xsupply__001     , 
        xsupply__gauze   =  xsupply__003     , 
        
        xsafe__entrance_screening    =  xsafe__001   , 
        xsafe__staff_entrance    =  xsafe__002   , 
        xsafe__sep_room  =  xsafe__003   , 
        xsafe__triage_c19    =  xsafe__triage    , 
        xsafe__isolatareas   =  xsafe__isolation     , 
        xsafe__triage_guidelines     =  xsafe__006   , 
        xsafe__distancing    =  xsafe__007   , 
        xsafe__hygiene_instructions  =  xsafe__008   , 
        xsafe__hygiene_stations  =  xsafe__009   , 
        xsafe__ppe   =  xsafe__010   , 
        xsafe__cleaning  =  xsafe__011   , 
                    
        xguideline__screening    =  xguideline__001  , 
        xguideline__c19_manage   =  xguideline__002  , 
        xguideline__ppe  =  xguideline__003  , 
        xguideline__c19_surveillance     =  xguideline__004  , 
        xguideline__deadbody     =  xguideline__005  , 
        xguideline__waste    =  xguideline__006  , 
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
        #xppe_allsome__mask_cloth    =  xppe_allsome__007    , 
                    
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
        #xppe_all__mask_cloth    =  xppe_all__007    , 
                    
        xipcitem__soap   =  xipcitem__001    , 
        xipcitem__sanitizer  =  xipcitem__002    , 
        xipcitem__biobag     =  xipcitem__003    , 
        xipcitem__boxes  =  xipcitem__004    , 
        xipcitem__bodybags   =  xipcitem__005    , 
        xipcitem__chlorine   =  xipcitem__006    , 
                    
        xspcmitem__transport     =  xspcmitem__001   , 
        xspcmitem__swab  =  xspcmitem__002   , 
                    
        xoffsitetime_24hours     =  xoffsitetime_1   , 
        xoffsitetime_2days   =  xoffsitetime_2   , 
        xoffsitetime_3days   =  xoffsitetime_3   , 
        xoffsitetime_7days   =  xoffsitetime_7   , 
            
        xequip_anyfunction__xray     =  xequip_anyfunction__001  , 
        xequip_anyfunction__oximeters    =  xequip_anyfunction__002  , 
        xequip_anyfunction__vicu     =  xequip_anyfunction__003  , 
        xequip_anyfunction__vnoninv  =  xequip_anyfunction__004  , 
                    
        xequip_allfunction__xray     =  xequip_allfunction__001  , 
        xequip_allfunction__oximeters    =  xequip_allfunction__002  , 
        xequip_allfunction__vicu     =  xequip_allfunction__003  , 
        xequip_allfunction__vnoninv  =  xequip_allfunction__004  , 
                    
        xequip_anymalfunction__vicu  =  xequip_anymalfunction__003   , 
        xequip_anymalfunction__vnoninv   =  xequip_anymalfunction__004   , 
                    
        xequip_malfunction_reason__inst  =  xequip_malfunction_reason__001   , 
        xequip_malfunction_reason__cons  =  xequip_malfunction_reason__002   , 
        xequip_malfunction_reason__staff     =  xequip_malfunction_reason__003   , 
        xequip_malfunction_reason__funds     =  xequip_malfunction_reason__004   , 
        xequip_malfunction_reason__power     =  xequip_malfunction_reason__005   , 
        xequip_malfunction_reason__other     =  xequip_malfunction_reason__007   , 
        xequip_malfunction_reason__train     =  xequip_malfunction_reason__006   , 
                    
        xcovax_offer__pfizer     =   xcovax_offer__001   , 
        xcovax_offerav__pfizer   =   xcovax_offerav__001     , 
        xcovax_offer__moderna    =   xcovax_offer__002   , 
        xcovax_offerav__moderna  =   xcovax_offerav__002     , 
        xcovax_offer__astra  =   xcovax_offer__003   , 
        xcovax_offerav__astra    =   xcovax_offerav__003     , 
        xcovax_offer__jj     =   xcovax_offer__004   , 
        xcovax_offerav__jj   =   xcovax_offerav__004     , 
        
        xcovax_train__storage    =   xcovax_train__001   , 
        xcovax_train__admin  =   xcovax_train__002   , 
        xcovax_train__manage_adverse     =   xcovax_train__003   , 
        xcovax_train__report_adverse     =   xcovax_train__004   
    )
tempZAMR1<- tempZAMR1%>%
    rename(
        xtraining__ipc   =  xtraining__001   , 
        xtraining__ppe   =  xtraining__002   , 
        xtraining__triage    =  xtraining__003   , 
        xtraining__emerg     =  xtraining__004   , 
        xtraining__remote    =  xtraining__005   , 
        xtraining__mental    =  xtraining__006   , 
        xtraining__ss_ipc    =  xtraining__007   , 
        xtraining__ss_ppe    =  xtraining__008   , 
        xtraining__ss_c19cm  =  xtraining__009   , 
        
        xdrug__chlorine  =  xdrug__002   , 
        xdrug__paracetamol   =  xdrug__010   , 
        xdrug__ampicillin    =  xdrug__005   , 
        xdrug__ceftriaxone   =  xdrug__004   , 
        xdrug__azithromycin  =  xdrug__006   , 
        xdrug__dexamethasone     =  xdrug__011   , 
        xdrug__heparin   =  xdrug__012   , 
        xdrug__rocuronium    =  xdrug__007   , 
        xdrug__morphine  =  xdrug__009   , 
        xdrug__haloperidol   =  xdrug__008   , 
        xdrug__epinephrine   =  xdrug__003   , 
        xdrug__saline    =  xdrug__013   , 
        xdrug__oxygen    =  xdrug__014   , 
        xrdrug__chlorhex     =  xdrug__001   , 
        
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__syringe     =  xsupply__001     , 
        xsupply__gauze   =  xsupply__003     , 
        
        xsafe__entrance_screening    =  xsafe__001   , 
        xsafe__staff_entrance    =  xsafe__006   , 
        #xsafe__triage_c19   =  xsafe__triage    , 
        xsafe__isolatareas   =  xsafe__isolation     , 
        xsafe__triage_guidelines     =  xsafe__004   , 
        xsafe__distancing    =  xsafe__002   , 
        xsafe__hygiene_instructions  =  xsafe__003   , 
        xsafe__hygiene_stations  =  xsafe__007   , 
        xsafe__ppe   =  xsafe__008   , 
        xsafe__cleaning  =  xsafe__009   , 
                    
        xguideline__screening    =  xguideline__001  , 
        xguideline__c19_manage   =  xguideline__002  , 
        xguideline__ppe  =  xguideline__003  , 
        xguideline__c19_surveillance     =  xguideline__004  , 
        xguideline__deadbody     =  xguideline__005  , 
        xguideline__waste    =  xguideline__006  , 
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
        
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
                    
        xipcitem__soap   =  xipcitem__001    , 
        xipcitem__sanitizer  =  xipcitem__002    , 
        xipcitem__biobag     =  xipcitem__003    , 
        xipcitem__boxes  =  xipcitem__004    , 
        xipcitem__bodybags   =  xipcitem__005    , 
        
        xspcmitem__transport     =  xspcmitem__001   , 
        xspcmitem__swab  =  xspcmitem__002   , 
                    
        xoffsitetime_24hours     =  xoffsitetime_1   , 
        xoffsitetime_2days   =  xoffsitetime_2   , 
        xoffsitetime_3days   =  xoffsitetime_3   , 
        xoffsitetime_7days   =  xoffsitetime_7   , 
                    
        xequip_anyfunction__xray     =  xequip_anyfunction__001  , 
        xequip_anyfunction__oximeters    =  xequip_anyfunction__002  , 
        xequip_anyfunction__vicu     =  xequip_anyfunction__003  , 
        xequip_anyfunction__vnoninv  =  xequip_anyfunction__004  , 
        
        xequip_allfunction__xray     =  xequip_allfunction__001  , 
        xequip_allfunction__oximeters    =  xequip_allfunction__002  , 
        xequip_allfunction__vicu     =  xequip_allfunction__003  , 
        xequip_allfunction__vnoninv  =  xequip_allfunction__004  , 
        
        xequip_anymalfunction__vicu  =  xequip_anymalfunction__003   , 
        xequip_anymalfunction__vnoninv   =  xequip_anymalfunction__004   , 
                    
        xequip_malfunction_reason__inst  =  xequip_malfunction_reason__001   , 
        xequip_malfunction_reason__cons  =  xequip_malfunction_reason__002   , 
        xequip_malfunction_reason__staff     =  xequip_malfunction_reason__003   , 
        xequip_malfunction_reason__funds     =  xequip_malfunction_reason__004   , 
        xequip_malfunction_reason__power     =  xequip_malfunction_reason__005   , 
        #xequip_malfunction_reason__other    =  xequip_malfunction_reason__006   , 
                    
        xcovax_offer__pfizer     =   xcovax_offer__001   , 
        xcovax_offerav__pfizer   =   xcovax_offerav__001     , 
        xcovax_offer__moderna    =   xcovax_offer__002   , 
        xcovax_offerav__moderna  =   xcovax_offerav__002     , 
        xcovax_offer__astra  =   xcovax_offer__003   , 
        xcovax_offerav__astra    =   xcovax_offerav__003     , 
        xcovax_offer__jj     =   xcovax_offer__004   , 
        xcovax_offerav__jj   =   xcovax_offerav__004     , 
        xcovax_offer__sinopharm  =   xcovax_offer__005   , 
        xcovax_offerav__sinopharm    =   xcovax_offerav__005     , 
        xcovax_offer__sinovac    =   xcovax_offer__006   , 
        xcovax_offerav__sinovac  =   xcovax_offerav__006     , 
        
        xcovax_train__storage    =   xcovax_train__001   , 
        xcovax_train__admin  =   xcovax_train__002   , 
        xcovax_train__manage_adverse     =   xcovax_train__003   , 
        xcovax_train__report_adverse     =   xcovax_train__004   
    )

2.5. Append country/survey chartbooks

#dtaC19CM<-rbind(temp1, temp2, temp3, temp4)
#dtaC19CM<-bind_rows(temp1, temp2, temp3, temp4)
#deal with different number of columns + different type of columns 

dflist <- list(tempCMRR1, tempGHAR1, tempKENR1, tempKENR2, tempZAMR1)

dtaC19CM<-rbindlist(dflist,
                   fill=TRUE)

class(dtaC19CM)
dim(dtaC19CM)
table(dtaC19CM$country)

str(dtaC19CM[, 1:10])

2.6. Further cleaning

# Drop empty rows 
dtaC19CM<-dtaC19CM%>%
    filter(country!="")%>%
    mutate(
        #https://unstats.un.org/unsd/tradekb/knowledgebase/country-code   
        countrycode="",
        countrycode=
            ifelse(tolower(country)=="cameroon", "CMR", 
            ifelse(tolower(country)=="kenya", "KEN", 
            ifelse(tolower(country)=="ukraine", "UKR", 
            ifelse(tolower(country)=="zambia", "ZMB", 
            ifelse(tolower(country)=="namibia", "NAM", 
            ifelse(tolower(country)=="peru", "PER", 
            ifelse(tolower(country)=="suriname", "SUR", 
            ifelse(tolower(country)=="ghana", "GHA", 
                   countrycode))))))))    
    )%>%    
    mutate(survey=paste0(countrycode,"_R",round))%>%
    rename(
        updatedate_survey = updatedate, 
        updatetime_survey = updatetime
    )%>%
    #mutate(updatedatetime=as.Date(Sys.time(    ), format='%d%b%Y'))
    mutate(updatedatetime=Sys.time() )
    
# CHECK if all numeric variables are indded numeric - and FIX it   
    dtaC19CM%>%select(starts_with("obs"))%>%str()
    
    dtaC19CM%>%select(starts_with("y"))%>%str()
    
    dtaC19CM%>%select(starts_with("x"))%>%str()
    
    dtaC19CM%>%select(starts_with("staff"))%>%str()
    
    dtaC19CM%>%select(-starts_with(c("x", "y", "obs", "staff")))%>%colnames()
  
varlist<-dtaC19CM%>%
    select(starts_with(c("x", "y", "obs", "staff")))%>%
    colnames()

dtaC19CM<-dtaC19CM%>%
    mutate_at(vars(varlist), funs(as.numeric))
 
# TRANSLATE French to English 
table(dtaC19CM$group, dtaC19CM$survey)

dtaC19CM<-dtaC19CM%>%
    mutate(
        group=replace(group, grepl("Tout", group)==TRUE, "All"),
        group=replace(group, grepl("Gestion", group)==TRUE, "Sector"),
        group=replace(group, grepl("Cat?gorie", group)==TRUE, "Level"),
        grouplabel=replace(grouplabel, grepl("Tout", grouplabel)==TRUE, "All")
        )%>%
    
# KEEP only common analyais domain   
    filter(group=="All"| group=="Level" | group=="Location" | group=="Sector")

table(dtaC19CM$grouplabel, dtaC19CM$survey)

2.7. Export

dta<-dtaC19CM

setcolorder(dta, 
            c("updatedatetime", "updatedate_survey", "updatetime_survey",
               "country", "round", "year", "month", 
              "group", "grouplabel"))

write.csv(dta, 
          paste0(path,"HFA database/Archive/C19CM_all_countries.csv"),
          row.names=FALSE)

dta<-dta%>%filter(group=="All")

pathdashboard<-"C:/Users/YoonJoung Choi/World Health Organization/BANICA, Sorin - HSA unit/2 Global goods & tools/2 HFAs/1 HFAs for COVID-19/7. Dashboards/Data/"

write.csv(dta, 
          paste0(pathdashboard,"C19CM_all_countries_national.csv"),
          row.names=FALSE)

3. CEHS

3.1. Import group 1 country/survey chartbooks

#https://freshbiostats.wordpress.com/2012/12/21/handling-many-data-frames-in-r/

tempCMRR1<-read_excel((paste0(path,"AFRO/Cameroun/Round1",chartbooks,
                                 "/CMR_CEHS_Chartbook_21July2021.xlsx")), 
                         #sheet = "Donn?es_estimations_indicateurs")
                         sheet = "Indicator estimate data")

tempGHAR1<-read_excel((paste0(path,"AFRO/Ghana/Round1",chartbooks,
                                 "/Ghana_CEHS_Chartbook.xlsx")), 
                         sheet = "Indicator estimate data")

tempKENR1<-read_excel((paste0(path,"AFRO/Kenya/Round1",chartbooks,
                                 "/KEN_CEHS_Chartbook_R1.xlsx")), 
                         sheet = "Indicator estimate data")

tempKENR2<-read_excel((paste0(path,"AFRO/Kenya/Round2",chartbooks,
                                 "/KEN_CEHS_Chartbook_R2_JK_01062021 (Jamlick).xlsx")), 
                         sheet = "Indicator estimate data")

tempUKRR1<-read_excel((paste0(path,"EURO/Ukraine/Round1",chartbooks,
                          "/WHO_CEHS_chartbook_UKRAINE_R1_v7_20210525.xlsx")), 
                         sheet = "Indicator estimate data")

tempZAMR1<-read_excel((paste0(path,"AFRO/Zambia/chartbook", "/WHO_CEHS_Zambia_Chartbook_Final_20082021.xlsx")), 
                         sheet = "Indicator estimate data")

3.2. Inspect group 1 country/survey chartbooks

dflist <- list(tempCMRR1, tempGHAR1, tempKENR1, tempKENR2, tempUKRR1, tempZAMR1)

lapply(dflist, dim)

3.3. Prepare further for select individual surveys that changed indicator names

# Ghane: fix naming convention - e.g., from *__02 to *__002  
    
tempGHAR1%>%select(grep("_0", names(tempGHAR1)))%>%colnames() 

    tempGHAR1%>%
        select(grep("_now_", names(tempGHAR1)), 
               grep("_last_", names(tempGHAR1)))%>%
        colnames()  
    
    varlist0<-tempGHAR1%>%
        select(grep("_now_", names(tempGHAR1)), 
               grep("_last_", names(tempGHAR1)))%>%
        colnames()  
    #varlist1<-tempGHAR1%>%
    #    select(starts_with("ximage_av"))%>%
    #    colnames() 

    newnames0<-gsub('_0', '_00', varlist0)
    #newnames1<-gsub('_00', '__00', varlist1)

    tempGHAR1<-tempGHAR1%>%
        rename_at(vars(varlist0), ~ newnames0)

#tempGHAR1%>%select(grep("__", names(tempGHAR1)))%>%colnames() 
# Kenya R2: changes var names for covid vaccine section 

    varlist0<-tempKENR2%>%
        select(grep("xcov_training", names(tempKENR2)))%>%
        colnames()  
    varlist1<-tempKENR2%>%
        select(grep("xvac_type_prov_", names(tempKENR2)), 
               -grep("xvac_type_prov_av_", names(tempKENR2)))%>%
        colnames() 
    varlist2<-tempKENR2%>%
        select(grep("xvac_type_prov_av_", names(tempKENR2)))%>%
        colnames()     
 
    newnames0<-gsub('xcov_training_0', 'xcovax_train__0', varlist0)
    newnames1<-gsub('xvac_type_prov_0', 'xcovax_offer__0', varlist1)
    newnames2<-gsub('xvac_type_prov_av_0', 'xcovax_offerav__0', varlist2)

    tempKENR2<-tempKENR2%>%
        rename_at(vars(varlist0), ~ newnames0)%>%
        rename_at(vars(varlist1), ~ newnames1)%>%
        rename_at(vars(varlist2), ~ newnames2)
    
#tempKENR2%>%select(grep("xcovax", names(tempKENR2)))%>%colnames() 
tempZAMR1<-tempZAMR1%>%
    rename(
        #Ah, during analysis indicator numbers shifted - intentioanlly. See do file. 
        xopt_decrease_reason__011 = xopt_decrease_reason__010,
        xopt_decrease_reason__010 = xopt_decrease_reason__009,
        xopt_decrease_reason__009 = xopt_decrease_reason__008,
        xopt_decrease_reason__008 = xopt_decrease_reason__007,
        xopt_decrease_reason__007 = xopt_decrease_reason__006,
        xopt_decrease_reason__006 = xopt_decrease_reason__005
    )
# Kenya R2: changes var names for covid vaccine section 

    varlist0<-tempCMRR1%>%
        select(grep("ptmild", names(tempCMRR1)))%>%
        colnames()     
 
    newnames0<-gsub('ptmild', 'pthbsi', varlist0)
    
    tempCMRR1<-tempCMRR1%>%
        rename_at(vars(varlist0), ~ newnames0)
    
#tempCMRR1%>%select(grep("pthbsi", names(tempCMRR1)))%>%colnames() 

3.4. Rename indicators ending with sub-question numbers with more friendly names. See "Template for indicators.xlsx" in the share point.

#dflist <- list(tempCMRR1, tempGHAR1, tempKENR1, tempKENR2, tempUKRR1, tempZAMR1)
dflist <- list(tempCMRR1)

for(df in dflist) {
    print(table(df$country))
    print(table(df$round))
    #print(df%>%select(starts_with(""))%>%colnames())
    print(df%>%select(grep("ptmild", names(df)))%>%colnames())
    
}  
tempKENR1<- tempKENR1%>%
    rename(
        xtraining__ipc   =  xtraining__001   , 
        xtraining__ppe   =  xtraining__002   , 
        xtraining__triage    =  xtraining__003   , 
        xtraining__emerg     =  xtraining__004   , 
        xtraining__remote    =  xtraining__005   , 
        xtraining__mental    =  xtraining__006   , 
        xtraining__ss_ipc    =  xtraining__007   , 
        xtraining__ss_ppe    =  xtraining__008   , 
        xtraining__ss_homebased  =  xtraining__009   , 
        xtraining__virtual_cme   =  xtraining__010   , 
                    
        xopt_increase__undiff    =  xopt_increase__001   , 
        xopt_increase__fp    =  xopt_increase__002   , 
        xopt_increase__anc   =  xopt_increase__003   , 
        xopt_increase__pnc   =  xopt_increase__004   ,  
        xopt_increase__immun     =  xopt_increase__005   , 
        xopt_increase__sickchild     =  xopt_increase__006   , 
        xopt_increase__hiv   =  xopt_increase__007   , 
        xopt_increase__tb    =  xopt_increase__008   , 
        xopt_increase__std   =  xopt_increase__009   , 
        xopt_increase__malaria   =  xopt_increase__010   , 
        xopt_increase__cvd   =  xopt_increase__011   , 
        xopt_increase__crd   =  xopt_increase__012   , 
        xopt_increase__diabetes  =  xopt_increase__013   , 
        xopt_increase__cancer    =  xopt_increase__014   , 
        xopt_increase__mental    =  xopt_increase__015   , 
        xopt_increase__violence  =  xopt_increase__016   , 
        xopt_increase__ntd   =  xopt_increase__017   , 
        xopt_increase__rehab     =  xopt_increase__018   , 
        xopt_decrease__undiff    =  xopt_decrease__001   , 
        xopt_decrease__fp    =  xopt_decrease__002   , 
        xopt_decrease__anc   =  xopt_decrease__003   , 
        xopt_decrease__pnc   =  xopt_decrease__004   , 
        xopt_decrease__immun     =  xopt_decrease__005   , 
        xopt_decrease__sickchild     =  xopt_decrease__006   , 
        xopt_decrease__hiv   =  xopt_decrease__007   , 
        xopt_decrease__tb    =  xopt_decrease__008   , 
        xopt_decrease__std   =  xopt_decrease__009   , 
        xopt_decrease__malaria   =  xopt_decrease__010   , 
        xopt_decrease__cvd   =  xopt_decrease__011   , 
        xopt_decrease__crd   =  xopt_decrease__012   , 
        xopt_decrease__diabetes  =  xopt_decrease__013   , 
        xopt_decrease__cancer    =  xopt_decrease__014   , 
        xopt_decrease__mental    =  xopt_decrease__015   , 
        xopt_decrease__violence  =  xopt_decrease__016   , 
        xopt_decrease__ntd   =  xopt_decrease__017   , 
        xopt_decrease__rehab     =  xopt_decrease__018   , 
        xopt_nochange__undiff    =  xopt_nochange__001   , 
        xopt_nochange__fp    =  xopt_nochange__002   , 
        xopt_nochange__anc   =  xopt_nochange__003   , 
        xopt_nochange__pnc   =  xopt_nochange__004   , 
        xopt_nochange__immun     =  xopt_nochange__005   , 
        xopt_nochange__sickchild     =  xopt_nochange__006   , 
        xopt_nochange__hiv   =  xopt_nochange__007   , 
        xopt_nochange__tb    =  xopt_nochange__008   , 
        xopt_nochange__std   =  xopt_nochange__009   , 
        xopt_nochange__malaria   =  xopt_nochange__010   , 
        xopt_nochange__cvd   =  xopt_nochange__011   , 
        xopt_nochange__crd   =  xopt_nochange__012   , 
        xopt_nochange__diabetes  =  xopt_nochange__013   , 
        xopt_nochange__cancer    =  xopt_nochange__014   , 
        xopt_nochange__mental    =  xopt_nochange__015   , 
        xopt_nochange__violence  =  xopt_nochange__016   , 
        xopt_nochange__ntd   =  xopt_nochange__017   , 
        xopt_nochange__rehab     =  xopt_nochange__018   , 
                    
        xopt_increase_reason__more_ari   =  xopt_increase_reason__001    , 
        xopt_increase_reason__redirect   =  xopt_increase_reason__002    , 
        xopt_increase_reason__backlog    =  xopt_increase_reason__003    , 
        xopt_increase_reason__react  =  xopt_increase_reason__004    , 
        xopt_increase_reason__comms  =  xopt_increase_reason__005    , 
        xopt_increase_reason__gbv    =  xopt_increase_reason__006    , 
        xopt_increase_reason__other  =  xopt_increase_reason__007    , 
        xopt_decrease_reason__changerecs     =  xopt_decrease_reason__001    , 
        xopt_decrease_reason__fear   =  xopt_decrease_reason__002    , 
        xopt_decrease_reason__lockdown   =  xopt_decrease_reason__003    , 
        xopt_decrease_reason__transport  =  xopt_decrease_reason__004    , 
        xopt_decrease_reason__redc_movements     =  xopt_decrease_reason__005    , 
        xopt_decrease_reason__othercom   =  xopt_decrease_reason__006    , 
        xopt_decrease_reason__servreduc  =  xopt_decrease_reason__007    , 
        xopt_decrease_reason__disrupt    =  xopt_decrease_reason__008    , 
        xopt_decrease_reason__hours  =  xopt_decrease_reason__009    , 
        xopt_decrease_reason__closure    =  xopt_decrease_reason__010    , 
        xopt_decrease_reason__drugs  =  xopt_decrease_reason__011    , 
        xopt_decrease_reason__staff  =  xopt_decrease_reason__012    , 
        #xopt_decrease_reason__otherfac  =  xopt_decrease_reason__013    , 
                    
        xer_increase__injuries   =  xer_increase__002    , 
        xer_increase__surgeries  =  xer_increase__003    , 
        xer_increase__ncd    =  xer_increase__004    , 
        xer_increase__blood  =  xer_increase__005    , 
        xer_decrease__injuries   =  xer_decrease__002    , 
        xer_decrease__surgeries  =  xer_decrease__003    , 
        xer_decrease__ncd    =  xer_decrease__004    , 
        xer_decrease__blood  =  xer_decrease__005    , 
                                
        xout_decrease__immun     =  xout_decrease__001   , 
        xout_decrease__malaria   =  xout_decrease__002   , 
        xout_decrease__ntd   =  xout_decrease__003   , 
        xout_decrease__cbc   =  xout_decrease__004   , 
        xout_decrease__home      =  xout_decrease__005   , 
                    
        xsafe__entrance_screening    =  xsafe__001   , 
        xsafe__staff_entrance    =  xsafe__006   , 
        xsafe__triage_c19    =  xsafe__triage    , 
        xsafe__isolatareas   =  xsafe__isolation     , 
        xsafe__distancing    =  xsafe__002   , 
        xsafe__hygiene_instructions  =  xsafe__003   , 
        xsafe__hygiene_stations  =  xsafe__007   , 
        xsafe__ppe   =  xsafe__008   , 
        xsafe__cleaning  =  xsafe__009   , 
        xsafe__handsanitizer     =  xsafe__010   , 
                    
        xguideline__screening    =  xguideline__001  , 
        xguideline__c19_manage   =  xguideline__002  , 
        xguideline__ppe  =  xguideline__003  , 
        xguideline__c19_surveillance     =  xguideline__004  , 
        xguideline__deadbody     =  xguideline__005  , 
        xguideline__waste    =  xguideline__006  , 
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
                    
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
        
        xcvd_pt__sep_room    =  xcvd_pt__001     , 
        xcvd_pt__c19_check   =  xcvd_pt__002     , 
        xcvd_pt__o2_measure  =  xcvd_pt__003     , 
        xcvd_pt__refer   =  xcvd_pt__004     , 
        xcvd_pt__diagtest    =  xcvd_pt__005     , 
        xcvd_pt__home_isolate    =  xcvd_pt__006     , 
        xcvd_pt__tele    =  xcvd_pt__007     , 
                    
        xcvd_pthbsi__tele    =  xcvd_pthbsi__003     , 
        xcvd_pthbsi__homevisit   =  xcvd_pthbsi__004     , 
        xcvd_pthbsi__followup_fac    =  xcvd_pthbsi__005     , 
        xcvd_pthbsi__safetyinstruct  =  xcvd_pthbsi__006     , 
        xcvd_pthbsi__report  =  xcvd_pthbsi__001     , 
        xcvd_pthbsi__followup_tele   =  xcvd_pthbsi__002     , 
                    
        xdrug__metformin     =  xdrug__002   , 
        xdrug__hydrochlorothiazide   =  xdrug__003   , 
        xdrug__paracetamol_susp  =  xdrug__004   , 
        xdrug__carbamazapine     =  xdrug__005   , 
        xdrug__amoxicillin_tabs  =  xdrug__006   , 
        xdrug__oralcontracept    =  xdrug__007   , 
        xdrug__oxytocin  =  xdrug__008   , 
        xdrug__magnesiumsulphate     =  xdrug__009   , 
        xdrug__heparin   =  xdrug__010   , 
        xdrug__hydrocortisone    =  xdrug__011   , 
        xdrug__epinephrine   =  xdrug__012   , 
        xdrug__artemether    =  xdrug__013   , 
        xdrug__isoniazid     =  xdrug__015   , 
        xdrug__ivfluids  =  xdrug__016   , 
        xdrug__oxygen    =  xdrug__017   , 
        xdrug__loratadine    =  xdrug__001   , 
        xdrug__tld   =  xdrug__014   , 
        
        xsupply__syringes    =  xsupply__001     , 
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__gauze   =  xsupply__003     , 
                    
        xvaccine__mcv    =  xvaccine__001    , 
        xvaccine__dtp    =  xvaccine__002    , 
        xvaccine__polio  =  xvaccine__003    , 
        xvaccine__bcg    =  xvaccine__004    , 
        xvaccine__pneumo     =  xvaccine__005    , 
                    
        xdiag_av__malaria    =  xdiag_av_a001    , 
        xdiag_av__bloodglucose   =  xdiag_av_a002    , 
        xdiag_av__urineglucose   =  xdiag_av_a003    , 
        xdiag_av__pregnancy  =  xdiag_av_a004    , 
        xdiag_avfun__malaria     =  xdiag_avfun_a001     , 
        xdiag_avfun__bloodglucose    =  xdiag_avfun_a002     , 
        xdiag_avfun__urineglucose    =  xdiag_avfun_a003     , 
        xdiag_avfun__pregnancy   =  xdiag_avfun_a004     , 
        xdiag_av__h_hiv  =  xdiag_av_h001    , 
        xidag_av__h_tb   =  xdiag_av_h002    , 
        xdiag_av__h_hbg  =  xdiag_av_h003    , 
        xdiag_av__h_bloodtype    =  xdiag_av_h004    , 
        xdiag_av__h_bloodcreatine    =  xdiag_av_h005    , 
        xdiag_avfun__h_hiv   =  xdiag_avfun_h001     , 
        xidag_avfun__h_tb    =  xdiag_avfun_h002     , 
        xdiag_avfun__h_hbg   =  xdiag_avfun_h003     , 
        xdiag_avfun__h_bloodtype     =  xdiag_avfun_h004     , 
        xdiag_avfun__h_bloodcreatine     =  xdiag_avfun_h005     , 
                    
        ximage_av__xray  =  ximage_av_001    , 
        ximage_av__mri   =  ximage_av_002    , 
        ximage_av__ultrasound    =  ximage_av_003    , 
        
        ximage_avfun__xray   =  ximage_avfun_001     , 
        ximage_avfun__mri    =  ximage_avfun_002     , 
        ximage_avfun__ultrasound     =  ximage_avfun_003      
    )
tempKENR2<- tempKENR2%>%
    rename(
        xtraining__ipc   =  xtraining__001   , 
        xtraining__ppe   =  xtraining__002   , 
        xtraining__triage    =  xtraining__003   , 
        xtraining__emerg     =  xtraining__004   , 
        xtraining__remote    =  xtraining__005   , 
        xtraining__mental    =  xtraining__006   , 
        xtraining__ss_ipc    =  xtraining__007   , 
        xtraining__ss_ppe    =  xtraining__008   , 
        xtraining__ss_homebased  =  xtraining__009   , 
        xtraining__virtual_cme   =  xtraining__010   , 
                    
        xopt_increase__undiff    =  xopt_increase__001   , 
        xopt_increase__fp    =  xopt_increase__002   , 
        xopt_increase__anc   =  xopt_increase__003   , 
        xopt_increase__pnc   =  xopt_increase__004   , 
        xopt_increase__immun     =  xopt_increase__005   , 
        xopt_increase__sickchild     =  xopt_increase__006   , 
        xopt_increase__hiv   =  xopt_increase__007   , 
        xopt_increase__tb    =  xopt_increase__008   , 
        xopt_increase__std   =  xopt_increase__009   , 
        xopt_increase__malaria   =  xopt_increase__010   , 
        xopt_increase__cvd   =  xopt_increase__011   , 
        xopt_increase__crd   =  xopt_increase__012   , 
        xopt_increase__diabetes  =  xopt_increase__013   , 
        xopt_increase__cancer    =  xopt_increase__014   , 
        xopt_increase__mental    =  xopt_increase__015   , 
        xopt_increase__violence  =  xopt_increase__016   , 
        xopt_increase__ntd   =  xopt_increase__017   , 
        xopt_increase__rehab     =  xopt_increase__018   , 
        xopt_decrease__undiff    =  xopt_decrease__001   , 
        xopt_decrease__fp    =  xopt_decrease__002   , 
        xopt_decrease__anc   =  xopt_decrease__003   , 
        xopt_decrease__pnc   =  xopt_decrease__004   , 
        xopt_decrease__immun     =  xopt_decrease__005   , 
        xopt_decrease__sickchild     =  xopt_decrease__006   , 
        xopt_decrease__hiv   =  xopt_decrease__007   , 
        xopt_decrease__tb    =  xopt_decrease__008   , 
        xopt_decrease__std   =  xopt_decrease__009   , 
        xopt_decrease__malaria   =  xopt_decrease__010   , 
        xopt_decrease__cvd   =  xopt_decrease__011   , 
        xopt_decrease__crd   =  xopt_decrease__012   , 
        xopt_decrease__diabetes  =  xopt_decrease__013   , 
        xopt_decrease__cancer    =  xopt_decrease__014   , 
        xopt_decrease__mental    =  xopt_decrease__015   , 
        xopt_decrease__violence  =  xopt_decrease__016   , 
        xopt_decrease__ntd   =  xopt_decrease__017   , 
        xopt_decrease__rehab     =  xopt_decrease__018   , 
        xopt_nochange__undiff    =  xopt_nochange__001   , 
        xopt_nochange__fp    =  xopt_nochange__002   , 
        xopt_nochange__anc   =  xopt_nochange__003   , 
        xopt_nochange__pnc   =  xopt_nochange__004   , 
        xopt_nochange__immun     =  xopt_nochange__005   , 
        xopt_nochange__sickchild     =  xopt_nochange__006   , 
        xopt_nochange__hiv   =  xopt_nochange__007   , 
        xopt_nochange__tb    =  xopt_nochange__008   , 
        xopt_nochange__std   =  xopt_nochange__009   , 
        xopt_nochange__malaria   =  xopt_nochange__010   , 
        xopt_nochange__cvd   =  xopt_nochange__011   , 
        xopt_nochange__crd   =  xopt_nochange__012   , 
        xopt_nochange__diabetes  =  xopt_nochange__013   , 
        xopt_nochange__cancer    =  xopt_nochange__014   , 
        xopt_nochange__mental    =  xopt_nochange__015   , 
        xopt_nochange__violence  =  xopt_nochange__016   , 
        xopt_nochange__ntd   =  xopt_nochange__017   , 
        xopt_nochange__rehab     =  xopt_nochange__018   ,  
                    
        xopt_increase_reason__more_ari   =  xopt_increase_reason__001    , 
        xopt_increase_reason__redirect   =  xopt_increase_reason__002    , 
        xopt_increase_reason__backlog    =  xopt_increase_reason__003    , 
        xopt_increase_reason__react  =  xopt_increase_reason__004    , 
        xopt_increase_reason__comms  =  xopt_increase_reason__005    , 
        xopt_increase_reason__gbv    =  xopt_increase_reason__006    , 
        xopt_increase_reason__other  =  xopt_increase_reason__007    , 
        xopt_decrease_reason__changerecs     =  xopt_decrease_reason__001    , 
        xopt_decrease_reason__fear   =  xopt_decrease_reason__002    , 
        xopt_decrease_reason__lockdown   =  xopt_decrease_reason__003    , 
        xopt_decrease_reason__transport  =  xopt_decrease_reason__004    , 
        xopt_decrease_reason__redc_movements     =  xopt_decrease_reason__005    , 
        xopt_decrease_reason__othercom   =  xopt_decrease_reason__006    , 
        xopt_decrease_reason__servreduc  =  xopt_decrease_reason__007    , 
        xopt_decrease_reason__disrupt    =  xopt_decrease_reason__008    , 
        xopt_decrease_reason__hours  =  xopt_decrease_reason__009    , 
        xopt_decrease_reason__closure    =  xopt_decrease_reason__010    , 
        xopt_decrease_reason__drugs  =  xopt_decrease_reason__011    , 
        xopt_decrease_reason__staff  =  xopt_decrease_reason__012    , 
        #xopt_decrease_reason__otherfac  =  xopt_decrease_reason__013    , 
                    
        xer_increase__injuries   =  xer_increase__002    , 
        xer_increase__surgeries  =  xer_increase__003    , 
        xer_increase__ncd    =  xer_increase__004    , 
        xer_increase__blood  =  xer_increase__005    , 
        xer_decrease__injuries   =  xer_increase__002    , 
        xer_decrease__surgeries  =  xer_increase__003    , 
        xer_decrease__ncd    =  xer_increase__004    , 
        xer_decrease__blood  =  xer_increase__005    , 
                    
        xout_decrease__immun     =  xout_decrease__001   , 
        xout_decrease__malaria   =  xout_decrease__002   , 
        xout_decrease__ntd   =  xout_decrease__003   , 
        xout_decrease__cbc   =  xout_decrease__004   , 
        xout_decrease__home      =  xout_decrease__005   , 
                    
        xsafe__entrance_screening    =  xsafe__001   , 
        xsafe__staff_entrance    =  xsafe__006   , 
        xsafe__triage_c19    =  xsafe__triage    , 
        xsafe__isolatareas   =  xsafe__isolation     , 
        xsafe__distancing    =  xsafe__002   , 
        xsafe__hygiene_instructions  =  xsafe__003   , 
        xsafe__hygiene_stations  =  xsafe__007   , 
        xsafe__ppe   =  xsafe__008   , 
        xsafe__cleaning  =  xsafe__009   , 
        xsafe__handsanitizer     =  xsafe__010   , 
                    
        xguideline__screening    =  xguideline__001  , 
        xguideline__c19_manage   =  xguideline__002  , 
        xguideline__ppe  =  xguideline__003  , 
        xguideline__c19_surveillance     =  xguideline__004  , 
        xguideline__deadbody     =  xguideline__005  , 
        xguideline__waste    =  xguideline__006  , 
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
                    
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
                    
        xcvd_pt__sep_room    =  xcvd_pt__001     , 
        xcvd_pt__c19_check   =  xcvd_pt__002     , 
        xcvd_pt__o2_measure  =  xcvd_pt__003     , 
        xcvd_pt__refer   =  xcvd_pt__004     , 
        xcvd_pt__diagtest    =  xcvd_pt__005     , 
        xcvd_pt__home_isolate    =  xcvd_pt__006     , 
        xcvd_pt__tele    =  xcvd_pt__007     , 
                    
        xcvd_pthbsi__tele    =  xcvd_pthbsi__003     , 
        xcvd_pthbsi__homevisit   =  xcvd_pthbsi__004     , 
        xcvd_pthbsi__followup_fac    =  xcvd_pthbsi__005     , 
        xcvd_pthbsi__safetyinstruct  =  xcvd_pthbsi__006     , 
        xcvd_pthbsi__report  =  xcvd_pthbsi__001     , 
        xcvd_pthbsi__followup_tele   =  xcvd_pthbsi__002     ,  
        
        xdrug__metformin     =  xdrug__002   , 
        xdrug__hydrochlorothiazide   =  xdrug__003   , 
        xdrug__paracetamol_susp  =  xdrug__004   , 
        xdrug__carbamazapine     =  xdrug__005   , 
        xdrug__amoxicillin_tabs  =  xdrug__006   , 
        xdrug__oralcontracept    =  xdrug__007   , 
        xdrug__oxytocin  =  xdrug__008   , 
        xdrug__magnesiumsulphate     =  xdrug__009   , 
        #xdrug__heparin  =  xdrug__010   , 
        #xdrug__hydrocortisone   =  xdrug__011   , 
        #xdrug__epinephrine  =  xdrug__012   , 
        #xdrug__artemether   =  xdrug__013   , 
        #xdrug__isoniazid    =  xdrug__015   , 
        #xdrug__ivfluids     =  xdrug__016   , 
        #xdrug__oxygen   =  xdrug__017   , 
        xdrug__loratadine    =  xdrug__001   , 
        xdrug__tld   =  xdrug__014   , 
                    
        xsupply__syringes    =  xsupply__001     , 
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__gauze   =  xsupply__003     , 
                    
        xvaccine__mcv    =  xvaccine__001    , 
        xvaccine__dtp    =  xvaccine__002    , 
        xvaccine__polio  =  xvaccine__003    , 
        xvaccine__bcg    =  xvaccine__004    , 
        xvaccine__pneumo     =  xvaccine__005    , 
                    
        xdiag_av__malaria    =  xdiag_av_a001    , 
        xdiag_av__bloodglucose   =  xdiag_av_a002    , 
        xdiag_av__urineglucose   =  xdiag_av_a003    , 
        xdiag_av__pregnancy  =  xdiag_av_a004    , 
        xdiag_avfun__malaria     =  xdiag_avfun_a001     , 
        xdiag_avfun__bloodglucose    =  xdiag_avfun_a002     , 
        xdiag_avfun__urineglucose    =  xdiag_avfun_a003     , 
        xdiag_avfun__pregnancy   =  xdiag_avfun_a004     , 
        xdiag_av__h_hiv  =  xdiag_av_h001    , 
        xidag_av__h_tb   =  xdiag_av_h002    , 
        xdiag_av__h_hbg  =  xdiag_av_h003    , 
        xdiag_av__h_bloodtype    =  xdiag_av_h004    , 
        xdiag_av__h_bloodcreatine    =  xdiag_av_h005    , 
        xdiag_avfun__h_hiv   =  xdiag_avfun_h001     , 
        xidag_avfun__h_tb    =  xdiag_avfun_h002     , 
        xdiag_avfun__h_hbg   =  xdiag_avfun_h003     , 
        xdiag_avfun__h_bloodtype     =  xdiag_avfun_h004     , 
        xdiag_avfun__h_bloodcreatine     =  xdiag_avfun_h005     , 
                    
        ximage_av__xray  =  ximage_av_001    , 
        ximage_av__mri   =  ximage_av_002    , 
        ximage_av__ultrasound    =  ximage_av_003    , 
        ximage_av__ct    =  ximage_av_004    , 
        ximage_avfun__xray   =  ximage_av_001    , 
        ximage_avfun__mri    =  ximage_av_002    , 
        ximage_avfun__ultrasound     =  ximage_av_003    , 
        ximage_avfun__ct     =  ximage_av_004    , 
                    
        xcovax_offer__pfizer     =   xcovax_offer__001   , 
        xcovax_offerav__pfizer   =   xcovax_offerav__001     , 
        xcovax_offer__moderna    =   xcovax_offer__002   , 
        xcovax_offerav__moderna  =   xcovax_offerav__002     , 
        xcovax_offer__astra  =   xcovax_offer__003   , 
        xcovax_offerav__astra    =   xcovax_offerav__003     , 
        xcovax_offer__jj     =   xcovax_offer__004   , 
        xcovax_offerav__jj   =   xcovax_offerav__004     , 
        xcovax_offer_sputnik     =   xcovax_offer__005   , 
        xcovax_offerav_sputnik   =   xcovax_offerav__005     , 
        xcovax_train__setup_vac  =   xcovax_train__001   , 
        xcovax_train__storage    =   xcovax_train__002   , 
        xcovax_train__admin  =   xcovax_train__003   , 
        xcovax_train__manage_adverse     =   xcovax_train__004   , 
        xcovax_train__report_adverse     =   xcovax_train__005   , 
        xcovax_train__waste_manage   =   xcovax_train__006   , 
        xcovax_train__IPC    =   xcovax_train__007           
    )
tempCMRR1<- tempCMRR1%>%
    rename(
        xtraining__ipc   =  xtraining__001   , 
        xtraining__ppe   =  xtraining__002   , 
        xtraining__triage    =  xtraining__003   , 
        xtraining__cov_manage    =  xtraining__004   , 
        xtraining__emerg     =  xtraining__005   , 
        xtraining__mental    =  xtraining__006   , 
        xtraining__ss_ipc    =  xtraining__007   , 
        xtraining__ss_ppe    =  xtraining__008   , 
        xtraining__ss_c19cm  =  xtraining__009   , 
        #xtraining__ss_any_latest    =  to confirm   , 
                    
        xopt_increase__undiff    =  xopt_increase__001   , 
        xopt_increase__fp    =  xopt_increase__002   , 
        xopt_increase__anc   =  xopt_increase__003   , 
        xopt_increase__pnc   =  xopt_increase__004   , 
        xopt_increase_immun_vita     =  xopt_increase__005   , 
        xopt_increase__sickchild     =  xopt_increase__006   , 
        xopt_increase__hiv   =  xopt_increase__007   , 
        xopt_increase__tb    =  xopt_increase__008   , 
        xopt_increase__std   =  xopt_increase__009   , 
        xopt_increase__malaria   =  xopt_increase__010   , 
        xopt_increase__cvd   =  xopt_increase__011   , 
        xopt_increase__crd   =  xopt_increase__012   , 
        xopt_increase_ard    =  xopt_increase__013   , 
        xopt_increase_gastro     =  xopt_increase__014   , 
        xopt_increase__diabetes  =  xopt_increase__015   , 
        xopt_increase__cancer    =  xopt_increase__016   , 
        xopt_increase__mental    =  xopt_increase__017   , 
        xopt_increase__violence  =  xopt_increase__018   , 
        xopt_increase__ntd   =  xopt_increase__019   , 
        xopt_increase__rehab     =  xopt_increase__020   , 
        xopt_increase__palliative    =  xopt_increase__021   , 
        xopt_decrease__undiff    =  xopt_decrease__001   , 
        xopt_decrease__fp    =  xopt_decrease__002   , 
        xopt_decrease__anc   =  xopt_decrease__003   , 
        xopt_decrease__pnc   =  xopt_decrease__004   , 
        xopt_decrease_immun_vita     =  xopt_decrease__005   , 
        xopt_decrease__sickchild     =  xopt_decrease__006   , 
        xopt_decrease__hiv   =  xopt_decrease__007   , 
        xopt_decrease__tb    =  xopt_decrease__008   , 
        xopt_decrease__std   =  xopt_decrease__009   , 
        xopt_decrease__malaria   =  xopt_decrease__010   , 
        xopt_decrease__cvd   =  xopt_decrease__011   , 
        xopt_decrease__crd   =  xopt_decrease__012   , 
        xopt_decrease_ard    =  xopt_decrease__013   , 
        xopt_decrease_gastro     =  xopt_decrease__014   , 
        xopt_decrease__diabetes  =  xopt_decrease__015   , 
        xopt_decrease__cancer    =  xopt_decrease__016   , 
        xopt_decrease__mental    =  xopt_decrease__017   , 
        xopt_decrease__violence  =  xopt_decrease__018   , 
        xopt_decrease__ntd   =  xopt_decrease__019   , 
        xopt_decrease__rehab     =  xopt_decrease__020   , 
        xopt_decrease__palliative    =  xopt_decrease__021   , 
        xopt_nochange__undiff    =  xopt_nochange__001   , 
        xopt_nochange__fp    =  xopt_nochange__002   , 
        xopt_nochange__anc   =  xopt_nochange__003   , 
        xopt_nochange__pnc   =  xopt_nochange__004   , 
        xopt_nochange_immun_vita     =  xopt_increase__005   , 
        xopt_nochange__sickchild     =  xopt_nochange__006   , 
        xopt_nochange__hiv   =  xopt_nochange__007   , 
        xopt_nochange__tb    =  xopt_nochange__008   , 
        xopt_nochange__std   =  xopt_nochange__009   , 
        xopt_nochange__malaria   =  xopt_nochange__010   , 
        xopt_nochange__cvd   =  xopt_nochange__011   , 
        xopt_nochange__crd   =  xopt_nochange__012   , 
        xopt_nochange_ard    =  xopt_nochange__013   , 
        xopt_nochange_gastro     =  xopt_nochange__014   , 
        xopt_nochange__diabetes  =  xopt_nochange__015   , 
        xopt_nochange__cancer    =  xopt_nochange__016   , 
        xopt_nochange__mental    =  xopt_nochange__017   , 
        xopt_nochange__violence  =  xopt_nochange__018   , 
        xopt_nochange__ntd   =  xopt_nochange__019   , 
        xopt_nochange__rehab     =  xopt_nochange__020   , 
        xopt_nochange__palliative    =  xopt_nochange__021   , 
                    
        xopt_increase_reason__more_ari   =  xopt_increase_reason__001    , 
        xopt_increase_reason__redirect   =  xopt_increase_reason__002    , 
        xopt_increase_reason__backlog    =  xopt_increase_reason__003    , 
        xopt_increase_reason__react  =  xopt_increase_reason__004    , 
        xopt_increase_reason__comms  =  xopt_increase_reason__005    , 
        xopt_increase_reason__gbv    =  xopt_increase_reason__006    , 
        xopt_increase_reason__other  =  xopt_increase_reason__007    , 
        #xopt_decrease_reason__changerecs    =  xopt_decrease_reason__001    , 
        #xopt_decrease_reason__fear  =  xopt_decrease_reason__002    , 
        #xopt_decrease_reason__lockdown  =  xopt_decrease_reason__003    , 
        #xopt_decrease_reason__transport     =  xopt_decrease_reason__004    , 
        #xopt_decrease_reason__othercom  =  xopt_decrease_reason__005    , 
        #xopt_decrease_reason__servreduc     =  xopt_decrease_reason__006    , 
        #xopt_decrease_reason__disrupt   =  xopt_decrease_reason__007    , 
        #xopt_decrease_reason__hours     =  xopt_decrease_reason__008    , 
        #xopt_decrease_reason__closure   =  xopt_decrease_reason__009    , 
        #xopt_decrease_reason__drugs     =  xopt_decrease_reason__010    , 
        #xopt_decrease_reason__staff     =  xopt_decrease_reason__011    , 
        #xopt_decrease_reason__otherfac  =  xopt_decrease_reason__012    , 
        
        xer_increase__injuries   =  xer_increase__002    , 
        xer_increase__surgeries  =  xer_increase__003    , 
        xer_increase__ncd    =  xer_increase__004    , 
        xer_increase__blood  =  xer_increase__005    , 
        xer_decrease__injuries   =  xer_increase__002    , 
        xer_decrease__surgeries  =  xer_increase__003    , 
        xer_decrease__ncd    =  xer_increase__004    , 
        xer_decrease__blood  =  xer_increase__005    , 
                    
        xout_decrease__immun     =  xout_decrease__001   , 
        xout_decrease__malaria   =  xout_decrease__002   , 
        xout_decrease__ntd   =  xout_decrease__003   , 
        xout_decrease__cbc   =  xout_decrease__004   , 
        xout_decrease__home      =  xout_decrease__005   , 
                    
        xsafe__entrance_screening    =  xsafe__001   , 
        xsafe__staff_entrance    =  xsafe__002   , 
        xsafe__sep_room  =  xsafe__003   , 
        xsafe__triage_c19    =  xsafe__triage    , 
        xsafe__isolatareas   =  xsafe__isolation     , 
        xsafe__distancing    =  xsafe__006   , 
        xsafe__hygiene_instructions  =  xsafe__007   , 
        xsafe__hygiene_stations  =  xsafe__008   , 
        xsafe__ppe   =  xsafe__009   , 
        xsafe__cleaning  =  xsafe__010   , 
        
        xguideline__screening    =  xguideline__001  , 
        xguideline__c19_manage   =  xguideline__002  , 
        xguideline__c19_surveillance     =  xguideline__003  , 
        xguideline__deadbody     =  xguideline__004  , 
        xguideline__waste    =  xguideline__005  , 
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    ,  
                    
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
                    
        xcvd_pt__sep_room    =  xcvd_pt__001     , 
        xcvd_pt__c19_check   =  xcvd_pt__002     , 
        xcvd_pt__o2_measure  =  xcvd_pt__003     , 
        xcvd_pt__refer   =  xcvd_pt__004     , 
        xcvd_pt__diagtest    =  xcvd_pt__005     , 
        xcvd_pt__home_isolate    =  xcvd_pt__006     , 
        xcvd_pt__tele    =  xcvd_pt__007     , 
                    
        xcvd_pthbsi__tele    =  xcvd_pthbsi__001     , 
        xcvd_pthbsi__homevisit   =  xcvd_pthbsi__002     , 
        xcvd_pthbsi__followup_fac    =  xcvd_pthbsi__003     , 
        xcvd_pthbsi__safetyinstruct  =  xcvd_pthbsi__004     , 
        xcvd_pthbsi__complianceassess    =  xcvd_pthbsi__005     , 
        xcvd_pthbsi__report  =  xcvd_pthbsi__006     , 
                    
        #xdrug__salbutamol   =  0    , 
        #xdrug__metformin    =  0    , 
        #xdrug__hydrochlorothiazide  =  0    , 
        #xdrug__paracetamol_susp     =  #xdrug__002  , 
        #xdrug__paracetamol_tabs     =  0    , 
        #xdrug__carbamazapine    =  0    , 
        #xdrug__amoxicillin_tabs     =  0    , 
        #xdrug__amoxicillin_susp     =  #xdrug__003  , 
        #xdrug__oralcontracept   =  0    , 
        #xdrug__oxytocin     =  #xdrug__006  , 
        #xdrug__magnesiumsulphate    =  #xdrug__007  , 
        #xdrug__heparin  =  0    , 
        #xdrug__hydrocortisone   =  #xdrug__010  , 
        #xdrug__epinephrine  =  0    , 
        #xdrug__artemether   =  0    , 
        #xdrug__efavirenz    =  #xdrug__015  , 
        #xdrug__isoniazid    =  #xdrug__004  , 
        #xdrug__ivfluids     =  0    , 
        #xdrug__oxygen   =  0    , 
        #xdrug__loratadine   =  0    , 
        #xdrug__tld  =  0    , 
        #xdrug__ceftriaxone  =  #xdrug__017  , 
        #xdrug__insulin  =  #xdrug__014  , 
        #xdrug__beclometasone    =  0    , 
                    
        xsupply__syringes    =  xsupply__001     , 
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__gauze   =  xsupply__003     , 
                    
        xvaccine__mcv    =  xvaccine__001    , 
        xvaccine__dtp    =  xvaccine__002    , 
        xvaccine__polio  =  xvaccine__003    , 
        xvaccine__bcg    =  xvaccine__004    , 
        xvaccine__pneumo     =  xvaccine__005    , 
                    
        xdiag_av__malaria    =  xdiag_av_a001    , 
        xdiag_av__bloodglucose   =  xdiag_av_a002    , 
        xdiag_av__urineglucose   =  xdiag_av_a003    , 
        xdiag_av__urineprotein   =  xdiag_av_a004    , 
        xdiag_av__pregnancy  =  xdiag_av_a005    , 
        xdiag_avfun__malaria     =  xdiag_avfun_a001     , 
        xdiag_avfun__bloodglucose    =  xdiag_avfun_a002     , 
        xdiag_avfun__urineglucose    =  xdiag_avfun_a003     , 
        xdiag_avfun__urineprotein    =  xdiag_avfun_a004     , 
        xdiag_avfun__pregnancy   =  xdiag_avfun_a005     , 
        xdiag_av__h_hiv  =  xdiag_av_h001    , 
        xidag_av__h_tb   =  xdiag_av_h002    , 
        xdiag_av__h_hbg  =  xdiag_av_h003    , 
        xdiag_av__h_bloodtype    =  xdiag_av_h004    , 
        xdiag_av__h_bloodcreatine    =  xdiag_av_h005    , 
        xdiag_avfun__h_hiv   =  xdiag_avfun_h001     , 
        xidag_avfun__h_tb    =  xdiag_avfun_h002     , 
        xdiag_avfun__h_hbg   =  xdiag_avfun_h003     , 
        xdiag_avfun__h_bloodtype     =  xdiag_avfun_h004     , 
        xdiag_avfun__h_bloodcreatine     =  xdiag_avfun_h005     , 
                    
        ximage_av__xray  =  ximage_av_001    , 
        ximage_av__mri   =  ximage_av_003    , 
        ximage_av__ultrasound    =  ximage_av_004    , 
        ximage_av__ct    =  ximage_av_002    , 
        ximage_avfun__xray   =  ximage_avfun_001     , 
        ximage_avfun__mri    =  ximage_avfun_003     , 
        ximage_avfun__ultrasound     =  ximage_avfun_004     , 
        ximage_avfun__ct     =  ximage_avfun_002             
    )
tempGHAR1<- tempGHAR1%>%
    rename(
        xtraining__ipc   =  xtraining__001   , 
        xtraining__ppe   =  xtraining__002   , 
        xtraining__triage    =  xtraining__003   , 
        xtraining__emerg     =  xtraining__004   , 
        xtraining__remote    =  xtraining__005   , 
        xtraining__mental    =  xtraining__006   , 
        xtraining__ss_ipc    =  xtraining__007   , 
        xtraining__ss_ppe    =  xtraining__008   , 
        xtraining__ss_c19cm  =  xtraining__009   , 
                    
        xopt_increase__undiff    =  xopt_increase__001   , 
        xopt_increase__fp    =  xopt_increase__002   , 
        xopt_increase__anc   =  xopt_increase__003   , 
        xopt_increase__pnc   =  xopt_increase__004   , 
        xopt_increase__immun     =  xopt_increase__005   , 
        xopt_increase__sickchild     =  xopt_increase__006   , 
        xopt_increase__hiv   =  xopt_increase__007   , 
        xopt_increase__tb    =  xopt_increase__008   , 
        xopt_increase__std   =  xopt_increase__009   , 
        xopt_increase__malaria   =  xopt_increase__010   , 
        xopt_increase__cvd   =  xopt_increase__011   , 
        xopt_increase__crd   =  xopt_increase__012   , 
        xopt_increase__diabetes  =  xopt_increase__013   , 
        xopt_increase__cancer    =  xopt_increase__014   , 
        xopt_increase__mental    =  xopt_increase__015   , 
        xopt_increase__violence  =  xopt_increase__016   , 
        xopt_increase__ntd   =  xopt_increase__017   , 
        xopt_increase__rehab     =  xopt_increase__018   , 
        xopt_decrease__undiff    =  xopt_decrease__001   , 
        xopt_decrease__fp    =  xopt_decrease__002   , 
        xopt_decrease__anc   =  xopt_decrease__003   , 
        xopt_decrease__pnc   =  xopt_decrease__004   , 
        xopt_decrease__immun     =  xopt_decrease__005   , 
        xopt_decrease__sickchild     =  xopt_decrease__006   , 
        xopt_decrease__hiv   =  xopt_decrease__007   , 
        xopt_decrease__tb    =  xopt_decrease__008   , 
        xopt_decrease__std   =  xopt_decrease__009   , 
        xopt_decrease__malaria   =  xopt_decrease__010   , 
        xopt_decrease__cvd   =  xopt_decrease__011   , 
        xopt_decrease__crd   =  xopt_decrease__012   , 
        xopt_decrease__diabetes  =  xopt_decrease__013   , 
        xopt_decrease__cancer    =  xopt_decrease__014   , 
        xopt_decrease__mental    =  xopt_decrease__015   , 
        xopt_decrease__violence  =  xopt_decrease__016   , 
        xopt_decrease__ntd   =  xopt_decrease__017   , 
        xopt_decrease__rehab     =  xopt_decrease__018   , 
        xopt_nochange__undiff    =  xopt_nochange__001   , 
        xopt_nochange__fp    =  xopt_nochange__002   , 
        xopt_nochange__anc   =  xopt_nochange__003   , 
        xopt_nochange__pnc   =  xopt_nochange__004   , 
        xopt_nochange__immun     =  xopt_nochange__005   , 
        xopt_nochange__sickchild     =  xopt_nochange__006   , 
        xopt_nochange__hiv   =  xopt_nochange__007   , 
        xopt_nochange__tb    =  xopt_nochange__008   , 
        xopt_nochange__std   =  xopt_nochange__009   , 
        xopt_nochange__malaria   =  xopt_nochange__010   , 
        xopt_nochange__cvd   =  xopt_nochange__011   , 
        xopt_nochange__crd   =  xopt_nochange__012   , 
        xopt_nochange__diabetes  =  xopt_nochange__013   , 
        xopt_nochange__cancer    =  xopt_nochange__014   , 
        xopt_nochange__mental    =  xopt_nochange__015   , 
        xopt_nochange__violence  =  xopt_nochange__016   , 
        xopt_nochange__ntd   =  xopt_nochange__017   , 
        xopt_nochange__rehab     =  xopt_nochange__018   , 
        
                    
        xopt_increase_reason__more_ari   =  xopt_increase_reason__001    , 
        xopt_increase_reason__redirect   =  xopt_increase_reason__002    , 
        xopt_increase_reason__backlog    =  xopt_increase_reason__003    , 
        xopt_increase_reason__react  =  xopt_increase_reason__004    , 
        xopt_increase_reason__comms  =  xopt_increase_reason__005    , 
        xopt_increase_reason__gbv    =  xopt_increase_reason__006    , 
        xopt_increase_reason__other  =  xopt_increase_reason__007    , 
        xopt_decrease_reason__changerecs     =  xopt_decrease_reason__001    , 
        xopt_decrease_reason__fear   =  xopt_decrease_reason__002    , 
        xopt_decrease_reason__lockdown   =  xopt_decrease_reason__003    , 
        xopt_decrease_reason__transport  =  xopt_decrease_reason__004    , 
        xopt_decrease_reason__servreduc  =  xopt_decrease_reason__005    , 
        xopt_decrease_reason__disrupt    =  xopt_decrease_reason__006    , 
        xopt_decrease_reason__hours  =  xopt_decrease_reason__007    , 
        xopt_decrease_reason__closure    =  xopt_decrease_reason__008    , 
        xopt_decrease_reason__drugs  =  xopt_decrease_reason__009    , 
        xopt_decrease_reason__staff  =  xopt_decrease_reason__010    , 
        xopt_decrease_reason__other  =  xopt_decrease_reason__011    , 
                    
        xer_increase__injuries   =  xer_increase__002    , 
        xer_increase__surgeries  =  xer_increase__003    , 
        xer_increase__ncd    =  xer_increase__004    , 
        xer_increase__blood  =  xer_increase__005    , 
        xer_decrease__injuries   =  xer_decrease__002    , 
        xer_decrease__surgeries  =  xer_decrease__003    , 
        xer_decrease__ncd    =  xer_decrease__004    , 
        xer_decrease__blood  =  xer_decrease__005    , 
                    
        xout_decrease__immun     =  xout_decrease__001   , 
        xout_decrease__malaria   =  xout_decrease__002   , 
        xout_decrease__ntd   =  xout_decrease__003   , 
        xout_decrease__cbc   =  xout_decrease__004   , 
        xout_decrease__home      =  xout_decrease__005   , 
                    
        xsafe__entrance_screening    =  xsafe__001   , 
        xsafe__staff_entrance    =  xsafe__002   , 
        xsafe__sep_room  =  xsafe__003   , 
        xsafe__triage_c19    =  xsafe__triage    , 
        xsafe__isolatareas   =  xsafe__isolation     , 
        xsafe__triage_guidelines     =  xsafe__006   , 
        xsafe__distancing    =  xsafe__007   , 
        xsafe__hygiene_instructions  =  xsafe__008   , 
        xsafe__hygiene_stations  =  xsafe__009   , 
        xsafe__ppe   =  xsafe__010   , 
        xsafe__cleaning  =  xsafe__011   , 
                    
        xguideline__screening    =  xguideline__001  , 
        xguideline__c19_manage   =  xguideline__002  , 
        xguideline__ppe  =  xguideline__003  , 
        xguideline__c19_surveillance     =  xguideline__004  , 
        xguideline__deadbody     =  xguideline__005  , 
        xguideline__waste    =  xguideline__006  , 
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
        xppe_allsome__mask_cloth     =  xppe_allsome__007    , 
                    
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
        xppe_all__mask_cloth     =  xppe_all__007    , 
                    
        xcvd_pt__sep_room    =  xcvd_pt__001     , 
        xcvd_pt__c19_check   =  xcvd_pt__002     , 
        xcvd_pt__o2_measure  =  xcvd_pt__003     , 
        xcvd_pt__refer   =  xcvd_pt__004     , 
        xcvd_pt__diagtest    =  xcvd_pt__005     , 
        xcvd_pt__home_isolate    =  xcvd_pt__006     , 
        xcvd_pt__tele    =  xcvd_pt__007     , 
                    
        xcvd_pthbsi__tele    =  xcvd_pthbsi__001     , 
        xcvd_pthbsi__homevisit   =  xcvd_pthbsi__002     , 
        xcvd_pthbsi__followup_fac    =  xcvd_pthbsi__003     , 
        xcvd_pthbsi__safetyinstruct  =  xcvd_pthbsi__004     , 
        xcvd_pthbsi__complianceassess    =  xcvd_pthbsi__005     , 
        xcvd_pthbsi__report  =  xcvd_pthbsi__006     , 
                    
        xdrug__salbutamol    =  xdrug__001   , 
        xdrug__metformin     =  xdrug__002   , 
        xdrug__hydrochlorothiazide   =  xdrug__003   , 
        xdrug__paracetamol_susp  =  xdrug__004   , 
        xdrug__carbamazapine     =  xdrug__005   , 
        xdrug__amoxicillin_tabs  =  xdrug__006   , 
        xdrug__oralcontracept    =  xdrug__007   , 
        xdrug__oxytocin  =  xdrug__008   , 
        xdrug__magnesiumsulphate     =  xdrug__009   , 
        xdrug__heparin   =  xdrug__010   , 
        xdrug__hydrocortisone    =  xdrug__011   , 
        xdrug__epinephrine   =  xdrug__012   , 
        xdrug__artemether    =  xdrug__013   , 
        xdrug__efavirenz     =  xdrug__014   , 
        xdrug__isoniazid     =  xdrug__015   , 
        xdrug__ivfluids  =  xdrug__016   , 
        xdrug__oxygen    =  xdrug__017   , 
                    
        xsupply__syringes    =  xsupply__001     , 
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__gauze   =  xsupply__003     , 
                    
        xvaccine__mcv    =  xvaccine__001    , 
        xvaccine__dtp    =  xvaccine__002    , 
        xvaccine__polio  =  xvaccine__003    , 
        xvaccine__bcg    =  xvaccine__004    , 
                    
        xdiag_av__malaria    =  xdiag_av_a001    , 
        xdiag_av__bloodglucose   =  xdiag_av_a002    , 
        xdiag_av__urineglucose   =  xdiag_av_a003    , 
        xdiag_av__urineprotein   =  xdiag_av_a004    , 
        xdiag_av__pregnancy  =  xdiag_av_a005    , 
        xdiag_avfun__malaria     =  xdiag_avfun_a001     , 
        xdiag_avfun__bloodglucose    =  xdiag_avfun_a002     , 
        xdiag_avfun__urineglucose    =  xdiag_avfun_a003     , 
        xdiag_avfun__urineprotein    =  xdiag_avfun_a004     , 
        xdiag_avfun__pregnancy   =  xdiag_avfun_a005     , 
        xdiag_av__h_hiv  =  xdiag_av_h001    , 
        xidag_av__h_tb   =  xdiag_av_h002    , 
        xdiag_av__h_hbg  =  xdiag_av_h003    , 
        xdiag_av__h_bloodtype    =  xdiag_av_h004    , 
        xdiag_av__h_bloodcreatine    =  xdiag_av_h005    , 
        xdiag_avfun__h_hiv   =  xdiag_avfun_h001     , 
        xidag_avfun__h_tb    =  xdiag_avfun_h002     , 
        xdiag_avfun__h_hbg   =  xdiag_avfun_h003     , 
        xdiag_avfun__h_bloodtype     =  xdiag_avfun_h004     , 
        xdiag_avfun__h_bloodcreatine     =  xdiag_avfun_h005     , 
                    
        ximage_av__xray  =  ximage_av_001    , 
        ximage_av__mri   =  ximage_av_003    , 
        ximage_av__ultrasound    =  ximage_av_004    , 
        ximage_av__ct    =  ximage_av_002    , 
        ximage_avfun__xray   =  ximage_avfun_001     , 
        ximage_avfun__mri    =  ximage_avfun_003     , 
        ximage_avfun__ultrasound     =  ximage_avfun_004     , 
        ximage_avfun__ct     =  ximage_avfun_002     , 
                    
        xcovax_offer__pfizer     =   xcovax_offer__001   , 
        xcovax_offerav__pfizer   =   xcovax_offerav__001     , 
        xcovax_offer__moderna    =   xcovax_offer__002   , 
        xcovax_offerav__moderna  =   xcovax_offerav__002     , 
        xcovax_offer__astra  =   xcovax_offer__003   , 
        xcovax_offerav__astra    =   xcovax_offerav__003     , 
        xcovax_offer__jj     =   xcovax_offer__004   , 
        xcovax_offerav__jj   =   xcovax_offerav__004     , 
        
        xcovax_train__storage    =   xcovax_train__001   , 
        xcovax_train__admin  =   xcovax_train__002   , 
        xcovax_train__manage_adverse     =   xcovax_train__003   , 
        xcovax_train__report_adverse     =   xcovax_train__004    
        
    )
tempUKRR1<- tempUKRR1%>%
    rename(
        xtraining__ipc   =  xtraining__001   , 
        xtraining__ppe   =  xtraining__002   , 
        xtraining__triage    =  xtraining__003   , 
        xtraining__emerg     =  xtraining__004   , 
        xtraining__remote    =  xtraining__009   , 
        xtraining__mental    =  xtraining__005   , 
        xtraining__ss_ipc    =  xtraining__006   , 
        xtraining__ss_ppe    =  xtraining__007   , 
        xtraining__ss_c19cm  =  xtraining__008   , 
        
        xopt_increase__undiff    =  xopt_increase__001   , 
        xopt_increase__fp    =  xopt_increase__002   , 
        xopt_increase__anc   =  xopt_increase__003   , 
        xopt_increase__pnc   =  xopt_increase__004   , 
        xopt_increase__immun     =  xopt_increase__005   , 
        xopt_increase__sickchild     =  xopt_increase__006   , 
        xopt_increase__hiv   =  xopt_increase__007   , 
        xopt_increase__tb    =  xopt_increase__008   , 
        xopt_increase__std   =  xopt_increase__009   ,  
        xopt_increase__cvd   =  xopt_increase__010   , 
        xopt_increase__crd   =  xopt_increase__011   , 
        xopt_increase__diabetes  =  xopt_increase__012   , 
        xopt_increase__cancer    =  xopt_increase__013   , 
        xopt_increase__mental    =  xopt_increase__014   , 
        xopt_increase__violence  =  xopt_increase__015   , 
        xopt_increase__rehab     =  xopt_increase__016   , 
        xopt_decrease__undiff    =  xopt_decrease__001   , 
        xopt_decrease__fp    =  xopt_decrease__002   , 
        xopt_decrease__anc   =  xopt_decrease__003   , 
        xopt_decrease__pnc   =  xopt_decrease__004   , 
        xopt_decrease__immun     =  xopt_decrease__005   , 
        xopt_decrease__sickchild     =  xopt_decrease__006   , 
        xopt_decrease__hiv   =  xopt_decrease__007   , 
        xopt_decrease__tb    =  xopt_decrease__008   , 
        xopt_decrease__std   =  xopt_decrease__009   ,  
        xopt_decrease__cvd   =  xopt_decrease__010   , 
        xopt_decrease__crd   =  xopt_decrease__011   , 
        xopt_decrease__diabetes  =  xopt_decrease__012   , 
        xopt_decrease__cancer    =  xopt_decrease__013   , 
        xopt_decrease__mental    =  xopt_decrease__014   , 
        xopt_decrease__violence  =  xopt_decrease__015   , 
        xopt_decrease__rehab     =  xopt_decrease__016   , 
        xopt_nochange__undiff    =  xopt_nochange__001   , 
        xopt_nochange__fp    =  xopt_nochange__002   , 
        xopt_nochange__anc   =  xopt_nochange__003   , 
        xopt_nochange__pnc   =  xopt_nochange__004   , 
        xopt_nochange__immun     =  xopt_nochange__005   , 
        xopt_nochange__sickchild     =  xopt_nochange__006   , 
        xopt_nochange__hiv   =  xopt_nochange__007   , 
        xopt_nochange__tb    =  xopt_nochange__008   , 
        xopt_nochange__std   =  xopt_nochange__009   , 
        xopt_nochange__cvd   =  xopt_nochange__010   , 
        xopt_nochange__crd   =  xopt_nochange__011   , 
        xopt_nochange__diabetes  =  xopt_nochange__012   , 
        xopt_nochange__cancer    =  xopt_nochange__013   , 
        xopt_nochange__mental    =  xopt_nochange__014   , 
        xopt_nochange__violence  =  xopt_nochange__015   , 
        xopt_nochange__rehab     =  xopt_nochange__016   , 
                    
        xopt_increase_reason__more_ari   =  xopt_increase_reason__001    , 
        xopt_increase_reason__redirect   =  xopt_increase_reason__002    , 
        xopt_increase_reason__backlog    =  xopt_increase_reason__003    , 
        xopt_increase_reason__react  =  xopt_increase_reason__004    , 
        xopt_increase_reason__comms  =  xopt_increase_reason__005    , 
        xopt_increase_reason__other  =  xopt_increase_reason__006    , 
        xopt_decrease_reason__changerecs     =  xopt_decrease_reason__001    , 
        xopt_decrease_reason__fear   =  xopt_decrease_reason__002    , 
        xopt_decrease_reason__lockdown   =  xopt_decrease_reason__003    , 
        xopt_decrease_reason__transport  =  xopt_decrease_reason__004    , 
        xopt_decrease_reason__othercom   =  xopt_decrease_reason__005    , 
        xopt_decrease_reason__servreduc  =  xopt_decrease_reason__006    , 
        xopt_decrease_reason__disrupt    =  xopt_decrease_reason__007    , 
        xopt_decrease_reason__hours  =  xopt_decrease_reason__008    , 
        xopt_decrease_reason__closure    =  xopt_decrease_reason__009    , 
        xopt_decrease_reason__drugs  =  xopt_decrease_reason__010    , 
        xopt_decrease_reason__staff  =  xopt_decrease_reason__011    , 
        xopt_decrease_reason__otherfac   =  xopt_decrease_reason__012    , 
                    
        xer_increase__injuries   =  xer_increase__002    , 
        xer_increase__surgeries  =  xer_increase__003    , 
        xer_increase__ncd    =  xer_increase__004    , 
        xer_increase__blood  =  xer_increase__005    , 
        xer_decrease__injuries   =  xer_decrease__002    , 
        xer_decrease__surgeries  =  xer_decrease__003    , 
        xer_decrease__ncd    =  xer_decrease__004    , 
        xer_decrease__blood  =  xer_decrease__005    , 
                    
        xout_decrease__immun     =  xout_decrease__001   , 
        xout_decrease__cbc   =  xout_decrease__002   , 
        xout_decrease__home      =  xout_decrease__003   , 
                    
        xsafe__entrance_screening    =  xsafe__001   , 
        xsafe__staff_entrance    =  xsafe__006   , 
        xsafe__triage_c19    =  xsafe__triage    , 
        xsafe__isolatareas   =  xsafe__isolation     , 
        xsafe__distancing    =  xsafe__002   , 
        xsafe__hygiene_instructions  =  xsafe__003   , 
        xsafe__hygiene_stations  =  xsafe__007   , 
        xsafe__ppe   =  xsafe__008   , 
        xsafe__cleaning  =  xsafe__009   , 
                    
        xguideline__screening    =  xguideline__001  , 
        xguideline__c19_manage   =  xguideline__002  , 
        xguideline__ppe  =  xguideline__003  , 
        xguideline__c19_surveillance     =  xguideline__004  , 
        xguideline__deadbody     =  xguideline__005  , 
        xguideline__waste    =  xguideline__006  , 
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
        
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
        
        xcvd_pt__sep_room    =  xcvd_pt__001     , 
        xcvd_pt__c19_check   =  xcvd_pt__002     , 
        xcvd_pt__o2_measure  =  xcvd_pt__003     , 
        xcvd_pt__refer   =  xcvd_pt__004     , 
        xcvd_pt__diagtest    =  xcvd_pt__005     , 
        xcvd_pt__home_isolate    =  xcvd_pt__006     , 
        xcvd_pt__tele    =  xcvd_pt__007     , 
                    
        xcvd_pthbsi__tele    =  xcvd_pthbsi__001     , 
        xcvd_pthbsi__homevisit   =  xcvd_pthbsi__002     , 
        xcvd_pthbsi__followup_fac    =  xcvd_pthbsi__003     , 
        xcvd_pthbsi__safetyinstruct  =  xcvd_pthbsi__004     , 
        xcvd_pthbsi__complianceassess    =  xcvd_pthbsi__005     , 
                    
        xdrug__salbutamol    =  xdrug__001   , 
        xdrug__metformin     =  xdrug__002   , 
        xdrug__hydrochlorothiazide   =  xdrug__003   , 
        xdrug__paracetamol_susp  =  xdrug__004   , 
        xdrug__carbamazapine     =  xdrug__005   , 
        xdrug__amoxicillin_tabs  =  xdrug__006   , 
        xdrug__oralcontracept    =  xdrug__007   , 
        xdrug__oxytocin  =  xdrug__008   , 
        xdrug__magnesiumsulphate     =  xdrug__009   , 
        xdrug__heparin   =  xdrug__010   , 
        xdrug__hydrocortisone    =  xdrug__011   , 
        xdrug__epinephrine   =  xdrug__012   , 
        xdrug__ivfluids  =  xdrug__016   , 
        xdrug__oxygen    =  xdrug__017   , 
        xdrug__ceftriaxone   =  xdrug__013   , 
        xdrug__insulin   =  xdrug__014   , 
        xdrug__beclometasone     =  xdrug__015   , 
                    
        xsupply__syringes    =  xsupply__001     , 
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__gauze   =  xsupply__003     , 
                    
        xvaccine__mcv    =  xvaccine__001    , 
        xvaccine__dtp    =  xvaccine__002    , 
        xvaccine__polio  =  xvaccine__004    , 
        xvaccine__bcg    =  xvaccine__005    , 
        
        xdiag_av__bloodglucose   =  xdiag_av_a001    , 
        xdiag_av__urineglucose   =  xdiag_av_a002    , 
        xdiag_av__urineprotein   =  xdiag_av_a003    , 
        xdiag_av__pregnancy  =  xdiag_av_a004    , 
        
        xdiag_avfun__bloodglucose    =  xdiag_avfun_a001     , 
        xdiag_avfun__urineglucose    =  xdiag_avfun_a002     , 
        xdiag_avfun__urineprotein    =  xdiag_avfun_a003     , 
        xdiag_avfun__pregnancy   =  xdiag_avfun_a004     , 
        xdiag_av__h_hiv  =  xdiag_av_h001    , 
        xidag_av__h_tb   =  xdiag_av_h002    , 
        xdiag_av__h_hbg  =  xdiag_av_h003    , 
        xdiag_av__h_bloodtype    =  xdiag_av_h004    , 
        xdiag_av__h_bloodcreatine    =  xdiag_av_h005    , 
        xdiag_avfun__h_hiv   =  xdiag_avfun_h001     , 
        xidag_avfun__h_tb    =  xdiag_avfun_h002     , 
        xdiag_avfun__h_hbg   =  xdiag_avfun_h003     , 
        xdiag_avfun__h_bloodtype     =  xdiag_avfun_h004     , 
        xdiag_avfun__h_bloodcreatine     =  xdiag_avfun_h005     , 
                    
        ximage_av__xray  =  ximage_av_001    , 
        ximage_av__mri   =  ximage_av_003    , 
        ximage_av__ultrasound    =  ximage_av_004    , 
        ximage_av__ct    =  ximage_av_002    , 
        ximage_avfun__xray   =  ximage_avfun_001     , 
        ximage_avfun__mri    =  ximage_avfun_003     , 
        ximage_avfun__ultrasound     =  ximage_avfun_004     , 
        ximage_avfun__ct     =  ximage_avfun_002     
    )
tempZAMR1<- tempZAMR1%>%
    rename(
        xtraining__ipc   =  xtraining__001   , 
        xtraining__ppe   =  xtraining__002   , 
        xtraining__triage    =  xtraining__003   , 
        xtraining__emerg     =  xtraining__004   , 
        xtraining__remote    =  xtraining__005   , 
        xtraining__mental    =  xtraining__006   , 
        xtraining__ss_ipc    =  xtraining__007   , 
        xtraining__ss_ppe    =  xtraining__008   , 
        xtraining__ss_c19cm  =  xtraining__009   , 
        
        xopt_increase__undiff    =  xopt_increase__001   , 
        xopt_increase__fp    =  xopt_increase__002   , 
        xopt_increase__anc   =  xopt_increase__003   , 
        xopt_increase__pnc   =  xopt_increase__004   , 
        xopt_increase__immun     =  xopt_increase__005   , 
        xopt_increase__sickchild     =  xopt_increase__006   , 
        xopt_increase__hiv   =  xopt_increase__007   , 
        xopt_increase__tb    =  xopt_increase__008   , 
        xopt_increase__std   =  xopt_increase__009   , 
        xopt_increase__malaria   =  xopt_increase__010   , 
        xopt_increase__cvd   =  xopt_increase__011   , 
        xopt_increase__crd   =  xopt_increase__012   , 
        xopt_increase__diabetes  =  xopt_increase__013   , 
        xopt_increase__cancer    =  xopt_increase__014   , 
        xopt_increase__mental    =  xopt_increase__015   , 
        xopt_increase__violence  =  xopt_increase__016   , 
        xopt_increase__ntd   =  xopt_increase__017   , 
        xopt_increase__rehab     =  xopt_increase__018   , 
        xopt_decrease__undiff    =  xopt_decrease__001   , 
        xopt_decrease__fp    =  xopt_decrease__002   , 
        xopt_decrease__anc   =  xopt_decrease__003   , 
        xopt_decrease__pnc   =  xopt_decrease__004   , 
        xopt_decrease__immun     =  xopt_decrease__005   , 
        xopt_decrease__sickchild     =  xopt_decrease__006   , 
        xopt_decrease__hiv   =  xopt_decrease__007   , 
        xopt_decrease__tb    =  xopt_decrease__008   , 
        xopt_decrease__std   =  xopt_decrease__009   , 
        xopt_decrease__malaria   =  xopt_decrease__010   , 
        xopt_decrease__cvd   =  xopt_decrease__011   , 
        xopt_decrease__crd   =  xopt_decrease__012   , 
        xopt_decrease__diabetes  =  xopt_decrease__013   , 
        xopt_decrease__cancer    =  xopt_decrease__014   , 
        xopt_decrease__mental    =  xopt_decrease__015   , 
        xopt_decrease__violence  =  xopt_decrease__016   , 
        xopt_decrease__ntd   =  xopt_decrease__017   , 
        xopt_decrease__rehab     =  xopt_decrease__018   , 
        xopt_nochange__undiff    =  xopt_nochange__001   , 
        xopt_nochange__fp    =  xopt_nochange__002   , 
        xopt_nochange__anc   =  xopt_nochange__003   , 
        xopt_nochange__pnc   =  xopt_nochange__004   , 
        xopt_nochange__immun     =  xopt_nochange__005   , 
        xopt_nochange__sickchild     =  xopt_nochange__006   , 
        xopt_nochange__hiv   =  xopt_nochange__007   , 
        xopt_nochange__tb    =  xopt_nochange__008   , 
        xopt_nochange__std   =  xopt_nochange__009   , 
        xopt_nochange__malaria   =  xopt_nochange__010   , 
        xopt_nochange__cvd   =  xopt_nochange__011   , 
        xopt_nochange__crd   =  xopt_nochange__012   , 
        xopt_nochange__diabetes  =  xopt_nochange__013   , 
        xopt_nochange__cancer    =  xopt_nochange__014   , 
        xopt_nochange__mental    =  xopt_nochange__015   , 
        xopt_nochange__violence  =  xopt_nochange__016   , 
        xopt_nochange__ntd   =  xopt_nochange__017   , 
        xopt_nochange__rehab     =  xopt_nochange__018   , 
                    
        xopt_increase_reason__more_ari   =  xopt_increase_reason__001    , 
        xopt_increase_reason__redirect   =  xopt_increase_reason__002    , 
        xopt_increase_reason__backlog    =  xopt_increase_reason__003    , 
        xopt_increase_reason__react  =  xopt_increase_reason__004    , 
        xopt_increase_reason__comms  =  xopt_increase_reason__005    , 
        xopt_increase_reason__gbv    =  xopt_increase_reason__006    , 
        
        xopt_decrease_reason__changerecs     =  xopt_decrease_reason__001    , 
        xopt_decrease_reason__fear   =  xopt_decrease_reason__002    , 
        xopt_decrease_reason__lockdown   =  xopt_decrease_reason__003    , 
        xopt_decrease_reason__transport  =  xopt_decrease_reason__004    , 
        #xopt_decrease_reason__othercom  =  xopt_decrease_reason__005    , 
        xopt_decrease_reason__servreduc  =  xopt_decrease_reason__006    , 
        xopt_decrease_reason__disrupt    =  xopt_decrease_reason__007    , 
        xopt_decrease_reason__hours  =  xopt_decrease_reason__008    , 
        xopt_decrease_reason__closure    =  xopt_decrease_reason__009    , 
        xopt_decrease_reason__drugs  =  xopt_decrease_reason__010    , 
        xopt_decrease_reason__staff  =  xopt_decrease_reason__011    , 
        #xopt_decrease_reason__otherfac  =  xopt_decrease_reason__012    , 
                    
        xer_increase__injuries   =  xer_increase__002    , 
        xer_increase__surgeries  =  xer_increase__003    , 
        xer_increase__ncd    =  xer_increase__004    , 
        xer_increase__blood  =  xer_increase__005    , 
        xer_decrease__injuries   =  xer_decrease__002    , 
        xer_decrease__surgeries  =  xer_decrease__003    , 
        xer_decrease__ncd    =  xer_decrease__004    , 
        xer_decrease__blood  =  xer_decrease__005    , 
                    
        xout_decrease__immun     =  xout_decrease__001   , 
        xout_decrease__malaria   =  xout_decrease__002   , 
        xout_decrease__ntd   =  xout_decrease__003   , 
        xout_decrease__cbc   =  xout_decrease__004   , 
        xout_decrease__home      =  xout_decrease__005   , 
                    
        xsafe__entrance_screening    =  xsafe__001   , 
        xsafe__staff_entrance    =  xsafe__002   , 
        xsafe__sep_room  =  xsafe__003   , 
        xsafe__triage_c19    =  xsafe__triage    , 
        xsafe__isolatareas   =  xsafe__isolation     , 
        xsafe__triage_guidelines     =  xsafe__006   , 
        xsafe__distancing    =  xsafe__007   , 
        xsafe__hygiene_instructions  =  xsafe__008   , 
        xsafe__hygiene_stations  =  xsafe__009   , 
        xsafe__ppe   =  xsafe__010   , 
        xsafe__cleaning  =  xsafe__011   , 
                    
        xguideline__screening    =  xguideline__001  , 
        xguideline__c19_manage   =  xguideline__002  , 
        xguideline__ppe  =  xguideline__003  , 
        xguideline__c19_surveillance     =  xguideline__004  , 
        xguideline__deadbody     =  xguideline__005  , 
        xguideline__waste    =  xguideline__006  , 
                    
        xppe_allsome__gown   =  xppe_allsome__001    , 
        xppe_allsome__gloves     =  xppe_allsome__002    , 
        xppe_allsome__goggles    =  xppe_allsome__003    , 
        xppe_allsome__faceshield     =  xppe_allsome__004    , 
        xppe_allsome__respirator     =  xppe_allsome__005    , 
        xppe_allsome__mask   =  xppe_allsome__006    , 
                    
        xppe_all__gown   =  xppe_all__001    , 
        xppe_all__gloves     =  xppe_all__002    , 
        xppe_all__goggles    =  xppe_all__003    , 
        xppe_all__faceshield     =  xppe_all__004    , 
        xppe_all__respirator     =  xppe_all__005    , 
        xppe_all__mask   =  xppe_all__006    , 
                    
        xcvd_pt__sep_room    =  xcvd_pt__001     , 
        xcvd_pt__c19_check   =  xcvd_pt__002     , 
        xcvd_pt__o2_measure  =  xcvd_pt__003     , 
        xcvd_pt__refer   =  xcvd_pt__004     , 
        xcvd_pt__diagtest    =  xcvd_pt__005     , 
        xcvd_pt__home_isolate    =  xcvd_pt__006     , 
        xcvd_pt__tele    =  xcvd_pt__007     , 
                    
        xcvd_pthbsi__tele    =  xcvd_pthbsi__001     , 
        xcvd_pthbsi__homevisit   =  xcvd_pthbsi__002     , 
        xcvd_pthbsi__followup_fac    =  xcvd_pthbsi__003     , 
        xcvd_pthbsi__safetyinstruct  =  xcvd_pthbsi__004     , 
        xcvd_pthbsi__complianceassess    =  xcvd_pthbsi__005     , 
        xcvd_pthbsi__report  =  xcvd_pthbsi__006     , 
        
        xdrug__salbutamol    =  xdrug__001   , 
        xdrug__metformin     =  xdrug__002   , 
        xdrug__hydrochlorothiazide   =  xdrug__003   , 
        xdrug__paracetamol_susp  =  xdrug__004   , 
        xdrug__paracetamol_tabs  =  xdrug__005   , 
        xdrug__carbamazapine     =  xdrug__006   , 
        xdrug__amoxicillin_tabs  =  xdrug__007   , 
        xdrug__amoxicillin_susp  =  xdrug__008   , 
        xdrug__oralcontracept    =  xdrug__009   , 
        xdrug__oxytocin  =  xdrug__010   , 
        xdrug__magnesiumsulphate     =  xdrug__011   , 
        xdrug__heparin   =  xdrug__012   , 
        xdrug__hydrocortisone    =  xdrug__013   , 
        xdrug__epinephrine   =  xdrug__014   , 
        xdrug__artemether    =  xdrug__015   , 
        xdrug__efavirenz     =  xdrug__016   , 
        xdrug__isoniazid     =  xdrug__017   , 
        xdrug__ivfluids  =  xdrug__018   , 
        xdrug__oxygen    =  xdrug__019   , 
                    
        xsupply__syringes    =  xsupply__001     , 
        xsupply__ivsets  =  xsupply__002     , 
        xsupply__gauze   =  xsupply__003     , 
                    
        xvaccine__mcv    =  xvaccine__001    , 
        xvaccine__dtp    =  xvaccine__002    , 
        xvaccine__polio  =  xvaccine__003    , 
        xvaccine__bcg    =  xvaccine__004    , 
                    
        xdiag_av__malaria    =  xdiag_av_a001    , 
        xdiag_av__bloodglucose   =  xdiag_av_a002    , 
        xdiag_av__urineglucose   =  xdiag_av_a003    , 
        xdiag_av__urineprotein   =  xdiag_av_a004    , 
        xdiag_av__pregnancy  =  xdiag_av_a005    , 
        xdiag_avfun__malaria     =  xdiag_avfun_a001     , 
        xdiag_avfun__bloodglucose    =  xdiag_avfun_a002     , 
        xdiag_avfun__urineglucose    =  xdiag_avfun_a003     , 
        xdiag_avfun__urineprotein    =  xdiag_avfun_a004     , 
        xdiag_avfun__pregnancy   =  xdiag_avfun_a005     , 
        xdiag_av__h_hiv  =  xdiag_av_h001    , 
        xidag_av__h_tb   =  xdiag_av_h002    , 
        xdiag_av__h_hbg  =  xdiag_av_h003    , 
        xdiag_av__h_bloodtype    =  xdiag_av_h004    , 
        xdiag_av__h_bloodcreatine    =  xdiag_av_h005    , 
        xdiag_avfun__h_hiv   =  xdiag_avfun_h001     , 
        xidag_avfun__h_tb    =  xdiag_avfun_h002     , 
        xdiag_avfun__h_hbg   =  xdiag_avfun_h003     , 
        xdiag_avfun__h_bloodtype     =  xdiag_avfun_h004     , 
        xdiag_avfun__h_bloodcreatine     =  xdiag_avfun_h005     , 
                    
        ximage_av__xray  =  ximage_av_001    , 
        ximage_av__mri   =  ximage_av_003    , 
        ximage_av__ultrasound    =  ximage_av_004    , 
        ximage_av__ct    =  ximage_av_002    , 
        ximage_avfun__xray   =  ximage_avfun_001     , 
        ximage_avfun__mri    =  ximage_avfun_003     , 
        ximage_avfun__ultrasound     =  ximage_avfun_004     , 
        ximage_avfun__ct     =  ximage_avfun_002     , 
                    
        xcovax_offer__pfizer     =   xcovax_offer__001   , 
        xcovax_offerav__pfizer   =   xcovax_offerav__001     , 
        xcovax_offer__moderna    =   xcovax_offer__002   , 
        xcovax_offerav__moderna  =   xcovax_offerav__002     , 
        xcovax_offer__astra  =   xcovax_offer__003   , 
        xcovax_offerav__astra    =   xcovax_offerav__003     , 
        xcovax_offer__jj     =   xcovax_offer__004   , 
        xcovax_offerav__jj   =   xcovax_offerav__004     , 
        xcovax_offer__sinopharm  =   xcovax_offer__005   , 
        xcovax_offerav__sinopharm    =   xcovax_offerav__005     , 
        xcovax_offer__sinovac    =   xcovax_offer__006   , 
        xcovax_offerav__sinovac  =   xcovax_offerav__006     , 
        
        xcovax_train__storage    =   xcovax_train__001   , 
        xcovax_train__admin  =   xcovax_train__002   , 
        xcovax_train__manage_adverse     =   xcovax_train__003   , 
        xcovax_train__report_adverse     =   xcovax_train__004           
    )
#No "Annex" data in Kenya R2. Otherwise no deviation
dflist <- list(tempCMRR1, tempGHAR1, tempKENR1, tempUKRR1, tempZAMR1)

for(df in dflist) {
df<-df%>%
    rename(  
        vol_opt_now_m1_opt   =  vol_opt_now_001  , 
        vol_opt_now_m2_opt   =  vol_opt_now_002  , 
        vol_opt_now_m3_opt   =  vol_opt_now_003  , 
        vol_opt_now_m4_opt   =  vol_opt_now_004  , 
        vol_opt_last_m1_opt  =  vol_opt_last_005     , 
        vol_opt_last_m2_opt  =  vol_opt_last_006     , 
        vol_opt_last_m3_opt  =  vol_opt_last_007     , 
        vol_opt_last_m4_opt  =  vol_opt_last_008     , 
        
        vol_ipt_now_m1_ipt   =  vol_ipt_now_001  , 
        vol_ipt_now_m2_ipt   =  vol_ipt_now_002  , 
        vol_ipt_now_m3_ipt   =  vol_ipt_now_003  , 
        vol_ipt_now_m4_ipt   =  vol_ipt_now_004  , 
        vol_ipt_last_m1_ipt  =  vol_ipt_last_005     , 
        vol_ipt_last_m2_ipt  =  vol_ipt_last_006     , 
        vol_ipt_last_m3_ipt  =  vol_ipt_last_007     , 
        vol_ipt_last_m4_ipt  =  vol_ipt_last_008     , 
        
        vol_del_now_m1_del   =  vol_del_now_001  , 
        vol_del_now_m2_del   =  vol_del_now_002  , 
        vol_del_now_m3_del   =  vol_del_now_003  , 
        vol_del_now_m4_del   =  vol_del_now_004  , 
        vol_del_last_m1_del  =  vol_del_last_005     , 
        vol_del_last_m2_del  =  vol_del_last_006     , 
        vol_del_last_m3_del  =  vol_del_last_007     , 
        vol_del_last_m4_del  =  vol_del_last_008     ,
        
        vol_dpt_now_m1_dpt   =  vol_dpt_now_001  , 
        vol_dpt_now_m2_dpt   =  vol_dpt_now_002  , 
        vol_dpt_now_m3_dpt   =  vol_dpt_now_003  , 
        vol_dpt_now_m4_dpt   =  vol_dpt_now_004  , 
        vol_dpt_last_m1_dpt  =  vol_dpt_last_005     , 
        vol_dpt_last_m2_dpt  =  vol_dpt_last_006     , 
        vol_dpt_last_m3_dpt  =  vol_dpt_last_007     , 
        vol_dpt_last_m4_dpt  =  vol_dpt_last_008     
    )   
}

3.5. Append country/survey chartbooks

#dtaCEHS<-rbind(temp1, temp2, temp3, temp4, temp5)
#dtaCEHS<-bind_rows(temp1, temp2, temp3, temp4, temp5)
#deal with different number of columns + different type of columns 

dflist <- list(tempCMRR1, tempGHAR1, tempKENR1, tempKENR2, tempUKRR1, tempZAMR1)

dtaCEHS<-rbindlist(dflist, 
                   fill=TRUE)

class(dtaCEHS)
dim(dtaCEHS)
table(dtaCEHS$country)

str(dtaCEHS[, 1:10])

3.6. Further cleaning

# Drop empty rows 
dtaCEHS<-dtaCEHS%>%
    filter(country!="")%>%
    mutate(
        #https://unstats.un.org/unsd/tradekb/knowledgebase/country-code   
        countrycode="",
        countrycode=
            ifelse(tolower(country)=="cameroon", "CMR", 
            ifelse(tolower(country)=="kenya", "KEN", 
            ifelse(tolower(country)=="ukraine", "UKR", 
            ifelse(tolower(country)=="zambia", "ZMB", 
            ifelse(tolower(country)=="namibia", "NAM", 
            ifelse(tolower(country)=="peru", "PER", 
            ifelse(tolower(country)=="suriname", "SUR", 
            ifelse(tolower(country)=="ghana", "GHA", 
                   countrycode))))))))     
    )%>%    
    mutate(survey=paste0(countrycode,"_R",round))%>%
    rename(
        updatedate_survey = updatedate, 
        updatetime_survey = updatetime
    )%>%
    #mutate(updatedatetime=as.Date(Sys.time(    ), format='%d%b%Y'))
    mutate(updatedatetime=Sys.time() )



# CHECK if all numeric variables are indded numeric - and FIX it   
    dtaCEHS%>%select(starts_with("obs"))%>%str()
    
    dtaCEHS%>%select(starts_with("y"))%>%str()
    
    dtaCEHS%>%select(starts_with("x"))%>%str()
    
    dtaCEHS%>%select(starts_with("staff"))%>%str()
    
    dtaCEHS%>%select(starts_with("vol"))%>%str()
    
    dtaCEHS%>%select(-starts_with(c("x", "y", "obs", "staff", "vol")))%>%colnames()

varlist<-dtaCEHS%>%
    select(starts_with(c("x", "y", "obs", "staff", "vol")))%>%
    colnames()

dtaCEHS<-dtaCEHS%>%
    mutate_at(vars(varlist), funs(as.numeric))
    
# TRANSLATE French to English 
dtaCEHS<-dtaCEHS%>%
    mutate(
        group=replace(group, grepl("Tout", group)==TRUE, "All"),
        group=replace(group, grepl("Gestion", group)==TRUE, "Sector"),
        group=replace(group, grepl("Cat?gorie", group)==TRUE, "Level"),
        grouplabel=replace(grouplabel, grepl("Tout", grouplabel)==TRUE, "All")
        )%>%
    
# KEEP only common analyais domain   
    filter(group=="All"| group=="Level" | group=="Location" | group=="Sector")


table(dtaCEHS$grouplabel, dtaCEHS$survey)    

3.7. Export

dta<-dtaCEHS

setcolorder(dta, 
            c("updatedatetime", "updatedate_survey", "updatetime_survey",
               "country", "round", "year", "month", 
              "group", "grouplabel"))

write.csv(dta, 
          paste0(path,"HFA database/Archive/CEHS_all_countries.csv"),
          row.names=FALSE)

dta<-dta%>%filter(group=="All")

write.csv(dta, 
          paste0(pathdashboard,"CEHS_all_countries_national.csv"),
          row.names=FALSE)

4. COMMUNITY

4.1. Import group 1 country/survey chartbooks

#https://freshbiostats.wordpress.com/2012/12/21/handling-many-data-frames-in-r/

tempCMRR1<-read_excel((paste0(path,"AFRO/Cameroun/Round1",chartbooks,
                                 "/CMR_Community_Chartbook21July2021.xlsx")), 
                         #sheet = "Donn?es_estimations_indicateurs")
                         sheet = "Indicator estimate data")

tempGHAR1<-read_excel((paste0(path,"AFRO/Ghana/Round1",chartbooks,
                                 "/GH_Community_Chartbook.xlsx")), 
                         sheet = "Indicator estimate data")

tempKENR1<-read_excel((paste0(path,"AFRO/Kenya/Round1",chartbooks,
                                 "/KEN_Community_Chartbook_R1.xlsx")), 
                         sheet = "Indicator estimate data")

4.2. Inspect group 1 country/survey chartbooks

dflist <- list(tempCMRR1, tempGHAR1, tempKENR1)

lapply(dflist, dim)
lapply(dflist, function(df) table(df$country) )

4.3. Prepare further for select individual surveys that changed indicator

(e.g., Ghana CEHS naming convention, and Kenya Round 1 old names)

# Kenya: changes var names

# In Kenya R1, xunmetsome_* was for some OR most people. Change them to Xunmetsomemost_*

tempKENR1%>%select(grep("xunmet", names(tempKENR1)))%>%colnames() 
        
tempKENR1<-tempKENR1%>%
        rename_all(.funs = funs(sub("xunmetsome", "xunmetsomemost", .)))
            
tempKENR1%>%select(grep("xunmet", names(tempKENR1)))%>%colnames() 
# Ghane: fix from *__02 to *__002  
    
tempGHAR1%>%select(grep("__", names(tempGHAR1)))%>%colnames() 
        
    tempGHAR1%>%
        select(grep("__", names(tempGHAR1)), 
               -grep("__00", names(tempGHAR1)))%>%
        colnames()  
    
    varlist<-tempGHAR1%>%
        select(grep("__", names(tempGHAR1))   )%>%
        colnames() 

    newnames<-gsub('__', '__00', varlist)
    
    tempGHAR1<-tempGHAR1%>%
        rename_at(vars(varlist), ~ newnames)%>%
        rename_all(.funs = funs(sub("0010", "010", .)))%>%
        rename_all(.funs = funs(sub("0011", "011", .)))%>%
        rename_all(.funs = funs(sub("0012", "012", .)))%>%
        rename_all(.funs = funs(sub("0013", "013", .)))%>%
        rename_all(.funs = funs(sub("0014", "014", .)))%>%
        rename_all(.funs = funs(sub("0015", "015", .)))%>%
        
        rename_all(.funs = funs(sub("00a", "001", .)))%>%
        rename_all(.funs = funs(sub("00b", "002", .)))%>%
        rename_all(.funs = funs(sub("00c", "003", .)))%>%
        rename_all(.funs = funs(sub("00d", "004", .)))%>%
        rename_all(.funs = funs(sub("00e", "005", .)))%>%
        rename_all(.funs = funs(sub("00f", "006", .)))%>%
        rename_all(.funs = funs(sub("00g", "007", .)))%>%
        rename_all(.funs = funs(sub("00h", "008", .)))%>%
        rename_all(.funs = funs(sub("00i", "009", .)))%>%
        rename_all(.funs = funs(sub("00j", "010", .)))
            
tempGHAR1%>%select(grep("__", names(tempGHAR1)))%>%colnames() 

# check unmet need variables. Ugh.. xunmetsome_* was NOT calculated 

tempGHAR1%>%select(grep("unmet", names(tempGHAR1)))%>%colnames() 

tempGHAR1%>%
    mutate(
        check__001=xnounmetneed__001 + xunmetsome__001 + xunmetmost__001, 
        check__002=xnounmetneed__002 + xunmetsome__002 + xunmetmost__002, 
        check__003=xnounmetneed__003 + xunmetsome__003 + xunmetmost__003, 
        check__004=xnounmetneed__004 + xunmetsome__004 + xunmetmost__004, 
        check__005=xnounmetneed__005 + xunmetsome__005 + xunmetmost__005)%>%
    select(starts_with("check"))%>%
    summary()

tempGHAR1<-tempGHAR1%>%
    mutate(
        xunmetsomemost__001   =  xunmetsome__001     + xunmetmost__001  ,
        xunmetsomemost__002   =  xunmetsome__002     + xunmetmost__002  ,
        xunmetsomemost__003   =  xunmetsome__003     + xunmetmost__003  ,
        xunmetsomemost__004   =  xunmetsome__004     + xunmetmost__004  ,
        xunmetsomemost__005   =  xunmetsome__005     + xunmetmost__005  ,
        xunmetsomemost__006   =  xunmetsome__006     + xunmetmost__006  ,
        xunmetsomemost__007   =  xunmetsome__007     + xunmetmost__007  ,
        xunmetsomemost__008   =  xunmetsome__008     + xunmetmost__008  ,
        xunmetsomemost__009   =  xunmetsome__009     + xunmetmost__009  ,
        xunmetsomemost__010   =  xunmetsome__010     + xunmetmost__010  ,
        
        xunmetsomemost__urgent    =  xunmetsome_urgent   + xunmetmost_urgent    ,
        xunmetsomemost__elecsurg      =  xunmetsome_elecsurg     + xunmetmost_elecsurg  ,
        xunmetsomemost__rmch      =  xunmetsome_rmch     + xunmetmost_rmch  ,
        xunmetsomemost__chronic   =  xunmetsome_chronic  + xunmetmost_chronic   ,
        xunmetsomemost__homebased  =  xunmetsome_homebased   + xunmetmost_homebased 
    )

4.4. Rename indicators ending with sub-question numbers with more friendly names. See "Template for indicators.xlsx" in the share point.

dflist <- list(tempCMRR1, tempGHAR1, tempKENR1)

for(df in dflist) {
    table<-table(df$country)
    list<-df%>%select(starts_with("xunmetso"))%>%colnames()
    
    print(table)
    print(list)
}
tempKENR1<- tempKENR1%>%
    rename(
        xunmet__urgent   =  xunmetsomemost__001  , 
        xunmet__electsurg    =  xunmetsomemost__002  , 
        xunmet__chronicmeds  =  xunmetsomemost__003  , 
        xunmet__testing  =  xunmetsomemost__004  , 
        xunmet__mental   =  xunmetsomemost__005  , 
        xunmet__fp   =  xunmetsomemost__006  , 
        xunmet__anc  =  xunmetsomemost__007  , 
        xunmet__sba  =  xunmetsomemost__008  , 
        xunmet__immun    =  xunmetsomemost__009  , 
        xunmet__tbhiv    =  xunmetsomemost__010  , 
        xunmetmost__urgent   =  xunmetmost__001  , 
        xunmetmost__electsurg    =  xunmetmost__002  , 
        xunmetmost__chronicmeds  =  xunmetmost__003  , 
        xunmetmost__testing  =  xunmetmost__004  , 
        xunmetmost__mental   =  xunmetmost__005  , 
        xunmetmost__fp   =  xunmetmost__006  , 
        xunmetmost__anc  =  xunmetmost__007  , 
        xunmetmost__sba  =  xunmetmost__008  , 
        xunmetmost__immun    =  xunmetmost__009  , 
        xunmetmost__tbhiv    =  xunmetmost__010  , 
                    
        xsource__chw     =  xsource__001     , 
        xsource__healthpost  =  xsource__002     , 
        xsource__hospital    =  xsource__004     , 
        xsource__pharm   =  xsource__005     , 
        xsource__c19testcentre   =  xsource__006     , 
        xsource__c19phone    =  xsource__007     , 
        xsource__othertrained    =  xsource__008     , 
        xsource__traditional     =  xsource__009     , 
        xsource__internet    =  xsource__010     , 
        xsource__other   =  xsource__011     , 
    
        xsource__healthcentre    =  xsource__003     , 
                        
        xmargin__poverty     =  xmargin__001     , 
        xmargin__informal    =  xmargin__002     , 
        xmargin__unemployed  =  xmargin__003     , 
        xmargin__singleparent    =  xmargin__004     , 
        xmargin__isolatedold     =  xmargin__005     , 
        xmargin__disabled    =  xmargin__006     , 
        xmargin__lgbti   =  xmargin__007     , 
        xmargin__indigenous  =  xmargin__008     , 
        xmargin__religious   =  xmargin__009     , 
        xmargin__nomadic     =  xmargin__010     , 
        xmargin__migrants    =  xmargin__011     , 
        xmargin__ethnic  =  xmargin__012     , 
        xmargin__homeless    =  xmargin__014     , 
        xmargin__orphan  =  xmargin__015     , 
        #xmargin__other  =  xmargin__017     , 
        xmargin__underage_girls  =  xmargin__013     , 
        xmargin__women   =  xmargin__016     , 
                        
        xvac_reason__notconcerned    =  xvac_reason__001     , 
        xvac_reason__uncertain   =  xvac_reason__002     , 
        xvac_reason__sideeffects     =  xvac_reason__003     , 
        xvac_reason__avoidfacilities     =  xvac_reason__004     , 
        xvac_reason__mistrust    =  xvac_reason__005     , 
        xvac_reason__toobusy     =  xvac_reason__006     , 
        xvac_reason__cost    =  xvac_reason__007     , 
        #xvac_reason__other  =  xvac_reason__008     , 
                        
        xinit_ses_increased__cash    =  xinit_ses_increased__001     , 
        xinit_ses_increased__gbv     =  xinit_ses_increased__002     , 
        xinit_ses_increased__food    =  xinit_ses_increased__003     , 
        xinit_ses_increased__school  =  xinit_ses_increased__004     , 
        xinit_ses_increased__hygiene     =  xinit_ses_increased__005     , 
        xinit_ses_increased__isolated    =  xinit_ses_increased__006     , 
        xinit_ses_increased__taxrelief   =  xinit_ses_increased__007     , 
        xinit_ses_increased__local   =  xinit_ses_increased__008     , 
        xinit_ses_increased__other   =  xinit_ses_increased__009     , 
                        
        xinit_health_increased__hp   =  xinit_health_increased__001  , 
        xinit_health_increased__info     =  xinit_health_increased__002  , 
        xinit_health_increased__isolated     =  xinit_health_increased__005  , 
        xinit_health_increased__transhw  =  xinit_health_increased__003  , 
        xinit_health_increased__transvp  =  xinit_health_increased__004  , 
        xinit_health_increased__masks    =  xinit_health_increased__006  , 
        xinit_health_increased__handwash     =  xinit_health_increased__007  , 
        xinit_health_increased__hsaccess     =  xinit_health_increased__009  , 
        xinit_health_increased__water    =  xinit_health_increased__010  , 
        #xinit_health_increased__other   =  xinit_health_increased__011  , 
        xinit_health_increased__sanitizer    =  xinit_health_increased__008  , 
                        
        xrisk_reason__manypeople     =  xrisk_reason__001    , 
        xrisk_reason__ppelack    =  xrisk_reason__002    , 
        xrisk_reason__age    =  xrisk_reason__003    , 
        xrisk_reason__hours  =  xrisk_reason__004    , 
        xrisk_reason__transport  =  xrisk_reason__005    , 
        xrisk_reason__public     =  xrisk_reason__006    , 
        #xrisk_reason__other     =  xrisk_reason__007    , 
                        
        xsupportneed__monetary   =  xsupportneed__001    , 
        xsupportneed__ppe    =  xsupportneed__002    , 
        xsupportneed__supp   =  xsupportneed__003    , 
        xsupportneed__traincovid     =  xsupportneed__004    , 
        xsupportneed__trainother     =  xsupportneed__005    , 
        xsupportneed__trans  =  xsupportneed__007    , 
        #xsupportneed__insurance     =  xsupportneed__008    , 
        #xsupportneed__other     =  xsupportneed__009    , 
        xsupportneed__pysch  =  xsupportneed__006    , 
                        
        xsrv_reduced__immune     =  xsrvc_reduced__001   , 
        xsrv_reduced__malaria    =  xsrvc_reduced__002   , 
        xsrv_reduced__ntd    =  xsrvc_reduced__003   , 
        xsrv_reduced__tb     =  xsrvc_reduced__004   , 
                        
        xsrv_reduced__mnch   =  xsrvc_reduced__005   , 
        xsrv_increased__immune   =  xsrvc_increased__001     , 
        xsrv_increased__malaria  =  xsrvc_increased__002     , 
        xsrv_increased__ntd  =  xsrvc_increased__003     , 
        xsrv_increased__tb   =  xsrvc_increased__004     , 
                        
        xsrv_increased__mnch     =  xsrvc_increased__005     , 
        xsrv_nochange__immune    =  xsrvc_nochange__001  , 
        xsrv_nochange__malaria   =  xsrvc_nochange__002  , 
        xsrv_nochange__ntd   =  xsrvc_nochange__003  , 
        xsrv_nochange__tb    =  xsrvc_nochange__004  , 
                        
        xsrv_nochange__mnch  =  xsrvc_nochange__005  , 
        xhbc     =  xhbc     , 
        xhbc_adhsome__stayhome   =  xhbc_adhsome__001    , 
        xhbc_adhsome__stayseparate   =  xhbc_adhsome__002    , 
        xhbc_adhsome__mininteract    =  xhbc_adhsome__003    , 
        xhbc_adhsome__mask   =  xhbc_adhsome__004    , 
        xhbc_adhsome__utensils   =  xhbc_adhsome__005    , 
        xhbc_adhsome__disinfect  =  xhbc_adhsome__006    , 
        xhbc_adhalways__stayhome     =  xhbc_adhalways__001  , 
        xhbc_adhalways__stayseparate     =  xhbc_adhalways__002  , 
        xhbc_adhalways__mininteract  =  xhbc_adhalways__003  , 
        xhbc_adhalways__mask     =  xhbc_adhalways__004  , 
        xhbc_adhalways__utensils     =  xhbc_adhalways__005  , 
        xhbc_adhalways__disinfect    =  xhbc_adhalways__006  , 
        xhbc_stigma  =  xhbc_stigma  , 
        xhbc_support__refer  =  xhbc_support__001    , 
        xhbc_support__ppe    =  xhbc_support__002    , 
        xhbc_support__followup   =  xhbc_support__003    , 
        xhbc_support__nutrition  =  xhbc_support__004    , 
        xhbc_support__linkage    =  xhbc_support__005    
        #xhbc_support__psych     =  xhbc_support__006    , 
        #xhbc_support__other     =  xhbc_support__007    
    )
tempCMRR1<- tempCMRR1%>%
    rename(
        xunmet__urgent   =  xunmetsomemost__001  , 
        xunmet__electsurg    =  xunmetsomemost__002  , 
        xunmet__chronicmeds  =  xunmetsomemost__003  , 
        xunmet__testing  =  xunmetsomemost__004  , 
        xunmet__mental   =  xunmetsomemost__005  , 
        xunmet__fp   =  xunmetsomemost__006  , 
        xunmet__anc  =  xunmetsomemost__007  , 
        xunmet__sba  =  xunmetsomemost__008  , 
        xunmet__immun    =  xunmetsomemost__009  , 
        xunmet__homebased    =  xunmetsomemost__010  , 
                    
        xunmetmost__urgent   =  xunmetmost__001  , 
        xunmetmost__electsurg    =  xunmetmost__002  , 
        xunmetmost__chronicmeds  =  xunmetmost__003  , 
        xunmetmost__testing  =  xunmetmost__004  , 
        xunmetmost__mental   =  xunmetmost__005  , 
        xunmetmost__fp   =  xunmetmost__006  , 
        xunmetmost__anc  =  xunmetmost__007  , 
        xunmetmost__sba  =  xunmetmost__008  , 
        xunmetmost__immun    =  xunmetmost__009  , 
        xunmetmost__homebased    =  xunmetmost__010  , 
                    
        xsource__chw     =  xsource__001     ,  
        xsource__hospital    =  xsource__003     , 
        xsource__pharm   =  xsource__004     , 
        xsource__c19testcentre   =  xsource__005     , 
        xsource__c19phone    =  xsource__006     , 
        xsource__othertrained    =  xsource__007     , 
        xsource__traditional     =  xsource__008     , 
        xsource__internet    =  xsource__010     , 
        xsource__other   =  xsource__011     , 

        xsource__healthcentre    =  xsource__002     , 
        xsource__religious   =  xsource__009     , 
                    
        xmargin__poverty     =  xmargin__001     , 
        xmargin__informal    =  xmargin__002     , 
        xmargin__unemployed  =  xmargin__003     , 
        xmargin__singleparent    =  xmargin__004     , 
        xmargin__isolatedold     =  xmargin__005     , 
        xmargin__disabled    =  xmargin__006     , 
        xmargin__indigenous  =  xmargin__007     , 
        xmargin__religious   =  xmargin__008     , 
        xmargin__nomadic     =  xmargin__009     , 
        xmargin__migrants    =  xmargin__010     , 
        xmargin__ethnic  =  xmargin__013     , 
        xmargin__homeless    =  xmargin__014     , 
        xmargin__orphan  =  xmargin__015     , 
        #xmargin__other  =  xmargin__016     , 
        xmargin__refuges     =  xmargin__010     , 
        xmargin__internal_diplaced   =  xmargin__011     , 
                    
        xvac_reason__notconcerned    =  xvac_reason__001     , 
        xvac_reason__uncertain   =  xvac_reason__002     , 
        xvac_reason__sideeffects     =  xvac_reason__003     , 
        xvac_reason__avoidfacilities     =  xvac_reason__004     , 
        xvac_reason__mistrust    =  xvac_reason__005     , 
        xvac_reason__toobusy     =  xvac_reason__006     , 
        xvac_reason__cost    =  xvac_reason__007     , 
        xvac_reason__other   =  xvac_reason__008     , 
                    
        xinit_ses_increased__cash    =  xinit_ses_increased__001     , 
        xinit_ses_increased__gbv     =  xinit_ses_increased__002     , 
        xinit_ses_increased__food    =  xinit_ses_increased__003     , 
        xinit_ses_increased__school  =  xinit_ses_increased__004     , 
        xinit_ses_increased__hygiene     =  xinit_ses_increased__005     , 
        xinit_ses_increased__isolated    =  xinit_ses_increased__006     , 
        xinit_ses_increased__taxrelief   =  xinit_ses_increased__007     , 
        xinit_ses_increased__local   =  xinit_ses_increased__008     , 
        #xinit_ses_increased__other  =  xinit_ses_increased__009     , 
                    
        xinit_health_increased__hp   =  xinit_health_increased__001  , 
        xinit_health_increased__info     =  xinit_health_increased__002  , 
        xinit_health_increased__isolated     =  xinit_health_increased__003  , 
        xinit_health_increased__transhw  =  xinit_health_increased__004  , 
        xinit_health_increased__transvp  =  xinit_health_increased__005  , 
        xinit_health_increased__masks    =  xinit_health_increased__006  , 
        xinit_health_increased__handwash     =  xinit_health_increased__007  , 
        xinit_health_increased__hsaccess     =  xinit_health_increased__008  , 
        xinit_health_increased__water    =  xinit_health_increased__009  , 
        xinit_health_increased__other    =  xinit_health_increased__010  , 
                        
        xrisk_reason__manypeople     =  xrisk_reason__001    , 
        xrisk_reason__ppelack    =  xrisk_reason__002    , 
        xrisk_reason__age    =  xrisk_reason__003    , 
        xrisk_reason__hours  =  xrisk_reason__004    , 
        xrisk_reason__transport  =  xrisk_reason__005    , 
        xrisk_reason__public     =  xrisk_reason__006    , 
        #xrisk_reason__other     =  xrisk_reason__007    , 
                    
        xsupportneed__monetary   =  xsupportneed__001    , 
        xsupportneed__ppe    =  xsupportneed__003    , 
        xsupportneed__supp   =  xsupportneed__004    , 
        xsupportneed__traincovid     =  xsupportneed__005    , 
        xsupportneed__trainother     =  xsupportneed__006    , 
        xsupportneed__trans  =  xsupportneed__007    , 
        xsupportneed__insurance  =  xsupportneed__008    , 
        #xsupportneed__other     =  xsupportneed__010    , 
        xsupportneed__admin  =  xsupportneed__002    , 
        
        xsrv_reduced__immune     =  xsrvc_reduced__001   , 
        xsrv_reduced__malaria    =  xsrvc_reduced__002   , 
        xsrv_reduced__ntd    =  xsrvc_reduced__003   , 
        xsrv_reduced__tb     =  xsrvc_reduced__004   , 
                    
        xsrv_increased__immune   =  xsrvc_increased__001     , 
        xsrv_increased__malaria  =  xsrvc_increased__002     , 
        xsrv_increased__ntd  =  xsrvc_increased__003     , 
        xsrv_increased__tb   =  xsrvc_increased__004     , 
                    
        xsrv_nochange__immune    =  xsrvc_nochange__001  , 
        xsrv_nochange__malaria   =  xsrvc_nochange__002  , 
        xsrv_nochange__ntd   =  xsrvc_nochange__003  , 
        xsrv_nochange__tb    =  xsrvc_nochange__004  
    )
tempGHAR1<- tempGHAR1%>%
    rename(
        xunmet__urgent   =  xunmetsomemost__001  , 
        xunmet__electsurg    =  xunmetsomemost__002  , 
        xunmet__chronicmeds  =  xunmetsomemost__003  , 
        xunmet__testing  =  xunmetsomemost__004  , 
        xunmet__mental   =  xunmetsomemost__005  , 
        xunmet__fp   =  xunmetsomemost__006  , 
        xunmet__anc  =  xunmetsomemost__007  , 
        xunmet__sba  =  xunmetsomemost__008  , 
        xunmet__immun    =  xunmetsomemost__009  , 
        xunmet__homebased    =  xunmetsomemost__010  , 
                    
        xunmetmost__urgent   =  xunmetmost__001  , 
        xunmetmost__electsurg    =  xunmetmost__002  , 
        xunmetmost__chronicmeds  =  xunmetmost__003  , 
        xunmetmost__testing  =  xunmetmost__004  , 
        xunmetmost__mental   =  xunmetmost__005  , 
        xunmetmost__fp   =  xunmetmost__006  , 
        xunmetmost__anc  =  xunmetmost__007  , 
        xunmetmost__sba  =  xunmetmost__008  , 
        xunmetmost__immun    =  xunmetmost__009  , 
        xunmetmost__homebased    =  xunmetmost__010  , 
                    
        xsource__chw     =  xsource__001     , 
        xsource__healthpost  =  xsource__002     , 
        xsource__hospital    =  xsource__004     , 
        xsource__pharm   =  xsource__005     , 
        xsource__c19testcentre   =  xsource__006     , 
        xsource__c19phone    =  xsource__007     , 
        xsource__othertrained    =  xsource__008     , 
        xsource__traditional     =  xsource__009     , 
        xsource__internet    =  xsource__010     , 
        xsource__other   =  xsource__011     , 
        
        xsource__healthcentre    =  xsource__003     , 
                    
        xmargin__poverty     =  xmargin__001     , 
        xmargin__informal    =  xmargin__002     , 
        xmargin__unemployed  =  xmargin__003     , 
        xmargin__singleparent    =  xmargin__004     , 
        xmargin__isolatedold     =  xmargin__005     , 
        xmargin__disabled    =  xmargin__006     , 
        xmargin__lgbti   =  xmargin__007     , 
        xmargin__indigenous  =  xmargin__008     , 
        xmargin__religious   =  xmargin__009     , 
        xmargin__nomadic     =  xmargin__010     , 
        xmargin__migrants    =  xmargin__011     , 
        xmargin__ethnic  =  xmargin__012     , 
        xmargin__homeless    =  xmargin__013     , 
        xmargin__orphan  =  xmargin__014     , 
        xmargin__other   =  xmargin__015     , 
                    
        xvac_reason__notconcerned    =  xvac_reason__001     , 
        xvac_reason__uncertain   =  xvac_reason__002     , 
        xvac_reason__sideeffects     =  xvac_reason__003     , 
        xvac_reason__avoidfacilities     =  xvac_reason__004     , 
        xvac_reason__mistrust    =  xvac_reason__005     , 
        xvac_reason__toobusy     =  xvac_reason__006     , 
        xvac_reason__cost    =  xvac_reason__007     , 
        #xvac_reason__other  =  xvac_reason__009     , 
        #xvac_reason__nocovid    =  xvac_reason__008     , 
                    
        xinit_ses_increased__cash    =  xinit_ses_increased__001     , 
        xinit_ses_increased__gbv     =  xinit_ses_increased__002     , 
        xinit_ses_increased__food    =  xinit_ses_increased__003     , 
        xinit_ses_increased__school  =  xinit_ses_increased__004     , 
        xinit_ses_increased__hygiene     =  xinit_ses_increased__005     , 
        xinit_ses_increased__isolated    =  xinit_ses_increased__006     , 
        xinit_ses_increased__taxrelief   =  xinit_ses_increased__007     , 
        xinit_ses_increased__local   =  xinit_ses_increased__008     , 
        xinit_ses_increased__other   =  xinit_ses_increased__009     , 
                    
        xinit_health_increased__hp   =  xinit_health_increased__001  , 
        xinit_health_increased__info     =  xinit_health_increased__002  , 
        xinit_health_increased__isolated     =  xinit_health_increased__003  , 
        xinit_health_increased__transhw  =  xinit_health_increased__004  , 
        xinit_health_increased__transvp  =  xinit_health_increased__005  , 
        xinit_health_increased__masks    =  xinit_health_increased__006  , 
        xinit_health_increased__handwash     =  xinit_health_increased__007  , 
        xinit_health_increased__hsaccess     =  xinit_health_increased__008  , 
        xinit_health_increased__water    =  xinit_health_increased__009  , 
        xinit_health_increased__other    =  xinit_health_increased__010  , 
                    
        xrisk_reason__manypeople     =  xrisk_reason__001    , 
        xrisk_reason__ppelack    =  xrisk_reason__002    , 
        xrisk_reason__age    =  xrisk_reason__003    , 
        xrisk_reason__hours  =  xrisk_reason__004    , 
        xrisk_reason__transport  =  xrisk_reason__005    , 
        xrisk_reason__public     =  xrisk_reason__006    , 
        xsrv_reduced__immune     =  xsrvc_reduced__001   , 
        xsrv_reduced__malaria    =  xsrvc_reduced__002   , 
        xsrv_reduced__ntd    =  xsrvc_reduced__003   , 
        xsrv_reduced__tb     =  xsrvc_reduced__004   , 
        xsrv_reduced__home   =  xsrvc_reduced__005   , 
                    
        xsrv_increased__immune   =  xsrvc_increased__001     , 
        xsrv_increased__malaria  =  xsrvc_increased__002     , 
        xsrv_increased__ntd  =  xsrvc_increased__003     , 
        xsrv_increased__tb   =  xsrvc_increased__004     , 
        xsrv_increased__home     =  xsrvc_increased__005     , 
                    
        xsrv_nochange__immune    =  xsrvc_nochange__001  , 
        xsrv_nochange__malaria   =  xsrvc_nochange__002  , 
        xsrv_nochange__ntd   =  xsrvc_nochange__003  , 
        xsrv_nochange__tb    =  xsrvc_nochange__004  , 
        xsrv_nochange__home  =  xsrvc_nochange__005  
    )

4.5. Append country/survey chartbooks

#dtaCOM<-rbind(temp1, temp2, temp3, temp4)
#dtaCOM<-bind_rows(temp1, temp2, temp3, temp4)
#deal with different number of columns + different type of columns 

dflist <- list(tempCMRR1, tempGHAR1, tempKENR1)

dtaCOM<-rbindlist(dflist,
                   fill=TRUE)

class(dtaCOM)
dim(dtaCOM)
table(dtaCOM$country)

str(dtaCOM[, 1:10])

4.6. Further cleaning

# Drop empty rows 
dtaCOM<-dtaCOM%>%
    filter(country!="")%>%
    mutate(
        #https://unstats.un.org/unsd/tradekb/knowledgebase/country-code   
        countrycode="",
        countrycode=
            ifelse(tolower(country)=="cameroon", "CMR", 
            ifelse(tolower(country)=="kenya", "KEN", 
            ifelse(tolower(country)=="ukraine", "UKR", 
            ifelse(tolower(country)=="zambia", "ZMB", 
            ifelse(tolower(country)=="namibia", "NAM", 
            ifelse(tolower(country)=="peru", "PER", 
            ifelse(tolower(country)=="suriname", "SUR", 
            ifelse(tolower(country)=="ghana", "GHA", 
                   countrycode))))))))      
    )%>%    
    mutate(survey=paste0(countrycode,"_R",round))%>%
    rename(
        updatedate_survey = updatedate, 
        updatetime_survey = updatetime
    )%>%
    #mutate(updatedatetime=as.Date(Sys.time(    ), format='%d%b%Y'))
    mutate(updatedatetime=Sys.time() )

# CHECK if all numeric variables are indded numeric - and FIX it   
    dtaCOM%>%select(starts_with("obs"))%>%str()
    
    dtaCOM%>%select(starts_with("y"))%>%str()
    
    dtaCOM%>%select(starts_with("x"))%>%str()
    
    dtaCOM%>%select(-starts_with(c("x", "y", "obs")))%>%colnames()
    
varlist<-dtaCOM%>%
    select(starts_with(c("x", "y", "obs")))%>%
    colnames()

dtaCOM<-dtaCOM%>%
    mutate_at(vars(varlist), funs(as.numeric))
    
# TRANSLATE French to English 
table(dtaCOM$group, dtaCOM$survey)

dtaCOM<-dtaCOM%>%
    mutate(
        group=replace(group, grepl("Tout", group)==TRUE, "All"),
        group=replace(group, grepl("Occupation", group)==TRUE, "Occupation"),
        group=replace(group, grepl("Role", group)==TRUE, "Occupation"),
        grouplabel=replace(grouplabel, grepl("Tout", grouplabel)==TRUE, "All")
        )%>%
    
# KEEP only common analyais domain   
    filter(group=="All"| group=="Occupation" | group=="Location")

table(dtaCOM$grouplabel, dtaCOM$survey)

4.7. Export

dta<-dtaCOM

setcolorder(dta, 
            c("updatedatetime", "updatedate_survey", "updatetime_survey",
               "country", "round", "year", "month", 
              "group", "grouplabel"))

write.csv(dta, 
          paste0(path,"HFA database/Archive/Community_all_countries.csv"),
          row.names=FALSE)

dta<-dta%>%filter(group=="All")

write.csv(dta, 
          paste0(pathdashboard,"Community_all_countries_national.csv"),
          row.names=FALSE)