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

check_ex_exstdtc_visit_ordinal_error(EX)

Arguments

EX

Exposure dataset with variables USUBJID, EXTRT, VISITNUM, VISIT, EXDTC, optional variable EXOCCUR

Value

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

Author

James Zhang

Examples


# no case
EX <- data.frame(USUBJID = 101:102,
                EXTRT = rep(c("A", "B"), 5),
                EXSTDTC = 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("Cycle 1", "Cycle 2", "Cycle 3", "Cycle 4", "uNscheDuledd"), 2),
                stringsAsFactors = FALSE)
check_ex_exstdtc_visit_ordinal_error(EX)
#> [1] TRUE

# adding cases with earlier date
EX$EXSTDTC[EX$USUBJID == 101 & EX$VISIT == "Cycle 4"] <- "2017-01-10T08:25"
EX$EXSTDTC[EX$USUBJID == 102 & EX$VISIT == "Cycle 2"] <- "2017-01-01T06:25"
check_ex_exstdtc_visit_ordinal_error(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "EX has 2 records with Possible EXSTDTC data entry error. "
#> attr(,"data")
#>   USUBJID EXTRT VISITNUM   VISIT          EXSTDTC     last.vis.dtc last.vis
#> 1     101     A        4 Cycle 4 2017-01-10T08:25 2017-01-15T10:25  Cycle 3
#> 2     102     B        2 Cycle 2 2017-01-01T06:25 2017-01-01T08:25  Cycle 1
#>   visit.order                       check.flag
#> 1           4 Datetime earlier than last Visit
#> 2           2 Datetime earlier than last Visit

# adding cases with duplicated date
EX$EXSTDTC[EX$USUBJID == 101 & EX$VISIT == "Cycle 5"] <- "2017-01-10T08:25"
EX$EXSTDTC[EX$USUBJID == 102 & EX$VISIT == "Cycle 3"] <- "2017-01-01T06:25"
check_ex_exstdtc_visit_ordinal_error(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "EX has 2 records with Possible EXSTDTC data entry error. "
#> attr(,"data")
#>   USUBJID EXTRT VISITNUM   VISIT          EXSTDTC     last.vis.dtc last.vis
#> 1     101     A        4 Cycle 4 2017-01-10T08:25 2017-01-15T10:25  Cycle 3
#> 2     102     B        2 Cycle 2 2017-01-01T06:25 2017-01-01T08:25  Cycle 1
#>   visit.order                       check.flag
#> 1           4 Datetime earlier than last Visit
#> 2           2 Datetime earlier than last Visit