-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
189 lines (123 loc) · 5.63 KB
/
README.Rmd
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<!-- badges: start -->
# patientcounter <img src="man/figures/logo.png" width="160px" align="right" />
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Build Status](https://travis-ci.com/johnmackintosh/patientcounter.svg?branch=master)](https://travis-ci.com/johnmackintosh/patientcounter)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/johnmackintosh/patientcounter?branch=master&svg=true)](https://ci.appveyor.com/project/johnmackintosh/patientcounter)
[![codecov](https://codecov.io/gh/johnmackintosh/patientcounter/branch/master/graph/badge.svg)](https://codecov.io/gh/johnmackintosh/patientcounter)
[![](https://img.shields.io/badge/devel%20version-0.1.0-blue.svg)](https://github.com/johnmackintosh/patientcounter)
[![](https://img.shields.io/github/last-commit/johnmackintosh/patientcounter.svg)](https://github.com/johnmackintosh/patientcounter/commits/master)
[![R-CMD-check](https://github.com/johnmackintosh/patientcounter/workflows/R-CMD-check/badge.svg)](https://github.com/johnmackintosh/patientcounter/actions)
<!-- badges: end -->
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.
## Installation
patientcounter is not on [CRAN](https://CRAN.R-project.org) yet, so install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes") # if not already installed
remotes::install_github("johnmackintosh/patientcounter")
```
## Example
Obtain data for each individual patient, by hour, for each hour of their stay.
Note we are restricting the outputs to keep this readable
```{r example_patient, echo=TRUE}
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:
```{r example_hour, echo=TRUE}
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.
## Grouped values
This example shows grouping results by bed and hour.
The first ten rows of the resulting grouped values are shown
```{r grouped}
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)
```
## General Help
- You must 'quote' your variables, for the time being at least..
## Results
- Set results to 'patient' for 1 row per patient per interval for each interval in the patient stay.
- Set results to 'group' to get a count per group per interval.
Remember this will also be influenced by the 'uniques' argument - set it to FALSE to ensure each move in each location is counted.
- Set results to 'total' for a summary of the data set - interval, base_hour and count.
## Tracking moves within the same interval with 'uniques'
- To count individual patients ONLY, leave 'uniques' at the default value of 'TRUE'.
- To count patient moves between locations during intervals, set uniques to 'FALSE'.
Patients who occupy beds in different locations during each interval are accounted for in each location. They will be counted at least twice during an interval - both in their initial location and their new location following a move.
## Timezones
- Everything is easier if you use "UTC" by default.
You can attempt to coerce the final results yourself using lubridate::force_tz()
To find your system timezone:
```r
Sys.timezone()
```
## Time Unit
See ? seq.POSIXt for valid values
E.G. '1 hour', '15 mins', '30 mins'
## Time Adjust
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
```{r example_start_min, echo=TRUE}
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'