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

check_eg_egdtc_visit_ordinal_error(EG)

Arguments

EG

ECG Test Results SDTM dataset with variables USUBJID, VISITNUM, VISIT, EGDTC, EGSTAT

Value

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

Author

James Zhang

Examples


# No case
EG<- data.frame(USUBJID = 101:102,
                EGDTC=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("Screening", "Cycle 1", "Cycle 2",
                "Cycle 3","UNschedUled"),2),
                EGSTAT="",
                stringsAsFactors=FALSE)
check_eg_egdtc_visit_ordinal_error(EG)
#> [1] TRUE

# Cases with earlier datetime
EG$EGDTC[EG$USUBJID == 101 & EG$VISIT == "Cycle 3"] <- "2017-01-10T08:25"
EG$EGDTC[EG$USUBJID == 102 & EG$VISIT == "Cycle 1"] <- "2017-01-01T06:25"
check_eg_egdtc_visit_ordinal_error(EG)
#> [1] FALSE
#> attr(,"msg")
#> [1] "EG has 2 records with Possible EGDTC data entry error. "
#> attr(,"data")
#>   USUBJID VISITNUM   VISIT            EGDTC EGSTAT     last.vis.dtc  last.vis
#> 1     101        4 Cycle 3 2017-01-10T08:25        2017-01-15T10:25   Cycle 2
#> 2     102        2 Cycle 1 2017-01-01T06:25        2017-01-01T08:25 Screening
#>   visit.order                       check.flag
#> 1           4 Datetime earlier than last Visit
#> 2           2 Datetime earlier than last Visit

# Cases with duplicated datetime
EG$EGDTC[EG$USUBJID == 101 & EG$VISIT == "Cycle 3"] <- "2017-01-15T10:25"
EG$EGDTC[EG$USUBJID == 102 & EG$VISIT == "Cycle 2"] <- "2017-01-01T06:25"
check_eg_egdtc_visit_ordinal_error(EG)
#> [1] FALSE
#> attr(,"msg")
#> [1] "EG has 1 records with Possible EGDTC data entry error. "
#> attr(,"data")
#>   USUBJID VISITNUM   VISIT            EGDTC EGSTAT     last.vis.dtc  last.vis
#> 1     102        2 Cycle 1 2017-01-01T06:25        2017-01-01T08:25 Screening
#>   visit.order                       check.flag
#> 1           2 Datetime earlier than last Visit

# Not checking duplicates
EG<- data.frame(USUBJID = rep("101",6),
                EGDTC=rep("2017-01-01T08:25", 6),
                VISITNUM=rep(1:2,3),
                VISIT=rep("Screening",6),
                EGSTAT="",
                stringsAsFactors=FALSE)

check_eg_egdtc_visit_ordinal_error(EG)
#> [1] TRUE