├── .gitattributes ├── .streamlit └── config.toml ├── DataforMock.xlsx ├── LICENSE ├── README.md ├── handover.py ├── images └── index.png └── requirements.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.streamlit/config.toml: -------------------------------------------------------------------------------- 1 | [theme] 2 | 3 | # Font family for all text in the app, except code blocks 4 | # Accepted values (serif | sans serif | monospace) 5 | # Default: "sans serif" 6 | font = "sans serif" -------------------------------------------------------------------------------- /DataforMock.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Data-Science-at-SWAST/handover_poc/d80e19ba16ea9d5fa2f5974b2cf50055107d6d3e/DataforMock.xlsx -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 APM135 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # handover_poc 2 | Proof of Concept for Handover Reporting running from streamlit 3 | 4 | All data is dummy data. However, the feeds are designed to be quickly replicatable from SQL, Excel or any other datafeed 5 | -------------------------------------------------------------------------------- /handover.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Tue Aug 24 10:17:07 2021 4 | 5 | @author: Andi5 6 | """ 7 | import streamlit as st 8 | import time 9 | import pandas as pd 10 | import plotly.express as px 11 | import plotly.graph_objects as go 12 | 13 | 14 | st.set_page_config(page_title='SWAST - Handover Delays', layout='wide', page_icon=':ambulance:') 15 | 16 | #this is the header 17 | 18 | 19 | t1, t2 = st.columns((0.07,1)) 20 | 21 | t1.image('images/index.png', width = 120) 22 | t2.title("South Western Ambulance Service - Hospital Handover Report") 23 | t2.markdown(" **tel:** 01392 451192 **| website:** https://www.swast.nhs.uk **| email:** mailto:data.science@swast.nhs.uk") 24 | 25 | 26 | 27 | ## Data 28 | 29 | with st.spinner('Updating Report...'): 30 | 31 | #Metrics setting and rendering 32 | 33 | hosp_df = pd.read_excel('DataforMock.xlsx',sheet_name = 'Hospitals') 34 | hosp = st.selectbox('Choose Hospital', hosp_df, help = 'Filter report to show only one hospital') 35 | 36 | m1, m2, m3, m4, m5 = st.columns((1,1,1,1,1)) 37 | 38 | todf = pd.read_excel('DataforMock.xlsx',sheet_name = 'metrics') 39 | to = todf[(todf['Hospital Attended']==hosp) & (todf['Metric']== 'Total Outstanding')] 40 | ch = todf[(todf['Hospital Attended']==hosp) & (todf['Metric']== 'Current Handover Average Mins')] 41 | hl = todf[(todf['Hospital Attended']==hosp) & (todf['Metric']== 'Hours Lost to Handovers Over 15 Mins')] 42 | 43 | m1.write('') 44 | m2.metric(label ='Total Outstanding Handovers',value = int(to['Value']), delta = str(int(to['Previous']))+' Compared to 1 hour ago', delta_color = 'inverse') 45 | m3.metric(label ='Current Handover Average',value = str(int(ch['Value']))+" Mins", delta = str(int(ch['Previous']))+' Compared to 1 hour ago', delta_color = 'inverse') 46 | m4.metric(label = 'Time Lost today (Above 15 mins)',value = str(int(hl['Value']))+" Hours", delta = str(int(hl['Previous']))+' Compared to yesterday') 47 | m1.write('') 48 | 49 | # Number of Completed Handovers by Hour 50 | 51 | g1, g2, g3 = st.columns((1,1,1)) 52 | 53 | fgdf = pd.read_excel('DataforMock.xlsx',sheet_name = 'Graph') 54 | 55 | fgdf = fgdf[fgdf['Hospital Attended']==hosp] 56 | 57 | fig = px.bar(fgdf, x = 'Arrived Destination Resolved', y='Number of Handovers', template = 'seaborn') 58 | 59 | fig.update_traces(marker_color='#264653') 60 | 61 | fig.update_layout(title_text="Number of Completed Handovers by Hour",title_x=0,margin= dict(l=0,r=10,b=10,t=30), yaxis_title=None, xaxis_title=None) 62 | 63 | g1.plotly_chart(fig, use_container_width=True) 64 | 65 | # Predicted Number of Arrivals 66 | 67 | fcst = pd.read_excel('DataforMock.xlsx',sheet_name = 'Forecast') 68 | 69 | fcst = fcst[fcst['Hospital Attended']==hosp] 70 | 71 | fig = px.bar(fcst, x = 'Arrived Destination Resolved', y='y', template = 'seaborn') 72 | 73 | fig.update_traces(marker_color='#7A9E9F') 74 | 75 | fig.update_layout(title_text="Predicted Number of Arrivals",title_x=0,margin= dict(l=0,r=10,b=10,t=30), yaxis_title=None, xaxis_title=None) 76 | 77 | g2.plotly_chart(fig, use_container_width=True) 78 | 79 | # Average Completed Handover Duration by hour 80 | 81 | fig = px.bar(fgdf, x = 'Arrived Destination Resolved', y='Average Duration',color = "Average Duration", template = 'seaborn', color_continuous_scale=px.colors.diverging.Temps) 82 | 83 | fig.add_scatter(x=fgdf['Arrived Destination Resolved'], y=fgdf['Target'], mode='lines', line=dict(color="black"), name='Target') 84 | 85 | fig.update_layout(title_text="Average Completed Handover Duration by hour",title_x=0,margin= dict(l=0,r=10,b=10,t=30), yaxis_title=None, xaxis_title=None, legend=dict(orientation="h",yanchor="bottom",y=0.9,xanchor="right",x=0.99)) 86 | 87 | g3.plotly_chart(fig, use_container_width=True) 88 | 89 | # Waiting Handovers table 90 | 91 | cw1, cw2 = st.columns((2.5, 1.7)) 92 | 93 | whdf = pd.read_excel('DataforMock.xlsx',sheet_name = 'WaitingHandovers') 94 | 95 | colourcode = [] 96 | 97 | for i in range(0,9): 98 | colourcode.append(whdf['c'+str(i)].tolist()) 99 | 100 | whdf = whdf[['Hospital Attended ', 'Expected', 'Inbound ', 'Arrived ', 'Waiting', '0 - 15 Mins', '15 - 30 Mins ', '30 - 60 Mins ', '60 - 90 Mins', '90 + Mins ', 101 | ]] 102 | 103 | 104 | fig = go.Figure( 105 | data = [go.Table (columnorder = [0,1,2,3,4,5,6,7,8,9], columnwidth = [30,10,10,10,10,15,15,15,15,15], 106 | header = dict( 107 | values = list(whdf.columns), 108 | font=dict(size=12, color = 'white'), 109 | fill_color = '#264653', 110 | line_color = 'rgba(255,255,255,0.2)', 111 | align = ['left','center'], 112 | #text wrapping 113 | height=20 114 | ) 115 | , cells = dict( 116 | values = [whdf[K].tolist() for K in whdf.columns], 117 | font=dict(size=12), 118 | align = ['left','center'], 119 | fill_color = colourcode, 120 | line_color = 'rgba(255,255,255,0.2)', 121 | height=20))]) 122 | 123 | fig.update_layout(title_text="Current Waiting Handovers",title_font_color = '#264653',title_x=0,margin= dict(l=0,r=10,b=10,t=30), height=480) 124 | 125 | cw1.plotly_chart(fig, use_container_width=True) 126 | 127 | # Current Waiting Table 128 | 129 | cwdf = pd.read_excel('DataforMock.xlsx',sheet_name = 'CurrentWaitingCallsigns') 130 | 131 | if hosp == 'All': 132 | cwdf = cwdf 133 | elif hosp != 'All': 134 | cwdf = cwdf[cwdf['Hospital Attended']==hosp] 135 | 136 | 137 | fig = go.Figure( 138 | data = [go.Table (columnorder = [0,1,2,3], columnwidth = [15,40,20,20], 139 | header = dict( 140 | values = list(cwdf.columns), 141 | font=dict(size=12, color = 'white'), 142 | fill_color = '#264653', 143 | align = 'left', 144 | height=20 145 | ) 146 | , cells = dict( 147 | values = [cwdf[K].tolist() for K in cwdf.columns], 148 | font=dict(size=12), 149 | align = 'left', 150 | fill_color='#F0F2F6', 151 | height=20))]) 152 | 153 | fig.update_layout(title_text="Current Waiting Callsigns",title_font_color = '#264653',title_x=0,margin= dict(l=0,r=10,b=10,t=30), height=480) 154 | 155 | cw2.plotly_chart(fig, use_container_width=True) 156 | 157 | with st.spinner('Report updated!'): 158 | time.sleep(1) 159 | 160 | # Performance Section 161 | 162 | with st.expander("Previous Performance"): 163 | 164 | hhc24 = pd.read_excel('DataforMock.xlsx',sheet_name = 'HospitalHandoversCompleted') 165 | 166 | colourcode = [] 167 | 168 | for i in range(0,13): 169 | colourcode.append(hhc24['c'+str(i)].tolist()) 170 | 171 | hhc24 = hhc24[['Hospital Attended','Handovers','In Progress','Average','Hours Lost','0 to 15 mins','15 to 30 mins','30 to 60 mins','60 to 90 mins','90 to 120 mins','120 mins','% 15 Mins','% 30 Mins']] 172 | 173 | fig = go.Figure( 174 | data = [go.Table (columnorder = [0,1,2,3,4,5,6,7,8,9,10,11,12], columnwidth = [18,12], 175 | header = dict( 176 | values = list(hhc24.columns), 177 | font=dict(size=11, color = 'white'), 178 | fill_color = '#264653', 179 | line_color = 'rgba(255,255,255,0.2)', 180 | align = ['left','center'], 181 | #text wrapping 182 | height=20 183 | ) 184 | , cells = dict( 185 | values = [hhc24[K].tolist() for K in hhc24.columns], 186 | font=dict(size=10), 187 | align = ['left','center'], 188 | fill_color = colourcode, 189 | line_color = 'rgba(255,255,255,0.2)', 190 | height=20))]) 191 | 192 | fig.update_layout(title_text="Hospital Handovers Completed in the Past 24 Hours",title_font_color = '#264653',title_x=0,margin= dict(l=0,r=10,b=10,t=30), height=400) 193 | 194 | st.plotly_chart(fig, use_container_width=True) 195 | 196 | p1,p2 = st.columns((3, 1.7)) 197 | 198 | # Current Waiting Handovers 199 | 200 | hhc = pd.read_excel('DataforMock.xlsx',sheet_name = 'HospitalHandoverCompletedByHour') 201 | 202 | hhc = hhc[hhc['Hospital Attended']==hosp] 203 | 204 | colourcode = [] 205 | 206 | for i in range(0,13): 207 | colourcode.append(hhc['c'+str(i)].tolist()) 208 | 209 | hhc = hhc[['dst','Handovers','In Progress','Average','Hours Lost','0 to 15 mins','15 to 30 mins','30 to 60 mins','60 to 90 mins','90 to 120 mins','120 mins','% 15 Mins','% 30 Mins']] 210 | 211 | fig = go.Figure( 212 | data = [go.Table (columnorder = [0,1,2,3,4,5,6,7,8,9,10,11,12], columnwidth = [18,12], 213 | header = dict( 214 | values = list(hhc.columns), 215 | font=dict(size=11, color = 'white'), 216 | fill_color = '#264653', 217 | line_color = 'rgba(255,255,255,0.2)', 218 | align = ['left','center'], 219 | #text wrapping 220 | height=20 221 | ) 222 | , cells = dict( 223 | values = [hhc[K].tolist() for K in hhc.columns], 224 | font=dict(size=10), 225 | align = ['left','center'], 226 | fill_color = colourcode, 227 | line_color = 'rgba(255,255,255,0.2)', 228 | height=20))]) 229 | 230 | fig.update_layout(title_text="Hospital Handovers Completed by Hour",title_font_color = '#264653',title_x=0,margin= dict(l=0,r=10,b=10,t=30), height=600) 231 | 232 | p1.plotly_chart(fig, use_container_width=True) 233 | 234 | 235 | # Longest Completed Handovers 236 | 237 | lch = pd.read_excel('DataforMock.xlsx',sheet_name = 'LongestCompletedHandover') 238 | 239 | if hosp == 'All': 240 | lch = lch 241 | elif hosp != 'All': 242 | lch = lch[lch['Hospital Attended']==hosp] 243 | 244 | fig = go.Figure( 245 | data = [go.Table (columnorder = [0,1,2,3,4], columnwidth = [10,35,20,20,10], 246 | header = dict( 247 | values = list(lch.columns), 248 | font=dict(size=12, color = 'white'), 249 | fill_color = '#264653', 250 | align = 'left', 251 | height=20 252 | ) 253 | , cells = dict( 254 | values = [lch[K].tolist() for K in lch.columns], 255 | font=dict(size=11), 256 | align = 'left', 257 | fill_color='#F0F2F6', 258 | height=20))]) 259 | 260 | fig.update_layout(title_text="Longest Completed Handovers",title_font_color = '#264653',title_x=0,margin= dict(l=0,r=10,b=10,t=30), height=600) 261 | 262 | p2.plotly_chart(fig, use_container_width=True) 263 | 264 | 265 | # Contact Form 266 | 267 | with st.expander("Contact us"): 268 | with st.form(key='contact', clear_on_submit=True): 269 | 270 | email = st.text_input('Contact Email') 271 | st.text_area("Query","Please fill in all the information or we may not be able to process your request") 272 | 273 | submit_button = st.form_submit_button(label='Send Information') 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | -------------------------------------------------------------------------------- /images/index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Data-Science-at-SWAST/handover_poc/d80e19ba16ea9d5fa2f5974b2cf50055107d6d3e/images/index.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit 2 | pandas 3 | plotly 4 | openpyxl 5 | --------------------------------------------------------------------------------