R/check_qs_qsdtc_after_dd.R
check_qs_qsdtc_after_dd.Rd
This check looks for QS dates that occur after death date
check_qs_qsdtc_after_dd(AE, DS, QS)
boolean value if check failed or passed with 'msg' attribute if the test failed
AE <- data.frame(USUBJID = c(1,1,1,2,2,2),
AEDTHDTC = c("", "", "2016-01-01", "", "2016-01", "2016-01-01"),
AESTDTC = "2016-01-01",
AEDECOD = LETTERS[1:6],
AETERM = LETTERS[1:6],
stringsAsFactors = FALSE)
DS <- data.frame(USUBJID = c(1,1,1,2,2,2),
DSSTDTC = "2016-01-01",
DSDECOD = c("A", "B", "death", "AC", "BC", "death"),
DSTERM = letters[1:6],
stringsAsFactors = FALSE)
QS <- data.frame(USUBJID = c(1,1,1,2,2,2),
QSDTC = c("2015-06-30", "2015-09-30", "2015-12-30",
"2015-06-30", "2015-09-30", "2015-12-30"),
QSCAT = "A",
QSORRES = LETTERS[1:6],
QSSTAT = "",
VISIT = c("Week 1", "Week 12", "Week 24", "Week 1", "Week 12", "Week 24"),
QSSTRESC = LETTERS[1:6],
stringsAsFactors = FALSE)
check_qs_qsdtc_after_dd(AE, DS, QS)
#> [1] TRUE
QS$QSDTC[3:5] <- "2016-01-03"
check_qs_qsdtc_after_dd(AE, DS, QS)
#> [1] FALSE
#> attr(,"msg")
#> [1] "2 unique patient(s) with 5 QS record(s) occurring after death date. "
#> attr(,"data")
#> USUBJID QSDTC VISIT QSCAT AEDTHDTC DSSTDTC EARLIEST_DTHDTC
#> 1 1 2016-01-03 Week 24 A 2016-01-01 2016-01-01 2016-01-01
#> 2 2 2016-01-03 Week 1 A 2016-01 2016-01-01 2016-01-01
#> 3 2 2016-01-03 Week 1 A 2016-01-01 2016-01-01 2016-01-01
#> 4 2 2016-01-03 Week 12 A 2016-01 2016-01-01 2016-01-01
#> 5 2 2016-01-03 Week 12 A 2016-01-01 2016-01-01 2016-01-01
QS$QSSTAT[3] <- "Not Done"
check_qs_qsdtc_after_dd(AE, DS, QS)
#> [1] FALSE
#> attr(,"msg")
#> [1] "1 unique patient(s) with 4 QS record(s) occurring after death date. "
#> attr(,"data")
#> USUBJID QSDTC VISIT QSCAT AEDTHDTC DSSTDTC EARLIEST_DTHDTC
#> 1 2 2016-01-03 Week 1 A 2016-01 2016-01-01 2016-01-01
#> 2 2 2016-01-03 Week 1 A 2016-01-01 2016-01-01 2016-01-01
#> 3 2 2016-01-03 Week 12 A 2016-01 2016-01-01 2016-01-01
#> 4 2 2016-01-03 Week 12 A 2016-01-01 2016-01-01 2016-01-01
DS$DSSTDTC <- NULL
check_qs_qsdtc_after_dd(AE, DS, QS)
#> [1] FALSE
#> attr(,"msg")
#> [1] "DS is missing the variable: DSSTDTC"
AE1 <- data.frame(USUBJID = 1,
AEDTHDTC = "",
AESTDTC = c("2015-11-01", "2016-02-01"),
AEDECOD = "Rash",
AETERM = "RASH",
stringsAsFactors = FALSE)
DS1 <- data.frame(USUBJID = 1,
DSSTDTC = "2016-01",
DSCAT = c("DISPOSITION EVENT", "OTHER"),
DSSCAT = c('STUDY COMPLETION/EARLY DISCONTINUATION', ''),
DSDECOD = "DEATH",
DSTERM = c("DEATH", "DEATH DUE TO PROGRESSIVE DISEASE"),
stringsAsFactors = FALSE)
QS1 <- data.frame(USUBJID = 1,
QSDTC = c("2015-06-30", "2016-01-15", "2016-01-15"),
QSCAT = rep("EQ-5D-5L"),
QSORRES = "1",
QSSTAT = "",
VISIT = c("Week 1", "Week 12", "Week 12"),
QSSTRESC = "1",
stringsAsFactors = FALSE)
check_qs_qsdtc_after_dd(AE=AE1, DS=DS1, QS=QS1)
#> [1] FALSE
#> attr(,"msg")
#> [1] "1 unique patient(s) with 2 QS record(s) occurring after death date. "
#> attr(,"data")
#> USUBJID QSDTC VISIT QSCAT AEDTHDTC DSSTDTC EARLIEST_DTHDTC
#> 1 1 2016-01-15 Week 12 EQ-5D-5L <NA> 2016-01 2016-01
AE1$AEDTHDTC[1:2] <- "2015-07-01"
check_qs_qsdtc_after_dd(AE=AE1, DS=DS1, QS=QS1)
#> [1] FALSE
#> attr(,"msg")
#> [1] "1 unique patient(s) with 2 QS record(s) occurring after death date. "
#> attr(,"data")
#> USUBJID QSDTC VISIT QSCAT AEDTHDTC DSSTDTC EARLIEST_DTHDTC
#> 1 1 2016-01-15 Week 12 EQ-5D-5L 2015-07-01 2016-01 2015-07-01