This check identifies QSDTC values that are duplicated or earlier than last visit's. Unscheduled visits are excluded.

check_qs_qsdtc_visit_ordinal_error(QS)

Arguments

QS

SDTM dataset with variables USUBJID, QSCAT, QSORRES, VISITNUM, VISIT, QSDTC

Value

boolean value if check failed or passed with 'msg' attribute if the test failed

Author

Simon Luo

Examples


# 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)

QS2 = QS1
QS2$QSCAT = "SKINDEX-29"

QS <- rbind(QS1, QS2)
check_qs_qsdtc_visit_ordinal_error(QS)
#> [1] TRUE

# 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"
check_qs_qsdtc_visit_ordinal_error(QS)
#> [1] FALSE
#> attr(,"msg")
#> [1] "QS has 2 records with Possible QSDTC data entry error. "
#> attr(,"data")
#>   USUBJID      QSCAT VISITNUM   VISIT            QSDTC     last.vis.dtc
#> 1     102       DLQI        2 Visit 2 2017-01-01T06:25 2017-01-01T08:25
#> 2     102 SKINDEX-29        2 Visit 2 2017-01-01T06:25 2017-01-01T08:25
#>   last.vis visit.order                       check.flag
#> 1  Visit 1           2 Datetime earlier than last Visit
#> 2  Visit 1           2 Datetime earlier than last Visit

# adding cases with duplicated date
QS$QSDTC[QS$USUBJID == 102 & QS$VISIT == "Visit 3"] <- "2017-01-01T06:25"
 check_qs_qsdtc_visit_ordinal_error(QS)
#> [1] FALSE
#> attr(,"msg")
#> [1] "QS has 4 records with Possible QSDTC data entry error. "
#> attr(,"data")
#>   USUBJID      QSCAT VISITNUM   VISIT            QSDTC     last.vis.dtc
#> 1     102       DLQI        2 Visit 2 2017-01-01T06:25 2017-01-01T08:25
#> 2     102       DLQI        3 Visit 3 2017-01-01T06:25 2017-01-01T06:25
#> 3     102 SKINDEX-29        2 Visit 2 2017-01-01T06:25 2017-01-01T08:25
#> 4     102 SKINDEX-29        3 Visit 3 2017-01-01T06:25 2017-01-01T06:25
#>   last.vis visit.order                       check.flag
#> 1  Visit 1           2 Datetime earlier than last Visit
#> 2  Visit 2           3                       Duplicated
#> 3  Visit 1           2 Datetime earlier than last Visit
#> 4  Visit 2           3                       Duplicated