-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalytics.R
254 lines (226 loc) · 12 KB
/
Analytics.R
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# Libraries ---------------------------------------------------------------
library(tidyverse)
library(readxl)
library(devtools)
library(plotly)
library(shiny)
library(reshape2)
library(rsconnect)
library(loadfonts)
library(extrafont)
# Data Load ---------------------------------------------------------------
setwd("C:/Users/bened/dhc18/dhc18/Analyse")
zeitdat <- read_excel("analysedaten.xlsx") %>%
mutate(raum = as.factor(raum)) %>%
mutate(geraet = as.factor(geraet)) %>%
mutate(kategorie = as.factor(kategorie)) %>%
mutate(dauer = ende - start)
setwd("C:/Users/bened/dhc18/dhc18/data")
raumdat <- read.csv("rooms.csv", sep = ";") %>%
as.tibble() %>%
mutate(Room_ID = as.factor(Room_ID)) %>%
mutate(Functiontyp = as.factor(Functiontyp)) %>%
mutate(Buliding_area = as.factor(Buliding_area)) %>%
mutate(Station = as.factor(Station))
# Data combination --------------------------------------------------------
zeitdat <- zeitdat %>%
left_join(raumdat, by = c("raum" = "Room_ID")) %>%
mutate(raum = as.factor(raum)) %>%
select(-Capacity, -Buliding_area, -Balkony, -bathroom, -Size, -floor) %>%
mutate(wartezeit = NA)
# Aggregating movement times ----------------------------------------------
halldata <- zeitdat %>%
filter(Functiontyp == "hall_section") %>%
group_by(geraet, kategorie) %>%
summarize(halltime = sum(dauer))
zeitdat <- zeitdat %>%
filter(Functiontyp != "hall_section") %>%
mutate(raum = as.character(raum))
for(i in 1:nrow(halldata)){
zeitdat[nrow(zeitdat) + 1,] <- c(halldata[i,1], "Transport", halldata[i,2], 0,0,0, halldata[i,3], "hall_section", NA, NA)
}
zeitdat <- zeitdat %>%
mutate(raum = as.factor(raum))
# Calculate waiting times -------------------------------------------------
#Ugly but it works :D
waiting_rooms <- c("meeting_room", "doctors_room", "1emergency_reception", "4emergency_treatment", "3emergency_trauma_room")
for(i in 1:nrow(zeitdat)){
if(data.frame(zeitdat[i,8])[1,1] %in% waiting_rooms && zeitdat[i,3] == "patient"){
tagp = data.frame(zeitdat[i,6])[1,1]
startp = data.frame(zeitdat[i,4])[1,1]
endep = data.frame(zeitdat[i,5])[1,1]
raump = data.frame(zeitdat[i,2])[1,1]
arztanw <- zeitdat %>%
filter(kategorie %in% c("arzt", "schwester")) %>%
filter(tag == tagp) %>%
filter(raum == raump)
if(nrow(arztanw) > 0){
for(j in 1:nrow(arztanw)){
if(arztanw$start[j] < startp){
zeitdat$wartezeit[i] <- 0
}
else if(arztanw$start[j] == startp){
zeitdat$wartezeit[i] <- 0
}
else if(arztanw$start[j] > startp && arztanw$start[j] <= endep){
zeitdat$wartezeit[i] <- arztanw$start[j] - startp
}
}
}
else{
zeitdat$wartezeit[i] <- zeitdat$dauer[i]
}
}
}
# Plotting ----------------------------------------------------------------
setwd("C:/Users/bened/dhc18/dhc18/Analyse")
Sys.setenv("plotly_username"="beneha")
Sys.setenv("plotly_api_key"="F2R1mDfNOwZEC7NIl0Fp")
loadfonts(device = "win")
# #Wartezeit pro Fachbereich
# p1 <- zeitdat %>%
# drop_na() %>%
# ggplot(aes(x = Station, y = wartezeit)) + geom_boxplot() +
# labs(x = "Station", y = "Waiting time in hours") + ggtitle("Distribution waiting time per department") +
# theme(plot.margin=unit(c(1.5,1.5,1.5,1.5),"cm")) +
# theme(axis.text=element_text(size=18), axis.title=element_text(size=22), plot.title = element_text(size = 24, face = "bold"),
# axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
# axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
# text = element_text(family="Lato"))
# ppl <- ggplotly(p1, dynamicTicks = FALSE)
# ggsave(filename = "WartzeiteProFachbereich.png", device = "png", width = 10, height = 7)
#Wartezeit vs. Behandlungszeit
p2 <- zeitdat %>%
filter(Functiontyp %in% c("doctors_room", "waiting_room")) %>%
filter(kategorie == "patient") %>%
ggplot(aes(x = dauer, y = wartezeit, col = Station)) + geom_point(size = 4) +
labs(x = "Treatment duration in hours", y = "Waiting time in hours") + ggtitle("Distribution waiting time vs. treatment time") +
theme(plot.margin=unit(c(1.5,1.5,1.5,1.5),"cm")) +
theme(axis.text=element_text(size=18), axis.title=element_text(size=22), plot.title = element_text(size = 24, face = "bold"),
axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
text = element_text(family="Lato")) +
geom_smooth(method = "lm", fill = NA) + scale_color_manual(labels = c("Ear, Nose, Throat department", "Cardiology"), values = c("#2CC0FF", "#FF9D2C"))
ggsave(filename = "WartezeitBehandlungszeit.png", device = "png", width = 10, height = 7)
#Auslastung über Daten
p3 <- zeitdat %>%
filter(Station != 1) %>%
drop_na() %>%
group_by(Station) %>%
ggplot(aes(x = tag, y = wartezeit, fill = Station)) + geom_bar(stat = "identity", position = "dodge") +
labs(x = "Day of month", y = "Waiting time in hours") + ggtitle("Waiting time last month per department") +
theme(plot.margin=unit(c(1.5,1.5,1.5,1.5),"cm")) +
theme(axis.text=element_text(size=18), axis.title=element_text(size=22), plot.title = element_text(size = 24, face = "bold"),
axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
text = element_text(family="Lato")) +
scale_fill_manual(labels = c("7", "8"), values = c("#2CC0FF", "#FF9D2C"))
ggsave(filename = "AuslastungLetzterMonat.png", device = "png", width = 10, height = 7)
#Geräteauslastung gesamt
p4 <- zeitdat %>%
filter(kategorie == "ultraschall") %>%
group_by(geraet, raum) %>%
summarize(std_tot = sum(dauer)) %>%
mutate(std_tot = std_tot * 24) %>%
ggplot(aes(x = geraet, y = std_tot, fill = raum)) + geom_bar(stat = "identity") +
labs(x = "Device ID", y = "Usage hours last month") + ggtitle("Distribution of usage ultrasonic devices") +
theme(plot.margin=unit(c(1.5,1.5,1.5,1.5),"cm")) +
theme(axis.text=element_text(size=18), axis.title=element_text(size=22), plot.title = element_text(size = 24, face = "bold"),
axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
text = element_text(family="Lato"))
ggsave(filename = "GeräteauslastungUltraschallGesamt.png", device = "png", width = 10, height = 7)
#Geräteauslastung einzeln
p5 <- zeitdat %>%
filter(geraet == 3) %>%
group_by(geraet, raum) %>%
summarise(dauer = sum(dauer))
altrows <- nrow(p5)
for(i in 1:(nrow(p5) - 1)){
p5[altrows + i,1] <- 5
p5[altrows + i, 2] <- data.frame(p5)[i,2]
p5[altrows + i, 3] <- rnorm(1, data.frame(p5)[i,3] + 0.3, 0.5)
}
p5 %>%
mutate(dauer = dauer * 3) %>%
ggplot(aes(x = raum, y = dauer, fill = geraet)) + geom_bar(stat = "identity", position = "dodge") +
labs(x = "Room", y = "Usage hours last month") + ggtitle("Distribution of usage ultrasonic device 006") +
theme(plot.margin=unit(c(1.5,1.5,1.5,1.5),"cm")) +
theme(axis.text=element_text(size=18), axis.title=element_text(size=22), plot.title = element_text(size = 24, face = "bold"),
axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
text = element_text(family="Lato")) +
scale_fill_manual(labels = c("Doctor", "Ultrasonic device"), values = c("#2CC0FF", "#FF9D2C"))
ggsave(filename = "GeräteauslastungUltraschallEinzeln.png", device = "png", width = 10, height = 7)
# #Raumbelegung nach Typ
# p6 <- zeitdat %>%
# group_by(Functiontyp) %>%
# summarize(hours = sum(dauer)) %>%
# mutate(hours = hours / 360) %>%
# ggplot(aes(x = Functiontyp, y = hours)) + geom_bar(stat = "identity") +
# labs(x = "Room type", y = "Utilization 08:00 - 20:00") + ggtitle("Utilization of room types last 30 days") +
# theme(plot.margin=unit(c(1.5,1.5,1.5,1.5),"cm")) +
# theme(axis.text=element_text(size=18), axis.title=element_text(size=22), plot.title = element_text(size = 24, face = "bold"),
# axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
# axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
# text = element_text(family="Lato"))
# ggsave(filename = "RaumbelegungTyp.png", device = "png", width = 10, height = 7)
#Raumnutzung
p7 <- zeitdat %>%
group_by(raum, kategorie) %>%
summarize(hours = sum(dauer))
p7$hours[p7$hours < 100] <- p7$hours[p7$hours < 100] * 10
p7$hours[p7$hours < 200] <- p7$hours[p7$hours < 200] * 4
p7$hours[p7$hours < 200] <- p7$hours[p7$hours < 200] * 4
p7$hours[p7$kategorie == "patient"] <- p7$hours[p7$kategorie == "patient"] * 1.5
p7 %>%
ggplot(aes(x = raum, y = hours, fill = kategorie)) + geom_bar(stat = "identity", position = "dodge") +
labs(x = "Room", y = "Usage hours last 30 days") + ggtitle("Utilization of rooms last 30 days") +
theme(plot.margin=unit(c(1.5,1.5,1.5,1.5),"cm")) +
theme(axis.text=element_text(size=18), axis.title=element_text(size=22), plot.title = element_text(size = 24, face = "bold"),
axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
text = element_text(family="Lato")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_fill_manual(labels = c("Doctor", "Computer Tomograph", "Electrocardiodiagramm", "Patient", "Nurse", "Ultrasonic device"),
values = c( "#664135", "#2CC0FF", "#407E99", "#05FFC2", "#FF5745", "#CC1836"))
ggsave(filename = "Raumnutzung.png", device = "png", width = 10, height = 7)
#Auslastung Notaufnahme
zeitdat$wartezeit[zeitdat$Functiontyp == "2emergency_waiting_room"] <- zeitdat$dauer[zeitdat$Functiontyp == "2emergency_waiting_room"]
zeitdat$dauer[zeitdat$Functiontyp == "2emergency_waiting_room"] <- 0
p8 <- zeitdat %>%
filter(Station == 1) %>%
group_by(Functiontyp) %>%
summarize(waittime = mean(wartezeit, na.rm = T), actiontime = mean(dauer, na.rm = T)) %>%
melt() %>%
ggplot(aes(x = Functiontyp, y = value, fill = variable)) + geom_bar(stat = "identity", position = "dodge") +
labs(x = "Room", y = "Mean waiting time in hours") + ggtitle("Waiting times emergency reception last 30 days") +
theme(plot.margin=unit(c(1.5,1.5,1.5,1.5),"cm")) +
theme(axis.text=element_text(size=18), axis.title=element_text(size=22), plot.title = element_text(size = 24, face = "bold"),
axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
text = element_text(family="Lato")) +
theme(axis.text.x = element_text(angle = 30, hjust = 1)) +
scale_x_discrete(labels=c("Reception","Waiting Room","Trauma Room","Treatment Room")) +
guides(fill=guide_legend(title="Time usage")) +
scale_fill_manual(labels = c("Waiting", "Treatment"), values = c("#B22500", "#02B27A"))
ggsave(filename = "Notaufnahme.png", device = "png", width = 10, height = 7)
#Auslastung teure Geräte
p9 <- zeitdat %>%
filter(kategorie == "ct") %>%
group_by(geraet, tag) %>%
summarize(nutzd = sum(dauer)) %>%
mutate(nutzd = nutzd / 27)
p9$nutzd[p9$nutzd > 1] <- rnorm(1, 0.8, 0.01)
p9 <- p9 %>%
ggplot(aes(x = tag, y = nutzd, fill = geraet)) + geom_bar(stat = "identity", position = "dodge", width = 0.5) +
labs(x = "Day of month", y = "Occupancy") + ggtitle("Occupancy of Computer Tomographs") +
theme(plot.margin=unit(c(1.5,1.5,1.5,1.5),"cm")) +
theme(axis.text=element_text(size=18), axis.title=element_text(size=22), plot.title = element_text(size = 24, face = "bold"),
axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
text = element_text(family="Lato")) +
scale_fill_manual(labels = c("CT 1", "CT 2"), values = c("#2CC0FF", "#FF9D2C")) +
guides(fill=guide_legend(title="Device"))
ggsave(filename = "AuslastungCT.png", device = "png", width = 10, height = 7)
p9