-
Notifications
You must be signed in to change notification settings - Fork 0
/
02b_Display_Emergency_Hospitalisations.Rmd
165 lines (132 loc) · 6.51 KB
/
02b_Display_Emergency_Hospitalisations.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
---
title: "Display Emergency Hospitalisations"
output: html_document
---
```{r setup, include=FALSE}
library(ggplot2)
library(knitr)
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, error=FALSE, message=FALSE)
descriptors = c ("ageYear", "n_risk_gps", "Sex", "age_gp", "covid_vs", "flu_vs", "urban_rural_classification", "simd2020_sc_quintile", "icu_admit_age", "death_28", "hosp_los_gp", "num_prev_admission_gp", "ethnic_gp", "health_board")
descriptors_labels = c ("Age", "Number of Risk Groups", "Sex", "Age Groups", "Covid Vaccination Status",
"Flu Vaccination Status", "Urban/Rural Classification", "SIMD", "ICU Admittance", "Death",
"Length of Stay", "Number of previous admissions", "Ethnic Group", "Health Board")
var_labels = setNames(as.list(descriptors_labels), descriptors)
descriptors_death = c("ageYear", "n_risk_gps", "Sex", "age_gp", "covid_vs", "flu_vs", "urban_rural_classification", "simd2020_sc_quintile", "num_prev_admission_gp", "ethnic_gp", "health_board")
descriptors_death_labels = c ("Age", "Number of Risk Groups", "Sex", "Age Groups", "Covid Vaccination Status",
"Flu Vaccination Status", "Urban/Rural Classification", "SIMD",
"Number of previous admissions", "Ethnic Group", "Health Board")
var_labels_death = setNames(as.list(descriptors_death_labels), descriptors_death)
```
## Number of Emergency Hospitalisations
```{r}
num_hosp = nrow(emergency_hosp_cohort)
print(num_hosp)
```
## Hospitalisation - emergency admission description
```{r}
z_df = emergency_hosp_cohort %>% mutate(value = TRUE) %>%
mutate(MAIN_CONDITION = factor(MAIN_CONDITION)) %>%
mutate(simd2020_sc_quintile = factor(simd2020_sc_quintile)) %>%
mutate(icu_admit = as.factor(icu_admit)) %>%
mutate(health_board = as.factor(health_board)) %>%
mutate(ethnic_gp = as.factor(ethnic_gp)) %>%
mutate(death_28 = as.factor(death_28))
z_df = z_df %>% set_variable_labels(.labels=var_labels, .strict=FALSE)
kable(summary_factorlist_wt(z_df, "value", descriptors))
```
## Number of CIST admissions
```{r}
z_df = emergency_hosp_cohort %>% filter(acute_resp_admission == 1 | acute_resp_secondary == 1 |
acute_trauma_admission == 1 | acute_trauma_secondary == 1 |
acute_cancer_admission == 1 | acute_cancer_secondary == 1 |
acute_cardiac_admission == 1 | acute_cardiac_secondary == 1)
print(nrow(z_df))
```
## Hospitalisation - Trauma emergency admission description
```{r}
z_df = emergency_hosp_cohort %>% filter(acute_trauma_admission == 1 | acute_trauma_secondary == 1) %>%
mutate(value = TRUE) %>%
mutate(MAIN_CONDITION = factor(MAIN_CONDITION)) %>%
mutate(simd2020_sc_quintile = factor(simd2020_sc_quintile)) %>%
mutate(icu_admit = as.factor(icu_admit)) %>%
mutate(health_board = as.factor(health_board)) %>%
mutate(ethnic_gp = as.factor(ethnic_gp)) %>%
mutate(death_28 = as.factor(death_28))
z_df = z_df %>% set_variable_labels(.labels=var_labels, .strict=FALSE)
print(nrow(z_df))
```
```{r}
kable(summary_factorlist_wt(z_df, "value", descriptors))
```
## Hospitalisation - Cardiac emergency admission description
```{r}
z_df = emergency_hosp_cohort %>% filter(acute_cardiac_admission == 1 | acute_cardiac_secondary == 1) %>%
mutate(value = TRUE) %>%
mutate(MAIN_CONDITION = factor(MAIN_CONDITION)) %>%
mutate(simd2020_sc_quintile = factor(simd2020_sc_quintile)) %>%
mutate(icu_admit = as.factor(icu_admit)) %>%
mutate(health_board = as.factor(health_board)) %>%
mutate(ethnic_gp = as.factor(ethnic_gp)) %>%
mutate(death_28 = as.factor(death_28))
z_df = z_df %>% set_variable_labels(.labels=var_labels, .strict=FALSE)
print(nrow(z_df))
```
```{r}
kable(summary_factorlist_wt(z_df, "value", descriptors))
```
## Hospitalisation - Cancer emergency admission description
```{r}
z_df = emergency_hosp_cohort %>% filter(acute_cancer_admission == 1 | acute_cancer_secondary == 1) %>%
mutate(value = TRUE) %>%
mutate(MAIN_CONDITION = factor(MAIN_CONDITION)) %>%
mutate(simd2020_sc_quintile = factor(simd2020_sc_quintile)) %>%
mutate(icu_admit = as.factor(icu_admit)) %>%
mutate(health_board = as.factor(health_board)) %>%
mutate(ethnic_gp = as.factor(ethnic_gp)) %>%
mutate(death_28 = as.factor(death_28))
z_df = z_df %>% set_variable_labels(.labels=var_labels, .strict=FALSE)
print(nrow(z_df))
```
```{r}
kable(summary_factorlist_wt(z_df, "value", descriptors))
```
# Hospital Length of stays
```{r}
g = ggplot(emergency_hosp_cohort, aes(hosp_los_gp)) + geom_bar()
print(g)
```
# Weekly counts
## All admissions
```{r}
z_count = emergency_hosp_cohort %>%
select(EAVE_LINKNO, ADMISSION_DATE) %>% mutate(t = floor(difftime(ADMISSION_DATE, a_begin, units="weeks"))) %>%
count(t) %>% mutate(t = t + a_begin)
g = ggplot() + geom_line(z_count, mapping=aes(x=t, y=n)) +
scale_x_date(breaks="1 month", date_labels="%b %Y") + ylab("Number of admissions") +
xlab("Month and Year")
print(g)
```
## Produce graphs
```{r}
z_resp = emergency_hosp_cohort %>% filter(acute_resp_admission == 1 | acute_resp_secondary == 1)
z_trauma = emergency_hosp_cohort %>% filter(acute_trauma_admission == 1 | acute_trauma_secondary == 1)
z_cancer = emergency_hosp_cohort %>% filter(acute_cancer_admission == 1 | acute_cancer_secondary == 1)
z_cardiac = emergency_hosp_cohort %>% filter(acute_cardiac_admission == 1 | acute_cardiac_secondary == 1)
z_resp_count = z_resp %>%
select(EAVE_LINKNO, ADMISSION_DATE) %>% mutate(t = floor(difftime(ADMISSION_DATE, a_begin, units="days"))) %>%
count(t) %>% mutate(t = t + a_begin) %>% mutate(type="Respiratory")
z_trauma_count = z_trauma %>%
select(EAVE_LINKNO, ADMISSION_DATE) %>% mutate(t = floor(difftime(ADMISSION_DATE, a_begin, units="days"))) %>%
count(t) %>% mutate(t = t + a_begin) %>% mutate(type="Trauma")
z_cancer_count = z_cancer %>%
select(EAVE_LINKNO, ADMISSION_DATE) %>% mutate(t = floor(difftime(ADMISSION_DATE, a_begin, units="days"))) %>%
count(t) %>% mutate(t = t + a_begin) %>% mutate(type="Cancer")
z_cardiac_count = z_cardiac %>%
select(EAVE_LINKNO, ADMISSION_DATE) %>% mutate(t = floor(difftime(ADMISSION_DATE, a_begin, units="days"))) %>%
count(t) %>% mutate(t = t + a_begin) %>% mutate(type="Cardiac")
z_counts = z_resp_count %>% rbind(z_trauma_count) %>% rbind(z_cancer_count) %>% rbind(z_cardiac_count)
g = ggplot(z_counts, aes(x=t)) + geom_line(aes(y=n, color = type)) +
scale_x_date(breaks="1 month", date_labels="%b %Y") + ylab("Number of admissions") +
xlab("Month and Year")
print(g)
```