Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Commit

Permalink
function to calculate the length of ICU stay
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanshi committed Feb 23, 2017
1 parent 398211e commit ff387df
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
15 changes: 8 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Type: Package
Title: The Critical Care Clinical Data Processing Tools
Version: 0.1
Date: 2017-01-30
Author: Sinan Shi, David Pérez-Suárez, Steve Harris, Niall MacCallum, David Brealey, Mervyn Singer, James Hetherington
Author: Sinan Shi, David Pérez-Suárez, Steve Harris, Niall MacCallum, David
Brealey, Mervyn Singer, James Hetherington
Maintainer: Sinan Shi <[email protected]>
Description:
A toolset to deal with the Critical Care Health Informatics Collaborative
dataset. It is created to address various data reliability and accessibility
problems of electronic healthcare records (EHR). It provides a unique
platform which enables data manipulation, transformation, reduction,
Description: A toolset to deal with the Critical Care Health Informatics
Collaborative dataset. It is created to address various data reliability and
accessibility problems of electronic healthcare records (EHR). It provides a
unique platform which enables data manipulation, transformation, reduction,
anonymisation, cleaning and validation.
Depends:
R (>= 3.1.0)
Expand All @@ -25,7 +25,7 @@ Imports:
methods,
knitr,
ggplot2,
pander,
pander,
stats,
utils
VignetteBuilder: knitr
Expand All @@ -38,6 +38,7 @@ Collate:
'create2dclean.R'
'data.quality.report.R'
'deltaTime.R'
'demographics.R'
'filter.categorical.R'
'filter.missingness.R'
'filter.range.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export(is.demographic)
export(is.drugs)
export(is.laboratory)
export(is.physiology)
export(lenstay)
export(lookup.items)
export(new.episode)
export(physio.distribution)
Expand Down
16 changes: 16 additions & 0 deletions R/demographics.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Calculate the lenght of stay in the ICU.
#'
#' Calculate the lenght of stay in the ICU and append it to the original demographic
#' table.
#' @param demg data.table the demograhic table which should at least contain
#' column DAICU and DDICU
#' @param units character The unit of lenstay column, by default the output will be in hours
#' @return data.table It is the original data.table with lenstay column (in
#' difftime) appended.
#' @export lenstay
lenstay <- function(demg, units="hours") {
len <- difftime(xmlTime2POSIX(demg$DDICU, allow=T),
xmlTime2POSIX(demg$DAICU, allow=T),
units=units)
return(cbind(demg, lenstay = len))
}
23 changes: 23 additions & 0 deletions man/lenstay.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions tests/testthat/test_demographics.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
context("Testing functionalities for the demographic table")

test_that("calculate length of stay in the ICU",{
demg <- data.table(DAICU="2007-01-01", DDICU="2007-01-02")
demg_ <- lenstay(demg)
expect_true(is.data.frame(demg_))
expect_equal(ncol(demg) + 1, ncol(demg_))
expect_equal(as.numeric(demg_$lenstay), 24)

demg <- data.table(DAICU="2007-01-01T00:00:00", DDICU="2007-01-01T22:00:00")
demg_ <- lenstay(demg)
expect_equal(as.numeric(demg_$lenstay), 22)

demg <- data.table(DAICU="2007-01-01", DDICU="wrong_format")
demg_ <- lenstay(demg)
expect_true(is.na(demg_$lenstay))

demg <- data.table(DAICU="wrong_format1", DDICU="wrong_format1")
demg_ <- lenstay(demg)
expect_true(is.na(demg_$lenstay))

demg <- data.table(DAICU="2007-01-01T00:00:00", DDICU="2007-01-01T22:00:00")
demg_ <- lenstay(demg, "days")
expect_equal(as.numeric(demg_$lenstay), 1-2/24)
})

0 comments on commit ff387df

Please sign in to comment.