-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFICM Logbook Summary.py
301 lines (248 loc) · 11.3 KB
/
FICM Logbook Summary.py
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# !/usr/bin/env python
# coding: utf-8
# # FICM Logbook Summary Report
# Creates a FICM Logbook Summary Report
# from an Anaesthetics LLP Logbook excel export
# Import Libararies
import pandas as pd
# User Defined Variables
name = 'Mark Jeffrey'
logbook = 'my logbook.xlsx'
start_date = '2018-8-1'
end_date = '2021-2-7'
# Define functions
def get_event_local(str): # counts no of 'str' under local supervision
return len(icu_log_local[icu_log_local['Event'].str.contains(str)])
def get_event_distant(str): # counts no of 'str' under distant supervision
return len(icu_log_distant[icu_log_distant['Event'].str.contains(str)])
def get_event_total(str): # counts total no of 'str'
return len(icu_log[icu_log['Event'].str.contains(str)])
def get_procedures_total(str): # counts total no of 'str'
return len(procedures_all[procedures_all['Procedure Type'] == str])
def get_procedures_local(str): # counts no of 'str' under local supervision
return len(procedures_all_local[
procedures_all_local['Procedure Type'] == str])
def get_procedures_distant(str): # counts no of str under distant supervision
return len(procedures_all_distant[
procedures_all_distant['Procedure Type'] == str])
# Import each sheet into a DataFrame
# Set Case ID as Index
# Change 'Date' to Datetime
# Filter by dates
anaesthetic_log = pd.read_excel(logbook, sheet_name='LOGBOOK_CASE_ANAESTHETIC', index_col=0)
anaesthetic_log['Date'] = pd.to_datetime(anaesthetic_log['Date'], format="%d %B %Y")
anaesthetic_log = anaesthetic_log[(anaesthetic_log['Date'] > start_date) & (anaesthetic_log['Date'] < end_date)]
procedure_log = pd.read_excel(logbook, sheet_name='LOGBOOK_STAND_ALONE_PROCEDURE',index_col=0)
procedure_log['Date'] = pd.to_datetime(procedure_log['Date'], format="%d %B %Y")
procedure_log = procedure_log[(procedure_log['Date'] > start_date) & (procedure_log['Date'] < end_date)]
session_log = pd.read_excel(logbook, sheet_name='LOGBOOK_SESSION',index_col=0)
session_log['Date'] = pd.to_datetime(session_log['Date'], format="%d %B %Y")
session_log = session_log[(session_log['Date'] > start_date) & (session_log['Date'] < end_date)]
icu_log = pd.read_excel(logbook, sheet_name='LOGBOOK_CASE_INTENSIVE',index_col=0)
icu_log['Date'] = pd.to_datetime(icu_log['Date'], format="%d %B %Y")
icu_log = icu_log[(icu_log['Date'] > start_date) & (icu_log['Date'] < end_date)]
# Divide DataFrame by levels of supervision
# local = immediate and local
# distant = distant and solo
icu_log_local = icu_log[(icu_log['Supervision'] == 'Immediate') | (
icu_log['Supervision'] == 'Local')]
icu_log_distant = icu_log[(icu_log['Supervision'] == 'Distant') | (
icu_log['Supervision'] == 'Solo')]
# Data for events table
event_local = [
get_event_local('ward-review'),
get_event_local('admission'),
get_event_local('lead-ward-round'),
get_event_local('cardiac-arrest'),
get_event_local('trauma-team'),
get_event_local('intra-hospital-transfer'),
get_event_local('inter-hospital-transfer'),
get_event_local('discussion-with-relatives'),
get_event_local('end-of-life-care')
]
event_distant = [
get_event_distant('ward-review'),
get_event_distant('admission'),
get_event_distant('lead-ward-round'),
get_event_distant('cardiac-arrest'),
get_event_distant('trauma-team'),
get_event_distant('intra-hospital-transfer'),
get_event_distant('inter-hospital-transfer'),
get_event_distant('discussion-with-relatives'),
get_event_distant('end-of-life-care')
]
event_total = [
get_event_total('ward-review'),
get_event_total('admission'),
get_event_total('lead-ward-round'),
get_event_total('cardiac-arrest'),
get_event_total('trauma-team'),
get_event_total('intra-hospital-transfer'),
get_event_total('inter-hospital-transfer'),
get_event_total('discussion-with-relatives'),
get_event_total('end-of-life-care')
]
# Create Events table
Events = pd.DataFrame(
data=[event_local, event_distant, event_total],
index=['Local Supervision', 'Distant Supervision', 'Total'],
columns=['Ward review', 'Admission', 'Lead ward round', 'Cardiac arrest',
'Trauma team', 'Intra-hospital transfer',
'Inter-hosptial transfer', 'Discussion with relatives',
'End of life care/donation']
)
# Format events table
Events = Events.T
Events.index.names = ['Events']
# Procedures Table
# Procedures Multi-index
outside = [
'Airways and Lungs', 'Airways and Lungs', 'Airways and Lungs',
'Airways and Lungs', 'Airways and Lungs', 'Airways and Lungs',
'Cardiovascular', 'Cardiovascular', 'Cardiovascular', 'Cardiovascular',
'Cardiovascular', 'Cardiovascular', 'Cardiovascular',
'Abdomen', 'Abdomen', 'Abdomen',
'CNS', 'CNS'
]
inside = [
'Emergency Intubation',
'Percutaneous Tracheostomy',
'Bronchoscopy',
'Chest Drain - Seldinger',
'Chest Drain - Surgical',
'Lung Ultrasound',
'Arterial cannulation',
'Central venous access – IJ',
'Central venous access – SC',
'Central venous access – Femoral',
'Pulmonary artery catheter',
'Non-invasive CO monitoring',
'Echocardiogram',
'Ascitic drain/tap',
'Sengstaken tube placement',
'Abdominal ultrasound/FAST',
'Lumbar puncture',
'Brainstem death testing'
]
hier_index = list(zip(outside, inside))
hier_index = pd.MultiIndex.from_tuples(hier_index)
# Creates table for each procedure column with supervision
# Removes rows with missing entries
# Renames columns to "Procedure Type" and "Supervision"
anaesthetic_procedure_log = procedure_log[
['Procedure Type (Anaesthesia)', 'Supervision']].dropna().rename(
columns={"Procedure Type (Anaesthesia)": "Procedure Type"})
medicine_procedure_log = procedure_log[
['Procedure Type (Medicine)', 'Supervision']].dropna().rename(
columns={"Procedure Type (Medicine)": "Procedure Type"})
pain_procedure_log = procedure_log[
['Procedure Type (Pain)', 'Supervision']].dropna().rename(
columns={"Procedure Type (Pain)": "Procedure Type"})
anaesthetic_sheet_procedure_log = anaesthetic_log[
['Procedure Type', 'Procedure Supervision']].dropna().rename(
columns={"Procedure Supervision": "Supervision"})
# Contatencates above into a single table with 2 columns
# "Procedure Type" and "Supervision"
procedures_all = pd.concat([
anaesthetic_procedure_log,
medicine_procedure_log,
pain_procedure_log,
anaesthetic_sheet_procedure_log]
)
# Makes Supervision column all lower case to avoid duplication
procedures_all['Supervision'] = procedures_all['Supervision'].str.lower()
# Subdivides all procedures by level of supervision
procedures_all_local = procedures_all[
(procedures_all['Supervision'] == 'supervised') | (
procedures_all['Supervision'] == 'observed')]
procedures_all_distant = procedures_all[
procedures_all['Supervision'] == 'solo']
# Data for Procedures table
procedures_total = [
len(procedures_all[(
procedures_all['Procedure Type'] == 'rsi') | (
procedures_all['Procedure Type'] == 'emergency-intubation') | (
procedures_all['Procedure Type'] == 'airway-protection')]),
get_procedures_total('percutaneous-tracheostomy'),
get_procedures_total('bronchoscopy'),
get_procedures_total('intercostal-drain:seldinger'),
get_procedures_total('intercostal-drain:open'),
get_procedures_total('lung-ultrasound'),
get_procedures_total('arterial-cannulation'),
get_procedures_total('central-venous-access–internal-jugular'),
get_procedures_total('central-venous-access–subclavian'),
get_procedures_total('central-venous-access–femoral'),
get_procedures_total('pulmonary-artery-catheter'),
get_procedures_total('non-invasive-co-monitoring'),
get_procedures_total('echocardiogram'),
len(procedures_all[(
procedures_all['Procedure Type'] == 'ascitic-tap') | (
procedures_all['Procedure Type'] == 'abdominal-paracentesis')]),
get_procedures_total('sengstacken-tube-placement'),
get_procedures_total('abdominal-ultrasound/fast'),
get_procedures_total('lumbar-puncture'),
get_procedures_total('brainstem-death-testing')
]
procedures_total_local = [
len(procedures_all_local[(
procedures_all_local['Procedure Type'] == 'rsi') | (
procedures_all_local['Procedure Type'] == 'emergency-intubation') | (
procedures_all_local['Procedure Type'] == 'airway-protection')]),
get_procedures_local('percutaneous-tracheostomy'),
get_procedures_local('bronchoscopy'),
get_procedures_local('intercostal-drain:seldinger'),
get_procedures_local('intercostal-drain:open'),
get_procedures_local('lung-ultrasound'),
get_procedures_local('arterial-cannulation'),
get_procedures_local('central-venous-access–internal-jugular'),
get_procedures_local('central-venous-access–subclavian'),
get_procedures_local('central-venous-access–femoral'),
get_procedures_local('pulmonary-artery-catheter'),
get_procedures_local('non-invasive-co-monitoring'),
get_procedures_local('echocardiogram'),
len(procedures_all_local[(
procedures_all_local['Procedure Type'] == 'ascitic-tap') | (
procedures_all_local['Procedure Type'] == 'abdominal-paracentesis')]),
get_procedures_local('sengstacken-tube-placement'),
get_procedures_local('abdominal-ultrasound/fast'),
get_procedures_local('lumbar-puncture'),
get_procedures_local('brainstem-death-testing')
]
procedures_total_distant = [
len(procedures_all_distant[(
procedures_all_distant['Procedure Type'] == 'rsi') | (
procedures_all_distant['Procedure Type'] == 'emergency-intubation') | (
procedures_all_distant['Procedure Type'] == 'airway-protection')]),
get_procedures_distant('percutaneous-tracheostomy'),
get_procedures_distant('bronchoscopy'),
get_procedures_distant('intercostal-drain:seldinger'),
get_procedures_distant('intercostal-drain:open'),
get_procedures_distant('lung-ultrasound'),
get_procedures_distant('arterial-cannulation'),
get_procedures_distant('central-venous-access–internal-jugular'),
get_procedures_distant('central-venous-access–subclavian'),
get_procedures_distant('central-venous-access–femoral'),
get_procedures_distant('pulmonary-artery-catheter'),
get_procedures_distant('non-invasive-co-monitoring'),
get_procedures_distant('echocardiogram'),
len(procedures_all_distant[(
procedures_all_distant['Procedure Type'] == 'ascitic-tap') | (
procedures_all_distant['Procedure Type'] == 'abdominal-paracentesis')]),
get_procedures_distant('sengstacken-tube-placement'),
get_procedures_distant('abdominal-ultrasound/fast'),
get_procedures_distant('lumbar-puncture'),
get_procedures_distant('brainstem-death-testing')
]
# Procedures Table
Procedures = pd.DataFrame(
data=[procedures_total_local, procedures_total_distant, procedures_total],
index=['Local Supervision', 'Distant Supervision', 'Total'],
columns=hier_index
)
# Format procedures table
Procedures = Procedures.T
Procedures.index.names = (['System', 'Procedure'])
# Export to Excel
with pd.ExcelWriter(f"{name} FICM Logbook Summary {start_date} to {end_date}.xlsx") as writer:
Events.to_excel(writer, sheet_name='Events')
Procedures.to_excel(writer, sheet_name='Procedures')