---
title: "WISN requirement"
author: "Yash"
date: "18/11/2020"
output: html_document
---
# Workforce problems at rural public health-centres in India: A WISN retrospective analysis and national-level modelling study
# ASAR

Analyzing WISN for cadres at individual facility level (across year) for each state

```{r packages}
library(reticulate)
#use_python("/usr/local/bin/python")
#use_virtualenv("myenv")
library(tidyverse)

```

# Read Data

WISN calculations for,
* Doc, Specialists, Nurse @ CHC
* Doc, Nurse @ PHC
* Doc, Nurse @ SC

WISN formulation
* [A] Total workload
* [B] CAF
* [C] IAF

## State | MP ----------
. ==================================================
General info
Data release information sheet | IHME_ABCE_IND_MP_2014_FACILITY_INFO_SHEET_Y2018M03D27.PDF
Codebook, with descriptions of all variables | IHME_ABCE_IND_MP_2014_FACILITY_CODEBOOK_Y2018M03D27.CSV
Public use survey dataset – CSV format | IHME_ABCE_IND_MP_2014_FACILITY_DATA_Y2018M03D27.CSV

```{r get Data | MP}
data_df <- read_csv("../data/ABCE/IHME_ABCE_IND_MP_2014_FACILITY_DATA_Y2018M03D27.CSV")
as_tibble(data_df)

```

### Specialists @ CHC
. --------------------------------------------------
> OBGYN | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy_13 Norm Del          | 10 mins/pt  6/hr
  2     | Cesarian-OT         | ipc_fy_14 C-section         | 30 mins/pt  2/hr 
  3     | Outpatients         | opc_fy_9 Antenatal          | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy_10 Postnatal         | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X

```{r OBGYN @ CHC | MP}
# getting_data
obgyn_chc_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs1,
         ipc_fy_13, ipc_fy_14, opc_fy_9, opc_fy_10,
         pers_fte_fy_21) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy_13) & !is.na(ipc_fy_14) & !is.na(opc_fy_9) & !is.na(opc_fy_10)) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_2), vi12 = max(teams_admin_dpw_2), vi13 = max(teams_admin_hpd_2),
            vi21 = max(teams_admin_pers_3), vi22 = max(teams_admin_dpw_3), vi23 = max(teams_admin_hpd_3),
            vi31 = max(teams_admin_pers_5), vi32 = max(teams_admin_dpw_5), vi33 = max(teams_admin_hpd_5))

leave = 102 # days
obgyn_chc_2012_df <- obgyn_chc_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
obgyn_chc_2012_df <- obgyn_chc_2012_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 2 *awt,
  sw3 = 4 *awt,
  sw4 = 4 *awt) # max_patient

obgyn_chc_2012_df <- obgyn_chc_2012_df %>% mutate(
  aw1 = ipc_fy_13,
  aw2 = ipc_fy_14,
  aw3 = opc_fy_9,
  aw4 = opc_fy_10)# patient_load | required staff

obgyn_chc_2012_df <- obgyn_chc_2012_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
obgyn_chc_2012_df <- obgyn_chc_2012_df %>% mutate(
  cas1 = (4*12) /awt *100 )

obgyn_chc_2012_df <- obgyn_chc_2012_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
obgyn_chc_2012_df <- obgyn_chc_2012_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3

obgyn_chc_2012_df <- obgyn_chc_2012_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
obgyn_chc_2012_df <- obgyn_chc_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

obgyn_chc_2012_df_sum <- obgyn_chc_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_chc_obgyn_df <- obgyn_chc_2012_df
mp_chc_obgyn_df_sum <- obgyn_chc_2012_df_sum

mp_chc_obgyn_df
mp_chc_obgyn_df_sum

```

> SurgerySpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_12 visits            | 10 mins/pt  6/hr
  2     | Inpatients          | ipc_fy_4 admissions         | 10 mins/pt  6/hr 
  3     | Operate Major       | ipc_fy_10 #major            | 2  hr/pt  0.5/hr
  4     | Operate minor       | ipc_fy_11 #minor            | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X

```{r SurgerySpec @ CHC | MP}
# getting_data
surgeryspec_chc_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs1,
         opc_fy_12, ipc_fy_4, ipc_fy_10, ipc_fy_11,
         pers_fte_fy_19) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_12) & !is.na(ipc_fy_4) & !is.na(ipc_fy_10) & !is.na(ipc_fy_11)) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_2), vi12 = max(teams_admin_dpw_2), vi13 = max(teams_admin_hpd_2),
            vi21 = max(teams_admin_pers_3), vi22 = max(teams_admin_dpw_3), vi23 = max(teams_admin_hpd_3),
            vi31 = max(teams_admin_pers_5), vi32 = max(teams_admin_dpw_5), vi33 = max(teams_admin_hpd_5))

leave = 102 # days
surgeryspec_chc_2012_df <- surgeryspec_chc_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
surgeryspec_chc_2012_df <- surgeryspec_chc_2012_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt,
  sw3 = 0.5 *awt,
  sw4 = 4 *awt) # max_patient

surgeryspec_chc_2012_df <- surgeryspec_chc_2012_df %>% mutate(
  aw1 = opc_fy_12,
  aw2 = ipc_fy_4,
  aw3 = ipc_fy_10,
  aw4 = ipc_fy_11)# patient_load | required staff

surgeryspec_chc_2012_df <- surgeryspec_chc_2012_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
surgeryspec_chc_2012_df <- surgeryspec_chc_2012_df %>% mutate(
  cas1 = (4*12) /awt *100 )

surgeryspec_chc_2012_df <- surgeryspec_chc_2012_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
surgeryspec_chc_2012_df <- surgeryspec_chc_2012_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3

surgeryspec_chc_2012_df <- surgeryspec_chc_2012_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
surgeryspec_chc_2012_df <- surgeryspec_chc_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

surgeryspec_chc_2012_df_sum <- surgeryspec_chc_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_chc_surgeryspec_df <- surgeryspec_chc_2012_df
mp_chc_surgeryspec_df_sum <- surgeryspec_chc_2012_df_sum

mp_chc_surgeryspec_df
mp_chc_surgeryspec_df_sum

```

> EyeSpec [Ophthalmologist] | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_8 visits             | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X

```{r EyeSpec @ CHC | MP}
# getting_data
eyespec_chc_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs1,
         opc_fy_8,
         pers_fte_fy_27) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_8)) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_2), vi12 = max(teams_admin_dpw_2), vi13 = max(teams_admin_hpd_2),
            vi21 = max(teams_admin_pers_3), vi22 = max(teams_admin_dpw_3), vi23 = max(teams_admin_hpd_3),
            vi31 = max(teams_admin_pers_5), vi32 = max(teams_admin_dpw_5), vi33 = max(teams_admin_hpd_5))

leave = 102 # days
eyespec_chc_2012_df <- eyespec_chc_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
eyespec_chc_2012_df <- eyespec_chc_2012_df %>% mutate(
  sw1 = 4 *awt) # max_patient

eyespec_chc_2012_df <- eyespec_chc_2012_df %>% mutate(
  aw1 = opc_fy_8)# patient_load | required staff

eyespec_chc_2012_df <- eyespec_chc_2012_df %>% mutate(
  HSA = aw1/sw1) #

'---------- CAF ----------'
eyespec_chc_2012_df <- eyespec_chc_2012_df %>% mutate(
  cas1 = (4*12) /awt *100 )

eyespec_chc_2012_df <- eyespec_chc_2012_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
eyespec_chc_2012_df <- eyespec_chc_2012_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3

eyespec_chc_2012_df <- eyespec_chc_2012_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
eyespec_chc_2012_df <- eyespec_chc_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

eyespec_chc_2012_df_sum <- eyespec_chc_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_chc_eyespec_df <- eyespec_chc_2012_df
mp_chc_eyespec_df_sum <- eyespec_chc_2012_df_sum

mp_chc_eyespec_df
mp_chc_eyespec_df_sum

```

> ChildSpec [Paedistrician] | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_4 visits             | 10 mins/pt  6/hr
  2     | Inpatients          | ipc_fy_2 admissions         | 10 mins/pt   6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X

```{r ChildSpec @ CHC | MP}
# getting_data
childspec_chc_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs1,
         opc_fy_4, ipc_fy_2,
         pers_fte_fy_24) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_4) & !is.na(ipc_fy_2)) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_2), vi12 = max(teams_admin_dpw_2), vi13 = max(teams_admin_hpd_2),
            vi21 = max(teams_admin_pers_3), vi22 = max(teams_admin_dpw_3), vi23 = max(teams_admin_hpd_3),
            vi31 = max(teams_admin_pers_5), vi32 = max(teams_admin_dpw_5), vi33 = max(teams_admin_hpd_5))

leave = 102 # days
childspec_chc_2012_df <- childspec_chc_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
childspec_chc_2012_df <- childspec_chc_2012_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt) # max_patient

childspec_chc_2012_df <- childspec_chc_2012_df %>% mutate(
  aw1 = opc_fy_4,
  aw2 = ipc_fy_2)# patient_load | required staff

childspec_chc_2012_df <- childspec_chc_2012_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2) #

'---------- CAF ----------'
childspec_chc_2012_df <- childspec_chc_2012_df %>% mutate(
  cas1 = (4*12) /awt *100 )

childspec_chc_2012_df <- childspec_chc_2012_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
childspec_chc_2012_df <- childspec_chc_2012_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3

childspec_chc_2012_df <- childspec_chc_2012_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
childspec_chc_2012_df <- childspec_chc_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

childspec_chc_2012_df_sum <- childspec_chc_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_chc_childspec_df <- childspec_chc_2012_df
mp_chc_childspec_df_sum <- childspec_chc_2012_df_sum

mp_chc_childspec_df
mp_chc_childspec_df_sum

```

> MedicalSpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_5 general            | 5 mins/pt  12/hr
  2     | Outpatients         | opc_fy_7 diabetic           | 5 mins/pt  12/hr 
  3     | Outpatients         | opc_fy_6 hypertension       | 10 mins/pt  6/hr
  4     | Inpatients          | ipc_fy_3 general            | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X

```{r MedicalSpec @ CHC | MP}
# getting_data
medicalspec_chc_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs1,
         opc_fy_5, opc_fy_7, opc_fy_6, ipc_fy_3,
         pers_fte_fy_20) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_5) & !is.na(opc_fy_7) & !is.na(opc_fy_6) & !is.na(ipc_fy_3)) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_2), vi12 = max(teams_admin_dpw_2), vi13 = max(teams_admin_hpd_2),
            vi21 = max(teams_admin_pers_3), vi22 = max(teams_admin_dpw_3), vi23 = max(teams_admin_hpd_3),
            vi31 = max(teams_admin_pers_5), vi32 = max(teams_admin_dpw_5), vi33 = max(teams_admin_hpd_5))

leave = 102 # days
medicalspec_chc_2012_df <- medicalspec_chc_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
medicalspec_chc_2012_df <- medicalspec_chc_2012_df %>% mutate(
  sw1 = 12 *awt,
  sw2 = 12 *awt,
  sw3 = 6 *awt,
  sw4 = 6 *awt) # max_patient

medicalspec_chc_2012_df <- medicalspec_chc_2012_df %>% mutate(
  aw1 = opc_fy_5,
  aw2 = opc_fy_7,
  aw3 = opc_fy_6,
  aw4 = ipc_fy_3)# patient_load | required staff

medicalspec_chc_2012_df <- medicalspec_chc_2012_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
medicalspec_chc_2012_df <- medicalspec_chc_2012_df %>% mutate(
  cas1 = (4*12) /awt *100 )

medicalspec_chc_2012_df <- medicalspec_chc_2012_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
medicalspec_chc_2012_df <- medicalspec_chc_2012_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3

medicalspec_chc_2012_df <- medicalspec_chc_2012_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
medicalspec_chc_2012_df <- medicalspec_chc_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

medicalspec_chc_2012_df_sum <- medicalspec_chc_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_chc_medicalspec_df <- medicalspec_chc_2012_df
mp_chc_medicalspec_df_sum <- medicalspec_chc_2012_df_sum

mp_chc_medicalspec_df
mp_chc_medicalspec_df_sum

```

### MO @ Facility
. --------------------------------------------------
> MedicalOfficer | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy_13 Normal Del        | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy_9 antenatal          | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy_10 postnatal         | 15 mins/pt  4/hr
  4     | Emergency           | ec_fy_1 emergency           | 20 mins/pt  3/hr    ----- X
  5     | Outpatients         | opc_fy_8 eye                | 15 mins/pt  4/hr    ----- X
  6     | Outpatients         | opc_fy_4 child              | 10 mins/pt  6/hr 
  7     | Inpatients          | ipc_fy_2 admissions         | 10 mins/pt  6/hr
  8     | Outpatients         | opc_fy_5 general            | 5 mins/pt  12/hr
  9     | Outpatients         | opc_fy_7 diabetes           | 5 mins/pt  12/hr 
  10    | Outpatients         | opc_fy_6 hypertension       | 10 mins/pt  6/hr
  11    | Inpatients          | ipc_fy_3 general            | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X
  4     | Immunization meet   | 1                           | 4 hr/month

```{r MedicalOfficer @ PHC | MP}
# getting_data
mo_phc_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs1,
         ipc_fy_13, opc_fy_9, opc_fy_10,
         #ec_fy_1,
         #opc_fy_8,
         opc_fy_4, ipc_fy_2,
         opc_fy_5, opc_fy_7, opc_fy_6, ipc_fy_3,
         pers_fte_fy_13) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  filter(!is.na(ipc_fy_13) & !is.na(opc_fy_9) & !is.na(opc_fy_10) & 
           #!is.na(ec_fy_1) &
           #!is.na(opc_fy_8) &
           !is.na(opc_fy_4) & !is.na(ipc_fy_2) &
           !is.na(opc_fy_5) & !is.na(opc_fy_7) & !is.na(opc_fy_6) & !is.na(ipc_fy_3)) %>%
  #filter(fte_hrs1 > 0) %>%
  filter(fte_hrs1 >= 24) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban"))

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5,
         imm_meetings) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_5, na.rm = TRUE), vi32 = max(teams_admin_dpw_5, na.rm = TRUE), vi33 = max(teams_admin_hpd_5), na.rm = TRUE)

leave = 102 # days
mo_phc_2012_df <- mo_phc_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
mo_phc_2012_df <- mo_phc_2012_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  #sw4 = 3 *awt,
  #sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 12 *awt,
  sw10 = 6 *awt,
  sw11 = 6 *awt) # max_patient

mo_phc_2012_df <- mo_phc_2012_df %>% mutate(
  aw1 = ipc_fy_13,
  aw2 = opc_fy_9,
  aw3 = opc_fy_10,
  #aw4 = ec_fy_1,
  #aw5 = opc_fy_8,
  aw6 = opc_fy_4,
  aw7 = ipc_fy_2,
  aw8 = opc_fy_5,
  aw9 = opc_fy_7,
  aw10 = opc_fy_6,
  aw11 = ipc_fy_3)# patient_load | required staff

mo_phc_2012_df <- mo_phc_2012_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  #+aw4/sw4
  #+aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11) #

'---------- CAF ----------'
mo_phc_2012_df <- mo_phc_2012_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs1 *12)  /awt *100)

mo_phc_2012_df <- mo_phc_2012_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_phc_2012_df <- mo_phc_2012_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias4 = 1 * 4*12) # dropped ias2, ias3

mo_phc_2012_df <- mo_phc_2012_df %>% mutate(
  IAF = (ias1 +ias4) /awt) #

'---------- WISN ----------'
mo_phc_2012_df <- mo_phc_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_phc_2012_df_sum <- mo_phc_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_phc_mo_df <- mo_phc_2012_df
mp_phc_mo_df_sum <- mo_phc_2012_df_sum

mp_phc_mo_df
mp_phc_mo_df_sum

```

> MedicalOfficer | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy_13 Normal Del        | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy_9 antenatal          | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy_10 postnatal         | 15 mins/pt  4/hr
  4     | Emergency           | ec_fy_1 emergency           | 20 mins/pt  3/hr    ----- X
  5     | Outpatients         | opc_fy_8 eye                | 15 mins/pt  4/hr    ----- X
  6     | Outpatients         | opc_fy_4 child              | 10 mins/pt  6/hr 
  7     | Inpatients          | ipc_fy_2 admissions         | 10 mins/pt  6/hr
  8     | Outpatients         | opc_fy_5 general            | 5 mins/pt  12/hr
  9     | Outpatients         | opc_fy_7 diabetes           | 5 mins/pt  12/hr 
  10    | Outpatients         | opc_fy_6 hypertension       | 10 mins/pt  6/hr
  11    | Inpatients          | ipc_fy_3 general            | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy_12                   | 10 mins/pt  6/hr    ----- X
  13    | Inpatients          | ipc_fy_4                    | 10 mins/pt  6/hr    ----- X
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X
  4     | Immunization meet   | 1                           | 4 hr/month

```{r MedicalOfficer @ CHC | MP}
# getting_data
mo_chc_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs1,
         ipc_fy_13, opc_fy_9, opc_fy_10,
         #ec_fy_1,
         #opc_fy_8,
         opc_fy_4, ipc_fy_2,
         opc_fy_5, opc_fy_7, opc_fy_6, ipc_fy_3,
         #opc_fy_12, ipc_fy_4,
         pers_fte_fy_13) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy_13) & !is.na(opc_fy_9) & !is.na(opc_fy_10) & 
           #!is.na(ec_fy_1) &
           #!is.na(opc_fy_8) &
           !is.na(opc_fy_4) & !is.na(ipc_fy_2) &
           !is.na(opc_fy_5) & !is.na(opc_fy_7) & !is.na(opc_fy_6) & !is.na(ipc_fy_3)
           #& !is.na(opc_fy_12) & !is.na(ipc_fy_4)
           ) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5,
         imm_meetings) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_5, na.rm = TRUE), vi32 = max(teams_admin_dpw_5, na.rm = TRUE), vi33 = max(teams_admin_hpd_5, na.rm = TRUE))

leave = 102 # days
mo_chc_2012_df <- mo_chc_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
mo_chc_2012_df <- mo_chc_2012_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  #sw4 = 3 *awt,
  #sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 12 *awt,
  sw10 = 6 *awt,
  sw11 = 6 *awt,
  #sw12 = 6 *awt,
  #sw13 = 6 *awt
  ) # max_patient

mo_chc_2012_df <- mo_chc_2012_df %>% mutate(
  aw1 = ipc_fy_13,
  aw2 = opc_fy_9,
  aw3 = opc_fy_10,
  #aw4 = ec_fy_1,
  #aw5 = opc_fy_8,
  aw6 = opc_fy_4,
  aw7 = ipc_fy_2,
  aw8 = opc_fy_5,
  aw9 = opc_fy_7,
  aw10 = opc_fy_6,
  aw11 = ipc_fy_3,
  #aw12 = opc_fy_12,
  #aw13 = ipc_fy_4
  )# patient_load | required staff

mo_chc_2012_df <- mo_chc_2012_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  #+aw4/sw4
  #+aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  #+aw12/sw12
  #+aw13/sw13
  ) #

'---------- CAF ----------'
mo_chc_2012_df <- mo_chc_2012_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs1 *12)  /awt *100)

mo_chc_2012_df <- mo_chc_2012_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_chc_2012_df <- mo_chc_2012_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias4 = 1 * 4*12) # dropped ias2, ias3

mo_chc_2012_df <- mo_chc_2012_df %>% mutate(
  IAF = (ias1 +ias4) /awt) #

'---------- WISN ----------'
mo_chc_2012_df <- mo_chc_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_chc_2012_df_sum <- mo_chc_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_chc_mo_df <- mo_chc_2012_df
mp_chc_mo_df_sum <- mo_chc_2012_df_sum

mp_chc_mo_df
mp_chc_mo_df_sum

```

> MedicalOfficer | DH
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy_13 Normal Del        | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy_9 antenatal          | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy_10 postnatal         | 15 mins/pt  4/hr
  4     | Emergency           | ec_fy_1 emergency           | 20 mins/pt  3/hr
  5     | Outpatients         | opc_fy_8 eye                | 15 mins/pt  4/hr
  6     | Outpatients         | opc_fy_4 child              | 10 mins/pt  6/hr 
  7     | Inpatients          | ipc_fy_2 admissions         | 10 mins/pt  6/hr
  8     | Outpatients         | opc_fy_5 general            | 5 mins/pt  12/hr
  9     | Outpatients         | opc_fy_7 diabetes           | 5 mins/pt  12/hr 
  10    | Outpatients         | opc_fy_6 hypertension       | 10 mins/pt  6/hr
  11    | Inpatients          | ipc_fy_3 general            | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy_12                   | 10 mins/pt  6/hr
  13    | Inpatients          | ipc_fy_4                    | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]
  3     | Edu services        | teams_admin_x_5 [max]       | [max]
  4     | Immunization meet   | 1                           | 4 hr/month

```{r MedicalOfficer @ DH | MP}
# getting_data
mo_dh_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs1,
         ipc_fy_13, opc_fy_9, opc_fy_10,
         ec_fy_1,
         opc_fy_8,
         opc_fy_4, ipc_fy_2,
         opc_fy_5, opc_fy_7, opc_fy_6, ipc_fy_3,
         opc_fy_12, ipc_fy_4,
         pers_fte_fy_13) %>%
  filter(platform_type == "District Hospital (DH)") %>%
  filter(!is.na(ipc_fy_13) & !is.na(opc_fy_9) & !is.na(opc_fy_10) & 
           !is.na(ec_fy_1) &
           !is.na(opc_fy_8) &
           !is.na(opc_fy_4) & !is.na(ipc_fy_2) &
           !is.na(opc_fy_5) & !is.na(opc_fy_7) & !is.na(opc_fy_6) & !is.na(ipc_fy_3)
           & !is.na(opc_fy_12) & !is.na(ipc_fy_4)
           ) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5,
         imm_meetings) %>%
  filter(platform_type == "District Hospital (DH)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_5, na.rm = TRUE), vi32 = max(teams_admin_dpw_5, na.rm = TRUE), vi33 = max(teams_admin_hpd_5, na.rm = TRUE))

leave = 102 # days
mo_dh_2012_df <- mo_dh_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
mo_dh_2012_df <- mo_dh_2012_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  sw4 = 3 *awt,
  sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 12 *awt,
  sw10 = 6 *awt,
  sw11 = 6 *awt,
  sw12 = 6 *awt,
  sw13 = 6 *awt
  ) # max_patient

mo_dh_2012_df <- mo_dh_2012_df %>% mutate(
  aw1 = ipc_fy_13,
  aw2 = opc_fy_9,
  aw3 = opc_fy_10,
  aw4 = ec_fy_1,
  aw5 = opc_fy_8,
  aw6 = opc_fy_4,
  aw7 = ipc_fy_2,
  aw8 = opc_fy_5,
  aw9 = opc_fy_7,
  aw10 = opc_fy_6,
  aw11 = ipc_fy_3,
  aw12 = opc_fy_12,
  aw13 = ipc_fy_4
  )# patient_load | required staff

mo_dh_2012_df <- mo_dh_2012_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  ) #

'---------- CAF ----------'
mo_dh_2012_df <- mo_dh_2012_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs1 *12)  /awt *100)

mo_dh_2012_df <- mo_dh_2012_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_dh_2012_df <- mo_dh_2012_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52,
  ias4 = 1 * 4*12)

mo_dh_2012_df <- mo_dh_2012_df %>% mutate(
  IAF = (ias1 +ias2 +ias3 +ias4) /awt) #

'---------- WISN ----------'
mo_dh_2012_df <- mo_dh_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_dh_2012_df_sum <- mo_dh_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_dh_mo_df <- mo_dh_2012_df
mp_dh_mo_df_sum <- mo_dh_2012_df_sum

mp_dh_mo_df
mp_dh_mo_df_sum

```

### Nurses @ Facility
. --------------------------------------------------
> Nurses | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs3
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_fy_13 Normal Del        | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_fy_14 C-section         | 40 mins/pt  1.5/hr 
  3     | ANC                 | opc_fy_9 antenatal          | 30 mins/pt  2/hr
  4     | Counseling          | opc_fy_10 postnatal         | 15 mins/pt  4/hr
  5     | Investigation       | ipc_fy_18 deaths            | 2.5 hr/pt   0.4/hr
  .
  6     | Outpatients         | opc_fy_12 surgery           | 10 mins/pt  6/hr
  7     | Outpatients         | ipc_fy_4 admissions         | 15 mins/pt  4/hr 
  8     | Inpatients          | ipc_fy_10 major             | 2 hr/pt     0.5/hr
  9     | Inpatients          | ipc_fy_11 minor             | 15 mins/pt  4/hr
  .
  10    | Outpatients         | opcv_fy_1 child vac         | 7 mins/pt  ~8.5/hr 
  11    | Outpatients         | opcv_fy_19 mother vac       | 7 mins/pt  ~8.5/hr
  .
  12    | Outpatients         | opc_fy_4 child              | 15 mins/pt  4/hr
  13    | Inpatients          | ipc_fy_2 child admission    | 15 mins/pt  4/hr
  14    | Investigation       | ipc_fy_15 stillbirths       | 25 mins/pt  2.4/hr
  .
  15    | Outpatients         | opc_fy_5 general            | 10 mins/pt  6/hr
  16    | Outpatients         | opc_fy_7 diabetes           | 10 mins/pt  6/hr 
  17    | Outpatients         | opc_fy_6 heart              | 10 mins/pt  6/hr
  18    | Inpatients          | ipc_fy_3 admissions         | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]
  2     | Record keeping      | teams_admin_x_4 [max]       | [max]

```{r Nurses @ CHC | MP}
# getting_data
nurses_chc_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs3,
         ipc_fy_13, ipc_fy_14, opc_fy_9, opc_fy_10, ipc_fy_18,
         opc_fy_12, ipc_fy_4, ipc_fy_10, ipc_fy_11,
         opcv_fy_1, opcv_fy_19,
         opc_fy_4, ipc_fy_2, ipc_fy_15,
         opc_fy_5, opc_fy_7, opc_fy_6, ipc_fy_3,
         pers_fte_fy_31, ohv_fy_1) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy_13) & !is.na(ipc_fy_14) & !is.na(opc_fy_9) & !is.na(opc_fy_10) & !is.na(ipc_fy_18) & 
           !is.na(opc_fy_12) & !is.na(ipc_fy_4) & !is.na(ipc_fy_10) & !is.na(ipc_fy_11) &
           !is.na(opcv_fy_1) & !is.na(opcv_fy_19) &
           !is.na(opc_fy_4) & !is.na(ipc_fy_2) & !is.na(ipc_fy_15) &
           !is.na(opc_fy_5) & !is.na(opc_fy_7) & !is.na(opc_fy_6) & !is.na(ipc_fy_3)
           ) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs3 >= 24)

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_1,teams_admin_dpw_1,teams_admin_hpd_1,
         teams_admin_pers_4,teams_admin_dpw_4,teams_admin_hpd_4
         ) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_1, na.rm = TRUE), vi12 = max(teams_admin_dpw_1, na.rm = TRUE), vi13 = max(teams_admin_hpd_1, na.rm = TRUE),
            vi21 = max(teams_admin_pers_4, na.rm = TRUE), vi22 = max(teams_admin_dpw_4, na.rm = TRUE), vi23 = max(teams_admin_hpd_4, na.rm = TRUE))

leave = 102 # days
nurses_chc_2012_df <- nurses_chc_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs3) # hrs of a year

'---------- HSA ----------'
nurses_chc_2012_df <- nurses_chc_2012_df %>% mutate(
  sw1 = 1 *awt,
  sw2 = 1.5 *awt,
  sw3 = 2 *awt,
  sw4 = 4 *awt,
  sw5 = 0.4 *awt,
  sw6 = 6 *awt,
  sw7 = 4 *awt,
  sw8 = 0.5 *awt,
  sw9 = 4 *awt,
  sw10 = 60/7 *awt,
  sw11 = 60/7 *awt,
  sw12 = 4 *awt,
  sw13 = 4 *awt,
  sw14 = 2.4 *awt,
  sw15 = 6 *awt,
  sw16 = 6 *awt,
  sw17 = 6 *awt,
  sw18 = 4 *awt
  ) # max_patient

nurses_chc_2012_df <- nurses_chc_2012_df %>% mutate(
  aw1 = ipc_fy_13,
  aw2 = ipc_fy_14,
  aw3 = opc_fy_9,
  aw4 = opc_fy_10,
  aw5 = ipc_fy_18,
  aw6 = opc_fy_12,
  aw7 = ipc_fy_4,
  aw8 = ipc_fy_10,
  aw9 = ipc_fy_11,
  aw10 = opcv_fy_1,
  aw11 = opcv_fy_19,
  aw12 = opc_fy_4,
  aw13 = ipc_fy_2,
  aw14 = ipc_fy_15,
  aw15 = opc_fy_5,
  aw16 = opc_fy_7,
  aw17 = opc_fy_6,
  aw18 = ipc_fy_3
  )# patient_load | required staff

nurses_chc_2012_df <- nurses_chc_2012_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  +aw14/sw14
  +aw15/sw15
  +aw16/sw16
  +aw17/sw17
  +aw18/sw18
  ) #

'---------- CAF ----------'
nurses_chc_2012_df <- nurses_chc_2012_df %>% mutate(
  cas1 = (6/7 *fte_hrs3) /awt *100,
  cas2 = (2 *ohv_fy_1)  /awt *100) # standard cas2?

nurses_chc_2012_df <- nurses_chc_2012_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
nurses_chc_2012_df <- nurses_chc_2012_df %>% mutate(
  ias1 = other_df$vi11 * other_df$vi12*other_df$vi13 *52,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52)

nurses_chc_2012_df <- nurses_chc_2012_df %>% mutate(
  IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
nurses_chc_2012_df <- nurses_chc_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

nurses_chc_2012_df_sum <- nurses_chc_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_chc_nurses_df <- nurses_chc_2012_df
mp_chc_nurses_df_sum <- nurses_chc_2012_df_sum

mp_chc_nurses_df
mp_chc_nurses_df_sum

```

> Nurses | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs3
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_fy_13 Normal Del        | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_fy_14 C-section         | 40 mins/pt  1.5/hr  - XXXXX
  3     | ANC                 | opc_fy_9 antenatal          | 30 mins/pt  2/hr
  4     | Counseling          | opc_fy_10 postnatal         | 15 mins/pt  4/hr
  5     | Investigation       | ipc_fy_18 deaths            | 2.5 hr/pt   0.4/hr
  .
  6     | Outpatients         | opc_fy_12 surgery           | 10 mins/pt  6/hr    - XXXXX
  7     | Outpatients         | ipc_fy_4 admissions         | 15 mins/pt  4/hr    - XXXXX
  8     | Inpatients          | ipc_fy_10 major             | 2 hr/pt     0.5/hr  - XXXXX
  9     | Inpatients          | ipc_fy_11 minor             | 15 mins/pt  4/hr    - XXXXX
  .
  10    | Outpatients         | opcv_fy_1 child vac         | 7 mins/pt  ~8.5/hr 
  11    | Outpatients         | opcv_fy_19 mother vac       | 7 mins/pt  ~8.5/hr
  .
  12    | Outpatients         | opc_fy_4 child              | 15 mins/pt  4/hr
  13    | Inpatients          | ipc_fy_2 child admission    | 15 mins/pt  4/hr
  14    | Investigation       | ipc_fy_15 stillbirths       | 25 mins/pt  2.4/hr
  .
  15    | Outpatients         | opc_fy_5 general            | 10 mins/pt  6/hr
  16    | Outpatients         | opc_fy_7 diabetes           | 10 mins/pt  6/hr 
  17    | Outpatients         | opc_fy_6 heart              | 10 mins/pt  6/hr
  18    | Inpatients          | ipc_fy_3 admissions         | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit                                        ----- X?
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]
  2     | Record keeping      | teams_admin_x_4 [max]       | [max]

```{r Nurses @ PHC | MP}
# getting_data
nurses_phc_2012_df <- data_df %>%
  select(customid, year, platform_type, rural, fte_hrs3,
         ipc_fy_13, opc_fy_9, opc_fy_10, ipc_fy_18, ###ipc_fy_14,
         ###opc_fy_12, ipc_fy_4, ipc_fy_10, ipc_fy_11,
         opcv_fy_1, opcv_fy_19,
         opc_fy_4, ipc_fy_2, ipc_fy_15,
         opc_fy_5, opc_fy_7, opc_fy_6, ipc_fy_3,
         pers_fte_fy_31, ohv_fy_1) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  filter(!is.na(ipc_fy_13) & !is.na(opc_fy_9) & !is.na(opc_fy_10) & !is.na(ipc_fy_18) &### !is.na(ipc_fy_14) &
           ###!is.na(opc_fy_12) & !is.na(ipc_fy_4) & !is.na(ipc_fy_10) & !is.na(ipc_fy_11) &
           !is.na(opcv_fy_1) & !is.na(opcv_fy_19) &
           !is.na(opc_fy_4) & !is.na(ipc_fy_2) & !is.na(ipc_fy_15) &
           !is.na(opc_fy_5) & !is.na(opc_fy_7) & !is.na(opc_fy_6) & !is.na(ipc_fy_3)
           ) %>%
  #filter(fte_hrs3 > 0) %>%
  filter(fte_hrs3 >= 24) %>%
  #filter(year == 2012) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban"))

other_df <- data_df %>%
  select(customid, year, platform_type,
         teams_admin_pers_1,teams_admin_dpw_1,teams_admin_hpd_1,
         teams_admin_pers_4,teams_admin_dpw_4,teams_admin_hpd_4
         ) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  #filter(year == 2012) %>%
  summarise(vi11 = max(teams_admin_pers_1, na.rm = TRUE), vi12 = max(teams_admin_dpw_1, na.rm = TRUE), vi13 = max(teams_admin_hpd_1, na.rm = TRUE),
            vi21 = max(teams_admin_pers_4, na.rm = TRUE), vi22 = max(teams_admin_dpw_4, na.rm = TRUE), vi23 = max(teams_admin_hpd_4, na.rm = TRUE))

leave = 102 # days
nurses_phc_2012_df <- nurses_phc_2012_df %>% mutate(awt = (365 - leave) /7 * fte_hrs3) # hrs of a year

'---------- HSA ----------'
nurses_phc_2012_df <- nurses_phc_2012_df %>% mutate(
  sw1 = 1 *awt,
  ###sw2 = 1.5 *awt,
  sw3 = 2 *awt,
  sw4 = 4 *awt,
  sw5 = 0.4 *awt,
  ###sw6 = 6 *awt,
  ###sw7 = 4 *awt,
  ###sw8 = 0.5 *awt,
  ###sw9 = 4 *awt,
  sw10 = 60/7 *awt,
  sw11 = 60/7 *awt,
  sw12 = 4 *awt,
  sw13 = 4 *awt,
  sw14 = 2.4 *awt,
  sw15 = 6 *awt,
  sw16 = 6 *awt,
  sw17 = 6 *awt,
  sw18 = 4 *awt
  ) # max_patient

nurses_phc_2012_df <- nurses_phc_2012_df %>% mutate(
  aw1 = ipc_fy_13,
  ###aw2 = ipc_fy_14,
  aw3 = opc_fy_9,
  aw4 = opc_fy_10,
  aw5 = ipc_fy_18,
  ###aw6 = opc_fy_12,
  ###aw7 = ipc_fy_4,
  ###aw8 = ipc_fy_10,
  ###aw9 = ipc_fy_11,
  aw10 = opcv_fy_1,
  aw11 = opcv_fy_19,
  aw12 = opc_fy_4,
  aw13 = ipc_fy_2,
  aw14 = ipc_fy_15,
  aw15 = opc_fy_5,
  aw16 = opc_fy_7,
  aw17 = opc_fy_6,
  aw18 = ipc_fy_3
  )# patient_load | required staff

nurses_phc_2012_df <- nurses_phc_2012_df %>% mutate(
  HSA = aw1/sw1
  ###+aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  ###+aw6/sw6
  ###+aw7/sw7
  ###+aw8/sw8
  ###+aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  +aw14/sw14
  +aw15/sw15
  +aw16/sw16
  +aw17/sw17
  +aw18/sw18
  ) #

'---------- CAF ----------'
nurses_phc_2012_df <- nurses_phc_2012_df %>% mutate(
  cas1 = (6/7 *fte_hrs3) /awt *100,
  cas2 = (2 *ohv_fy_1)  /awt *100) # standard cas2?

nurses_phc_2012_df <- nurses_phc_2012_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
nurses_phc_2012_df <- nurses_phc_2012_df %>% mutate(
  ias1 = other_df$vi11 * other_df$vi12*other_df$vi13 *52,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52)

nurses_phc_2012_df <- nurses_phc_2012_df %>% mutate(
  IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
nurses_phc_2012_df <- nurses_phc_2012_df %>% mutate(
  WISN = HSA*CAF +IAF) #

nurses_phc_2012_df_sum <- nurses_phc_2012_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

mp_phc_nurses_df <- nurses_phc_2012_df
mp_phc_nurses_df_sum <- nurses_phc_2012_df_sum

mp_phc_nurses_df
mp_phc_nurses_df_sum

```

## State | GJ ----------
. ==================================================
General info
Data release information sheet | -
Codebook, with descriptions of all variables | IHME_ABCE_IND_od_2015_2016_FACILITY_CODEBOOK_Y2018M03D27.CSV
Public use survey dataset – CSV format | IHME_ABCE_IND_od_2015_2016_FACILITY_DATA_Y2018M03D27.CSV

```{r get Data | GJ}
data_df <- read_csv("../data/ABCE/IHME_ABCE_IND_GJ_2015_2016_FACILITY_DATA_Y2018M03D27.CSV")
#as_tibble(data_df)

data_df <- within(data_df, platform_type[platform_type == "Community Health Centre  (CHC)"] <- "Community Health Centre (CHC)")
data_df <- within(data_df, platform_type[platform_type == "Subdistrict Hosptial (SDH)"] <- "Subdistrict Hospital (SDH)")

data_df

```

```{r GJ transform}
# transforming year data into rows
# "\w*_fy[0-9]_\d*"
temp0 <- data_df %>% select(-contains("_fy"))
temp1 <- data_df %>% select(contains("_fy1")) %>%
  add_column(year = 2010) %>%
  rename_all(gsub, pattern = '\\_fy1', replacement = '_fy5')
temp2 <- data_df %>% select(contains("_fy2")) %>%
  add_column(year = 2011) %>%
  rename_all(gsub, pattern = '\\_fy2', replacement = '_fy5')
temp3 <- data_df %>% select(contains("_fy3")) %>%
  add_column(year = 2012) %>%
  rename_all(gsub, pattern = '\\_fy3', replacement = '_fy5')
temp4 <- data_df %>% select(contains("_fy4")) %>%
  add_column(year = 2013) %>%
  rename_all(gsub, pattern = '\\_fy4', replacement = '_fy5')
temp5 <- data_df %>% select(contains("_fy5")) %>%
  add_column(year = 2014)

temp01 <- bind_cols(temp0, temp1)
temp02 <- bind_cols(temp0, temp2)
temp03 <- bind_cols(temp0, temp3)
temp04 <- bind_cols(temp0, temp4)
temp05 <- bind_cols(temp0, temp5)

data_df <- bind_rows(
  temp01,
  temp02,
  temp03,
  temp04,
  temp05
)

```


### Specialists @ CHC
. --------------------------------------------------
> OBGYN | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy5_13 Norm Del         | 10 mins/pt  6/hr
  2     | Cesarian-OT         | ipc_fy5_14 C-section        | 30 mins/pt  2/hr 
  3     | Outpatients         | opc_fy5_9 Antenatal         | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy5_10 Postnatal        | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?

```{r OBGYN @ CHC | GJ}
# getting_data
obgyn_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q1,
         ipc_fy5_13, ipc_fy5_14, opc_fy5_9, opc_fy5_10,
         fy5_ip_reg_med_19) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy5_13) & !is.na(ipc_fy5_14) & !is.na(opc_fy5_9) & !is.na(opc_fy5_10)) %>%
  filter((ipc_fy5_13 >= 0 ) & (ipc_fy5_14 >= 0 ) & (opc_fy5_9 >= 0 ) & (opc_fy5_10 >= 0 )) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 2 *awt,
  sw3 = 4 *awt,
  sw4 = 4 *awt) # max_patient

obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  aw1 = ipc_fy5_13,
  aw2 = ipc_fy5_14,
  aw3 = opc_fy5_9,
  aw4 = opc_fy5_10)# patient_load | required staff

obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100 )

obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3?

obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

obgyn_chc_2015_df_sum <- obgyn_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_chc_obgyn_df <- obgyn_chc_2015_df
gj_chc_obgyn_df_sum <- obgyn_chc_2015_df_sum

gj_chc_obgyn_df
gj_chc_obgyn_df_sum

```

> SurgerySpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy5_12 visits           | 10 mins/pt  6/hr
  2     | Inpatients          | ipc_fy5_4 admissions        | 10 mins/pt  6/hr 
  3     | Operate Major       | ipc_fy5_10 #major           | 2  hr/pt  0.5/hr
  4     | Operate minor       | ipc_fy5_11 #minor           | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?

```{r SurgerySpec @ CHC | GJ}
# getting_data
surgeryspec_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q1,
         opc_fy5_12, ipc_fy5_4, ipc_fy5_10, ipc_fy5_11,
         fy5_ip_reg_med_17) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy5_12) & !is.na(ipc_fy5_4) & !is.na(ipc_fy5_10) & !is.na(ipc_fy5_11)) %>%
  filter((opc_fy5_12 >= 0 ) & (ipc_fy5_4 >= 0 ) & (ipc_fy5_10 >= 0 ) & (ipc_fy5_11 >= 0 )) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt,
  sw3 = 0.5 *awt,
  sw4 = 4 *awt) # max_patient

surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  aw1 = opc_fy5_12,
  aw2 = ipc_fy5_4,
  aw3 = ipc_fy5_10,
  aw4 = ipc_fy5_11)# patient_load | required staff

surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100 )

surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3?

surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

surgeryspec_chc_2015_df_sum <- surgeryspec_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_chc_surgeryspec_df <- surgeryspec_chc_2015_df
gj_chc_surgeryspec_df_sum <- surgeryspec_chc_2015_df_sum

gj_chc_surgeryspec_df
gj_chc_surgeryspec_df_sum

```

> EyeSpec [Ophthalmologist] | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy5_8 visits            | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?

```{r EyeSpec @ CHC | GJ}
# getting_data
eyespec_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q1,
         opc_fy5_8,
         fy5_ip_reg_med_25) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy5_8)) %>%
  filter((opc_fy5_8 >= 0 )) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(
  sw1 = 4 *awt) # max_patient

eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(
  aw1 = opc_fy5_8)# patient_load | required staff

eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(
  HSA = aw1/sw1) #

'---------- CAF ----------'
eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100 )

eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3?

eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

eyespec_chc_2015_df_sum <- eyespec_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_chc_eyespec_df <- eyespec_chc_2015_df
gj_chc_eyespec_df_sum <- eyespec_chc_2015_df_sum

gj_chc_eyespec_df
gj_chc_eyespec_df_sum

```

> ChildSpec [Paedistrician] | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy5_4 visits            | 10 mins/pt  6/hr
  2     | Inpatients          | ipc_fy5_2 admissions        | 10 mins/pt   6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?

```{r ChildSpec @ CHC | GJ}
# getting_data
childspec_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q1,
         opc_fy5_4, ipc_fy5_2,
         fy5_ip_reg_med_22) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy5_4) & !is.na(ipc_fy5_2)) %>%
  filter((opc_fy5_4 >= 0 ) & (ipc_fy5_2 >= 0 )) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt) # max_patient

childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  aw1 = opc_fy5_4,
  aw2 = ipc_fy5_2)# patient_load | required staff

childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2) #

'---------- CAF ----------'
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100 )

childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3?

childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

childspec_chc_2015_df_sum <- childspec_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_chc_childspec_df <- childspec_chc_2015_df
gj_chc_childspec_df_sum <- childspec_chc_2015_df_sum

gj_chc_childspec_df
gj_chc_childspec_df_sum

```

> MedicalSpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy5_3 general           | 5 mins/pt  12/hr
  2     | Inpatients          | ipc_fy5_3 admissions        | 10 mins/pt  6/hr 
  3     | Outpatients         | opc_fy5_7 diabetes          | 5 mins/pt  12/hr
  4     | Oupatients          | opc_fy5_6 surgical          | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?

```{r MedicalSpec @ CHC | GJ}
# getting_data
medicalspec_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q1,
         opc_fy5_3, ipc_fy5_3, opc_fy5_7, opc_fy5_6,
         fy5_ip_reg_med_18) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy5_3) & !is.na(ipc_fy5_3) & !is.na(opc_fy5_7) & !is.na(opc_fy5_6)) %>%
  filter((opc_fy5_3 >= 0 ) & (ipc_fy5_3 >= 0 ) & (opc_fy5_7 >= 0 ) & (opc_fy5_6 >= 0 )) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  sw1 = 12 *awt,
  sw2 = 6 *awt,
  sw3 = 12 *awt,
  sw4 = 6 *awt) # max_patient

medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  aw1 = opc_fy5_3,
  aw2 = ipc_fy5_3,
  aw3 = opc_fy5_7,
  aw4 = opc_fy5_6)# patient_load | required staff

medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100 )

medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12) # dropped ias2, ias3?

medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

medicalspec_chc_2015_df_sum <- medicalspec_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_chc_medicalspec_df <- medicalspec_chc_2015_df
gj_chc_medicalspec_df_sum <- medicalspec_chc_2015_df_sum

gj_chc_medicalspec_df
gj_chc_medicalspec_df_sum

```

### MO @ Facility
. --------------------------------------------------
> MedicalOfficer | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy5_13 Normal Del       | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy5_9 antenatal         | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy5_10 postnatal        | 15 mins/pt  4/hr
  4     | Emergency           | ec_fy5_1 emergency          | 20 mins/pt  3/hr    ----- X
  5     | Outpatients         | opc_fy5_8 eye               | 15 mins/pt  4/hr    ----- X
  6     | Outpatients         | opc_fy5_4 child             | 10 mins/pt  6/hr 
  7     | Inpatients          | ipc_fy5_2 admissions        | 10 mins/pt  6/hr
  8     | Outpatients         | opc_fy5_3 general           | 5 mins/pt  12/hr
  9     | Inpatients          | ipc_fy5_3 admission         | 10 mins/pt  6/hr 
  10    | Outpatients         | opc_fy5_7 diabetes          | 5 mins/pt  12/hr
  11    | Outpatients         | opc_fy5_6 surgical          | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy5_12 surgery visit    | 10 mins/pt  6/hr    ----- X
  13    | Inpatients          | ipc_fy5_4 surgery admission | 10 mins/pt  6/hr    ----- X
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?
  4     | Immunization meet   | 1                           | 4 hr/month

```{r MedicalOfficer @ PHC | GJ}
# getting_data
mo_phc_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q1,
         ipc_fy5_13, opc_fy5_9, opc_fy5_10,
         #ec_fy5_1, opc_fy5_8,
         opc_fy5_4, ipc_fy5_2,
         opc_fy5_3, ipc_fy5_3, opc_fy5_7, opc_fy5_6,
         #opc_fy5_12, ipc_fy5_4,
         fy5_ip_reg_med_15) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  filter(!is.na(ipc_fy5_13) & !is.na(opc_fy5_9) & !is.na(opc_fy5_10)
         #& !is.na(ec_fy5_1) & !is.na(opc_fy5_8)
         & !is.na(opc_fy5_4) & !is.na(ipc_fy5_2)
         & !is.na(opc_fy5_3) & !is.na(ipc_fy5_3) & !is.na(opc_fy5_7) & !is.na(opc_fy5_6)
         #& !is.na(opc_fy5_12) & !is.na(ipc_fy5_4)
         ) %>%
  filter((ipc_fy5_13 >= 0 ) & (opc_fy5_9 >= 0 ) & (opc_fy5_10 >= 0 )
         #& (ec_fy5_1 >= 0 ) & (opc_fy5_8 >= 0 )
         & (opc_fy5_4 >= 0 ) & (ipc_fy5_2 >= 0 )
         & (opc_fy5_3 >= 0 ) & (ipc_fy5_3 >= 0 ) & (opc_fy5_7 >= 0 ) & (opc_fy5_6 >= 0 )
         #& (opc_fy5_12 >= 0 ) & (ipc_fy5_4 >= 0 )
    ) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  #sw4 = 3 *awt,
  #sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 6 *awt,
  sw10 = 12 *awt,
  sw11 = 6 *awt,
  #sw12 = 6 *awt,
  #sw13 = 6 *awt
  ) # max_patient

mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  aw1 = ipc_fy5_13,
  aw2 = opc_fy5_9,
  aw3 = opc_fy5_10,
  #aw4 = ec_fy5_1,
  #aw5 = opc_fy5_8,
  aw6 = opc_fy5_4,
  aw7 = ipc_fy5_2,
  aw8 = opc_fy5_3,
  aw9 = ipc_fy5_3,
  aw10 = opc_fy5_7,
  aw11 = opc_fy5_6,
  #aw12 = opc_fy5_12,
  #aw13 = ipc_fy5_4
  )# patient_load | required staff

mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  #+aw4/sw4
  #+aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  #+aw12/sw12
  #+aw13/sw13
  ) #

'---------- CAF ----------'
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs_q1 *12)  /awt *100)

mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias4 = 1 * 4*12) # dropped ias3?

mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  IAF = (ias1 +ias2 +ias4) /awt) #

'---------- WISN ----------'
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_phc_2015_df_sum <- mo_phc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_phc_mo_df <- mo_phc_2015_df
gj_phc_mo_df_sum <- mo_phc_2015_df_sum

gj_phc_mo_df
gj_phc_mo_df_sum

```

> MedicalOfficer | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy5_13 Normal Del       | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy5_9 antenatal         | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy5_10 postnatal        | 15 mins/pt  4/hr
  4     | Emergency           | ec_fy5_1 emergency          | 20 mins/pt  3/hr    ----- X
  5     | Outpatients         | opc_fy5_8 eye               | 15 mins/pt  4/hr    ----- X
  6     | Outpatients         | opc_fy5_4 child             | 10 mins/pt  6/hr 
  7     | Inpatients          | ipc_fy5_2 admissions        | 10 mins/pt  6/hr
  8     | Outpatients         | opc_fy5_3 general           | 5 mins/pt  12/hr
  9     | Inpatients          | ipc_fy5_3 admission         | 10 mins/pt  6/hr 
  10    | Outpatients         | opc_fy5_7 diabetes          | 5 mins/pt  12/hr
  11    | Outpatients         | opc_fy5_6 surgical          | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy5_12 surgery visit    | 10 mins/pt  6/hr    ----- X
  13    | Inpatients          | ipc_fy5_4 surgery admission | 10 mins/pt  6/hr    ----- X
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?
  4     | Immunization meet   | 1                           | 4 hr/month

```{r MedicalOfficer @ CHC | GJ}
# getting_data
mo_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q1,
         ipc_fy5_13, opc_fy5_9, opc_fy5_10,
         #ec_fy5_1, opc_fy5_8,
         opc_fy5_4, ipc_fy5_2,
         opc_fy5_3, ipc_fy5_3, opc_fy5_7, opc_fy5_6,
         #opc_fy5_12, ipc_fy5_4,
         fy5_ip_reg_med_15) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy5_13) & !is.na(opc_fy5_9) & !is.na(opc_fy5_10)
         #& !is.na(ec_fy5_1) & !is.na(opc_fy5_8)
         & !is.na(opc_fy5_4) & !is.na(ipc_fy5_2)
         & !is.na(opc_fy5_3) & !is.na(ipc_fy5_3) & !is.na(opc_fy5_7) & !is.na(opc_fy5_6)
         #& !is.na(opc_fy5_12) & !is.na(ipc_fy5_4)
         ) %>%
  filter((ipc_fy5_13 >= 0 ) & (opc_fy5_9 >= 0 ) & (opc_fy5_10 >= 0 )
         #& (ec_fy5_1 >= 0 ) & (opc_fy5_8 >= 0 )
         & (opc_fy5_4 >= 0 ) & (ipc_fy5_2 >= 0 )
         & (opc_fy5_3 >= 0 ) & (ipc_fy5_3 >= 0 ) & (opc_fy5_7 >= 0 ) & (opc_fy5_6 >= 0 )
         #& (opc_fy5_12 >= 0 ) & (ipc_fy5_4 >= 0 )
    ) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  #sw4 = 3 *awt,
  #sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 6 *awt,
  sw10 = 12 *awt,
  sw11 = 6 *awt,
  #sw12 = 6 *awt,
  #sw13 = 6 *awt
  ) # max_patient

mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  aw1 = ipc_fy5_13,
  aw2 = opc_fy5_9,
  aw3 = opc_fy5_10,
  #aw4 = ec_fy5_1,
  #aw5 = opc_fy5_8,
  aw6 = opc_fy5_4,
  aw7 = ipc_fy5_2,
  aw8 = opc_fy5_3,
  aw9 = ipc_fy5_3,
  aw10 = opc_fy5_7,
  aw11 = opc_fy5_6,
  #aw12 = opc_fy5_12,
  #aw13 = ipc_fy5_4
  )# patient_load | required staff

mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  #+aw4/sw4
  #+aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  #+aw12/sw12
  #+aw13/sw13
  ) #

'---------- CAF ----------'
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs_q1 *12)  /awt *100)

mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  #ias2 = other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias4 = 1 * 4*12) # dropped ias2, ias3?

mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  IAF = (ias1 +ias4) /awt) #

'---------- WISN ----------'
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_chc_2015_df_sum <- mo_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_chc_mo_df <- mo_chc_2015_df
gj_chc_mo_df_sum <- mo_chc_2015_df_sum

gj_chc_mo_df
gj_chc_mo_df_sum

```

> MedicalOfficer | DH & SDH
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy5_13 Normal Del       | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy5_9 antenatal         | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy5_10 postnatal        | 15 mins/pt  4/hr
  4     | Emergency           | ec_fy5_1 emergency          | 20 mins/pt  3/hr
  5     | Outpatients         | opc_fy5_8 eye               | 15 mins/pt  4/hr
  6     | Outpatients         | opc_fy5_4 child             | 10 mins/pt  6/hr 
  7     | Inpatients          | ipc_fy5_2 admissions        | 10 mins/pt  6/hr
  8     | Outpatients         | opc_fy5_3 general           | 5 mins/pt  12/hr
  9     | Inpatients          | ipc_fy5_3 admission         | 10 mins/pt  6/hr 
  10    | Outpatients         | opc_fy5_7 diabetes          | 5 mins/pt  12/hr
  11    | Outpatients         | opc_fy5_6 surgical          | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy5_12 surgery visit    | 10 mins/pt  6/hr
  13    | Inpatients          | ipc_fy5_4 surgery admission | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?
  4     | Immunization meet   | 1                           | 4 hr/month

```{r MedicalOfficer @ DH & SDH | GJ}
# getting_data
mo_dh_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q1,
         ipc_fy5_13, opc_fy5_9, opc_fy5_10,
         ec_fy5_1, opc_fy5_8,
         opc_fy5_4, ipc_fy5_2,
         opc_fy5_3, ipc_fy5_3, opc_fy5_7, opc_fy5_6,
         opc_fy5_12, ipc_fy5_4,
         fy5_ip_reg_med_15) %>%
  filter(platform_type == "District Hospital (DH)" | platform_type == "Subdistrict Hospital (SDH)" ) %>%
  filter(!is.na(ipc_fy5_13) & !is.na(opc_fy5_9) & !is.na(opc_fy5_10)
         & !is.na(ec_fy5_1) & !is.na(opc_fy5_8)
         & !is.na(opc_fy5_4) & !is.na(ipc_fy5_2)
         & !is.na(opc_fy5_3) & !is.na(ipc_fy5_3) & !is.na(opc_fy5_7) & !is.na(opc_fy5_6)
         & !is.na(opc_fy5_12) & !is.na(ipc_fy5_4)
         ) %>%
  filter((ipc_fy5_13 >= 0 ) & (opc_fy5_9 >= 0 ) & (opc_fy5_10 >= 0 )
         & (ec_fy5_1 >= 0 ) & (opc_fy5_8 >= 0 )
         & (opc_fy5_4 >= 0 ) & (ipc_fy5_2 >= 0 )
         & (opc_fy5_3 >= 0 ) & (ipc_fy5_3 >= 0 ) & (opc_fy5_7 >= 0 ) & (opc_fy5_6 >= 0 )
         & (opc_fy5_12 >= 0 ) & (ipc_fy5_4 >= 0 )
    ) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "District Hospital (DH)" | platform_type == "Subdistrict Hospital (SDH)" ) %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  sw4 = 3 *awt,
  sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 6 *awt,
  sw10 = 12 *awt,
  sw11 = 6 *awt,
  sw12 = 6 *awt,
  sw13 = 6 *awt
  ) # max_patient

mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  aw1 = ipc_fy5_13,
  aw2 = opc_fy5_9,
  aw3 = opc_fy5_10,
  aw4 = ec_fy5_1,
  aw5 = opc_fy5_8,
  aw6 = opc_fy5_4,
  aw7 = ipc_fy5_2,
  aw8 = opc_fy5_3,
  aw9 = ipc_fy5_3,
  aw10 = opc_fy5_7,
  aw11 = opc_fy5_6,
  aw12 = opc_fy5_12,
  aw13 = ipc_fy5_4
  )# patient_load | required staff

mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  ) #

'---------- CAF ----------'
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs_q1 *12)  /awt *100)

mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  #ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52,
  ias4 = 1 * 4*12) # dropped ias3?

mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  IAF = (ias1 +ias2 +ias4) /awt) #

'---------- WISN ----------'
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_dh_2015_df_sum <- mo_dh_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_dh_mo_df <- mo_dh_2015_df
gj_dh_mo_df_sum <- mo_dh_2015_df_sum

gj_dh_mo_df
gj_dh_mo_df_sum

```

### Nurses @ Facility
. --------------------------------------------------
> Nurses | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q2
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_fy5_13 Normal Del       | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_fy5_14 C-section        | 40 mins/pt  1.5/hr 
  3     | ANC                 | opc_fy5_9 antenatal         | 30 mins/pt  2/hr
  4     | Counseling          | opc_fy5_10 postnatal        | 15 mins/pt  4/hr
  5     | Investigation       | ipc_fy5_18 deaths           | 2.5 hr/pt   0.4/hr
  .
  6     | Outpatients         | opc_fy5_12 surgery          | 10 mins/pt  6/hr    ----- X
  7     | Inpatients          | ipc_fy5_4 admissions        | 15 mins/pt  4/hr    ----- X 
  8     | Inpatients          | ipc_fy5_10 major            | 2 hr/pt     0.5/hr  ----- X
  9     | Inpatients          | ipc_fy5_11 minor            | 15 mins/pt  4/hr    ----- X
  .
  10    | Outpatients         | opc_fy5_8 eye               | 15 mins/pt  4/hr    ----- X
  .
  11    | Outpatients         | opc_fy5_4 child             | 15 mins/pt  4/hr
  12    | Inpatients          | ipc_fy5_2 child admission   | 15 mins/pt  4/hr
  13    | Investigation       | ipc_fy5_15 stillbirths      | 25 mins/pt  2.4/hr
  .
  14    | Outpatients         | vacc_out_y5_total_1 child   | 7 mins/pt  ~8.5/hr  ----- X
  .
  15    | Outpatients         | opc_fy5_3 general           | 10 mins/pt  6/hr
  16    | Inpatients          | ipc_fy5_3 admissions        | 15 mins/pt  4/hr 
  17    | Outpatients         | opc_fy5_7 diabetes          | 10 mins/pt  6/hr
  18    | Outpatients         | opc_fy5_6 admissions        | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit                                        ----- X?
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]
  2     | Record keeping      | teams_admin_x_4 [max]       | [max]

```{r Nurses @ CHC | GJ}
# getting_data
nurses_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q2,
         ipc_fy5_13, ipc_fy5_14, opc_fy5_9, opc_fy5_10, ipc_fy5_18,
         #opc_fy5_12, ipc_fy5_4, ipc_fy5_10, ipc_fy5_11,
         #opc_fy5_8,
         opc_fy5_4, ipc_fy5_2, ipc_fy5_15,
         #vacc_out_y5_total_1,
         opc_fy5_3, ipc_fy5_3, opc_fy5_7, opc_fy5_6,
         fy5_sanc_reg_nur_29, fy5_ip_reg_nur_29, ohv_fy5_1) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy5_13) & !is.na(ipc_fy5_14) & !is.na(opc_fy5_9) & !is.na(opc_fy5_10) & !is.na(ipc_fy5_18) & 
           #!is.na(opc_fy5_12) & !is.na(ipc_fy5_4) & !is.na(ipc_fy5_10) & !is.na(ipc_fy5_11) &
           #!is.na(opc_fy5_8) &
           !is.na(opc_fy5_4) & !is.na(ipc_fy5_2) & !is.na(ipc_fy5_15) & 
           #!is.na(vacc_out_y5_total_1) &
           !is.na(opc_fy5_3) & !is.na(ipc_fy5_3) & !is.na(opc_fy5_7) & !is.na(opc_fy5_6)
           ) %>%
  filter((ipc_fy5_13 >= 0 ) & (ipc_fy5_14 >= 0 ) & (opc_fy5_9 >= 0 ) & (opc_fy5_10 >= 0 ) & (ipc_fy5_18 >= 0 )
         #& (opc_fy5_12 >= 0 ) & (ipc_fy5_4 >= 0 ) & (ipc_fy5_10 >= 0 ) & (ipc_fy5_11 >= 0 )
         #& (opc_fy5_8 >= 0 )
         & (opc_fy5_4 >= 0 ) & (ipc_fy5_2 >= 0 ) & (ipc_fy5_15 >= 0 )
         #& (vacc_out_y5_total_1 >= 0 )
         & (opc_fy5_3 >= 0 ) & (ipc_fy5_3 >= 0 ) & (opc_fy5_7 >= 0 ) & (opc_fy5_6 >= 0 )
         & (ohv_fy5_1 >= 0 )
    ) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q2 >= 24)


other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs1,teams_admin_dpw1,teams_admin_hpd1,
         teams_admin_docs4,teams_admin_dpw4,teams_admin_hpd4
         ) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs1, na.rm = TRUE), vi12 = max(teams_admin_dpw1, na.rm = TRUE), vi13 = max(teams_admin_hpd1, na.rm = TRUE),
            vi21 = max(teams_admin_docs4, na.rm = TRUE), vi22 = max(teams_admin_dpw4, na.rm = TRUE), vi23 = max(teams_admin_hpd4, na.rm = TRUE))

leave = 102 # days
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q2) # hrs of a year

'---------- HSA ----------'
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  sw1 = 1 *awt,
  sw2 = 1.5 *awt,
  sw3 = 2 *awt,
  sw4 = 4 *awt,
  sw5 = 0.4 *awt,
  #sw6 = 6 *awt,
  #sw7 = 4 *awt,
  #sw8 = 0.5 *awt,
  #sw9 = 4 *awt,
  #sw10 = 4 *awt,
  sw11 = 4 *awt,
  sw12 = 4 *awt,
  sw13 = 2.4 *awt,
  #sw14 = 60/7 *awt,
  sw15 = 6 *awt,
  sw16 = 4 *awt,
  sw17 = 6 *awt,
  sw18 = 6 *awt
  ) # max_patient

nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  aw1 = ipc_fy5_13,
  aw2 = ipc_fy5_14,
  aw3 = opc_fy5_9,
  aw4 = opc_fy5_10,
  aw5 = ipc_fy5_18,
  #aw6 = opc_fy5_12,
  #aw7 = ipc_fy5_4,
  #aw8 = ipc_fy5_10,
  #aw9 = ipc_fy5_11,
  #aw10 = opc_fy5_8,
  aw11 = opc_fy5_4,
  aw12 = ipc_fy5_2,
  aw13 = ipc_fy5_15,
  #aw14 = vacc_out_y5_total_1,
  aw15 = opc_fy5_3,
  aw16 = ipc_fy5_3,
  aw17 = opc_fy5_7,
  aw18 = opc_fy5_6
  )# patient_load | required staff

nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  #+aw6/sw6
  #+aw7/sw7
  #+aw8/sw8
  #+aw9/sw9
  #+aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  #+aw14/sw14
  +aw15/sw15
  +aw16/sw16
  +aw17/sw17
  +aw18/sw18
  ) #

'---------- CAF ----------'
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  cas1 = (6/7 *fte_hrs_q2) /awt *100,
  cas2 = (2 *ohv_fy5_1)  /awt *100) # standard cas2?

nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * other_df$vi12*other_df$vi13 *52,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52)

nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

nurses_chc_2015_df_sum <- nurses_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_chc_nurses_df <- nurses_chc_2015_df
gj_chc_nurses_df_sum <- nurses_chc_2015_df_sum

gj_chc_nurses_df
gj_chc_nurses_df_sum

```

> Nurses | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q2
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_fy5_13 Normal Del       | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_fy5_14 C-section        | 40 mins/pt  1.5/hr  - XXXXX
  3     | ANC                 | opc_fy5_9 antenatal         | 30 mins/pt  2/hr
  4     | Counseling          | opc_fy5_10 postnatal        | 15 mins/pt  4/hr
  5     | Investigation       | ipc_fy5_18 deaths           | 2.5 hr/pt   0.4/hr
  .
  6     | Outpatients         | opc_fy5_12 surgery          | 10 mins/pt  6/hr    - XXXXX
  7     | Inpatients          | ipc_fy5_4 admissions        | 15 mins/pt  4/hr    - XXXXX 
  8     | Inpatients          | ipc_fy5_10 major            | 2 hr/pt     0.5/hr  - XXXXX
  9     | Inpatients          | ipc_fy5_11 minor            | 15 mins/pt  4/hr    - XXXXX
  .
  10    | Outpatients         | opc_fy5_8 eye               | 15 mins/pt  4/hr    ----- X
  .
  11    | Outpatients         | opc_fy5_4 child             | 15 mins/pt  4/hr    ----- X
  12    | Inpatients          | ipc_fy5_2 child admission   | 15 mins/pt  4/hr    ----- X
  13    | Investigation       | ipc_fy5_15 stillbirths      | 25 mins/pt  2.4/hr  ----- X
  .
  14    | Outpatients         | vacc_out_y5_total_1 child   | 7 mins/pt  ~8.5/hr  ----- X?
  .
  15    | Outpatients         | opc_fy5_3 general           | 10 mins/pt  6/hr
  16    | Inpatients          | ipc_fy5_3 admissions        | 15 mins/pt  4/hr 
  17    | Outpatients         | opc_fy5_7 diabetes          | 10 mins/pt  6/hr
  18    | Outpatients         | opc_fy5_6 admissions        | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit                                        ----- X?
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]
  2     | Record keeping      | teams_admin_x_4 [max]       | [max]

```{r Nurses @ PHC | GJ}
# getting_data
nurses_phc_2015_df <- data_df %>%
  select(customid, platform_type, year, urban_rural, fte_hrs_q2,
         ipc_fy5_13, opc_fy5_9, opc_fy5_10, ipc_fy5_18, ###ipc_fy5_14,
         ###opc_fy5_12, ipc_fy5_4, ipc_fy5_10, ipc_fy5_11,
         #opc_fy5_8,
         #opc_fy5_4, ipc_fy5_2, ipc_fy5_15,
         #vacc_out_y5_total_1,
         opc_fy5_3, ipc_fy5_3, opc_fy5_7, opc_fy5_6,
         fy5_sanc_reg_nur_29, fy5_ip_reg_nur_29, ohv_fy5_1) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  filter(!is.na(ipc_fy5_13) & !is.na(opc_fy5_9) & !is.na(opc_fy5_10) & !is.na(ipc_fy5_18) &### & !is.na(ipc_fy5_14) 
           ###!is.na(opc_fy5_12) & !is.na(ipc_fy5_4) & !is.na(ipc_fy5_10) & !is.na(ipc_fy5_11) &
           #!is.na(opc_fy5_8) &
           #!is.na(opc_fy5_4) & !is.na(ipc_fy5_2) & !is.na(ipc_fy5_15) & 
           #!is.na(vacc_out_y5_total_1) &
           !is.na(opc_fy5_3) & !is.na(ipc_fy5_3) & !is.na(opc_fy5_7) & !is.na(opc_fy5_6)
           ) %>%
  filter((ipc_fy5_13 >= 0 ) & (opc_fy5_9 >= 0 ) & (opc_fy5_10 >= 0 ) & (ipc_fy5_18 >= 0 )### & (ipc_fy5_14 >= 0 )
         ###& (opc_fy5_12 >= 0 ) & (ipc_fy5_4 >= 0 ) & (ipc_fy5_10 >= 0 ) & (ipc_fy5_11 >= 0 )
         #& (opc_fy5_8 >= 0 )
         #& (opc_fy5_4 >= 0 ) & (ipc_fy5_2 >= 0 ) & (ipc_fy5_15 >= 0 )
         #& (vacc_out_y5_total_1 >= 0 )
         & (opc_fy5_3 >= 0 ) & (ipc_fy5_3 >= 0 ) & (opc_fy5_7 >= 0 ) & (opc_fy5_6 >= 0 )
         & (ohv_fy5_1 >= 0 ) & (fte_hrs_q2 > 0 )
    ) %>%
  mutate(f_type = replace(urban_rural, urban_rural == "Semi-/peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q2 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs1,teams_admin_dpw1,teams_admin_hpd1,
         teams_admin_docs4,teams_admin_dpw4,teams_admin_hpd4
         ) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  summarise(vi11 = max(teams_admin_docs1, na.rm = TRUE), vi12 = max(teams_admin_dpw1, na.rm = TRUE), vi13 = max(teams_admin_hpd1, na.rm = TRUE),
            vi21 = max(teams_admin_docs4, na.rm = TRUE), vi22 = max(teams_admin_dpw4, na.rm = TRUE), vi23 = max(teams_admin_hpd4, na.rm = TRUE))

leave = 102 # days
nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q2) # hrs of a year

'---------- HSA ----------'
nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
  sw1 = 1 *awt,
  ###sw2 = 1.5 *awt,
  sw3 = 2 *awt,
  sw4 = 4 *awt,
  sw5 = 0.4 *awt,
  ###sw6 = 6 *awt,
  ###sw7 = 4 *awt,
  ###sw8 = 0.5 *awt,
  ###sw9 = 4 *awt,
  #sw10 = 4 *awt,
  #sw11 = 4 *awt,
  #sw12 = 4 *awt,
  #sw13 = 2.4 *awt,
  #sw14 = 60/7 *awt,
  sw15 = 6 *awt,
  sw16 = 4 *awt,
  sw17 = 6 *awt,
  sw18 = 6 *awt
  ) # max_patient

nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
  aw1 = ipc_fy5_13,
  ###aw2 = ipc_fy5_14,
  aw3 = opc_fy5_9,
  aw4 = opc_fy5_10,
  aw5 = ipc_fy5_18,
  ###aw6 = opc_fy5_12,
  ###aw7 = ipc_fy5_4,
  ###aw8 = ipc_fy5_10,
  ###aw9 = ipc_fy5_11,
  #aw10 = opc_fy5_8,
  #aw11 = opc_fy5_4,
  #aw12 = ipc_fy5_2,
  #aw13 = ipc_fy5_15,
  #aw14 = vacc_out_y5_total_1,
  aw15 = opc_fy5_3,
  aw16 = ipc_fy5_3,
  aw17 = opc_fy5_7,
  aw18 = opc_fy5_6
  )# patient_load | required staff

nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
  HSA = aw1/sw1
  ###+aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  ###+aw6/sw6
  ###+aw7/sw7
  ###+aw8/sw8
  ###+aw9/sw9
  #+aw10/sw10
  #+aw11/sw11
  #+aw12/sw12
  #+aw13/sw13
  #+aw14/sw14
  +aw15/sw15
  +aw16/sw16
  +aw17/sw17
  +aw18/sw18
  ) #

'---------- CAF ----------'
nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
  cas1 = (6/7 *fte_hrs_q2) /awt *100,
  cas2 = (2 *ohv_fy5_1)  /awt *100) # standard cas2?

nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
  ias1 = other_df$vi11 * other_df$vi12*other_df$vi13 *52,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52)

nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
  IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

nurses_phc_2015_df_sum <- nurses_phc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

gj_phc_nurses_df <- nurses_phc_2015_df
gj_phc_nurses_df_sum <- nurses_phc_2015_df_sum

gj_phc_nurses_df
gj_phc_nurses_df_sum

```

## State | TN ----------
. ==================================================
General info
Data release information sheet | -
Codebook, with descriptions of all variables | IHME_ABCE_IND_TN_2012_2013_FACILITY_CODEBOOK_Y2018M03D27.CSV
Public use survey dataset – CSV format | IHME_ABCE_IND_TN_2012_2013_FACILITY_DATA_Y2018M03D27.CSV

```{r get Data | TN}
data_df <- read_csv("../data/ABCE/IHME_ABCE_IND_TN_2012_2013_FACILITY_DATA_Y2018M03D27.CSV")
as_tibble(data_df)

```

### Specialists @ CHC
. --------------------------------------------------
> OBGYN | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy_total_13 Norm Del    | 10 mins/pt  6/hr
  2     | Cesarian-OT         | ipc_fy_total_14 C-section   | 30 mins/pt  2/hr 
  3     | Outpatients         | opc_fy_total_10 Antenatal   | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy_total_11 Postnatal   | 15 mins/pt  4/hr
  5     | Family planning     | opc_fy_total_5 Welfare      | 5 mins/pt  12/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_x [max]       | 4 hr/month          ----- X?
  2     | Ethic meet          | teams_admin_x_2 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_6 [max]       | [max]               ----- X

```{r OBGYN @ CHC | TN}
# getting_data
obgyn_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         ipc_fy_total_13, ipc_fy_total_14, opc_fy_total_10, opc_fy_total_11, opc_fy_total_5,
         pers_fte_fy_21) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy_total_13) & !is.na(ipc_fy_total_14) & !is.na(opc_fy_total_10) & !is.na(opc_fy_total_11) & !is.na(opc_fy_total_5)) %>%
  filter((ipc_fy_total_13 >= 0 ) & (ipc_fy_total_14 >= 0 ) & (opc_fy_total_10 >= 0 ) & (opc_fy_total_11 >= 0 ) & (opc_fy_total_5 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         #teams_admin_pers_x,teams_admin_dpw_x,teams_admin_hpd_x,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_6,teams_admin_dpw_6,teams_admin_hpd_6) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(
    #vi11 = max(teams_admin_pers_x, na.rm = TRUE), vi12 = max(teams_admin_dpw_x, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_2, na.rm = TRUE), vi22 = max(teams_admin_dpw_2, na.rm = TRUE), vi23 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi31 = max(teams_admin_pers_6, na.rm = TRUE), vi32 = max(teams_admin_dpw_6, na.rm = TRUE), vi33 = max(teams_admin_hpd_6, na.rm = TRUE))

leave = 102 # days
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 2 *awt,
  sw3 = 4 *awt,
  sw4 = 4 *awt,
  sw5 = 12 *awt) # max_patient

obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  aw1 = ipc_fy_total_13,
  aw2 = ipc_fy_total_14,
  aw3 = opc_fy_total_10,
  aw4 = opc_fy_total_11,
  aw5 = opc_fy_total_5)# patient_load | required staff

obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4 +aw5/sw5) #

'---------- CAF ----------'
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  ias1 = 0) #other_df$vi11 * 4*12) # ignored? dropped ias1?, ias2, ias3

obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

obgyn_chc_2011_df_sum <- obgyn_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_chc_obgyn_df <- obgyn_chc_2011_df
tn_chc_obgyn_df_sum <- obgyn_chc_2011_df_sum

tn_chc_obgyn_df
tn_chc_obgyn_df_sum

```

> SurgerySpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_total_13 visits      | 10 mins/pt  6/hr
  2     | Inpatients          | ipc_fy_total_4 admissions   | 10 mins/pt  6/hr 
  3     | Operate Major       | ipc_fy_total_10 #major      | 2  hr/pt  0.5/hr
  4     | Operate minor       | ipc_fy_total_11 #minor      | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_x [max]       | 4 hr/month          ----- x?
  2     | Ethic meet          | teams_admin_x_2 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_6 [max]       | [max]               ----- X

```{r SurgerySpec @ CHC | TN}
# getting_data
surgeryspec_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         opc_fy_total_13, ipc_fy_total_4, ipc_fy_total_10, ipc_fy_total_11,
         pers_fte_fy_19) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_total_13) & !is.na(ipc_fy_total_4) & !is.na(ipc_fy_total_10) & !is.na(ipc_fy_total_11)) %>%
  filter((opc_fy_total_13 >= 0 ) & (ipc_fy_total_4 >= 0 ) & (ipc_fy_total_10 >= 0 ) & (ipc_fy_total_11 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         #teams_admin_pers_x,teams_admin_dpw_x,teams_admin_hpd_x,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_6,teams_admin_dpw_6,teams_admin_hpd_6) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(
    #vi11 = max(teams_admin_pers_x, na.rm = TRUE), vi12 = max(teams_admin_dpw_x, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_2, na.rm = TRUE), vi22 = max(teams_admin_dpw_2, na.rm = TRUE), vi23 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi31 = max(teams_admin_pers_6, na.rm = TRUE), vi32 = max(teams_admin_dpw_6, na.rm = TRUE), vi33 = max(teams_admin_hpd_6, na.rm = TRUE))

leave = 102 # days
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt,
  sw3 = 0.5 *awt,
  sw4 = 4 *awt) # max_patient

surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  aw1 = opc_fy_total_13,
  aw2 = ipc_fy_total_4,
  aw3 = ipc_fy_total_10,
  aw4 = ipc_fy_total_11)# patient_load | required staff

surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  ias1 = 0) #other_df$vi11 * 4*12) # ignored? dropped ias1?, ias2, ias3

surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

surgeryspec_chc_2011_df_sum <- surgeryspec_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_chc_surgeryspec_df <- surgeryspec_chc_2011_df
tn_chc_surgeryspec_df_sum <- surgeryspec_chc_2011_df_sum

tn_chc_surgeryspec_df
tn_chc_surgeryspec_df_sum

```

> EyeSpec [Ophthalmologist] | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_total_9 visits       | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_x [max]       | 4 hr/month          ----- x?
  2     | Ethic meet          | teams_admin_x_2 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_6 [max]       | [max]               ----- X

```{r EyeSpec @ CHC | TN}
# getting_data
eyespec_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         opc_fy_total_9,
         pers_fte_fy_27) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_total_9)) %>%
  filter((opc_fy_total_9 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         #teams_admin_pers_x,teams_admin_dpw_x,teams_admin_hpd_x,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_6,teams_admin_dpw_6,teams_admin_hpd_6) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(
    #vi11 = max(teams_admin_pers_x, na.rm = TRUE), vi12 = max(teams_admin_dpw_x, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_2, na.rm = TRUE), vi22 = max(teams_admin_dpw_2, na.rm = TRUE), vi23 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi31 = max(teams_admin_pers_6, na.rm = TRUE), vi32 = max(teams_admin_dpw_6, na.rm = TRUE), vi33 = max(teams_admin_hpd_6, na.rm = TRUE))

leave = 102 # days
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  sw1 = 4 *awt) # max_patient

eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  aw1 = opc_fy_total_9)# patient_load | required staff

eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  HSA = aw1/sw1) #

'---------- CAF ----------'
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  ias1 = 0) #other_df$vi11 * 4*12) # ignored! dropped ias1?, ias2, ias3

eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

eyespec_chc_2011_df_sum <- eyespec_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_chc_eyespec_df <- eyespec_chc_2011_df
tn_chc_eyespec_df_sum <- eyespec_chc_2011_df_sum

tn_chc_eyespec_df
tn_chc_eyespec_df_sum

```

> ChildSpec [Paedistrician] | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_total_4 visits            | 10 mins/pt  6/hr
  2     | Inpatients          | ipc_fy_total_2 admissions        | 10 mins/pt   6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_x [max]       | 4 hr/month          ----- x?
  2     | Ethic meet          | teams_admin_x_2 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_6 [max]       | [max]               ----- X

```{r ChildSpec @ CHC | TN}
# getting_data
childspec_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         opc_fy_total_4, ipc_fy_total_2,
         pers_fte_fy_24) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_total_4) & !is.na(ipc_fy_total_2)) %>%
  filter((opc_fy_total_4 >= 0 ) & (ipc_fy_total_2 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         #teams_admin_pers_x,teams_admin_dpw_x,teams_admin_hpd_x,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_6,teams_admin_dpw_6,teams_admin_hpd_6) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(
    #vi11 = max(teams_admin_pers_x, na.rm = TRUE), vi12 = max(teams_admin_dpw_x, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_2, na.rm = TRUE), vi22 = max(teams_admin_dpw_2, na.rm = TRUE), vi23 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi31 = max(teams_admin_pers_6, na.rm = TRUE), vi32 = max(teams_admin_dpw_6, na.rm = TRUE), vi33 = max(teams_admin_hpd_6, na.rm = TRUE))

leave = 102 # days
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt) # max_patient

childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  aw1 = opc_fy_total_4,
  aw2 = ipc_fy_total_2)# patient_load | required staff

childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2) #

'---------- CAF ----------'
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  ias1 = 0) #other_df$vi11 * 4*12) # ignored? dropped ias1?, ias2, ias3

childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

childspec_chc_2011_df_sum <- childspec_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_chc_childspec_df <- childspec_chc_2011_df
tn_chc_childspec_df_sum <- childspec_chc_2011_df_sum

tn_chc_childspec_df
tn_chc_childspec_df_sum

```

> MedicalSpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy5_6 visits            | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy5_8 diabetes          | 10 mins/pt  6/hr 
  3     | Inpatients          | ipc_fy5_3 admissions        | 10 mins/pt  6/hr
  4     | Oupatients          | opc_fy5_7 non-surgical      | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_x [max]       | 4 hr/month          ----- x?
  2     | Ethic meet          | teams_admin_x_2 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_6 [max]       | [max]               ----- X

```{r MedicalSpec @ CHC | TN}
# getting_data
medicalspec_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         opc_fy_total_6, opc_fy_total_8, ipc_fy_total_3, opc_fy_total_7,
         pers_fte_fy_20) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_total_6) & !is.na(opc_fy_total_8) & !is.na(ipc_fy_total_3) & !is.na(opc_fy_total_7)) %>%
  filter((opc_fy_total_6 >= 0 ) & (opc_fy_total_8 >= 0 ) & (ipc_fy_total_3 >= 0 ) & (opc_fy_total_7 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         #teams_admin_pers_x,teams_admin_dpw_x,teams_admin_hpd_x,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_6,teams_admin_dpw_6,teams_admin_hpd_6) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(
    #vi11 = max(teams_admin_pers_x, na.rm = TRUE), vi12 = max(teams_admin_dpw_x, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_2, na.rm = TRUE), vi22 = max(teams_admin_dpw_2, na.rm = TRUE), vi23 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi31 = max(teams_admin_pers_6, na.rm = TRUE), vi32 = max(teams_admin_dpw_6, na.rm = TRUE), vi33 = max(teams_admin_hpd_6, na.rm = TRUE))

leave = 102 # days
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt,
  sw3 = 6 *awt,
  sw4 = 6 *awt) # max_patient

medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  aw1 = opc_fy_total_6,
  aw2 = opc_fy_total_8,
  aw3 = ipc_fy_total_3,
  aw4 = opc_fy_total_7)# patient_load | required staff

medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  ias1 = 0) #other_df$vi11 * 4*12) # ignored? dropped ias1?, ias2, ias3

medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  IAF = (ias1) /awt) #

'---------- WISN ----------'
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

medicalspec_chc_2011_df_sum <- medicalspec_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_chc_medicalspec_df <- medicalspec_chc_2011_df
tn_chc_medicalspec_df_sum <- medicalspec_chc_2011_df_sum

tn_chc_medicalspec_df
tn_chc_medicalspec_df_sum

```

### MO @ Facility
. --------------------------------------------------
> MedicalOfficer | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy5_13 Normal Del       | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy5_10 antenatal        | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy5_11 postnatal        | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy5_5 family welfare    | 5 mins/pt  12/hr
  5     | Outpatients         | opc_fy5_13 surgical         | 10 mins/pt  6/hr    ----- X
  6     | Inpatients          | ipc_fy5_4 surgery admission | 10 mins/pt  6/hr    ----- X
  7     | Emergency           | ec_fy5_1 visits             | 20 mins/pt  3/hr    ----- X
  8     | Emergency           | ec_fy5_4 transfers          | - mins/pt  --/hr    ----- X
  9     | Outpatients         | opc_fy5_9 eye               | 15 mins/pt  4/hr    ----- X
  10    | Outpatients         | opc_fy5_4 child             | 10 mins/pt  6/hr
  11    | Inpatients          | ipc_fy5_2 child admissions  | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy5_6 surgery visit     | 10 mins/pt  6/hr
  13    | Outpatients         | opc_fy5_8 diabetes          | 10 mins/pt  6/hr
  14    | Inpatients          | ipc_fy5_3 admissions        | 10 mins/pt  6/hr
  15    | Outpatients         | opc_fy5_7 general           | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_x [max]       | 4 hr/month          ----- X?
  2     | Ethic meet          | teams_admin_x_2 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_6 [max]       | [max]               ----- X
  4     | Immunization meet   | 1                           | 4 hr/month          ----- X?

```{r MedicalOfficer @ PHC | TN}
# getting_data
mo_phc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         ipc_fy_total_13, opc_fy_total_10, opc_fy_total_11, opc_fy_total_5,
         #opc_fy_total_13, ipc_fy_total_4,
         #ec_fy_total_1, ec_fy_total_4,
         #opc_fy_total_9,
         opc_fy_total_4, ipc_fy_total_2,
         opc_fy_total_6, opc_fy_total_8, ipc_fy_total_3, opc_fy_total_7,
         pers_fte_fy_13) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  filter(!is.na(ipc_fy_total_13) & !is.na(opc_fy_total_10) & !is.na(opc_fy_total_11) & !is.na(opc_fy_total_5)
         #& !is.na(opc_fy_total_13) & !is.na(ipc_fy_total_4)
         #& !is.na(ec_fy_total_1) & !is.na(ec_fy_total_4)
         #& !is.na(opc_fy_total_9)
         & !is.na(opc_fy_total_4) & !is.na(ipc_fy_total_2)
         & !is.na(opc_fy_total_6) & !is.na(opc_fy_total_8) & !is.na(ipc_fy_total_3) & !is.na(opc_fy_total_7)
         ) %>%
  filter((ipc_fy_total_13 >= 0 ) & (opc_fy_total_10 >= 0 ) & (opc_fy_total_11 >= 0 ) & (opc_fy_total_5 >= 0 )
         #& (opc_fy_total_13 >= 0 ) & (ipc_fy_total_4 >= 0 )
         #& (ec_fy_total_1 >= 0 ) & (ec_fy_total_4 >= 0 )
         #& (opc_fy_total_9 >= 0 )
         & (opc_fy_total_4 >= 0 ) & (ipc_fy_total_2 >= 0 )
         & (opc_fy_total_6 >= 0 ) & (opc_fy_total_8 >= 0 ) & (ipc_fy_total_3 >= 0 ) & (opc_fy_total_7 >= 0 )
    ) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         #teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_6,teams_admin_dpw_6,teams_admin_hpd_6) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  summarise(
    #vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_2, na.rm = TRUE), vi22 = max(teams_admin_dpw_2, na.rm = TRUE), vi23 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi31 = max(teams_admin_pers_6, na.rm = TRUE), vi32 = max(teams_admin_dpw_6, na.rm = TRUE), vi33 = max(teams_admin_hpd_6, na.rm = TRUE))

leave = 102 # days
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  sw4 = 12 *awt,
  #sw5 = 6 *awt,
  #sw6 = 6 *awt,
  #sw7 = 3 *awt,
  #sw8 = 0 *awt,
  #sw9 = 4 *awt,
  sw10 = 6 *awt,
  sw11 = 6 *awt,
  sw12 = 6 *awt,
  sw13 = 6 *awt,
  sw14 = 6 *awt,
  sw15 = 6 *awt
  ) # max_patient

mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  aw1 = ipc_fy_total_13,
  aw2 = opc_fy_total_10,
  aw3 = opc_fy_total_11,
  aw4 = opc_fy_total_5,
  #aw5 = opc_fy_total_13,
  #aw6 = ipc_fy_total_4,
  #aw7 = ec_fy_total_1,
  #aw8 = ec_fy_total_4,
  #aw9 = opc_fy_total_9,
  aw10 = opc_fy_total_4,
  aw11 = ipc_fy_total_2,
  aw12 = opc_fy_total_6,
  aw13 = opc_fy_total_8,
  aw14 = ipc_fy_total_3,
  aw15 = opc_fy_total_7
  )# patient_load | required staff

mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  #+aw5/sw5
  #+aw6/sw6
  #+aw7/sw7
  #+aw8/sw8
  #+aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  +aw14/sw14
  +aw15/sw15
  ) #

'---------- CAF ----------'
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs1 *12)  /awt *100)

mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  #ias1 = other_df$vi11 * 4*12,
  ias2 = 0, #other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = 0, #other_df$vi31 * other_df$vi32*other_df$vi33*52,
  #ias4 = 1 * 4*12
  ) # ignored? dropped ias2, ias3, ias1?, ias4?

mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  IAF = (ias2 +ias3) /awt) #

'---------- WISN ----------'
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_phc_2011_df_sum <- mo_phc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_phc_mo_df <- mo_phc_2011_df
tn_phc_mo_df_sum <-  mo_phc_2011_df_sum

tn_phc_mo_df
tn_phc_mo_df_sum

```

> MedicalOfficer | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy5_13 Normal Del       | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy5_10 antenatal        | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy5_11 postnatal        | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy5_5 family welfare    | 5 mins/pt  12/hr
  5     | Outpatients         | opc_fy5_13 surgical         | 10 mins/pt  6/hr    ----- X
  6     | Inpatients          | ipc_fy5_4 surgery admission | 10 mins/pt  6/hr    ----- X
  7     | Emergency           | ec_fy5_1 visits             | 20 mins/pt  3/hr    ----- X
  8     | Emergency           | ec_fy5_4 transfers          | - mins/pt  --/hr    ----- X
  9     | Outpatients         | opc_fy5_9 eye               | 15 mins/pt  4/hr    ----- X
  10    | Outpatients         | opc_fy5_4 child             | 10 mins/pt  6/hr
  11    | Inpatients          | ipc_fy5_2 child admissions  | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy5_6 surgery visit     | 10 mins/pt  6/hr
  13    | Outpatients         | opc_fy5_8 diabetes          | 10 mins/pt  6/hr
  14    | Inpatients          | ipc_fy5_3 admissions        | 10 mins/pt  6/hr
  15    | Outpatients         | opc_fy5_7 general           | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_x [max]       | 4 hr/month          ----- X?
  2     | Ethic meet          | teams_admin_x_2 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_6 [max]       | [max]               ----- X
  4     | Immunization meet   | 1                           | 4 hr/month          ----- X?

```{r MedicalOfficer @ CHC | TN}
# getting_data
mo_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         ipc_fy_total_13, opc_fy_total_10, opc_fy_total_11, opc_fy_total_5,
         #opc_fy_total_13, ipc_fy_total_4,
         #ec_fy_total_1, ec_fy_total_4,
         #opc_fy_total_9,
         opc_fy_total_4, ipc_fy_total_2,
         opc_fy_total_6, opc_fy_total_8, ipc_fy_total_3, opc_fy_total_7,
         pers_fte_fy_13) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy_total_13) & !is.na(opc_fy_total_10) & !is.na(opc_fy_total_11) & !is.na(opc_fy_total_5)
         #& !is.na(opc_fy_total_13) & !is.na(ipc_fy_total_4)
         #& !is.na(ec_fy_total_1) & !is.na(ec_fy_total_4)
         #& !is.na(opc_fy_total_9)
         & !is.na(opc_fy_total_4) & !is.na(ipc_fy_total_2)
         & !is.na(opc_fy_total_6) & !is.na(opc_fy_total_8) & !is.na(ipc_fy_total_3) & !is.na(opc_fy_total_7)
         ) %>%
  filter((ipc_fy_total_13 >= 0 ) & (opc_fy_total_10 >= 0 ) & (opc_fy_total_11 >= 0 ) & (opc_fy_total_5 >= 0 )
         #& (opc_fy_total_13 >= 0 ) & (ipc_fy_total_4 >= 0 )
         #& (ec_fy_total_1 >= 0 ) & (ec_fy_total_4 >= 0 )
         #& (opc_fy_total_9 >= 0 )
         & (opc_fy_total_4 >= 0 ) & (ipc_fy_total_2 >= 0 )
         & (opc_fy_total_6 >= 0 ) & (opc_fy_total_8 >= 0 ) & (ipc_fy_total_3 >= 0 ) & (opc_fy_total_7 >= 0 )
    ) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         #teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_6,teams_admin_dpw_6,teams_admin_hpd_6) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(
    #vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_2, na.rm = TRUE), vi22 = max(teams_admin_dpw_2, na.rm = TRUE), vi23 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi31 = max(teams_admin_pers_6, na.rm = TRUE), vi32 = max(teams_admin_dpw_6, na.rm = TRUE), vi33 = max(teams_admin_hpd_6, na.rm = TRUE))

leave = 102 # days
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  sw4 = 12 *awt,
  #sw5 = 6 *awt,
  #sw6 = 6 *awt,
  #sw7 = 3 *awt,
  #sw8 = 0 *awt,
  #sw9 = 4 *awt,
  sw10 = 6 *awt,
  sw11 = 6 *awt,
  sw12 = 6 *awt,
  sw13 = 6 *awt,
  sw14 = 6 *awt,
  sw15 = 6 *awt
  ) # max_patient

mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  aw1 = ipc_fy_total_13,
  aw2 = opc_fy_total_10,
  aw3 = opc_fy_total_11,
  aw4 = opc_fy_total_5,
  #aw5 = opc_fy_total_13,
  #aw6 = ipc_fy_total_4,
  #aw7 = ec_fy_total_1,
  #aw8 = ec_fy_total_4,
  #aw9 = opc_fy_total_9,
  aw10 = opc_fy_total_4,
  aw11 = ipc_fy_total_2,
  aw12 = opc_fy_total_6,
  aw13 = opc_fy_total_8,
  aw14 = ipc_fy_total_3,
  aw15 = opc_fy_total_7
  )# patient_load | required staff

mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  #+aw5/sw5
  #+aw6/sw6
  #+aw7/sw7
  #+aw8/sw8
  #+aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  +aw14/sw14
  +aw15/sw15
  ) #

'---------- CAF ----------'
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs1 *12)  /awt *100)

mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  #ias1 = other_df$vi11 * 4*12,
  ias2 = 0, #other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = 0, #other_df$vi31 * other_df$vi32*other_df$vi33*52,
  #ias4 = 1 * 4*12
  ) # ignored? dropped ias2, ias3, ias1?, ias4?

mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  IAF = (ias2 +ias3) /awt) #

'---------- WISN ----------'
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_chc_2011_df_sum <- mo_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_chc_mo_df <- mo_chc_2011_df
tn_chc_mo_df_sum <- mo_chc_2011_df_sum

tn_chc_mo_df
tn_chc_mo_df_sum

```

> MedicalOfficer | DH & SDH
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy5_13 Normal Del       | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy5_10 antenatal        | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy5_11 postnatal        | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy5_5 family welfare    | 5 mins/pt  12/hr
  5     | Outpatients         | opc_fy5_13 surgical         | 10 mins/pt  6/hr    ----- X
  6     | Inpatients          | ipc_fy5_4 surgery admission | 10 mins/pt  6/hr    ----- X
  7     | Emergency           | ec_fy5_1 visits             | 20 mins/pt  3/hr    ----- X
  8     | Emergency           | ec_fy5_4 transfers          | - mins/pt  --/hr    ----- X
  9     | Outpatients         | opc_fy5_9 eye               | 15 mins/pt  4/hr    ----- X
  10    | Outpatients         | opc_fy5_4 child             | 10 mins/pt  6/hr
  11    | Inpatients          | ipc_fy5_2 child admissions  | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy5_6 surgery visit     | 10 mins/pt  6/hr
  13    | Outpatients         | opc_fy5_8 diabetes          | 10 mins/pt  6/hr
  14    | Inpatients          | ipc_fy5_3 admissions        | 10 mins/pt  6/hr
  15    | Outpatients         | opc_fy5_7 general           | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_x [max]       | 4 hr/month          ----- X?
  2     | Ethic meet          | teams_admin_x_2 [max]       | [max]               ----- X
  3     | Edu services        | teams_admin_x_6 [max]       | [max]               ----- X
  4     | Immunization meet   | 1                           | 4 hr/month          ----- X?

```{r MedicalOfficer @ DH & SDH | TN}
# getting_data
mo_dh_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         ipc_fy_total_13, opc_fy_total_10, opc_fy_total_11, opc_fy_total_5,
         #opc_fy_total_13, ipc_fy_total_4,
         #ec_fy_total_1, ec_fy_total_4,
         #opc_fy_total_9,
         opc_fy_total_4, ipc_fy_total_2,
         opc_fy_total_6, opc_fy_total_8, ipc_fy_total_3, opc_fy_total_7,
         pers_fte_fy_13) %>%
  filter(platform_type == "District Hospital (DH)" | platform_type == "Sub-district Hospital (SDH)" ) %>%
  filter(!is.na(ipc_fy_total_13) & !is.na(opc_fy_total_10) & !is.na(opc_fy_total_11) & !is.na(opc_fy_total_5)
         #& !is.na(opc_fy_total_13) & !is.na(ipc_fy_total_4)
         #& !is.na(ec_fy_total_1) & !is.na(ec_fy_total_4)
         #& !is.na(opc_fy_total_9)
         & !is.na(opc_fy_total_4) & !is.na(ipc_fy_total_2)
         & !is.na(opc_fy_total_6) & !is.na(opc_fy_total_8) & !is.na(ipc_fy_total_3) & !is.na(opc_fy_total_7)
         ) %>%
  filter((ipc_fy_total_13 >= 0 ) & (opc_fy_total_10 >= 0 ) & (opc_fy_total_11 >= 0 ) & (opc_fy_total_5 >= 0 )
         #& (opc_fy_total_13 >= 0 ) & (ipc_fy_total_4 >= 0 )
         #& (ec_fy_total_1 >= 0 ) & (ec_fy_total_4 >= 0 )
         #& (opc_fy_total_9 >= 0 )
         & (opc_fy_total_4 >= 0 ) & (ipc_fy_total_2 >= 0 )
         & (opc_fy_total_6 >= 0 ) & (opc_fy_total_8 >= 0 ) & (ipc_fy_total_3 >= 0 ) & (opc_fy_total_7 >= 0 )
    ) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         #teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_6,teams_admin_dpw_6,teams_admin_hpd_6) %>%
  filter(platform_type == "District Hospital (DH)" | platform_type == "Sub-district Hospital (SDH)" ) %>%
  summarise(
    #vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_2, na.rm = TRUE), vi22 = max(teams_admin_dpw_2, na.rm = TRUE), vi23 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi31 = max(teams_admin_pers_6, na.rm = TRUE), vi32 = max(teams_admin_dpw_6, na.rm = TRUE), vi33 = max(teams_admin_hpd_6, na.rm = TRUE))

leave = 102 # days
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  sw4 = 12 *awt,
  #sw5 = 6 *awt,
  #sw6 = 6 *awt,
  #sw7 = 3 *awt,
  #sw8 = 0 *awt,
  #sw9 = 4 *awt,
  sw10 = 6 *awt,
  sw11 = 6 *awt,
  sw12 = 6 *awt,
  sw13 = 6 *awt,
  sw14 = 6 *awt,
  sw15 = 6 *awt
  ) # max_patient

mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  aw1 = ipc_fy_total_13,
  aw2 = opc_fy_total_10,
  aw3 = opc_fy_total_11,
  aw4 = opc_fy_total_5,
  #aw5 = opc_fy_total_13,
  #aw6 = ipc_fy_total_4,
  #aw7 = ec_fy_total_1,
  #aw8 = ec_fy_total_4,
  #aw9 = opc_fy_total_9,
  aw10 = opc_fy_total_4,
  aw11 = ipc_fy_total_2,
  aw12 = opc_fy_total_6,
  aw13 = opc_fy_total_8,
  aw14 = ipc_fy_total_3,
  aw15 = opc_fy_total_7
  )# patient_load | required staff

mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  #+aw5/sw5
  #+aw6/sw6
  #+aw7/sw7
  #+aw8/sw8
  #+aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  +aw14/sw14
  +aw15/sw15
  ) #

'---------- CAF ----------'
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs1 *12)  /awt *100)

mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  #ias1 = other_df$vi11 * 4*12,
  ias2 = 0, #other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = 0, #other_df$vi31 * other_df$vi32*other_df$vi33*52,
  #ias4 = 1 * 4*12
  ) # ignored? dropped ias2, ias3, ias1?, ias4?

mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  IAF = (ias2 +ias3) /awt) #

'---------- WISN ----------'
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_dh_2011_df_sum <- mo_dh_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_dh_mo_df <- mo_dh_2011_df
tn_dh_mo_df_sum <- mo_dh_2011_df_sum

tn_dh_mo_df
tn_dh_mo_df_sum

```

### Nurses @ Facility
. --------------------------------------------------
> Nurses | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs3
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_fy_total_13 Normal Del  | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_fy_total_14 C-section   | 40 mins/pt  1.5/hr 
  3     | ANC                 | opc_fy_total_10 antenatal   | 30 mins/pt  2/hr
  4     | Counseling          | opc_fy_total_11 postnatal   | 15 mins/pt  4/hr
  5     | Family planning     | opc_fy_total_5 welfare      | 5 mins/pt  12/hr
  6     | Investigation       | ipc_fy_total_18 deaths      | 2.5 hr/pt   0.4/hr
  .
  7     | Outpatients         | opc_fy_total_13 surgery     | 10 mins/pt  6/hr    ----- X
  8     | Inpatients          | ipc_fy_total_4 admissions   | 15 mins/pt  4/hr    ----- X 
  9     | Inpatients          | ipc_fy_total_10 major       | 2 hr/pt     0.5/hr  ----- X
  10    | Inpatients          | ipc_fy_total_11 minor       | 15 mins/pt  4/hr    ----- X
  .
  11    | Outpatients         | opc_fy_total_9 eye          | 15 mins/pt  4/hr    ----- X
  .
  12    | Outpatients         | opc_fy_total_4 child        | 15 mins/pt  4/hr
  13    | Inpatients          | ipc_fy_total_2 admission    | 15 mins/pt  4/hr
  14    | Investigation       | ipc_fy_total_15 stillbirths | 25 mins/pt  2.4/hr
  .
  15    | Immunisations       | opcv_fy_total_9 women       | 7 mins/pt  ~8.5/hr  ----- X
  16    | Immunisations       | opcv_fy_total_1 child       | 7 mins/pt  ~8.5/hr  ----- X
  .
  17    | Outpatients         | opc_fy_total_6 general      | 10 mins/pt  6/hr
  18    | Outpatients         | opc_fy_total_8 diabetes     | 10 mins/pt  6/hr 
  19    | Outpatients         | opc_fy_total_7 heart        | 10 mins/pt  6/hr
  20    | Inpatients          | ipc_fy_total_3 admissions   | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit                                        ----- X?
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]               ----- X?
  2     | Record keeping      | teams_admin_x_4 [max]       | [max]               ----- X?

```{r Nurses @ CHC | TN}
# getting_data
nurses_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs3,
         ipc_fy_total_13, ipc_fy_total_14, opc_fy_total_10, opc_fy_total_11, opc_fy_total_5, ipc_fy_total_18,
         #opc_fy_total_13, ipc_fy_total_4, ipc_fy_total_10, ipc_fy_total_11,
         #opc_fy_total_9,
         opc_fy_total_4, ipc_fy_total_2, ipc_fy_total_15,
         #opcv_fy_total_9, opcv_fy_total_1,
         opc_fy_total_6, opc_fy_total_8, opc_fy_total_7, ipc_fy_total_3,
         pers_fte_fy_31, ohv_fy_total_1) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  filter(!is.na(ipc_fy_total_13) & !is.na(ipc_fy_total_14) & !is.na(opc_fy_total_10) & !is.na(opc_fy_total_11) & !is.na(opc_fy_total_5) & !is.na(ipc_fy_total_18) & 
           #!is.na(opc_fy_total_13) & !is.na(ipc_fy_total_4) & !is.na(ipc_fy_total_10) & !is.na(ipc_fy_total_11) &
           #!is.na(opc_fy_total_9) &
           !is.na(opc_fy_total_4) & !is.na(ipc_fy_total_2) & !is.na(ipc_fy_total_15) & 
           #!is.na(opcv_fy_total_9) & !is.na(opcv_fy_total_1) &
           !is.na(opc_fy_total_6) & !is.na(opc_fy_total_8) & !is.na(opc_fy_total_7) & !is.na(ipc_fy_total_3)
           ) %>%
  filter((ipc_fy_total_13 >= 0 ) & (ipc_fy_total_14 >= 0 ) & (opc_fy_total_10 >= 0 ) & (opc_fy_total_11 >= 0 ) & (opc_fy_total_5 >= 0 ) & (ipc_fy_total_18 >= 0 )
         #& (opc_fy_total_13 >= 0 ) & (ipc_fy_total_4 >= 0 ) & (ipc_fy_total_10 >= 0 ) & (ipc_fy_total_11 >= 0 )
         #& (opc_fy_total_9 >= 0 )
         & (opc_fy_total_4 >= 0 ) & (ipc_fy_total_2 >= 0 ) & (ipc_fy_total_15 >= 0 )
         #& (opcv_fy_total_9 >= 0 ) & (opcv_fy_total_1 >= 0 )
         & (opc_fy_total_6 >= 0 ) & (opc_fy_total_8 >= 0 ) & (opc_fy_total_7 >= 0 ) & (ipc_fy_total_3 >= 0 )
         #& (ohv_fy_total_1 >= 0 )
    ) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs3 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_1,teams_admin_dpw_1,teams_admin_hpd_1,
         teams_admin_pers_4,teams_admin_dpw_4,teams_admin_hpd_4
         ) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_1, na.rm = TRUE), vi12 = max(teams_admin_dpw_1, na.rm = TRUE), vi13 = max(teams_admin_hpd_1, na.rm = TRUE),
            vi21 = max(teams_admin_pers_4, na.rm = TRUE), vi22 = max(teams_admin_dpw_4, na.rm = TRUE), vi23 = max(teams_admin_hpd_4, na.rm = TRUE))

leave = 102 # days
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs3) # hrs of a year

'---------- HSA ----------'
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  sw1 = 1 *awt,
  sw2 = 1.5 *awt,
  sw3 = 2 *awt,
  sw4 = 4 *awt,
  sw5 = 12 *awt,
  sw6 = 0.4 *awt,
  #sw7 = 6 *awt,
  #sw8 = 4 *awt,
  #sw9 = 0.5 *awt,
  #sw10 = 4 *awt,
  #sw11 = 4 *awt,
  sw12 = 4 *awt,
  sw13 = 4 *awt,
  sw14 = 2.4 *awt,
  #sw15 = 60/7 *awt,
  #sw16 = 60/7 *awt,
  sw17 = 6 *awt,
  sw18 = 6 *awt,
  sw19 = 6 *awt,
  sw20 = 4 *awt
  ) # max_patient

nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  aw1 = ipc_fy_total_13,
  aw2 = ipc_fy_total_14,
  aw3 = opc_fy_total_10,
  aw4 = opc_fy_total_11,
  aw5 = opc_fy_total_5,
  aw6 = ipc_fy_total_18,
  #aw7 = opc_fy_total_13,
  #aw8 = ipc_fy_total_4,
  #aw9 = ipc_fy_total_10,
  #aw10 = ipc_fy_total_11,
  #aw11 = opc_fy_total_9,
  aw12 = opc_fy_total_4,
  aw13 = ipc_fy_total_2,
  aw14 = ipc_fy_total_15,
  #aw15 = opcv_fy_total_9,
  #aw16 = opcv_fy_total_1,
  aw17 = opc_fy_total_6,
  aw18 = opc_fy_total_8,
  aw19 = opc_fy_total_7,
  aw20 = ipc_fy_total_3
  )# patient_load | required staff

nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  #+aw7/sw7
  #+aw8/sw8
  #+aw9/sw9
  #+aw10/sw10
  #+aw11/sw11
  +aw12/sw12
  +aw13/sw13
  +aw14/sw14
  #+aw15/sw15
  #+aw16/sw16
  +aw17/sw17
  +aw18/sw18
  +aw19/sw19
  +aw20/sw20
  ) #

'---------- CAF ----------'
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  cas1 = (6/7 *fte_hrs3) /awt *100,
  cas2 = (0 *2 *ohv_fy_total_1)  /awt *100) # ignored? standard cas2?

nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  ias1 = 0, #other_df$vi11 * other_df$vi12*other_df$vi13 *52,
  ias2 = 0) #other_df$vi21 * other_df$vi22*other_df$vi23 *52) # dropped ias1?, ias2?

nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

nurses_chc_2011_df_sum <- nurses_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_chc_nurses_df <- nurses_chc_2011_df
tn_chc_nurses_df_sum <- nurses_chc_2011_df_sum

tn_chc_nurses_df
tn_chc_nurses_df_sum

```

> Nurses | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs3
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_fy_total_13 Normal Del  | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_fy_total_14 C-section   | 40 mins/pt  1.5/hr  - XXXXX
  3     | ANC                 | opc_fy_total_10 antenatal   | 30 mins/pt  2/hr
  4     | Counseling          | opc_fy_total_11 postnatal   | 15 mins/pt  4/hr
  5     | Family planning     | opc_fy_total_5 welfare      | 5 mins/pt  12/hr
  6     | Investigation       | ipc_fy_total_18 deaths      | 2.5 hr/pt   0.4/hr
  .
  7     | Outpatients         | opc_fy_total_13 surgery     | 10 mins/pt  6/hr    - XXXXX
  8     | Inpatients          | ipc_fy_total_4 admissions   | 15 mins/pt  4/hr    - XXXXX 
  9     | Inpatients          | ipc_fy_total_10 major       | 2 hr/pt     0.5/hr  - XXXXX
  10    | Inpatients          | ipc_fy_total_11 minor       | 15 mins/pt  4/hr    - XXXXX
  .
  11    | Outpatients         | opc_fy_total_9 eye          | 15 mins/pt  4/hr    ----- X
  .
  12    | Outpatients         | opc_fy_total_4 child        | 15 mins/pt  4/hr    ----- X
  13    | Inpatients          | ipc_fy_total_2 admission    | 15 mins/pt  4/hr    ----- X
  14    | Investigation       | ipc_fy_total_15 stillbirths | 25 mins/pt  2.4/hr  ----- X
  .
  15    | Immunisations       | opcv_fy_total_9 women       | 7 mins/pt  ~8.5/hr
  16    | Immunisations       | opcv_fy_total_1 child       | 7 mins/pt  ~8.5/hr
  .
  17    | Outpatients         | opc_fy_total_6 general      | 10 mins/pt  6/hr
  18    | Outpatients         | opc_fy_total_8 diabetes     | 10 mins/pt  6/hr 
  19    | Outpatients         | opc_fy_total_7 heart        | 10 mins/pt  6/hr
  20    | Inpatients          | ipc_fy_total_3 admissions   | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit                                        ----- X!
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]               ----- X?
  2     | Record keeping      | teams_admin_x_4 [max]       | [max]               ----- X?

```{r Nurses @ PHC | TN}
# getting_data
nurses_phc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs3,
         ipc_fy_total_13, opc_fy_total_10, opc_fy_total_11, opc_fy_total_5, ipc_fy_total_18, ###ipc_fy_total_14,
         ###opc_fy_total_13, ipc_fy_total_4, ipc_fy_total_10, ipc_fy_total_11,
         #opc_fy_total_9,
         #opc_fy_total_4, ipc_fy_total_2, ipc_fy_total_15,
         opcv_fy_total_9, opcv_fy_total_1,
         opc_fy_total_6, opc_fy_total_8, opc_fy_total_7, ipc_fy_total_3,
         pers_fte_fy_31, ohv_fy_total_1) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  #filter(year == 2011) %>%
  filter(!is.na(ipc_fy_total_13) & !is.na(opc_fy_total_10) & !is.na(opc_fy_total_11) & !is.na(opc_fy_total_5) & !is.na(ipc_fy_total_18) & ### !is.na(ipc_fy_total_14) &
           ###!is.na(opc_fy_total_13) & !is.na(ipc_fy_total_4) & !is.na(ipc_fy_total_10) & !is.na(ipc_fy_total_11) &
           #!is.na(opc_fy_total_9) &
           #!is.na(opc_fy_total_4) & !is.na(ipc_fy_total_2) & !is.na(ipc_fy_total_15) & 
           !is.na(opcv_fy_total_9) & !is.na(opcv_fy_total_1) &
           !is.na(opc_fy_total_6) & !is.na(opc_fy_total_8) & !is.na(opc_fy_total_7) & !is.na(ipc_fy_total_3)
           ) %>%
  filter((ipc_fy_total_13 >= 0 ) & (opc_fy_total_10 >= 0 ) & (opc_fy_total_11 >= 0 ) & (opc_fy_total_5 >= 0 ) & (ipc_fy_total_18 >= 0 )### & (ipc_fy_total_14 >= 0 )
         ###& (opc_fy_total_13 >= 0 ) & (ipc_fy_total_4 >= 0 ) & (ipc_fy_total_10 >= 0 ) & (ipc_fy_total_11 >= 0 )
         #& (opc_fy_total_9 >= 0 )
         #& (opc_fy_total_4 >= 0 ) & (ipc_fy_total_2 >= 0 ) & (ipc_fy_total_15 >= 0 )
         & (opcv_fy_total_9 >= 0 ) & (opcv_fy_total_1 >= 0 )
         & (opc_fy_total_6 >= 0 ) & (opc_fy_total_8 >= 0 ) & (opc_fy_total_7 >= 0 ) & (ipc_fy_total_3 >= 0 )
         & (ohv_fy_total_1 > 0 )
    ) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban /", "Semi/Peri-Urban")) %>%
  filter(fte_hrs3 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_1,teams_admin_dpw_1,teams_admin_hpd_1,
         teams_admin_pers_4,teams_admin_dpw_4,teams_admin_hpd_4
         ) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_1, na.rm = TRUE), vi12 = max(teams_admin_dpw_1, na.rm = TRUE), vi13 = max(teams_admin_hpd_1, na.rm = TRUE),
            vi21 = max(teams_admin_pers_4, na.rm = TRUE), vi22 = max(teams_admin_dpw_4, na.rm = TRUE), vi23 = max(teams_admin_hpd_4, na.rm = TRUE))

leave = 102 # days
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs3) # hrs of a year

'---------- HSA ----------'
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  sw1 = 1 *awt,
  ###sw2 = 1.5 *awt,
  sw3 = 2 *awt,
  sw4 = 4 *awt,
  sw5 = 12 *awt,
  sw6 = 0.4 *awt,
  ###sw7 = 6 *awt,
  ###sw8 = 4 *awt,
  ###sw9 = 0.5 *awt,
  ###sw10 = 4 *awt,
  #sw11 = 4 *awt,
  #sw12 = 4 *awt,
  #sw13 = 4 *awt,
  #sw14 = 2.4 *awt,
  sw15 = 60/7 *awt,
  sw16 = 60/7 *awt,
  sw17 = 6 *awt,
  sw18 = 6 *awt,
  sw19 = 6 *awt,
  sw20 = 4 *awt
  ) # max_patient

nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  aw1 = ipc_fy_total_13,
  ###aw2 = ipc_fy_total_14,
  aw3 = opc_fy_total_10,
  aw4 = opc_fy_total_11,
  aw5 = opc_fy_total_5,
  aw6 = ipc_fy_total_18,
  ###aw7 = opc_fy_total_13,
  ###aw8 = ipc_fy_total_4,
  ###aw9 = ipc_fy_total_10,
  ###aw10 = ipc_fy_total_11,
  #aw11 = opc_fy_total_9,
  #aw12 = opc_fy_total_4,
  #aw13 = ipc_fy_total_2,
  #aw14 = ipc_fy_total_15,
  aw15 = opcv_fy_total_9,
  aw16 = opcv_fy_total_1,
  aw17 = opc_fy_total_6,
  aw18 = opc_fy_total_8,
  aw19 = opc_fy_total_7,
  aw20 = ipc_fy_total_3
  )# patient_load | required staff

nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  HSA = aw1/sw1
  ###+aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  ###+aw7/sw7
  ###+aw8/sw8
  ###+aw9/sw9
  ###+aw10/sw10
  #+aw11/sw11
  #+aw12/sw12
  #+aw13/sw13
  #+aw14/sw14
  +aw15/sw15
  +aw16/sw16
  +aw17/sw17
  +aw18/sw18
  +aw19/sw19
  +aw20/sw20
  ) #

'---------- CAF ----------'
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  cas1 = (6/7 *fte_hrs3) /awt *100,
  cas2 = (2 *ohv_fy_total_1)  /awt *100) # standard cas2?

nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  ias1 = 0, #other_df$vi11 * other_df$vi12*other_df$vi13 *52,
  ias2 = 0) #other_df$vi21 * other_df$vi22*other_df$vi23 *52) # dropped ias1?, ias2?

nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

nurses_phc_2011_df_sum <- nurses_phc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

tn_phc_nurses_df <- nurses_phc_2011_df
tn_phc_nurses_df_sum <- nurses_phc_2011_df_sum

tn_phc_nurses_df
tn_phc_nurses_df_sum

```

## State | OD ----------
. ==================================================
General info
Data release information sheet | -
Codebook, with descriptions of all variables | IHME_ABCE_IND_OD_2014_2015_FACILITY_CODEBOOK_Y2019M07D22.CSV
Public use survey dataset – CSV format | IHME_ABCE_IND_OD_2014_2015_FACILITY_DATA_Y2019M07D22.CSV

```{r get Data | OD}
data_df <- read_csv("../data/ABCE/IHME_ABCE_IND_OD_2014_2015_FACILITY_DATA_Y2019M07D22.CSV")

data_df <- within(data_df, platform_type[platform_type == "Community Health Centre  (CHC)"] <- "Community Health Centre (CHC)")

data_df

```

```{r OD transform}
# transforming year variables into rows
# "\w*_cy[0-9]_\d*"
temp0 <- data_df %>% select(-contains("_cy"))
temp1 <- data_df %>% select(contains("_cy1")) %>%
  add_column(year = 2009) %>%
  rename_all(gsub, pattern = '\\_cy1', replacement = '_cy5')
temp2 <- data_df %>% select(contains("_cy2")) %>%
  add_column(year = 2010) %>%
  rename_all(gsub, pattern = '\\_cy2', replacement = '_cy5')
temp3 <- data_df %>% select(contains("_cy3")) %>%
  add_column(year = 2011) %>%
  rename_all(gsub, pattern = '\\_cy3', replacement = '_cy5')
temp4 <- data_df %>% select(contains("_cy4")) %>%
  add_column(year = 2012) %>%
  rename_all(gsub, pattern = '\\_cy4', replacement = '_cy5')
temp5 <- data_df %>% select(contains("_cy5")) %>%
  add_column(year = 2013)

temp01 <- bind_cols(temp0, temp1)
temp02 <- bind_cols(temp0, temp2)
temp03 <- bind_cols(temp0, temp3)
temp04 <- bind_cols(temp0, temp4)
temp05 <- bind_cols(temp0, temp5)

data_df <- bind_rows(
  temp01,
  temp02,
  temp03,
  temp04,
  temp05
)

```

### Specialists @ CHC
. --------------------------------------------------
> OBGYN | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_cy5_13 Norm Del         | 10 mins/pt  6/hr
  2     | Cesarian-OT         | ipc_cy5_14 C-section        | 30 mins/pt  2/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?

```{r OBGYN @ CHC | OD}
# getting_data
obgyn_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs_q1,
         ipc_cy5_13, ipc_cy5_14,
         ) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_cy5_13) & !is.na(ipc_cy5_14)) %>%
  filter((ipc_cy5_13 >= 0 ) & (ipc_cy5_14 >= 0 )) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 2 *awt) # max_patient

obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  aw1 = ipc_cy5_13,
  aw2 = ipc_cy5_14)# patient_load | required staff

obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2) #

'---------- CAF ----------'
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100 )

obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33*52) # dropped ias3?

obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  IAF = (ias1 +ias3 +ias3) /awt) #

'---------- WISN ----------'
obgyn_chc_2015_df <- obgyn_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

obgyn_chc_2015_df_sum <- obgyn_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

od_chc_obgyn_df <- obgyn_chc_2015_df
od_chc_obgyn_df_sum <- obgyn_chc_2015_df_sum

od_chc_obgyn_df
od_chc_obgyn_df_sum

```

> SurgerySpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Inpatients          | ipc_cy5_4 admissions        | 10 mins/pt  6/hr 
  2     | Operate Major       | ipc_cy5_10 #major           | 2  hr/pt  0.5/hr
  3     | Operate minor       | ipc_cy5_11 #minor           | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?

```{r SurgerySpec @ CHC | OD}
# getting_data
surgeryspec_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs_q1,
         ipc_cy5_4, ipc_cy5_10, ipc_cy5_11,
         ) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_cy5_4) & !is.na(ipc_cy5_10) & !is.na(ipc_cy5_11)) %>%
  filter((ipc_cy5_4 >= 0 ) & (ipc_cy5_10 >= 0 ) & (ipc_cy5_11 >= 0 )) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 0.5 *awt,
  sw3 = 4 *awt) # max_patient

surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  aw1 = ipc_cy5_4,
  aw2 = ipc_cy5_10,
  aw3 = ipc_cy5_11)# patient_load | required staff

surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3) #

'---------- CAF ----------'
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100 )

surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33*52) # dropped ias3?

surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
surgeryspec_chc_2015_df <- surgeryspec_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

surgeryspec_chc_2015_df_sum <- surgeryspec_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

od_chc_surgeryspec_df <- surgeryspec_chc_2015_df
od_chc_surgeryspec_df_sum <- surgeryspec_chc_2015_df_sum

od_chc_surgeryspec_df
od_chc_surgeryspec_df_sum

```

> EyeSpec [Ophthalmologist] | CHC
AWT
Health service activity
Support activity | CAS
Additional activity | IAS

No Data Available 

```{r EyeSpec @ CHC | OD}
# getting_data
#eyespec_chc_2015_df <- data_df %>%
#  select(customid, platform_type, fte_hrs_q1
#         ) %>%
#  filter(platform_type == "Community Health Centre  (CHC)") %>%
#  #filter() %>%
#  #filter()

#other_df <- data_df %>%
#  select(customid, platform_type,
#         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
#         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
#         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
#  filter(platform_type == "Community Health Centre  (CHC)") %>%
#  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
#            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
#            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

#leave = 102 # days
#eyespec_chc_2015_df <- eyespec_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'

'---------- CAF ----------'

'---------- IAF ----------'

'---------- WISN ----------'

#eyespec_chc_2015_df
#eyespec_chc_2015_df_sum

#od_chc_eyespec_df <- data.frame(customid=NA, HSA=NA, CAF=NA, IAF=NA, WISN=NA)
#od_chc_childspec_df_sum <- NaN

od_chc_eyespec_df <- mo_phc_2012_df # mp_phc_mo_df # adding empty df !!!

od_chc_eyespec_df

```

> ChildSpec [Paedistrician] | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_cy5_4 visits            | 10 mins/pt    6/hr
  2     | Inpatients          | ipc_cy5_2 admissions        | 10 mins/pt    6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?

```{r ChildSpec @ CHC | OD}
# getting_data
childspec_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs_q1,
         opc_cy5_4, ipc_cy5_2,
         ) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_cy5_4) & !is.na(ipc_cy5_2)) %>%
  filter((opc_cy5_4 >= 0 ) & (ipc_cy5_2 >= 0 )) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt) # max_patient

childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  aw1 = opc_cy5_4,
  aw2 = ipc_cy5_2)# patient_load | required staff

childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2) #

'---------- CAF ----------'
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100 )

childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33*52) # dropped ias3?

childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
childspec_chc_2015_df <- childspec_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

childspec_chc_2015_df_sum <- childspec_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

od_chc_childspec_df <- childspec_chc_2015_df
od_chc_childspec_df_sum <- childspec_chc_2015_df_sum

od_chc_childspec_df
od_chc_childspec_df_sum

```

> MedicalSpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_cy5_3 general           | 5 mins/pt  12/hr
  2     | Inpatients          | ipc_cy5_3 admissions        | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?

```{r MedicalSpec @ CHC | OD}
# getting_data
medicalspec_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs_q1,
         opc_cy5_3, ipc_cy5_3,
         ) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_cy5_3) & !is.na(ipc_cy5_3)) %>%
  filter((opc_cy5_3 >= 0 ) & (ipc_cy5_3 >= 0 )) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  sw1 = 12 *awt,
  sw2 = 6 *awt) # max_patient

medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  aw1 = opc_cy5_3,
  aw2 = ipc_cy5_3)# patient_load | required staff

medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2) #

'---------- CAF ----------'
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100 )

medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33*52) # dropped ias3?

medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
medicalspec_chc_2015_df <- medicalspec_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

medicalspec_chc_2015_df_sum <- medicalspec_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

od_chc_medicalspec_df <- medicalspec_chc_2015_df
od_chc_medicalspec_df_sum <- medicalspec_chc_2015_df_sum

od_chc_medicalspec_df
od_chc_medicalspec_df_sum

```

### MO @ Facility
. --------------------------------------------------
> MedicalOfficer | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_cy5_13 Normal Del       | 10 mins/pt  6/hr
  2     | Outpatients         | opc_cy5_9 antenatal         | 15 mins/pt  4/hr    - XXXXX
  3     | Outpatients         | opc_cy5_10 postnatal        | 15 mins/pt  4/hr    - XXXXX
  4     | Emergency           | ec_cy5_1 emergency          | 20 mins/pt  3/hr    ----- X
  5     | Outpatients         | opc_cy5_8 eye               | 15 mins/pt  4/hr    - XXXXX
  6     | Outpatients         | opc_cy5_4 child             | 10 mins/pt  6/hr
  7     | Inpatients          | ipc_cy5_2 admissions        | 10 mins/pt  6/hr
  8     | Outpatients         | opc_cy5_3 general           | 5 mins/pt  12/hr
  9     | Inpatients          | ipc_cy5_3 admission         | 10 mins/pt  6/hr 
  10    | Outpatients         | opc_cy5_7 diabetes          | 5 mins/pt  12/hr    - XXXXX
  11    | Outpatients         | opc_cy5_6 surgical          | 10 mins/pt  6/hr    - XXXXX
  12    | Outpatients         | opc_cy5_12 surgery visit    | 10 mins/pt  6/hr    - XXXXX
  13    | Inpatients          | ipc_cy5_4 surgery admission | 10 mins/pt  6/hr    - XXXXX
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month          ----- X?
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X?
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?
  4     | Immunization meet   | 1                           | 4 hr/month

```{r MedicalOfficer @ PHC | OD}
# getting_data
mo_phc_2015_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs_q1,
         ipc_cy5_13, ###opc_cy5_9, opc_cy5_10,
         #ec_cy5_1, ###opc_cy5_8,
         opc_cy5_4, ipc_cy5_2,
         opc_cy5_3, ipc_cy5_3, ###opc_cy5_7, opc_cy5_6, opc_cy5_12, ipc_cy5_4,
         fte_tot_fy5_2) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  filter(!is.na(ipc_cy5_13) ###& !is.na(opc_cy5_9) & !is.na(opc_cy5_10)
         #& !is.na(ec_cy5_1) ###& !is.na(opc_cy5_8)
         & !is.na(opc_cy5_4) & !is.na(ipc_cy5_2)
         & !is.na(opc_cy5_3) & !is.na(ipc_cy5_3) ###& !is.na(opc_cy5_7) & !is.na(opc_cy5_6) & !is.na(opc_cy5_12) & !is.na(ipc_cy5_4)
         ) %>%
  filter((ipc_cy5_13 >= 0 ) ###& (opc_cy5_9 >= 0 ) & (opc_cy5_10 >= 0 )
         #& (ec_cy5_1 >= 0 ) ###& (opc_cy5_8 >= 0 )
         & (opc_cy5_4 >= 0 ) & (ipc_cy5_2 >= 0 )
         & (opc_cy5_3 >= 0 ) & (ipc_cy5_3 >= 0 ) ###& (opc_cy5_7 >= 0 ) & (opc_cy5_6 >= 0 ) & (opc_cy5_12 >= 0 ) & (ipc_cy5_4 >= 0 )
    ) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  sw1 = 6 *awt,
  ###sw2 = 4 *awt,
  ###sw3 = 4 *awt,
  #sw4 = 3 *awt,
  ###sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 6 *awt,
  ###sw10 = 12 *awt,
  ###sw11 = 6 *awt,
  ###sw12 = 6 *awt,
  ###sw13 = 6 *awt
  ) # max_patient

mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  aw1 = ipc_cy5_13,
  ###aw2 = opc_cy5_9,
  ###aw3 = opc_cy5_10,
  #aw4 = ec_cy5_1,
  ###aw5 = opc_cy5_8,
  aw6 = opc_cy5_4,
  aw7 = ipc_cy5_2,
  aw8 = opc_cy5_3,
  aw9 = ipc_cy5_3,
  ###aw10 = opc_cy5_7,
  ###aw11 = opc_cy5_6,
  ###aw12 = opc_cy5_12,
  ###aw13 = ipc_cy5_4
  )# patient_load | required staff

mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  HSA = aw1/sw1
  ###+aw2/sw2
  ###+aw3/sw3
  #+aw4/sw4
  ###+aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  ###+aw10/sw10
  ###+aw11/sw11
  ###+aw12/sw12
  ###+aw13/sw13
  ) #

'---------- CAF ----------'
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs_q1 *12)  /awt *100)

mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  ias1 = 0,# other_df$vi11 * 4*12,
  ias2 = 0,# other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = 0,# other_df$vi31 * other_df$vi32*other_df$vi33*52,
  ias4 = 1 * 4*12) # dropped ias1?, ias2?, ias3?

mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  IAF = (ias4) /awt) #

'---------- WISN ----------'
mo_phc_2015_df <- mo_phc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_phc_2015_df_sum <- mo_phc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

od_phc_mo_df <- mo_phc_2015_df
od_phc_mo_df_sum <- mo_phc_2015_df_sum

od_phc_mo_df
od_phc_mo_df_sum

```

> MedicalOfficer | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_cy5_13 Normal Del       | 10 mins/pt  6/hr
  2     | Outpatients         | opc_cy5_9 antenatal         | 15 mins/pt  4/hr    - XXXXX
  3     | Inpatients          | ipc_cy5_4 surgery admission | 10 mins/pt  6/hr
  4     | Emergency           | ec_cy5_1 emergency          | 20 mins/pt  3/hr
  5     | Outpatients         | opc_cy5_8 eye               | 15 mins/pt  4/hr    - XXXXX
  6     | Outpatients         | opc_cy5_4 child             | 10 mins/pt  6/hr
  7     | Inpatients          | ipc_cy5_2 admissions        | 10 mins/pt  6/hr
  8     | Outpatients         | opc_cy5_3 general           | 5 mins/pt  12/hr
  9     | Inpatients          | ipc_cy5_3 admission         | 10 mins/pt  6/hr 
  10    | Outpatients         | opc_cy5_7 diabetes          | 5 mins/pt  12/hr    - XXXXX
  11    | Outpatients         | opc_cy5_6 surgical          | 10 mins/pt  6/hr    - XXXXX
  12    | Outpatients         | opc_cy5_12 surgery visit    | 10 mins/pt  6/hr    - XXXXX
  13    | Inpatients          | ipc_cy5_4 surgery admission | 10 mins/pt  6/hr    - XXXXX
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]
  3     | Edu services        | teams_admin_x_5 [max]       | [max]               ----- X?
  4     | Immunization meet   | 1                           | 4 hr/month

```{r MedicalOfficer @ CHC | OD}
# getting_data
mo_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs_q1,
         ipc_cy5_13, ###opc_cy5_9,
         ipc_cy5_4,
         ec_cy5_1, ###opc_cy5_8,
         opc_cy5_4, ipc_cy5_2,
         opc_cy5_3, ipc_cy5_3, ###opc_cy5_7, opc_cy5_6, opc_cy5_12, ipc_cy5_4,
         fte_tot_fy5_2) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_cy5_13) ###& !is.na(opc_cy5_9)
         & !is.na(ipc_cy5_4)
         & !is.na(ec_cy5_1) ###& !is.na(opc_cy5_8)
         & !is.na(opc_cy5_4) & !is.na(ipc_cy5_2)
         & !is.na(opc_cy5_3) & !is.na(ipc_cy5_3) ###& !is.na(opc_cy5_7) & !is.na(opc_cy5_6) & !is.na(opc_cy5_12) & !is.na(ipc_cy5_4)
         ) %>%
  filter((ipc_cy5_13 >= 0 ) ###& (opc_cy5_9 >= 0 )
         & (ipc_cy5_4 >= 0 )
         & (ec_cy5_1 >= 0 ) ###& (opc_cy5_8 >= 0 )
         & (opc_cy5_4 >= 0 ) & (ipc_cy5_2 >= 0 )
         & (opc_cy5_3 >= 0 ) & (ipc_cy5_3 >= 0 ) ###& (opc_cy5_7 >= 0 ) & (opc_cy5_6 >= 0 ) & (opc_cy5_12 >= 0 ) & (ipc_cy5_4 >= 0 )
    ) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  sw1 = 6 *awt,
  ###sw2 = 4 *awt,
  sw3 = 6 *awt,
  sw4 = 3 *awt,
  ###sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 6 *awt,
  ###sw10 = 12 *awt,
  ###sw11 = 6 *awt,
  ###sw12 = 6 *awt,
  ###sw13 = 6 *awt
  ) # max_patient

mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  aw1 = ipc_cy5_13,
  ###aw2 = opc_cy5_9,
  aw3 = ipc_cy5_4,
  aw4 = ec_cy5_1,
  ###aw5 = opc_cy5_8,
  aw6 = opc_cy5_4,
  aw7 = ipc_cy5_2,
  aw8 = opc_cy5_3,
  aw9 = ipc_cy5_3,
  ###aw10 = opc_cy5_7,
  ###aw11 = opc_cy5_6,
  ###aw12 = opc_cy5_12,
  ###aw13 = ipc_cy5_4
  )# patient_load | required staff

mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  HSA = aw1/sw1
  ###+aw2/sw2
  +aw3/sw3
  +aw4/sw4
  ###+aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  ###+aw10/sw10
  ###+aw11/sw11
  ###+aw12/sw12
  ###+aw13/sw13
  ) #

'---------- CAF ----------'
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs_q1 *12)  /awt *100)

mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33*52,
  ias4 = 1 * 4*12) # dropped ias3?

mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  IAF = (ias1 +ias2 +ias3 +ias4) /awt) #

'---------- WISN ----------'
mo_chc_2015_df <- mo_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_chc_2015_df_sum <- mo_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

od_chc_mo_df <- mo_chc_2015_df
od_chc_mo_df_sum <- mo_chc_2015_df_sum

od_chc_mo_df
od_chc_mo_df_sum

```

> MedicalOfficer | DH & SDH
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_cy5_13 Normal Del       | 10 mins/pt  6/hr
  2     | Outpatients         | opc_cy5_9 antenatal         | 15 mins/pt  4/hr    - XXXXX
  3     | Inpatients          | ipc_cy5_4 surgery admission | 10 mins/pt  6/hr
  4     | Emergency           | ec_cy5_1 emergency          | 20 mins/pt  3/hr
  5     | Outpatients         | opc_cy5_8 eye               | 15 mins/pt  4/hr    - XXXXX
  6     | Outpatients         | opc_cy5_4 child             | 10 mins/pt  6/hr
  7     | Inpatients          | ipc_cy5_2 admissions        | 10 mins/pt  6/hr
  8     | Outpatients         | opc_cy5_3 general           | 5 mins/pt  12/hr
  9     | Inpatients          | ipc_cy5_3 admission         | 10 mins/pt  6/hr 
  10    | Outpatients         | opc_cy5_7 diabetes          | 5 mins/pt  12/hr    - XXXXX
  11    | Outpatients         | opc_cy5_6 surgical          | 10 mins/pt  6/hr    - XXXXX
  12    | Outpatients         | opc_cy5_12 surgery visit    | 10 mins/pt  6/hr    - XXXXX
  13    | Inpatients          | ipc_cy5_4 surgery admission | 10 mins/pt  6/hr    - XXXXX
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X?
  3     | Edu services        | teams_admin_x_5 [max]       | [max]
  4     | Immunization meet   | 1                           | 4 hr/month

```{r MedicalOfficer @ DH & SDH | OD}
# getting_data
mo_dh_2015_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs_q1,
         ipc_cy5_13, ###opc_cy5_9,
         ipc_cy5_4,
         ec_cy5_1, ###opc_cy5_8,
         opc_cy5_4, ipc_cy5_2,
         opc_cy5_3, ipc_cy5_3, ###opc_cy5_7, opc_cy5_6, opc_cy5_12, ipc_cy5_4,
         fte_tot_fy5_2) %>%
  filter(platform_type == "District Hospital (DH)" | platform_type == "Subdistrict Hospital (SDH)" ) %>%
  filter(!is.na(ipc_cy5_13) ###& !is.na(opc_cy5_9)
         & !is.na(ipc_cy5_4)
         & !is.na(ec_cy5_1) ###& !is.na(opc_cy5_8)
         & !is.na(opc_cy5_4) & !is.na(ipc_cy5_2)
         & !is.na(opc_cy5_3) & !is.na(ipc_cy5_3) ###& !is.na(opc_cy5_7) & !is.na(opc_cy5_6) & !is.na(opc_cy5_12) & !is.na(ipc_cy5_4)
         ) %>%
  filter((ipc_cy5_13 >= 0 ) ###& (opc_cy5_9 >= 0 )
         & (ipc_cy5_4 >= 0 )
         & (ec_cy5_1 >= 0 ) ###& (opc_cy5_8 >= 0 )
         & (opc_cy5_4 >= 0 ) & (ipc_cy5_2 >= 0 )
         & (opc_cy5_3 >= 0 ) & (ipc_cy5_3 >= 0 ) ###& (opc_cy5_7 >= 0 ) & (opc_cy5_6 >= 0 ) & (opc_cy5_12 >= 0 ) & (ipc_cy5_4 >= 0 )
    ) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs2,teams_admin_dpw2,teams_admin_hpd2,
         teams_admin_docs3,teams_admin_dpw3,teams_admin_hpd3,
         teams_admin_docs5,teams_admin_dpw5,teams_admin_hpd5) %>%
  filter(platform_type == "District Hospital (DH)" | platform_type == "Subdistrict Hospital (SDH)" ) %>%
  summarise(vi11 = max(teams_admin_docs2, na.rm = TRUE), vi12 = max(teams_admin_dpw2, na.rm = TRUE), vi13 = max(teams_admin_hpd2, na.rm = TRUE),
            vi21 = max(teams_admin_docs3, na.rm = TRUE), vi22 = max(teams_admin_dpw3, na.rm = TRUE), vi23 = max(teams_admin_hpd3, na.rm = TRUE),
            vi31 = max(teams_admin_docs5, na.rm = TRUE), vi32 = max(teams_admin_dpw5, na.rm = TRUE), vi33 = max(teams_admin_hpd5, na.rm = TRUE))

leave = 102 # days
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q1) # hrs of a year

'---------- HSA ----------'
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  sw1 = 6 *awt,
  ###sw2 = 4 *awt,
  sw3 = 6 *awt,
  sw4 = 3 *awt,
  ###sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 6 *awt,
  ###sw10 = 12 *awt,
  ###sw11 = 6 *awt,
  ###sw12 = 6 *awt,
  ###sw13 = 6 *awt
  ) # max_patient

mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  aw1 = ipc_cy5_13,
  ###aw2 = opc_cy5_9,
  aw3 = ipc_cy5_4,
  aw4 = ec_cy5_1,
  ###aw5 = opc_cy5_8,
  aw6 = opc_cy5_4,
  aw7 = ipc_cy5_2,
  aw8 = opc_cy5_3,
  aw9 = ipc_cy5_3,
  ###aw10 = opc_cy5_7,
  ###aw11 = opc_cy5_6,
  ###aw12 = opc_cy5_12,
  ###aw13 = ipc_cy5_4
  )# patient_load | required staff

mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  HSA = aw1/sw1
  ###+aw2/sw2
  +aw3/sw3
  +aw4/sw4
  ###+aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  ###+aw10/sw10
  ###+aw11/sw11
  ###+aw12/sw12
  ###+aw13/sw13
  ) #

'---------- CAF ----------'
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs_q1 *12)  /awt *100)

mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23*52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33*52,
  ias4 = 1 * 4*12) # dropped ias2?

mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  IAF = (ias1 +ias2 +ias3 +ias4) /awt) #

'---------- WISN ----------'
mo_dh_2015_df <- mo_dh_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_dh_2015_df_sum <- mo_dh_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

od_dh_mo_df <- mo_dh_2015_df
od_dh_mo_df_sum <- mo_dh_2015_df_sum

od_dh_mo_df
od_dh_mo_df_sum

```

### Nurses @ Facility
. --------------------------------------------------
> Nurses | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q2
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_cy5_13 Normal Del       | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_cy5_14 C-section        | 40 mins/pt  1.5/hr
  3     | Investigation       | ipc_cy5_21 deaths           | 2.5 hr/pt   0.4/hr
  .
  4     | Inpatients          | ipc_cy5_4 admissions        | 15 mins/pt  4/hr    ----- X?
  5     | Inpatients          | ipc_cy5_10 major            | 2 hr/pt     0.5/hr  ----- X?
  6     | Inpatients          | ipc_cy5_11 minor            | 15 mins/pt  4/hr    ----- X?
  .
  7     | Outpatients         | opc_cy5_4 child             | 15 mins/pt  4/hr
  8     | Inpatients          | ipc_cy5_2 admission         | 15 mins/pt  4/hr
  9     | Investigation       | ipc_cy5_15 stillbirths      | 25 mins/pt  2.4/hr
  .
  10    | Immunisations       | opcv_fy5_1 child            | 7 mins/pt  ~8.5/hr  ----- X?
  11    | Immunisations       | opcv_fy5_16 women           | 7 mins/pt  ~8.5/hr  ----- X?
  .
  12    | Outpatients         | opc_cy5_3 visits            | 10 mins/pt  6/hr
  13    | Inpatients          | ipc_cy5_3 admissions        | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit                                        ----- X!?
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]
  2     | Record keeping      | teams_admin_x_4 [max]       | [max]

```{r Nurses @ CHC | OD}
# getting_data
nurses_chc_2015_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs_q2,
         ipc_cy5_13, ipc_cy5_14, ipc_cy5_21,
         #ipc_cy5_4, ipc_cy5_10, ipc_cy5_11,
         opc_cy5_4, ipc_cy5_2, ipc_cy5_15,
         #opcv_fy5_1, opcv_fy5_16,
         opc_cy5_3, ipc_cy5_3,
         ohv_cy5_1) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_cy5_13) & !is.na(ipc_cy5_14) & !is.na(ipc_cy5_21) & 
           #!is.na(ipc_cy5_4) & !is.na(ipc_cy5_10) & !is.na(ipc_cy5_11) &
           !is.na(opc_cy5_4) & !is.na(ipc_cy5_2) & !is.na(ipc_cy5_15) & 
           #!is.na(opcv_fy5_1) & !is.na(opcv_fy5_16) &
           !is.na(opc_cy5_3) & !is.na(ipc_cy5_3)
           ) %>%
  filter((ipc_cy5_13 >= 0 ) & (ipc_cy5_14 >= 0 ) & (ipc_cy5_21 >= 0 )
         #& (ipc_cy5_4 >= 0 ) & (ipc_cy5_10 >= 0 ) & (ipc_cy5_11 >= 0 )
         & (opc_cy5_4 >= 0 ) & (ipc_cy5_2 >= 0 ) & (ipc_cy5_15 >= 0 )
         #& (opcv_fy5_1 >= 0 ) & (opcv_fy5_16 >= 0 )
         & (opc_cy5_3 >= 0 ) & (ipc_cy5_3 >= 0 )
         #& (ohv_cy5_1 >= 0 )
         & (fte_hrs_q2 > 0 )
    ) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q2 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs1,teams_admin_dpw1,teams_admin_hpd1,
         teams_admin_docs4,teams_admin_dpw4,teams_admin_hpd4
         ) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  summarise(vi11 = max(teams_admin_docs1, na.rm = TRUE), vi12 = max(teams_admin_dpw1, na.rm = TRUE), vi13 = max(teams_admin_hpd1, na.rm = TRUE),
            vi21 = max(teams_admin_docs4, na.rm = TRUE), vi22 = max(teams_admin_dpw4, na.rm = TRUE), vi23 = max(teams_admin_hpd4, na.rm = TRUE))

leave = 102 # days
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q2) # hrs of a year

'---------- HSA ----------'
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  sw1 = 1 *awt,
  sw2 = 1.5 *awt,
  sw3 = 0.4 *awt,
  #sw4 = 4 *awt,
  #sw5 = 0.5 *awt,
  #sw6 = 4 *awt,
  sw7 = 4 *awt,
  sw8 = 4 *awt,
  sw9 = 2.4 *awt,
  #sw10 = 60/7 *awt,
  #sw11 = 60/7 *awt,
  sw12 = 6 *awt,
  sw13 = 4 *awt
  ) # max_patient

nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  aw1 = ipc_cy5_13,
  aw2 = ipc_cy5_14,
  aw3 = ipc_cy5_21,
  #aw4 = ipc_cy5_4,
  #aw5 = ipc_cy5_10,
  #aw6 = ipc_cy5_11,
  aw7 = opc_cy5_4,
  aw8 = ipc_cy5_2,
  aw9 = ipc_cy5_15,
  #aw10 = opcv_fy5_1,
  #aw11 = opcv_fy5_16,
  aw12 = opc_cy5_3,
  aw13 = ipc_cy5_3
  )# patient_load | required staff

nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  #+aw4/sw4
  #+aw5/sw5
  #+aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  #+aw10/sw10
  #+aw11/sw11
  +aw12/sw12
  +aw13/sw13
  ) #

'---------- CAF ----------'
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  cas1 = (6/7 *fte_hrs_q2) /awt *100,
  cas2 = (0 *2 *ohv_cy5_1)  /awt *100) # ignored? standard cas2?

nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  ias1 = other_df$vi11 * other_df$vi12*other_df$vi13 *52,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52) #

nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
nurses_chc_2015_df <- nurses_chc_2015_df %>% mutate(
  WISN = HSA*CAF +IAF) #

nurses_chc_2015_df_sum <- nurses_chc_2015_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

od_chc_nurses_df <- nurses_chc_2015_df
od_chc_nurses_df_sum <- nurses_chc_2015_df_sum

od_chc_nurses_df
od_chc_nurses_df_sum

```

> Nurses | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs_q2
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_cy5_13 Normal Del       | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_cy5_14 C-section        | 40 mins/pt  1.5/hr  - XXXXX
  3     | Investigation       | ipc_cy5_21 deaths           | 2.5 hr/pt   0.4/hr
  .
  4     | Inpatients          | ipc_cy5_4 admissions        | 15 mins/pt  4/hr    - XXXXX
  5     | Inpatients          | ipc_cy5_10 major            | 2 hr/pt     0.5/hr  - XXXXX
  6     | Inpatients          | ipc_cy5_11 minor            | 15 mins/pt  4/hr    - XXXXX
  .
  7     | Outpatients         | opc_cy5_4 child             | 15 mins/pt  4/hr    ----- X
  8     | Inpatients          | ipc_cy5_2 admission         | 15 mins/pt  4/hr    ----- X
  9     | Investigation       | ipc_cy5_15 stillbirths      | 25 mins/pt  2.4/hr  ----- X
  .
  10    | Immunisations       | opcv_fy5_1 child            | 7 mins/pt  ~8.5/hr
  11    | Immunisations       | opcv_fy5_16 women           | 7 mins/pt  ~8.5/hr
  .
  12    | Outpatients         | opc_cy5_3 visits            | 10 mins/pt  6/hr
  13    | Inpatients          | ipc_cy5_3 admissions        | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit                                        ----- X?
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]
  2     | Record keeping      | teams_admin_x_4 [max]       | [max]               ----- X?

```{r Nurses @ PHC | OD}
# getting_data
nurses_phc_2015_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs_q2,
         ipc_cy5_13, ipc_cy5_21,###ipc_cy5_14
         ###ipc_cy5_4, ipc_cy5_10, ipc_cy5_11,
         #opc_cy5_4, ipc_cy5_2, ipc_cy5_15,
         opcv_fy5_1, opcv_fy5_16,
         opc_cy5_3, ipc_cy5_3,
         ohv_cy5_1) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  filter(!is.na(ipc_cy5_13) & !is.na(ipc_cy5_21) & ### !is.na(ipc_cy5_14) &
           ###!is.na(ipc_cy5_4) & !is.na(ipc_cy5_10) & !is.na(ipc_cy5_11) &
           #!is.na(opc_cy5_4) & !is.na(ipc_cy5_2) & !is.na(ipc_cy5_15) & 
           !is.na(opcv_fy5_1) & !is.na(opcv_fy5_16) &
           !is.na(opc_cy5_3) & !is.na(ipc_cy5_3)
           ) %>%
  filter((ipc_cy5_13 >= 0 ) & (ipc_cy5_21 >= 0 )### & (ipc_cy5_14 >= 0 )
         ###& (ipc_cy5_4 >= 0 ) & (ipc_cy5_10 >= 0 ) & (ipc_cy5_11 >= 0 )
         #& (opc_cy5_4 >= 0 ) & (ipc_cy5_2 >= 0 ) & (ipc_cy5_15 >= 0 )
         & (opcv_fy5_1 >= 0 ) & (opcv_fy5_16 >= 0 )
         & (opc_cy5_3 >= 0 ) & (ipc_cy5_3 >= 0 )
         & (ohv_cy5_1 >= 0 )
    ) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs_q2 >= 24)

other_df <- data_df %>%
  select(customid, platform_type,
         teams_admin_docs1,teams_admin_dpw1,teams_admin_hpd1,
         teams_admin_docs4,teams_admin_dpw4,teams_admin_hpd4
         ) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  summarise(vi11 = max(teams_admin_docs1, na.rm = TRUE), vi12 = max(teams_admin_dpw1, na.rm = TRUE), vi13 = max(teams_admin_hpd1, na.rm = TRUE),
            vi21 = max(teams_admin_docs4, na.rm = TRUE), vi22 = max(teams_admin_dpw4, na.rm = TRUE), vi23 = max(teams_admin_hpd4, na.rm = TRUE))

leave = 102 # days
nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(awt = (365 - leave) /7 * fte_hrs_q2) # hrs of a year

'---------- HSA ----------'
# nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
#   sw1 = 1 *awt,
#   ###sw2 = 1.5 *awt,
#   sw3 = 0.4 *awt,
#   ###sw4 = 4 *awt,
#   ###sw5 = 0.5 *awt,
#   ###sw6 = 4 *awt,
#   #sw7 = 4 *awt,
#   #sw8 = 4 *awt,
#   #sw9 = 2.4 *awt,
#   sw10 = 60/7 *awt,
#   sw11 = 60/7 *awt,
#   sw12 = 6 *awt,
#   sw13 = 4 *awt
#   ) # max_patient
# 
# nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
#   aw1 = ipc_cy5_13,
#   ###aw2 = ipc_cy5_14,
#   aw3 = ipc_cy5_21,
#   ###aw4 = ipc_cy5_4,
#   ###aw5 = ipc_cy5_10,
#   ###aw6 = ipc_cy5_11,
#   #aw7 = opc_cy5_4,
#   #aw8 = ipc_cy5_2,
#   #aw9 = ipc_cy5_15,
#   aw10 = opcv_fy5_1,
#   aw11 = opcv_fy5_16,
#   aw12 = opc_cy5_3,
#   aw13 = ipc_cy5_3
#   )# patient_load | required staff
# 
# nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
#   HSA = aw1/sw1
#   ###+aw2/sw2
#   +aw3/sw3
#   ###+aw4/sw4
#   ###+aw5/sw5
#   ###+aw6/sw6
#   #+aw7/sw7
#   #+aw8/sw8
#   #+aw9/sw9
#   +aw10/sw10
#   +aw11/sw11
#   +aw12/sw12
#   +aw13/sw13
#   ) #

'---------- CAF ----------'
# nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
#   cas1 = (6/7 *fte_hrs_q2) /awt *100,
#   cas2 = (0 *2 *ohv_cy5_1)  /awt *100) # ignored? standard cas2?
# 
# nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
#   CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
# nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
#   ias1 = other_df$vi11 * other_df$vi12*other_df$vi13 *52,
#   ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52) #
# 
# nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
#   IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
# nurses_phc_2015_df <- nurses_phc_2015_df %>% mutate(
#   WISN = HSA*CAF +IAF) #
# 
# nurses_phc_2015_df_sum <- nurses_phc_2015_df %>% summarise(
#   n_centre = n(),
#   WISN_mean = mean(WISN),
#   WISN_median = median(WISN),
#   WISN_std = sd(WISN) ) #
# 
# nurses_phc_2015_df
# nurses_phc_2015_df_sum

od_phc_nurses_df <- mp_phc_mo_df # ----- !!! empty | No Centres found

```

## State | AP&TG ----------
. ==================================================
General info
Data release information sheet | -
Codebook, with descriptions of all variables | IHME_ABCE_IND_AP_TG_2013_FACILITY_CODEBOOK_Y2018M03D27.CSV
Public use survey dataset – CSV format | IHME_ABCE_IND_AP_TG_2013_FACILITY_DATA_Y2018M03D27.CSV

```{r get Data | AP}
data_df <- read_csv("../data/ABCE/IHME_ABCE_IND_AP_TG_2013_FACILITY_DATA_Y2018M03D27.CSV")

data_df

```

### Specialists @ CHC
. --------------------------------------------------
> OBGYN | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy_sum_13 Norm Del    | 10 mins/pt  6/hr
  2     | Cesarian-OT         | ipc_fy_sum_14 C-section   | 30 mins/pt  2/hr 
  3     | Outpatients         | opc_fy_sum_10 Antenatal   | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy_sum_11 Postnatal   | 15 mins/pt  4/hr
  5     | Family planning     | opc_fy_sum_5 Welfare      | 5 mins/pt  12/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]              ----- X?
  3     | Edu services        | teams_admin_x_7 [max]       | [max]              ----- X?

```{r OBGYN @ CHC | AP}
# getting_data
obgyn_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         ipc_fy_sum_13, ipc_fy_sum_14, opc_fy_sum_10, opc_fy_sum_11, opc_fy_sum_5,
         pers_fte_fy_23) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy_sum_13) & !is.na(ipc_fy_sum_14) & !is.na(opc_fy_sum_10) & !is.na(opc_fy_sum_11) & !is.na(opc_fy_sum_5)) %>%
  filter((ipc_fy_sum_13 >= 0 ) & (ipc_fy_sum_14 >= 0 ) & (opc_fy_sum_10 >= 0 ) & (opc_fy_sum_11 >= 0 ) & (opc_fy_sum_5 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_7,teams_admin_dpw_7,teams_admin_hpd_7) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_7, na.rm = TRUE), vi32 = max(teams_admin_dpw_7, na.rm = TRUE), vi33 = max(teams_admin_hpd_7, na.rm = TRUE))

leave = 102 # days
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 2 *awt,
  sw3 = 4 *awt,
  sw4 = 4 *awt,
  sw5 = 12 *awt) # max_patient

obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  aw1 = ipc_fy_sum_13,
  aw2 = ipc_fy_sum_14,
  aw3 = opc_fy_sum_10,
  aw4 = opc_fy_sum_11,
  aw5 = opc_fy_sum_5)# patient_load | required staff

obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4 +aw5/sw5) #

'---------- CAF ----------'
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52) # dropped

obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
obgyn_chc_2011_df <- obgyn_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

obgyn_chc_2011_df_sum <- obgyn_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_chc_obgyn_df <- obgyn_chc_2011_df
ap_chc_obgyn_df_sum <- obgyn_chc_2011_df_sum

ap_chc_obgyn_df
ap_chc_obgyn_df_sum

```

> SurgerySpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_sum_13 visits        | 10 mins/pt  6/hr
  2     | Inpatients          | ipc_fy_sum_4 admissions     | 10 mins/pt  6/hr 
  3     | Operate Major       | ipc_fy_sum_10 #major        | 2  hr/pt  0.5/hr
  4     | Operate minor       | ipc_fy_sum_11 #minor        | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]              ----- X?
  3     | Edu services        | teams_admin_x_7 [max]       | [max]              ----- X?

```{r SurgerySpec @ CHC | AP}
# getting_data
surgeryspec_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         opc_fy_sum_13, ipc_fy_sum_4, ipc_fy_sum_10, ipc_fy_sum_11,
         pers_fte_fy_21) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_sum_13) & !is.na(ipc_fy_sum_4) & !is.na(ipc_fy_sum_10) & !is.na(ipc_fy_sum_11)) %>%
  filter((opc_fy_sum_13 >= 0 ) & (ipc_fy_sum_4 >= 0 ) & (ipc_fy_sum_10 >= 0 ) & (ipc_fy_sum_11 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_7,teams_admin_dpw_7,teams_admin_hpd_7) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_7, na.rm = TRUE), vi32 = max(teams_admin_dpw_7, na.rm = TRUE), vi33 = max(teams_admin_hpd_7, na.rm = TRUE))

leave = 102 # days
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt,
  sw3 = 0.5 *awt,
  sw4 = 4 *awt) # max_patient

surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  aw1 = opc_fy_sum_13,
  aw2 = ipc_fy_sum_4,
  aw3 = ipc_fy_sum_10,
  aw4 = ipc_fy_sum_11)# patient_load | required staff

surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52) # dropped

surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
surgeryspec_chc_2011_df <- surgeryspec_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

surgeryspec_chc_2011_df_sum <- surgeryspec_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_chc_surgeryspec_df <- surgeryspec_chc_2011_df
ap_chc_surgeryspec_df_sum <- surgeryspec_chc_2011_df_sum

ap_chc_surgeryspec_df
ap_chc_surgeryspec_df_sum

```

> EyeSpec [Ophthalmologist] | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_sum_9 visits         | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X?
  3     | Edu services        | teams_admin_x_7 [max]       | [max]               ----- X?

```{r EyeSpec @ CHC | AP}
# getting_data
eyespec_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         opc_fy_sum_9,
         pers_fte_fy_29) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_sum_9)) %>%
  filter((opc_fy_sum_9 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_7,teams_admin_dpw_7,teams_admin_hpd_7) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_7, na.rm = TRUE), vi32 = max(teams_admin_dpw_7, na.rm = TRUE), vi33 = max(teams_admin_hpd_7, na.rm = TRUE))

leave = 102 # days
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  sw1 = 4 *awt) # max_patient

eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  aw1 = opc_fy_sum_9)# patient_load | required staff

eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  HSA = aw1/sw1) #

'---------- CAF ----------'
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52) # dropped

eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
eyespec_chc_2011_df <- eyespec_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

eyespec_chc_2011_df_sum <- eyespec_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_chc_eyespec_df <- eyespec_chc_2011_df
ap_chc_eyespec_df_sum <- eyespec_chc_2011_df_sum

ap_chc_eyespec_df
ap_chc_eyespec_df_sum

```

> ChildSpec [Paedistrician] | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_sum_4 visits         | 10 mins/pt  6/hr
  2     | Inpatients          | ipc_fy_sum_2 admissions     | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X?
  3     | Edu services        | teams_admin_x_7 [max]       | [max]               ----- X?

```{r ChildSpec @ CHC | AP}
# getting_data
childspec_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         opc_fy_sum_4, ipc_fy_sum_2,
         pers_fte_fy_26) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_sum_4) & !is.na(ipc_fy_sum_2)) %>%
  filter((opc_fy_sum_4 >= 0 ) & (ipc_fy_sum_2 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_7,teams_admin_dpw_7,teams_admin_hpd_7) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_7, na.rm = TRUE), vi32 = max(teams_admin_dpw_7, na.rm = TRUE), vi33 = max(teams_admin_hpd_7, na.rm = TRUE))

leave = 102 # days
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 6 *awt) # max_patient

childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  aw1 = opc_fy_sum_4,
  aw2 = ipc_fy_sum_2)# patient_load | required staff

childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2) #

'---------- CAF ----------'
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52) # dropped

childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
childspec_chc_2011_df <- childspec_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

childspec_chc_2011_df_sum <- childspec_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_chc_childspec_df <- childspec_chc_2011_df
ap_chc_childspec_df_sum <- childspec_chc_2011_df_sum

ap_chc_childspec_df
ap_chc_childspec_df_sum

```

> MedicalSpec | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Outpatients         | opc_fy_sum_6 general        | 5 mins/pt  12/hr
  2     | Inpatients          | ipc_fy_sum_3 admissions     | 10 mins/pt  6/hr 
  3     | Outpatients         | opc_fy_sum_8 diabetes       | 5 mins/pt  12/hr
  4     | Oupatients          | opc_fy_sum_7 surgical       | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X?
  3     | Edu services        | teams_admin_x_7 [max]       | [max]               ----- X?

```{r MedicalSpec @ CHC | AP}
# getting_data
medicalspec_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         opc_fy_sum_6, ipc_fy_sum_3, opc_fy_sum_8, opc_fy_sum_7,
         pers_fte_fy_22) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(opc_fy_sum_6) & !is.na(ipc_fy_sum_3) & !is.na(opc_fy_sum_8) & !is.na(opc_fy_sum_7)) %>%
  filter((opc_fy_sum_6 >= 0 ) & (ipc_fy_sum_3 >= 0 ) & (opc_fy_sum_8 >= 0 ) & (opc_fy_sum_7 >= 0 )) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_7,teams_admin_dpw_7,teams_admin_hpd_7) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_7, na.rm = TRUE), vi32 = max(teams_admin_dpw_7, na.rm = TRUE), vi33 = max(teams_admin_hpd_7, na.rm = TRUE))

leave = 102 # days
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  sw1 = 12 *awt,
  sw2 = 6 *awt,
  sw3 = 12 *awt,
  sw4 = 6 *awt) # max_patient

medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  aw1 = opc_fy_sum_6,
  aw2 = ipc_fy_sum_3,
  aw3 = opc_fy_sum_8,
  aw4 = opc_fy_sum_7)# patient_load | required staff

medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  HSA = aw1/sw1 +aw2/sw2 +aw3/sw3 +aw4/sw4) #

'---------- CAF ----------'
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100 )

medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52) # dropped

medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
medicalspec_chc_2011_df <- medicalspec_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

medicalspec_chc_2011_df_sum <- medicalspec_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_chc_medicalspec_df <- medicalspec_chc_2011_df
ap_chc_medicalspec_df_sum <-  medicalspec_chc_2011_df_sum

ap_chc_medicalspec_df
ap_chc_medicalspec_df_sum

```

### MO @ Facility
. --------------------------------------------------
> MedicalOfficer | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy_sum_13 Normal Del    | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy_sum_11 antenatal     | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy_sum_10 postnatal     | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy_sum_5 family welfare | 5 mins/pt  12/hr
  5     | Outpatients         | opc_fy_sum_13 surgery visit | 10 mins/pt  6/hr
  6     | Inpatients          | ipc_fy_sum_4 admissions     | 10 mins/pt  6/hr 
  7     | Outpatients         | opc_fy_sum_9 visits         | 15 mins/pt  4/hr
  8     | Outpatients         | opc_fy_sum_4 child          | 10 mins/pt  6/hr
  9     | Inpatients          | ipc_fy_sum_2 admissions     | 10 mins/pt  6/hr 
  10    | Outpatients         | opc_fy_sum_6 visits         | 5 mins/pt  12/hr
  11    | Inpatients          | ipc_fy_sum_3 admissions     | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy_sum_8 diabetes       | 5 mins/pt  12/hr
  13    | Outpatients         | opc_fy_sum_7 op visits      | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month          ----- X
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X?
  3     | Edu services        | teams_admin_x_7 [max]       | [max]               ----- X?

```{r MedicalOfficer @ PHC | AP}
# getting_data
mo_phc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         ipc_fy_sum_13, opc_fy_sum_11, opc_fy_sum_10, opc_fy_sum_5,
         opc_fy_sum_13, ipc_fy_sum_4,
         opc_fy_sum_9,
         opc_fy_sum_4, ipc_fy_sum_2,
         opc_fy_sum_6, ipc_fy_sum_3, opc_fy_sum_8, opc_fy_sum_7,
         pers_fte_fy_15) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  filter(!is.na(ipc_fy_sum_13) & !is.na(opc_fy_sum_11) & !is.na(opc_fy_sum_10) & !is.na(opc_fy_sum_5)
         & !is.na(opc_fy_sum_13) & !is.na(ipc_fy_sum_4)
         & !is.na(opc_fy_sum_9)
         & !is.na(opc_fy_sum_4) & !is.na(ipc_fy_sum_2)
         & !is.na(opc_fy_sum_6) & !is.na(ipc_fy_sum_3) & !is.na(opc_fy_sum_8) & !is.na(opc_fy_sum_7)
         ) %>%
  filter((ipc_fy_sum_13 >= 0 ) & (opc_fy_sum_11 >= 0 ) & (opc_fy_sum_10 >= 0 ) & (opc_fy_sum_5 >= 0 )
         & (opc_fy_sum_13 >= 0 ) & (ipc_fy_sum_4 >= 0 )
         & (opc_fy_sum_9 >= 0 )
         & (opc_fy_sum_4 >= 0 ) & (ipc_fy_sum_2 >= 0 )
         & (opc_fy_sum_6 >= 0 ) & (ipc_fy_sum_3 >= 0 ) & (opc_fy_sum_8 >= 0 ) & (opc_fy_sum_7 >= 0 )
    ) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_7,teams_admin_dpw_7,teams_admin_hpd_7) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_7, na.rm = TRUE), vi32 = max(teams_admin_dpw_7, na.rm = TRUE), vi33 = max(teams_admin_hpd_7, na.rm = TRUE))

leave = 102 # days
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  sw4 = 3 *awt,
  sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 6 *awt,
  sw10 = 12 *awt,
  sw11 = 6 *awt,
  sw12 = 6 *awt,
  sw13 = 6 *awt
  ) # max_patient

mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  aw1 = ipc_fy_sum_13,
  aw2 = opc_fy_sum_11,
  aw3 = opc_fy_sum_10,
  aw4 = opc_fy_sum_5,
  aw5 = opc_fy_sum_13,
  aw6 = ipc_fy_sum_4,
  aw7 = opc_fy_sum_9,
  aw8 = opc_fy_sum_4,
  aw9 = ipc_fy_sum_2,
  aw10 = opc_fy_sum_6,
  aw11 = ipc_fy_sum_3,
  aw12 = opc_fy_sum_8,
  aw13 = opc_fy_sum_7
  )# patient_load | required staff

mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  ) #

'---------- CAF ----------'
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs1 *12)  /awt *100)

mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52) # dropped

mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
mo_phc_2011_df <- mo_phc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_phc_2011_df_sum <- mo_phc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_phc_mo_df <- mo_phc_2011_df
ap_phc_mo_df_sum <- mo_phc_2011_df_sum

ap_phc_mo_df
ap_phc_mo_df_sum

```

> MedicalOfficer | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy_sum_13 Normal Del    | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy_sum_11 antenatal     | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy_sum_10 postnatal     | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy_sum_5 family welfare | 5 mins/pt  12/hr
  5     | Outpatients         | opc_fy_sum_13 surgery visit | 10 mins/pt  6/hr
  6     | Inpatients          | ipc_fy_sum_4 admissions     | 10 mins/pt  6/hr 
  7     | Outpatients         | opc_fy_sum_9 visits         | 15 mins/pt  4/hr
  8     | Outpatients         | opc_fy_sum_4 child          | 10 mins/pt  6/hr
  9     | Inpatients          | ipc_fy_sum_2 admissions     | 10 mins/pt  6/hr 
  10    | Outpatients         | opc_fy_sum_6 visits         | 5 mins/pt  12/hr
  11    | Inpatients          | ipc_fy_sum_3 admissions     | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy_sum_8 diabetes       | 5 mins/pt  12/hr
  13    | Outpatients         | opc_fy_sum_7 op visits      | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month          ----- X
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X?
  3     | Edu services        | teams_admin_x_7 [max]       | [max]               ----- X?

```{r MedicalOfficer @ CHC | AP}
# getting_data
mo_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         ipc_fy_sum_13, opc_fy_sum_11, opc_fy_sum_10, opc_fy_sum_5,
         opc_fy_sum_13, ipc_fy_sum_4,
         opc_fy_sum_9,
         opc_fy_sum_4, ipc_fy_sum_2,
         opc_fy_sum_6, ipc_fy_sum_3, opc_fy_sum_8, opc_fy_sum_7,
         pers_fte_fy_15) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  filter(!is.na(ipc_fy_sum_13) & !is.na(opc_fy_sum_11) & !is.na(opc_fy_sum_10) & !is.na(opc_fy_sum_5)
         & !is.na(opc_fy_sum_13) & !is.na(ipc_fy_sum_4)
         & !is.na(opc_fy_sum_9)
         & !is.na(opc_fy_sum_4) & !is.na(ipc_fy_sum_2)
         & !is.na(opc_fy_sum_6) & !is.na(ipc_fy_sum_3) & !is.na(opc_fy_sum_8) & !is.na(opc_fy_sum_7)
         ) %>%
  filter((ipc_fy_sum_13 >= 0 ) & (opc_fy_sum_11 >= 0 ) & (opc_fy_sum_10 >= 0 ) & (opc_fy_sum_5 >= 0 )
         & (opc_fy_sum_13 >= 0 ) & (ipc_fy_sum_4 >= 0 )
         & (opc_fy_sum_9 >= 0 )
         & (opc_fy_sum_4 >= 0 ) & (ipc_fy_sum_2 >= 0 )
         & (opc_fy_sum_6 >= 0 ) & (ipc_fy_sum_3 >= 0 ) & (opc_fy_sum_8 >= 0 ) & (opc_fy_sum_7 >= 0 )
    ) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_7,teams_admin_dpw_7,teams_admin_hpd_7) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_7, na.rm = TRUE), vi32 = max(teams_admin_dpw_7, na.rm = TRUE), vi33 = max(teams_admin_hpd_7, na.rm = TRUE))

leave = 102 # days
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  sw4 = 3 *awt,
  sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 6 *awt,
  sw10 = 12 *awt,
  sw11 = 6 *awt,
  sw12 = 6 *awt,
  sw13 = 6 *awt
  ) # max_patient

mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  aw1 = ipc_fy_sum_13,
  aw2 = opc_fy_sum_11,
  aw3 = opc_fy_sum_10,
  aw4 = opc_fy_sum_5,
  aw5 = opc_fy_sum_13,
  aw6 = ipc_fy_sum_4,
  aw7 = opc_fy_sum_9,
  aw8 = opc_fy_sum_4,
  aw9 = ipc_fy_sum_2,
  aw10 = opc_fy_sum_6,
  aw11 = ipc_fy_sum_3,
  aw12 = opc_fy_sum_8,
  aw13 = opc_fy_sum_7
  )# patient_load | required staff

mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  ) #

'---------- CAF ----------'
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs1 *12)  /awt *100)

mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52) # dropped

mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
mo_chc_2011_df <- mo_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_chc_2011_df_sum <- mo_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_chc_mo_df <- mo_chc_2011_df
ap_chc_mo_df_sum <- mo_chc_2011_df_sum

ap_chc_mo_df
ap_chc_mo_df_sum

```

> MedicalOfficer | DH & SDH
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs1
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Vaginal delivery    | ipc_fy_sum_13 Normal Del    | 10 mins/pt  6/hr
  2     | Outpatients         | opc_fy_sum_11 antenatal     | 15 mins/pt  4/hr 
  3     | Outpatients         | opc_fy_sum_10 postnatal     | 15 mins/pt  4/hr
  4     | Outpatients         | opc_fy_sum_5 family welfare | 5 mins/pt  12/hr
  5     | Outpatients         | opc_fy_sum_13 surgery visit | 10 mins/pt  6/hr
  6     | Inpatients          | ipc_fy_sum_4 admissions     | 10 mins/pt  6/hr 
  7     | Outpatients         | opc_fy_sum_9 visits         | 15 mins/pt  4/hr
  8     | Outpatients         | opc_fy_sum_4 child          | 10 mins/pt  6/hr
  9     | Inpatients          | ipc_fy_sum_2 admissions     | 10 mins/pt  6/hr 
  10    | Outpatients         | opc_fy_sum_6 visits         | 5 mins/pt  12/hr
  11    | Inpatients          | ipc_fy_sum_3 admissions     | 10 mins/pt  6/hr
  12    | Outpatients         | opc_fy_sum_8 diabetes       | 5 mins/pt  12/hr
  13    | Outpatients         | opc_fy_sum_7 op visits      | 10 mins/pt  6/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Admin meetings      | 4 hr/month (1 hr/week)
  2     | Outreach services   | 4 days/month
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Patient review      | teams_admin_x_2 [max]       | 4 hr/month          ----- X
  2     | Ethic meet          | teams_admin_x_3 [max]       | [max]               ----- X?
  3     | Edu services        | teams_admin_x_7 [max]       | [max]               ----- X?

```{r MedicalOfficer @ DH | AP}
# getting_data
mo_dh_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs1,
         ipc_fy_sum_13, opc_fy_sum_11, opc_fy_sum_10, opc_fy_sum_5,
         opc_fy_sum_13, ipc_fy_sum_4,
         opc_fy_sum_9,
         opc_fy_sum_4, ipc_fy_sum_2,
         opc_fy_sum_6, ipc_fy_sum_3, opc_fy_sum_8, opc_fy_sum_7,
         pers_fte_fy_15) %>%
  filter(platform_type == "District Hospital (DH)") %>%
  filter(!is.na(ipc_fy_sum_13) & !is.na(opc_fy_sum_11) & !is.na(opc_fy_sum_10) & !is.na(opc_fy_sum_5)
         & !is.na(opc_fy_sum_13) & !is.na(ipc_fy_sum_4)
         & !is.na(opc_fy_sum_9)
         & !is.na(opc_fy_sum_4) & !is.na(ipc_fy_sum_2)
         & !is.na(opc_fy_sum_6) & !is.na(ipc_fy_sum_3) & !is.na(opc_fy_sum_8) & !is.na(opc_fy_sum_7)
         ) %>%
  filter((ipc_fy_sum_13 >= 0 ) & (opc_fy_sum_11 >= 0 ) & (opc_fy_sum_10 >= 0 ) & (opc_fy_sum_5 >= 0 )
         & (opc_fy_sum_13 >= 0 ) & (ipc_fy_sum_4 >= 0 )
         & (opc_fy_sum_9 >= 0 )
         & (opc_fy_sum_4 >= 0 ) & (ipc_fy_sum_2 >= 0 )
         & (opc_fy_sum_6 >= 0 ) & (ipc_fy_sum_3 >= 0 ) & (opc_fy_sum_8 >= 0 ) & (opc_fy_sum_7 >= 0 )
    ) %>%
  #filter(year == 2011) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs1 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_2,teams_admin_dpw_2,teams_admin_hpd_2,
         teams_admin_pers_3,teams_admin_dpw_3,teams_admin_hpd_3,
         teams_admin_pers_7,teams_admin_dpw_7,teams_admin_hpd_7) %>%
  filter(platform_type == "District Hospital (DH)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_2, na.rm = TRUE), vi12 = max(teams_admin_dpw_2, na.rm = TRUE), vi13 = max(teams_admin_hpd_2, na.rm = TRUE),
            vi21 = max(teams_admin_pers_3, na.rm = TRUE), vi22 = max(teams_admin_dpw_3, na.rm = TRUE), vi23 = max(teams_admin_hpd_3, na.rm = TRUE),
            vi31 = max(teams_admin_pers_7, na.rm = TRUE), vi32 = max(teams_admin_dpw_7, na.rm = TRUE), vi33 = max(teams_admin_hpd_7, na.rm = TRUE))

leave = 102 # days
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs1) # hrs of a year

'---------- HSA ----------'
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  sw1 = 6 *awt,
  sw2 = 4 *awt,
  sw3 = 4 *awt,
  sw4 = 3 *awt,
  sw5 = 4 *awt,
  sw6 = 6 *awt,
  sw7 = 6 *awt,
  sw8 = 12 *awt,
  sw9 = 6 *awt,
  sw10 = 12 *awt,
  sw11 = 6 *awt,
  sw12 = 6 *awt,
  sw13 = 6 *awt
  ) # max_patient

mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  aw1 = ipc_fy_sum_13,
  aw2 = opc_fy_sum_11,
  aw3 = opc_fy_sum_10,
  aw4 = opc_fy_sum_5,
  aw5 = opc_fy_sum_13,
  aw6 = ipc_fy_sum_4,
  aw7 = opc_fy_sum_9,
  aw8 = opc_fy_sum_4,
  aw9 = ipc_fy_sum_2,
  aw10 = opc_fy_sum_6,
  aw11 = ipc_fy_sum_3,
  aw12 = opc_fy_sum_8,
  aw13 = opc_fy_sum_7
  )# patient_load | required staff

mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  ) #

'---------- CAF ----------'
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  cas1 = (4*12) /awt *100,
  cas2 = (4/7*fte_hrs1 *12)  /awt *100)

mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  CAF = (1 /(1-((cas1 +cas2)/100))) ) #

'---------- IAF ----------'
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  ias1 = other_df$vi11 * 4*12,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52,
  ias3 = other_df$vi31 * other_df$vi32*other_df$vi33 *52) # dropped

mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  IAF = (ias1 +ias2 +ias3) /awt) #

'---------- WISN ----------'
mo_dh_2011_df <- mo_dh_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

mo_dh_2011_df_sum <- mo_dh_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_dh_mo_df <- mo_dh_2011_df
ap_dh_mo_df_sum <- mo_dh_2011_df_sum

ap_dh_mo_df
ap_dh_mo_df_sum

```

### Nurses @ Facility
. --------------------------------------------------
> Nurses | CHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs3
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_fy_sum_13 Normal Del  | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_fy_sum_14 C-section   | 40 mins/pt  1.5/hr 
  3     | ANC                 | opc_fy_sum_10 antenatal   | 30 mins/pt  2/hr
  4     | Counseling          | opc_fy_sum_11 postnatal   | 15 mins/pt  4/hr
  5     | Family planning     | opc_fy_sum_5 welfare      | 5 mins/pt  12/hr
  6     | Investigation       | ipc_fy_sum_18 deaths      | 2.5 hr/pt   0.4/hr
  .
  7     | Outpatients         | opc_fy_sum_13 surgery     | 10 mins/pt  6/hr
  8     | Inpatients          | ipc_fy_sum_4 admissions   | 15 mins/pt  4/hr
  9     | Inpatients          | ipc_fy_sum_10 major       | 2 hr/pt     0.5/hr
  10    | Inpatients          | ipc_fy_sum_11 minor       | 15 mins/pt  4/hr
  .
  11    | Outpatients         | opc_fy_sum_9 eye          | 15 mins/pt  4/hr
  .
  12    | Outpatients         | opc_fy_sum_4 child        | 15 mins/pt  4/hr
  13    | Inpatients          | ipc_fy_sum_2 admission    | 15 mins/pt  4/hr
  14    | Investigation       | ipc_fy_sum_15 stillbirths | 25 mins/pt  2.4/hr
  .
  15    | Immunisations       | opcv_fy_sum_9 women       | 7 mins/pt  ~8.5/hr    - XXXXX
  16    | Immunisations       | opcv_fy_sum_1 child       | 7 mins/pt  ~8.5/hr
  .
  17    | Outpatients         | opc_fy_sum_6 general      | 10 mins/pt  6/hr
  18    | Outpatients         | opc_fy_sum_7 heart        | 10 mins/pt  6/hr 
  19    | Outpatients         | opc_fy_sum_8 diabetes     | 10 mins/pt  6/hr
  20    | Inpatients          | ipc_fy_sum_3 admissions   | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit                                        ----- X?
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]
  2     | Record keeping      | teams_admin_x_5 [max]       | [max]

```{r Nurses @ CHC | AP}
# getting_data
nurses_chc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs3,
         ipc_fy_sum_13, ipc_fy_sum_14, opc_fy_sum_10, opc_fy_sum_11, opc_fy_sum_5, ipc_fy_sum_18,
         opc_fy_sum_13, ipc_fy_sum_4, ipc_fy_sum_10, ipc_fy_sum_11,
         opc_fy_sum_9,
         opc_fy_sum_4, ipc_fy_sum_2, ipc_fy_sum_15,
         opcv_fy_sum_1, ###opcv_fy_sum_9,
         opc_fy_sum_6, opc_fy_sum_8, opc_fy_sum_7, ipc_fy_sum_3,
         ohv_fy_sum_1) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  filter(!is.na(ipc_fy_sum_13) & !is.na(ipc_fy_sum_14) & !is.na(opc_fy_sum_10) & !is.na(opc_fy_sum_11) & !is.na(opc_fy_sum_5) & !is.na(ipc_fy_sum_18) & 
           !is.na(opc_fy_sum_13) & !is.na(ipc_fy_sum_4) & !is.na(ipc_fy_sum_10) & !is.na(ipc_fy_sum_11) &
           !is.na(opc_fy_sum_9) &
           !is.na(opc_fy_sum_4) & !is.na(ipc_fy_sum_2) & !is.na(ipc_fy_sum_15) & 
           !is.na(opcv_fy_sum_1) & ###!is.na(opcv_fy_sum_9) &
           !is.na(opc_fy_sum_6) & !is.na(opc_fy_sum_8) & !is.na(opc_fy_sum_7) & !is.na(ipc_fy_sum_3)
           ) %>%
  filter((ipc_fy_sum_13 >= 0 ) & (ipc_fy_sum_14 >= 0 ) & (opc_fy_sum_10 >= 0 ) & (opc_fy_sum_11 >= 0 ) & (opc_fy_sum_5 >= 0 ) & (ipc_fy_sum_18 >= 0 )
         & (opc_fy_sum_13 >= 0 ) & (ipc_fy_sum_4 >= 0 ) & (ipc_fy_sum_10 >= 0 ) & (ipc_fy_sum_11 >= 0 )
         & (opc_fy_sum_9 >= 0 )
         & (opc_fy_sum_4 >= 0 ) & (ipc_fy_sum_2 >= 0 ) & (ipc_fy_sum_15 >= 0 )
         & (opcv_fy_sum_1 >= 0 ) ###& (opcv_fy_sum_9 >= 0 )
         & (opc_fy_sum_6 >= 0 ) & (opc_fy_sum_8 >= 0 ) & (opc_fy_sum_7 >= 0 ) & (ipc_fy_sum_3 >= 0 )
         #& (ohv_fy_sum_1 >= 0 )
    ) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs3 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_1,teams_admin_dpw_1,teams_admin_hpd_1,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5
         ) %>%
  filter(platform_type == "Community Health Centre (CHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_1, na.rm = TRUE), vi12 = max(teams_admin_dpw_1, na.rm = TRUE), vi13 = max(teams_admin_hpd_1, na.rm = TRUE),
            vi21 = max(teams_admin_pers_5, na.rm = TRUE), vi22 = max(teams_admin_dpw_5, na.rm = TRUE), vi23 = max(teams_admin_hpd_5, na.rm = TRUE))

leave = 102 # days
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs3) # hrs of a year

'---------- HSA ----------'
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  sw1 = 1 *awt,
  sw2 = 1.5 *awt,
  sw3 = 2 *awt,
  sw4 = 4 *awt,
  sw5 = 12 *awt,
  sw6 = 0.4 *awt,
  sw7 = 6 *awt,
  sw8 = 4 *awt,
  sw9 = 0.5 *awt,
  sw10 = 4 *awt,
  sw11 = 4 *awt,
  sw12 = 4 *awt,
  sw13 = 4 *awt,
  sw14 = 2.4 *awt,
  ###sw15 = 60/7 *awt,
  sw16 = 60/7 *awt,
  sw17 = 6 *awt,
  sw18 = 6 *awt,
  sw19 = 6 *awt,
  sw20 = 4 *awt
  ) # max_patient

nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  aw1 = ipc_fy_sum_13,
  aw2 = ipc_fy_sum_14,
  aw3 = opc_fy_sum_10,
  aw4 = opc_fy_sum_11,
  aw5 = opc_fy_sum_5,
  aw6 = ipc_fy_sum_18,
  aw7 = opc_fy_sum_13,
  aw8 = ipc_fy_sum_4,
  aw9 = ipc_fy_sum_10,
  aw10 = ipc_fy_sum_11,
  aw11 = opc_fy_sum_9,
  aw12 = opc_fy_sum_4,
  aw13 = ipc_fy_sum_2,
  aw14 = ipc_fy_sum_15,
  ###aw15 = opcv_fy_sum_9,
  aw16 = opcv_fy_sum_1,
  aw17 = opc_fy_sum_6,
  aw18 = opc_fy_sum_8,
  aw19 = opc_fy_sum_7,
  aw20 = ipc_fy_sum_3
  )# patient_load | required staff

nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  HSA = aw1/sw1
  +aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  +aw7/sw7
  +aw8/sw8
  +aw9/sw9
  +aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  +aw14/sw14
  ###+aw15/sw15
  +aw16/sw16
  +aw17/sw17
  +aw18/sw18
  +aw19/sw19
  +aw20/sw20
  ) #

'---------- CAF ----------'
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  cas1 = (6/7 *fte_hrs3) /awt *100,
  cas2 = (0 *2 *ohv_fy_sum_1)  /awt *100) # ignored? standard cas2?

nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  ias1 = other_df$vi11 * other_df$vi12*other_df$vi13 *52,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52) #

nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
nurses_chc_2011_df <- nurses_chc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

nurses_chc_2011_df_sum <- nurses_chc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_chc_nurses_df <- nurses_chc_2011_df
ap_chc_nurses_df_sum <- nurses_chc_2011_df_sum

ap_chc_nurses_df
ap_chc_nurses_df_sum

```

> Nurses | PHC
AWT
  #     | Component           | #days
  ----- | -----               | -----
  1     | WeekHours           | fte_hrs3
  2     | Leave               | 102 [(14+30)+30+28] days
Health service activity
  #     | Component           | Annual workload             | Standrard workload
  ----- | -----               | -----                       | -----
  1     | Assist delivery     | ipc_fy_sum_13 Normal Del  | 60 mins/pt  1/hr
  2     | Resuscitate baby    | ipc_fy_sum_14 C-section   | 40 mins/pt  1.5/hr    - XXXXX 
  3     | ANC                 | opc_fy_sum_10 antenatal   | 30 mins/pt  2/hr
  4     | Counseling          | opc_fy_sum_11 postnatal   | 15 mins/pt  4/hr
  5     | Family planning     | opc_fy_sum_5 welfare      | 5 mins/pt  12/hr
  6     | Investigation       | ipc_fy_sum_18 deaths      | 2.5 hr/pt   0.4/hr
  .
  7     | Outpatients         | opc_fy_sum_13 surgery     | 10 mins/pt  6/hr      - XXXXX
  8     | Inpatients          | ipc_fy_sum_4 admissions   | 15 mins/pt  4/hr      - XXXXX 
  9     | Inpatients          | ipc_fy_sum_10 major       | 2 hr/pt     0.5/hr    - XXXXX
  10    | Inpatients          | ipc_fy_sum_11 minor       | 15 mins/pt  4/hr      - XXXXX
  .
  11    | Outpatients         | opc_fy_sum_9 eye          | 15 mins/pt  4/hr
  .
  12    | Outpatients         | opc_fy_sum_4 child        | 15 mins/pt  4/hr
  13    | Inpatients          | ipc_fy_sum_2 admission    | 15 mins/pt  4/hr
  14    | Investigation       | ipc_fy_sum_15 stillbirths | 25 mins/pt  2.4/hr
  .
  15    | Immunisations       | opcv_fy_sum_9 women       | 7 mins/pt  ~8.5/hr    - XXXXX
  16    | Immunisations       | opcv_fy_sum_1 child       | 7 mins/pt  ~8.5/hr
  .
  17    | Outpatients         | opc_fy_sum_6 general      | 10 mins/pt  6/hr
  18    | Outpatients         | opc_fy_sum_7 heart        | 10 mins/pt  6/hr 
  19    | Outpatients         | opc_fy_sum_8 diabetes     | 10 mins/pt  6/hr
  20    | Inpatients          | ipc_fy_sum_3 admissions   | 15 mins/pt  4/hr
Support activity | CAS
  #     | Component           | Load
  ----- | -----               | -----
  1     | Training            | 6 dy/yr (6 days)
  2     | Outreach services   | 2 hr/visit                                        ----- X?!!!
Additional activity | IAS
  #     | Component           | #staff                      | #days x #hours
  ----- | -----               | -----                       | -----
  1     | Accounts & Billing  | teams_admin_x_1 [max]       | [max]
  2     | Record keeping      | teams_admin_x_5 [max]       | [max]

```{r Nurses @ PHC | AP}
# getting_data
nurses_phc_2011_df <- data_df %>%
  select(customid, platform_type, year, rural, fte_hrs3,
         ipc_fy_sum_13, opc_fy_sum_10, opc_fy_sum_11, opc_fy_sum_5, ipc_fy_sum_18,###, ipc_fy_sum_14
         ###opc_fy_sum_13, ipc_fy_sum_4, ipc_fy_sum_10, ipc_fy_sum_11,
         opc_fy_sum_9,
         opc_fy_sum_4, ipc_fy_sum_2, ipc_fy_sum_15,
         opcv_fy_sum_1, ###opcv_fy_sum_9,
         opc_fy_sum_6, opc_fy_sum_8, opc_fy_sum_7, ipc_fy_sum_3,
         ohv_fy_sum_1) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  #filter(year == 2011) %>%
  filter(!is.na(ipc_fy_sum_13) & !is.na(opc_fy_sum_10) & !is.na(opc_fy_sum_11) & !is.na(opc_fy_sum_5) & !is.na(ipc_fy_sum_18) & ### !is.na(ipc_fy_sum_14) &
           ###!is.na(opc_fy_sum_13) & !is.na(ipc_fy_sum_4) & !is.na(ipc_fy_sum_10) & !is.na(ipc_fy_sum_11) &
           !is.na(opc_fy_sum_9) &
           !is.na(opc_fy_sum_4) & !is.na(ipc_fy_sum_2) & !is.na(ipc_fy_sum_15) & 
           !is.na(opcv_fy_sum_1) & ###!is.na(opcv_fy_sum_9) &
           !is.na(opc_fy_sum_6) & !is.na(opc_fy_sum_8) & !is.na(opc_fy_sum_7) & !is.na(ipc_fy_sum_3)
           ) %>%
  filter((ipc_fy_sum_13 >= 0 ) & (opc_fy_sum_10 >= 0 ) & (opc_fy_sum_11 >= 0 ) & (opc_fy_sum_5 >= 0 ) & (ipc_fy_sum_18 >= 0 )### & (ipc_fy_sum_14 >= 0 )
         ###& (opc_fy_sum_13 >= 0 ) & (ipc_fy_sum_4 >= 0 ) & (ipc_fy_sum_10 >= 0 ) & (ipc_fy_sum_11 >= 0 )
         & (opc_fy_sum_9 >= 0 )
         & (opc_fy_sum_4 >= 0 ) & (ipc_fy_sum_2 >= 0 ) & (ipc_fy_sum_15 >= 0 )
         & (opcv_fy_sum_1 >= 0 ) ###& (opcv_fy_sum_9 >= 0 )
         & (opc_fy_sum_6 >= 0 ) & (opc_fy_sum_8 >= 0 ) & (opc_fy_sum_7 >= 0 ) & (ipc_fy_sum_3 >= 0 )
         #& (ohv_fy_sum_1 >= 0 )
    ) %>%
  mutate(f_type = replace(rural, rural == "Semi-/Peri-urban", "Semi/Peri-Urban")) %>%
  filter(fte_hrs3 >= 24)

other_df <- data_df %>%
  select(customid, platform_type, year,
         teams_admin_pers_1,teams_admin_dpw_1,teams_admin_hpd_1,
         teams_admin_pers_5,teams_admin_dpw_5,teams_admin_hpd_5
         ) %>%
  filter(platform_type == "Primary Health Centre (PHC)") %>%
  #filter(year == 2011) %>%
  summarise(vi11 = max(teams_admin_pers_1, na.rm = TRUE), vi12 = max(teams_admin_dpw_1, na.rm = TRUE), vi13 = max(teams_admin_hpd_1, na.rm = TRUE),
            vi21 = max(teams_admin_pers_5, na.rm = TRUE), vi22 = max(teams_admin_dpw_5, na.rm = TRUE), vi23 = max(teams_admin_hpd_5, na.rm = TRUE))

leave = 102 # days
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(awt = (365 - leave) /7 * fte_hrs3) # hrs of a year

'---------- HSA ----------'
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  sw1 = 1 *awt,
  ###sw2 = 1.5 *awt,
  sw3 = 2 *awt,
  sw4 = 4 *awt,
  sw5 = 12 *awt,
  sw6 = 0.4 *awt,
  ###sw7 = 6 *awt,
  ###sw8 = 4 *awt,
  ###sw9 = 0.5 *awt,
  ###sw10 = 4 *awt,
  sw11 = 4 *awt,
  sw12 = 4 *awt,
  sw13 = 4 *awt,
  sw14 = 2.4 *awt,
  ###sw15 = 60/7 *awt,
  sw16 = 60/7 *awt,
  sw17 = 6 *awt,
  sw18 = 6 *awt,
  sw19 = 6 *awt,
  sw20 = 4 *awt
  ) # max_patient

nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  aw1 = ipc_fy_sum_13,
  ###aw2 = ipc_fy_sum_14,
  aw3 = opc_fy_sum_10,
  aw4 = opc_fy_sum_11,
  aw5 = opc_fy_sum_5,
  aw6 = ipc_fy_sum_18,
  ###aw7 = opc_fy_sum_13,
  ###aw8 = ipc_fy_sum_4,
  ###aw9 = ipc_fy_sum_10,
  ###aw10 = ipc_fy_sum_11,
  aw11 = opc_fy_sum_9,
  aw12 = opc_fy_sum_4,
  aw13 = ipc_fy_sum_2,
  aw14 = ipc_fy_sum_15,
  ###aw15 = opcv_fy_sum_9,
  aw16 = opcv_fy_sum_1,
  aw17 = opc_fy_sum_6,
  aw18 = opc_fy_sum_8,
  aw19 = opc_fy_sum_7,
  aw20 = ipc_fy_sum_3
  )# patient_load | required staff

nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  HSA = aw1/sw1
  ###+aw2/sw2
  +aw3/sw3
  +aw4/sw4
  +aw5/sw5
  +aw6/sw6
  ###+aw7/sw7
  ###+aw8/sw8
  ###+aw9/sw9
  ###+aw10/sw10
  +aw11/sw11
  +aw12/sw12
  +aw13/sw13
  +aw14/sw14
  ###+aw15/sw15
  +aw16/sw16
  +aw17/sw17
  +aw18/sw18
  +aw19/sw19
  +aw20/sw20
  ) #

'---------- CAF ----------'
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  cas1 = (6/7 *fte_hrs3) /awt *100,
  cas2 = (0 *2 *ohv_fy_sum_1)  /awt *100) # ignored!!! standard cas2?

nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  CAF = (1 /(1-((cas1)/100))) ) #

'---------- IAF ----------'
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  ias1 = other_df$vi11 * other_df$vi12*other_df$vi13 *52,
  ias2 = other_df$vi21 * other_df$vi22*other_df$vi23 *52) #

nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  IAF = (ias1 +ias2) /awt) #

'---------- WISN ----------'
nurses_phc_2011_df <- nurses_phc_2011_df %>% mutate(
  WISN = HSA*CAF +IAF) #

nurses_phc_2011_df_sum <- nurses_phc_2011_df %>% summarise(
  n_centre = n(),
  WISN_mean = mean(WISN),
  WISN_median = median(WISN),
  WISN_std = sd(WISN) ) #

ap_phc_nurses_df <- nurses_phc_2011_df
ap_phc_nurses_df_sum <- nurses_phc_2011_df_sum

ap_phc_nurses_df
ap_phc_nurses_df_sum

```

# ----- Analysis
. --------------------------------------------------
```{r pool variables}
WISN <- bind_rows(
  # MP
  mp_chc_obgyn_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'O and G specialist', .before = "customid"),
  mp_chc_surgeryspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'Surgery specialist', .before = "customid"),
  mp_chc_eyespec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'Ophthalmologist', .before = "customid"),
  mp_chc_childspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'Paedistrician', .before = "customid"),
  mp_chc_medicalspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'Medical specialist', .before = "customid"),

  mp_phc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'Medical officer', .before = "customid"),
  mp_chc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'Medical officer', .before = "customid"),
  mp_dh_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'Medical officer', .before = "customid"),

  mp_chc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'Nurses', .before = "customid"),
  mp_phc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'MP', Cadre = 'Nurses', .before = "customid"),

  # GJ
  gj_chc_obgyn_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'O and G specialist', .before = "customid"),
  gj_chc_surgeryspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'Surgery specialist', .before = "customid"),
  gj_chc_eyespec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'Ophthalmologist', .before = "customid"),
  gj_chc_childspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'Paedistrician', .before = "customid"),
  gj_chc_medicalspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'Medical specialist', .before = "customid"),

  gj_phc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'Medical officer', .before = "customid"),
  gj_chc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'Medical officer', .before = "customid"),
  gj_dh_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'Medical officer', .before = "customid"),

  gj_chc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'Nurses', .before = "customid"),
  gj_phc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'GJ', Cadre = 'Nurses', .before = "customid"),

  # TN
  tn_chc_obgyn_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'O and G specialist', .before = "customid"),
  tn_chc_surgeryspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'Surgery specialist', .before = "customid"),
  tn_chc_eyespec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'Ophthalmologist', .before = "customid"),
  tn_chc_childspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'Paedistrician', .before = "customid"),
  tn_chc_medicalspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'Medical specialist', .before = "customid"),

  tn_phc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'Medical officer', .before = "customid"),
  tn_chc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'Medical officer', .before = "customid"),
  tn_dh_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'Medical officer', .before = "customid"),

  tn_chc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'Nurses', .before = "customid"),
  tn_phc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'TN', Cadre = 'Nurses', .before = "customid"),

  # OD
  od_chc_obgyn_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'O and G specialist', .before = "customid"),
  od_chc_surgeryspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'Surgery specialist', .before = "customid"),
  od_chc_eyespec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'Ophthalmologist', .before = "customid"),
  od_chc_childspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'Paedistrician', .before = "customid"),
  od_chc_medicalspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'Medical specialist', .before = "customid"),

  od_phc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'Medical officer', .before = "customid"),
  od_chc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'Medical officer', .before = "customid"),
  od_dh_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'Medical officer', .before = "customid"),

  od_chc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'Nurses', .before = "customid"),
  od_phc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'OD', Cadre = 'Nurses', .before = "customid"),

  # AP & TG
  ap_chc_obgyn_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'O and G specialist', .before = "customid"),
  ap_chc_surgeryspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'Surgery specialist', .before = "customid"),
  ap_chc_eyespec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'Ophthalmologist', .before = "customid"),
  ap_chc_childspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'Paedistrician', .before = "customid"),
  ap_chc_medicalspec_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'Medical specialist', .before = "customid"),

  ap_phc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'Medical officer', .before = "customid"),
  ap_chc_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'Medical officer', .before = "customid"),
  ap_dh_mo_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'Medical officer', .before = "customid"),

  ap_chc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'Nurses', .before = "customid"),
  ap_phc_nurses_df %>%
    select(customid, platform_type, year, f_type, HSA, CAF, IAF, WISN) %>%
    add_column(State = 'AP & TG', Cadre = 'Nurses', .before = "customid")
)

WISN <- WISN %>% rename(Facility = platform_type, Area = f_type, Year = year)

WISN <- within(WISN, Facility[Facility == "Subdistrict Hospital (SDH)"] <- "Sub-District Hospital (SDH)")
WISN <- within(WISN, Facility[Facility == "Sub-district Hospital (SDH)"] <- "Sub-District Hospital (SDH)")

#WISN <- within(WISN, Year[State == 'OD'] <- 2013)
#WISN <- within(WISN, Year[State == 'GJ'] <- 2014)

write.csv(WISN, "../analysis/Data_WISN_ABCE_raw.csv")

```

### ...













