This check identifies TRDTC values when TREVAL == 'INVESTIGATOR' are duplicated or earlier than last visit's. Unscheduled and 'NOT DONE' visits are excluded.

check_tr_trdtc_visit_ordinal_error(TR)

Arguments

TR

Tumor Response Measurement SDTM dataset with variables USUBJID, VISITNUM, VISIT, TRDTC, TREVAL, TRSTAT

Value

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

Author

James Zhang

Examples


# no case
TR<- data.frame(USUBJID = 101:102,
                TRSEQ=rep(1:5,2),
                TRDTC=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","Follow-up"),2),
                TREVAL="INVESTIGATOR",
                TRSTAT="",
                stringsAsFactors=FALSE)
check_tr_trdtc_visit_ordinal_error(TR)
#> [1] TRUE

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