-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from pharmaverse/141_QS_tests
add 4 QS tests
- Loading branch information
Showing
4 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
QS1 <- data.frame(USUBJID = c(rep(101, 5), rep(102, 5)), | ||
QSCAT = "DLQI", | ||
QSDTC = rep(c("2017-01-01T08:25", "2017-01-05T09:25", | ||
"2017-01-15T10:25","2017-01-20T08:25","2017-01-25T08:25"), 2), | ||
VISITNUM = rep(1:5,2), | ||
VISIT = rep(c( "Visit 1", "Visit 2", "Visit 3", "UNSCheduled!!!","VIsit 5"), 2), | ||
stringsAsFactors = FALSE) | ||
|
||
|
||
test_that("Function returns true when no errors are present", { | ||
|
||
expect_true(check_qs_dup(QS1)) | ||
}) | ||
|
||
|
||
test_that("Function returns false when multiple dates, QSDTC, for the same visit", { | ||
|
||
# multiple dates for the same visit in QS | ||
QS2 <- QS1 | ||
QS2$VISIT[QS2$USUBJID == 101] <- "Visit 1" | ||
|
||
expect_false(check_qs_dup(QS2)) | ||
}) | ||
|
||
|
||
|
||
test_that("Function returns true when multiple visit labels for the same date, QSDTC", { | ||
|
||
# multiple visit labels for the same date | ||
QS3 <- QS1 | ||
QS3$QSDTC[QS3$USUBJID == 101] <- "2017-01-01" | ||
|
||
expect_true(check_qs_dup(QS3)) | ||
}) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
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) | ||
|
||
|
||
|
||
test_that("Function returns true when no errors are present", { | ||
|
||
expect_true(check_qs_qsdtc_after_dd(AE, DS, QS)) | ||
}) | ||
|
||
|
||
test_that("Function returns false when QSDTC is after death date for USUBJID", { | ||
|
||
QS1 <- QS | ||
QS1$QSDTC[3:5] <- "2016-01-03" | ||
|
||
expect_false(check_qs_qsdtc_after_dd(AE, DS, QS1)) | ||
|
||
}) | ||
|
||
|
||
test_that("Function returns true when no errors are present", { | ||
|
||
QS2 <- QS | ||
QS2$QSSTAT[3] <- "Not Done" | ||
|
||
expect_true(check_qs_qsdtc_after_dd(AE, DS, QS2)) | ||
}) | ||
|
||
|
||
|
||
test_that("Function returns true when no errors are present", { | ||
|
||
QS2 <- QS | ||
QS2$QSSTAT[3] <- "Not Done" | ||
|
||
expect_true(check_qs_qsdtc_after_dd(AE, DS, QS2)) | ||
}) | ||
|
||
|
||
|
||
test_that("Function returns false when key variable not available", { | ||
|
||
DS1 <- DS | ||
DS1$DSSTDTC <- NULL | ||
|
||
expect_false(check_qs_qsdtc_after_dd(AE, DS1, QS)) | ||
}) | ||
|
||
|
||
test_that("Function returns false when error is present", { | ||
|
||
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) | ||
|
||
expect_false(check_qs_qsdtc_after_dd(AE1, DS1, QS1)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# no case | ||
QS1 <- data.frame(USUBJID = c(rep(101, 5), rep(102, 5)), | ||
QSCAT = "DLQI", | ||
QSDTC = rep(c("2017-01-01T08:25", "2017-01-05T09:25", | ||
"2017-01-15T10:25","2017-01-20T08:25","2017-01-25T08:25"), 2), | ||
VISITNUM = rep(1:5,2), | ||
VISIT = rep(c( "Visit 1", "Visit 2", "Visit 3", "UNSCheduled!!!","VIsit 5"), 2), | ||
stringsAsFactors = FALSE) | ||
|
||
|
||
test_that("Function returns true when no errors are present", { | ||
|
||
QS2 = QS1 | ||
|
||
expect_true(check_qs_qsdtc_visit_ordinal_error(QS1)) | ||
}) | ||
|
||
|
||
|
||
|
||
|
||
test_that("Function returns true when no errors are present", { | ||
QS2 = QS1 | ||
|
||
QS2$QSCAT = "SKINDEX-29" | ||
|
||
QS <- rbind(QS1, QS2) | ||
|
||
expect_true(check_qs_qsdtc_visit_ordinal_error(QS)) | ||
}) | ||
|
||
|
||
|
||
|
||
test_that("Function returns false when date out of sequence", { | ||
QS2 = QS1 | ||
QS2$QSCAT = "SKINDEX-29" | ||
|
||
QS <- rbind(QS1, QS2) | ||
|
||
# adding cases with earlier date | ||
QS$QSDTC[QS$USUBJID == 101 & QS$VISIT == "Visit 3"] <- "2017-01-10T08:25" | ||
QS$QSDTC[QS$USUBJID == 102 & QS$VISIT == "Visit 2"] <- "2017-01-01T06:25" | ||
|
||
expect_false(check_qs_qsdtc_visit_ordinal_error(QS)) | ||
}) | ||
|
||
|
||
|
||
|
||
test_that("Function returns false when duplicated date", { | ||
QS2 = QS1 | ||
QS2$QSCAT = "SKINDEX-29" | ||
|
||
QS <- rbind(QS1, QS2) | ||
|
||
# adding cases with duplicated date | ||
QS$QSDTC[QS$USUBJID == 102 & QS$VISIT == "Visit 3"] <- "2017-01-01T06:25" | ||
|
||
expect_false(check_qs_qsdtc_visit_ordinal_error(QS)) | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
|
||
QS <- data.frame( | ||
STUDYID = 1, | ||
USUBJID = c(rep(1,6),rep(2,6)), | ||
QSSTRESC = 1:12, | ||
VISIT = c(rep(1,3),rep(2,3),rep(1,3),rep(2,3)), | ||
QSSTAT = rep(c("DONE","NOT DONE"),6), | ||
QSCAT = rep(c("INDIVIDUAL","OVERALL","BFI"),4), | ||
QSDTC = "2016-01-01", | ||
QSTESTCD = "QSALL", | ||
stringsAsFactors = FALSE | ||
) | ||
|
||
|
||
test_that("Function returns false when errors are present", { | ||
|
||
expect_false(check_qs_qsstat_qsstresc(QS)) | ||
}) | ||
|
||
|
||
test_that("Function returns false when errors are present", { | ||
|
||
QS1 <- QS | ||
QS1$QSSTRESC[4]=" " | ||
QS1$QSSTRESC[6]=NA | ||
QS1$QSSTRESC[8]="." | ||
|
||
expect_false(check_qs_qsstat_qsstresc(QS1)) | ||
}) | ||
|
||
|
||
|
||
test_that("Function returns false when missing key variable", { | ||
|
||
QS2 <- QS | ||
QS2$QSSTRESC=NULL | ||
|
||
expect_false(check_qs_qsstat_qsstresc(QS2)) | ||
}) | ||
|