knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
How many patients were in the hospital at 10 AM yesterday?
How many were in during each 15 minute spell between 2pm and 6pm?
How many were in during the last week, by hour?
This package aims to make answering these questions easier and quicker.
No SQL? No problem!
If you have time in, time out, a unique patient identifier, and optionally, a grouping variable to track moves between departments, this package will tell you how many patients were 'IN' at any time, at whatever granularity you need.
patientcounter is not on CRAN yet, so install the development version from GitHub with:
# install.packages("remotes") # if not already installed remotes::install_github("johnmackintosh/patientcounter")
Obtain data for each individual patient, by hour, for each hour of their stay.
Note we are restricting the outputs to keep this readable
library(patientcounter) patient_count <- interval_census(beds, identifier = 'patient', admit = 'start_time', discharge = 'end_time', group_var = 'bed', time_unit = '1 hour', results = "patient", uniques = TRUE) head(patient_count)
To obtain summary data for every hour, for all combined patient stays:
library(patientcounter) patient_count_hour <- interval_census(beds, identifier = 'patient', admit = 'start_time', discharge = 'end_time', group_var = 'bed', time_unit = '1 hour', results = "total", uniques = TRUE) head(patient_count_hour)
Note that you also receive the base date and base hour for each interval to enable easier filtering of the results.
This example shows grouping results by bed and hour.
The first ten rows of the resulting grouped values are shown
library(patientcounter) grouped <- interval_census(beds, identifier = 'patient', admit = 'start_time', discharge = 'end_time', group_var = 'bed', time_unit = '1 hour', results = "group", uniques = FALSE) head(grouped[bed %chin% c('A', 'B')],10)
To find your system timezone:
Sys.timezone()
See ? seq.POSIXt for valid values
E.G. '1 hour', '15 mins', '30 mins'
Want to count those in between 10:01 to 11:00? You can do that using 'time_adjust_period' - set it to 'start_min' and then set 'time_adjust_interval' to 1.
10:00 to 10:59?
Yes, that's possible as well - set 'time_adjust_period' to 'end_min' and set
'time_adjust_interval' as before. You can set these periods to any value, as long as it makes sense in relation to your chosen time_unit.
Here we adjust the start_time by 5 minutes
library(patientcounter) patient_count_time_adjust <- interval_census(beds, identifier = 'patient', admit = 'start_time', discharge = 'end_time', group_var = 'bed', time_unit = '1 hour', time_adjust_period = 'start_min', time_adjust_value = 5, results = "total", uniques = TRUE) head(patient_count_time_adjust)
Valid values for time_adjust_period are 'start_min', 'start_sec', 'end_min' and 'end_sec'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.