-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXAM-app.qmd
489 lines (395 loc) · 18.8 KB
/
EXAM-app.qmd
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
---
title: "EXAM: Ex-vivo allograft monitoring"
author: "v1.2"
logo: images/SWT_icon_cmyk2020.dashboard.png
format:
dashboard:
nav-buttons:
- icon: github
href: https://github.com/Swisstransplant/EXAM
link-external-icon: false
link-external-newwindow: true
# link-external-filter: '^(?:http:|https:)\/\/www\.quarto\.org\/custom'
theme:
- swt_dashboard.scss
fontsize: 0.95em
linestretch: 1.2
server: shiny
include-in-header:
text: |
<link rel="icon" type="image/png" href="./images/Kreis_Niere_196x196.png">
---
```{r}
#| context: setup
#| warning: false
#| message: false
library(fs) # MIT
library(shiny) # GPL-3
suppressPackageStartupMessages(library(plotly)) # MIT
library(swt) # GPL-3
# Quarto MIT
# SWT colors
col = swt_colors()
# load internal example data from package swt
data("exam-examples")
# load swt data instead and overwrite example variables
# PATH_DATA = file.path(path_home(), "OneDrive - Swisstransplant", "Projects", "EXAM", "data")
# load(file.path(PATH_DATA, "exam.RData"))
#
# exam.device = data.device
# exam.organ = data.organ
# exam.sumstats = data.sumstats
# exam.timeseries = data.timeseries
# helper functions for plotly
hline <- function(y = 0, color = "grey", type="dash") {
list(
type = "line",
x0 = 0,
x1 = 1,
xref = "paper",
y0 = y,
y1 = y,
line = list(color = color, dash=type)
)
}
vline <- function(x = 0, color = "grey", type="dash") {
list(
type = "line",
y0 = 0,
y1 = 1,
yref = "paper",
x0 = x,
x1 = x,
line = list(color = color, dash=type)
)
}
```
# {.sidebar}
```{r}
selectInput(inputId = "ID", label = "Select example dataset:",
choices = sort(exam.organ$ID, decreasing = TRUE))
fileInput(inputId = "file1", label = "Upload LifePort data file:",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
```
::: {.callout-warning collapse="false"}
## Important
Hypothermic machine perfusion data alone should never be used as the sole basis to discard a kidney allograft.
:::
---
::: {.callout-note collapse="true"}
## Terms of use
EXAM: Ex-vivo allograft monitoring
Copyright (C) 2023, 2024 Swisstransplant
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html) for more details.
:::
# Kidney LifePort Dashboard
## Row {height="13%"}
```{r}
#| title: Organ and Device Information
tableOutput('Tab_info')
```
## Row {.flow height="37%"}
::: {.card title="Pressure" padding="16px"}
```{r}
plotlyOutput('Fig1', height = "300px")
tableOutput('Tab1')
```
:::
::: {.card title="Flow Rate"}
```{r}
plotlyOutput('Fig2', height = "300px")
tableOutput('Tab2')
```
:::
## Row {height="37%"}
::: {.card title="Vascular Resistance"}
```{r}
plotlyOutput('Fig3', height = "300px")
tableOutput('Tab3')
```
:::
::: {.card title="Temperature"}
```{r}
plotlyOutput('Fig4', height = "300px")
tableOutput('Tab4')
```
:::
## Row {height="13%"}
```{r}
#| title: Quality Control
tableOutput('Tab_qual')
```
# Indicators
| Class | Indicator | Meaning | Unit |
|------------------------|:------------|:-------------------------|:----------------|
| Perfusion indicators | $md_{sys}$ | median systolic pressure | mmHg |
| | $m_{dia}$ | mean diastolic pressure | mmHg |
| | $m_{flow}$ | mean flow rate | ml/min |
| | $m_{res}$ | mean vascular resistance | mmHg/ml/min |
| | $SD_{res}$ | standard deviation of vascular resistance | mmHg/ml/min |
| | $\Delta_{res}$ | drop in vascular resistance within the first 60 min | mmHg/ml/min |
| | $\beta_{res}$ | drop in vascular resistance per Minute | mmHg/ml/min$^2$ |
| Temperature indicators | $m_{ice}$ | mean ice temperature | $\textdegree$C |
| | $SD_{ice}$ | standard deviation of ice temperature | $\textdegree$C |
| | $\Delta t_{ice>2.5}$ | time duration ice temperature is above 2.5$\textdegree$C | MM:HH:SS |
| | $y_{\text{start}}$ | perfusate temperature at start | $\textdegree$C |
| | $m_{perf}$ | mean perfusate temperature | $\textdegree$C |
| | $SD_{perf}$ | standard deviation of perfusate temperature | $\textdegree$C |
| | $\Delta t_{perf>10}$ | time duration perfusate temperature is above 10$\textdegree$C | MM:HH:SS |
| Quality control | $D^2_{perf}$ | Distance of the case from other cases with respect to perfusion indicators (a lower score is better). It can be seen as the deviation from the norm. | *unitless* |
| | $P_{perf}$ | Percentile rank of $D^2_{perf}$. For example, a score of 0.90 means that 90% of the cases had a better result (thus, a lower score is better). | % |
| | $D^2_{temp}$ | Distance of the case from other cases with respect to temperature indicators (a lower score is better). It can be seen as the deviation from the norm. | *unitless* |
| | $P_{temp}$ | Percentile rank of $D^2_{temp}$. For example, a score of 0.90 means that 90% of the cases had a better result (thus, a lower score is better). | % |
# About
::: {.card}
## What is EXAM?
EXAM is an analytics dashboard for HMP data in deceased-donor kidney transplantation and supports data from the [ORS LifePort Kidney Transporter](https://www.organ-recovery.com/lifeport-kidney-transporter/). EXAM was designed for retrospective analysis of hypothermic machine perfusion (HMP) data for quality control to help identify problems and enable interventions to improve and optimize kidney machine perfusion.
EXAM is free software written in the R programming language that statisticians and data scientists can quickly deploy to enable quality control at transplant organizations that use LifePort kidney transporters.
## Who created EXAM?
EXAM was developed by [Swisstransplant](https://www.swisstransplant.org/) and the transplant centers. Further information can be found in the reference below.
## What is the added value of using EXAM?
Quality control with EXAM can identify problems during HMP and inform guidelines, checklists, and training for healthcare providers. This can all lead to optimizing the intervention for the benefit of the kidney allograft and the transplant candidate.
## Contact
For inquiries about EXAM, please get in touch with Simon Schwab <simon.schwab@swisstransplant.org>.
## Reference
Schwab S, Steck H, Binet I, Elmer A, Ender W, Franscini N, Haidar F, Kuhn C, Sidler D, Storni F, Krügel N, Immer F. EXAM: Ex vivo allograft monitoring dashboard for the analysis of hypothermic machine perfusion data in deceased-donor kidney transplantation. *Research Square*. 2023. [doi:10.21203/rs.3.rs-2713168/v1](http://dx.doi.org/10.21203/rs.3.rs-2713168/v1)
::: {{layout-ncol=4}}
![Surus](images/SWT_2955_2021.png){height=80 style="float:left; padding:16px"}
![Surus](images/HUG.png){height=80 style="float:left; padding:16px"}
![Surus](images/Insel.png){height=80 style="float:left; padding:16px"}
![Surus](images/KSSG.png){height=80 style="padding:16px"}
:::
:::
```{r}
#| context: server
# I need reactive value because the dataset can either be from
# 1) the internal data or
# 2) the file upload
dataset = reactiveVal()
# 1) select dataset from internal example data from package swt
observeEvent(input$ID, {
i = which(exam.organ$ID == input$ID)
# I create a data list from the internal data
dataset(list(data.device = exam.device[i,],
data.organ = exam.organ[i,],
data = exam.timeseries[[i]],
data.sumstats = exam.sumstats[i,]))
})
# 2) read data from file upload
observeEvent(input$file1, {
# read data, processing and sumstats
# error handling when damaged lifeport data file is uploaded
lp_data = tryCatch({
lp_data = lifeport_read(file = input$file1$datapath, format = "guess")
lp_data = lifeport_process(lp_data)
lp_data = lifeport_sumstats(lp_data)
lp_data$data.organ$ID = gsub("\\.txt$|\\.TXT$", "", basename(input$file1$name))
# Calculate quality indicator
# subset variables: 7 dimensions
tmp.perf = subset(lp_data$data.sumstats, select = c("systolicPressure.md",
"diastolicPressure.mean",
"flowRate.mean",
"organResistance.mean",
"organResistance.sd",
"organResistance.delta",
"organResistance.slope"))
tmp.temp = subset(lp_data$data.sumstats, select = c("iceContainerTemperature.mean",
"iceContainerTemperature.sd",
"iceContainerTemperature.minAbove",
"infuseTemperature.start",
"infuseTemperature.mean",
"infuseTemperature.sd",
"infuseTemperature.minAbove"))
# calculate for all datasets, if missing data D2 will be NA
lp_data$data.sumstats$D2perf = lifeport_d2(data = tmp.perf, type = "perf")
lp_data$data.sumstats$D2temp = lifeport_d2(data = tmp.temp, type = "temp")
lp_data$data.sumstats$Pperf = lifeport_d2toRank(lp_data$data.sumstats$D2perf, type = "perf")
lp_data$data.sumstats$Ptemp = lifeport_d2toRank(lp_data$data.sumstats$D2temp, type = "temp")
dataset(lp_data)
}, error = function(e) {
showModal(modalDialog(
title = "Error reading file",
"The file does not contain valid LifePort data. Maybe you selected the wrong file or the file has been damaged.",
easyClose = FALSE
))
})
})
# Figure 1: Pressure Chart
output$Fig1 <- renderPlotly({
lst = dataset() # data is a list
# converting from wide to long
d = data.frame(pressure = c(lst$data$SystolicPressure.flt,
lst$data$DiastolicPressure.flt),
time.clock = c(lst$data$time.clock,
lst$data$time.clock),
group = c(rep("systolic pressure", nrow(lst$data)),
rep("diastolic pressure", nrow(lst$data))))
d$group = factor(d$group, levels = c("systolic pressure", "diastolic pressure"))
# figure
fig = plot_ly(d, x=~time.clock, y=~pressure, type="scatter", mode="lines",
color=~group, colors = c(col$blue.swt, col$darkyellow.kidney))
fig = fig %>% layout(yaxis = list(title = "mmHg", range = c(0, 45)),
xaxis = list(title = "Time"),
legend = list(orientation = 'h', yanchor = "bottom",
y = 1.02, x = 1, xanchor = "right"),
shapes = list(hline(30))
)
})
# Figure 2: Flow Rate Chart
output$Fig2 <- renderPlotly({
lst = dataset() # data is a list
d = lst$data
# handle timeseries shorter than 30 min.
if(length(d$time.clock) >= 181) {
tgreyend = d$time.clock[181]
} else {
tgreyend = d$time.clock[length(d$time.clock)]
}
# figure
fig = plot_ly(d, x=~time.clock, y=~FlowRate.flt, type="scatter", mode="lines",
color="all", colors = col$blue.swt)
fig = fig %>% layout(yaxis = list(title = "ml/min", range = c(0, 200)),
xaxis = list(title = "Time"),
shapes = list(hline(85),
list(type = "rect", fillcolor = "grey",
line = list(color = "grey"), opacity = 0.3,
x0 = d$time.clock[1], x1 = tgreyend, xref = "x",
y0 = 0, y1 = 200, yref = "y")
)
)
})
# Figure 3: Flow Rate Chart
output$Fig3 <- renderPlotly({
lst = dataset() # data is a list
d = lst$data
s = lst$data.sumstats
# handle timeseries shorter than 30 min.
if(length(d$time.clock) >= 181) {
tgreyend = d$time.clock[181]
} else {
tgreyend = d$time.clock[length(d$time.clock)]
}
# figure
fig = plot_ly(d, x=~time.clock, y=~OrganResistance.flt, type="scatter", mode="lines",
color="all", colors = col$blue.swt, name = "vascular resistance")
fig = fig %>% add_trace(x = c(d$time.clock[s$organResistance.x1],
d$time.clock[s$organResistance.x2]),
y = c(s$organResistance.y1, s$organResistance.y2),
mode = "markers+lines", color = I(col$strongred.akzent), name = "slope")
fig = fig %>% layout(yaxis = list(title = "mmHg/ml/min", range = c(0, 0.5)),
xaxis = list(title = "Time"),
legend = list(orientation = 'h', yanchor = "bottom",
y = 1.02, x = 1, xanchor = "right"),
shapes = list(hline(0.10),
hline(0.30),
list(type = "rect", fillcolor = "grey",
line = list(color = "grey"), opacity = 0.3,
x0 = d$time.clock[1], x1 = tgreyend, xref = "x",
y0 = 0, y1 = 0.5, yref = "y")
)
)
})
# Figure 4: Temperature Chart
output$Fig4 <- renderPlotly({
HIGH_INF_TEMP = 10
HIGH_ICE_TEMP = 2.5
lst = dataset() # data is a list
# prepare time series of ice and perf temp too high
is_high_perf = lst$data$InfuseTemperature > HIGH_INF_TEMP &
lst$data$FlowRate.flt > 5 & !is.na(lst$data$FlowRate.flt)
high_perf = lst$data$InfuseTemperature
high_perf[!is_high_perf] = NA
is_high_ice = lst$data$IceContainerTemperature > HIGH_ICE_TEMP
high_ice = lst$data$IceContainerTemperature
high_ice[!is_high_ice] = NA
# converting from wide to long
d = data.frame(temperature = c(lst$data$IceContainerTemperature,
lst$data$InfuseTemperature,
high_perf,
high_ice),
time.clock = rep(lst$data$time.clock, 4),
group = c(rep("ice temperature", nrow(lst$data)),
rep("perfusate temperature", nrow(lst$data)),
rep("high temperature", nrow(lst$data)),
rep("high temperature", nrow(lst$data))
))
d$group = factor(d$group, levels = c("ice temperature",
"perfusate temperature",
"high temperature"))
# figure
fig = plot_ly(d, x=~time.clock, y=~temperature, type="scatter", mode="lines",
color=~group, colors = c(col$blue.swt,
col$darkyellow.kidney,
col$strongred.akzent))
fig = fig %>% layout(yaxis = list(title = "Degrees Celsius", range = c(0, 20)),
xaxis = list(title = "Time"),
legend = list(orientation = 'h', yanchor = "bottom",
y = 1.02, x = 1, xanchor = "right"),
shapes = list(hline(5), hline(10))
)
})
# Info table
output$Tab_info <- renderTable({
lst = dataset()
tab = cbind(lst$data.organ[, "ID"],
lst$data.device[, c("SerialNumber", "UnitID", "StartTime",
"StopTime", "Runtime")],
lst$data.sumstats[, "perfusion.dur.str"]
)
colnames(tab) = c("File ID", "Serial no.", "Unit ID",
"Start time", "Stop time", "Run time", "Perfusion time")
tab
})
# Tables with Summary statistics
output$Tab1 <- renderTable({
lst = dataset()
tab = lst$data.sumstats[, c("systolicPressure.md", "diastolicPressure.mean")]
colnames(tab) = c("<i>md</i><sub>sys</sub>", "<i>m</i><sub>dia</sub>")
tab
}, sanitize.text.function = function(x) x) # needed for formatting special characters
output$Tab2 <- renderTable({
lst = dataset()
tab = lst$data.sumstats[, "flowRate.mean", drop = FALSE]
colnames(tab) = c("<i>m</i><sub>flow</sub>")
tab
}, sanitize.text.function = function(x) x) # needed for formatting special characters
output$Tab3 <- renderTable({
lst = dataset()
tab = lst$data.sumstats[, c("organResistance.mean", "organResistance.sd",
"organResistance.delta","organResistance.slope"), drop = FALSE]
colnames(tab) = c("<i>m</i><sub>res</sub>", "<i>SD</i><sub>res</sub>",
"<i>Δ</i><sub>res</sub>", "<i>β</i><sub>res</sub>")
tab
}, sanitize.text.function = function(x) x) # needed for formatting special characters
output$Tab4 <- renderTable({
lst = dataset()
tab = lst$data.sumstats[, c("iceContainerTemperature.mean","iceContainerTemperature.sd",
"iceContainerTemperature.minAbove.str", "infuseTemperature.start",
"infuseTemperature.mean", "infuseTemperature.sd",
"infuseTemperature.minAbove.str")]
colnames(tab) = c("<i>m</i><sub>ice</sub>", "<i>SD</i><sub>ice</sub>",
"<i>Δt</i><sub>y>2.5</sub>", "<i>y</i><sub>start</sub>",
"<i>m</i><sub>perf</sub>", "<i>SD</i><sub>perf</sub>",
"<i>Δt</i><sub>y>10</sub>")
tab
}, sanitize.text.function = function(x) x) # needed for formatting special characters
# Table Quality Control
output$Tab_qual <- renderTable({
lst = dataset()
tab = cbind(
lst$data.organ[, c("OrganID", "KidneySide")],
lst$data.sumstats[, c("D2perf", "Pperf", "D2temp", "Ptemp")]
)
tab$Pperf = sprintf("%.0f%%", tab$Pperf*100)
tab$Ptemp = sprintf("%.0f%%", tab$Ptemp*100)
colnames(tab) = c("Organ ID entry", "Kidney side entry",
"<i>D</i><sup>2</sup><sub>perf</sub>",
"<i>P</i><sub>perf</sub>",
"<i>D</i><sup>2</sup><sub>temp</sub>",
"<i>P</i><sub>temp</sub>")
tab
}, sanitize.text.function = function(x) x) # needed for formatting special characters
```