-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data_Processing.Rmd
103 lines (80 loc) · 3.44 KB
/
Data_Processing.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
title: "produce clean data for plotting for SMT Dental Pack"
---
```{r UDA delivered/contracted}
get_delivery_data <- function(data = UDA_calendar_data,
UDAorUOA = "UDA",
all_regions_and_STPs = F,
contractor_level = F,
renameColumns = F){
#show different levels of information in output data if specified
if(all_regions_and_STPs == TRUE){
data <- data %>%
group_by(month, region_name, commissioner_name)
}else if(contractor_level == TRUE){
data <- data %>%
group_by(month, contract_number, commissioner_name)
}else{
data <- data %>%
group_by(month)
}
if(UDAorUOA == "UDA"){
#group by month/ICB/Region (depends on the previous step) and calculate total no UDAs delivered and contracted UDA
UDA_UOAs_delivered <- data %>%
summarise(monthly_UDA_UOAs_BAND1_delivered = sum(UDA_band_1, na.rm = T),
monthly_UDA_UOAs_BAND2_delivered = sum(UDA_band_2, na.rm = T),
monthly_UDA_UOAs_BAND3_delivered = sum(UDA_band_3, na.rm = T),
monthly_UDA_UOAs_BAND_OTHER_delivered = sum(UDA_other, na.rm = T),
monthly_UDA_UOAs_BAND_URGENT_delivered = sum(UDA_urgent, na.rm = T),
monthly_UDA_UOAs_delivered = sum(UDA_delivered, na.rm = T),
annual_contracted_UDA_UOA = sum(annual_contracted_UDA, na.rm = T))
#for PCOR and SOF table
if(renameColumns){
new_data <- UDA_UOAs_delivered %>%
select(treatment_month = month,
commissioner_name,
region_name,
monthly_UDA_BAND1_delivered,
monthly_UDA_BAND2_delivered,
monthly_UDA_BAND3_delivered,
monthly_UDA_BAND_URGENT_delivered,
monthly_UDA_BAND_OTHER_delivered,
monthly_UDAs_delivered = monthly_UDA_UOAs_delivered,
annual_contracted_UDAs = annual_contracted_UDA_UOA)
}
}else if(UDAorUOA == "UOA"){
#group by month/ICB/Region (depends on the previous step) and calculate total no UOAs delivered and contracted UOA
UDA_UOAs_delivered <- data %>%
summarise(monthly_UDA_UOAs_delivered = sum(UOA_delivered, na.rm = T),
annual_contracted_UDA_UOA = sum(annual_contracted_UOA, na.rm = T))
}
new_data <- UDA_UOAs_delivered
}
```
```{r banded CoT data}
get_banded_COTs_data <- function(data = UDA_calendar_data_FD,
level = "National",
all_regions_and_STPs = FALSE){
if(level == "National"){
#group by month and sum UDAs delivered
new_data <- data %>%
group_by(month)
}else{
#group by month and sum UDAs delivered
# start from 2020-04-01 as region/ICB information not available before then
new_data <- data %>%
group_by(month, region_name, commissioner_name) %>%
filter(month >= "2020-04-01")
}
#calculate total no of FP17s in each band
new_data <- new_data %>%
summarise(band1 = sum(FP17s_band_1, na.rm = T),
band2 = sum(FP17s_band_2, na.rm = T),
band2a = sum(FP17s_band_2a, na.rm = T),
band2b = sum(FP17s_band_2b, na.rm = T),
band2c = sum(FP17s_band_2c, na.rm = T),
band3 = sum(FP17s_band_3, na.rm = T),
other = sum(FP17s_band_other, na.rm = T),
urgent = sum(FP17s_band_urgent, na.rm = T))
}
```