How to count "active" cases using bupaR?

37 Views Asked by At

I'd like to count the number of patients simultaneaously present in the hospital, using bupaR. For this problem, I'll be using the patients eventlog.

One can calculate a throughput time for the whole process

library(bupaverse)
library(tidyverse)

patients %>% throughput_time(level = "log")

But is it possible to count the number of cases simultaneously present for the whole expected trace (from start of Registration to end of Chek-out) or during one or a group of activities ?

I think I can do something similar using the data.table package :

library(data.table)
df = patients %>%
  group_by(patient) %>%
  summarise(In = time[handling == "Registration" & registration_type == "start"],
            Out = time[handling == "Check-out" & registration_type == "complete"]
  ) %>%
  as.data.table  %>%
  setkey(In, Out)


DatesList <- tibble(In = seq.Date( min(patients$time) %>% as_date(),
                                   max(patients$time) %>% as_date(), by= "day"), 
                    Out = In + days(1)) %>% 
  mutate(across(everything(), ~as.POSIXct(.x, , tz = "UTC"))) %>%
  setDT()


patients.present = foverlaps(DatesList, df, type="any") %>%
  .[, .(N = .N), by = "i.In"] 

stats.patients.present = patients.present$N %>% summary
stats.patients.present

patients.median = stats.patients.present %>% .[3]

patients.present %>% 
  ggplot(aes(i.In, N)) + 
  geom_line(size = 1) +
  geom_hline(yintercept = patients.median, color = "red")

Can someone tell me if the bupaverse is able to achieve this ?

Thanks a lot for your help !

0

There are 0 best solutions below