-
Notifications
You must be signed in to change notification settings - Fork 7
/
check_ss_ssstat_ssorres.R
90 lines (80 loc) · 2.75 KB
/
check_ss_ssstat_ssorres.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#' @title Check for non-missing SSORRES if SSSTAT is NOT DONE
#'
#' @description This check is for studies with LTFU mapped to the SS domain,
#' check that if 'NOT DONE' (Unable to Contact), then there should not be
#' a response (SSORRES)
#'
#' @param SS Long-Term Survival Follow-Up SDTM dataset with variables USUBJID,
#' VISIT, SSSTAT, SSDTC, SSORRES, SSSPID (optional)
#' @param preproc An optional company specific preprocessing script
#' @param ... Other arguments passed to methods
#'
#' @importFrom dplyr %>% filter select arrange
#' @importFrom tidyselect any_of
#'
#' @return boolean value if check failed or passed with 'msg' attribute if the
#' test failed
#'
#' @export
#'
#' @author Sara Bodach
#'
#' @examples
#'
#' SS <- data.frame(
#' STUDYID = 1,
#' USUBJID = c(rep(1,6),rep(2,6)),
#' SSSTRESC = c("ALIVE", "DEAD", "ALIVE", "", "", "U"),
#' SSORRES = c("ALIVE", "DEAD", "ALIVE", "", "", "U"),
#' VISIT = rep(c("SURVIVAL FOLLOW UP 3 MONTHS"),6),
#' SSSTAT = rep(c("","NOT DONE"),6),
#' SSDTC = "2016-01-01",
#' SSSPID = "",
#' stringsAsFactors = FALSE
#' )
#'
#' check_ss_ssstat_ssorres(SS)
#'
#' SS$SSORRES[2]=NA
#' check_ss_ssstat_ssorres(SS)
#'
#' SS$SSSPID="FORMNAME-R:5/L:5XXXX"
#' check_ss_ssstat_ssorres(SS,preproc=roche_derive_rave_row)
#'
#' SS$SSORRES[6]=NA
#' SS$SSORRES[8]=""
#' SS$SSORRES[12]=NA
#' check_ss_ssstat_ssorres(SS)
#'
#' SS$SSORRES=NULL
#' check_ss_ssstat_ssorres(SS)
#'
#'
check_ss_ssstat_ssorres <- function(SS,preproc=identity,...){
###First check that required variables exist and return a message if they don't
if( SS %lacks_any% c("USUBJID", "SSORRES", "VISIT", "SSSTAT", "SSDTC") ){
fail(lacks_msg(SS, c("USUBJID", "SSORRES", "VISIT", "SSSTAT", "SSDTC")))
} else{
#Apply company specific preprocessing function
SS = preproc(SS,...)
mydf <- SS %>%
## Subset to required and optional variables
select(any_of(c("USUBJID", "VISIT", "SSDTC", "SSORRES", "SSSTAT", "RAVE"))) %>%
# potential future refinement - exclude 'U' and 'UNKNOWN' result
# use SSORRES, variable used for LSTALVDT
filter(SSSTAT=="NOT DONE" & !is_sas_na(SSORRES)) %>%
arrange(USUBJID, SSDTC, VISIT) %>%
unique()
rownames(mydf)=NULL
###Print to report
### Return message if no records with issue in SS
if(nrow(mydf)==0){
pass()
### Return subset dataframe if there are issues in SS with NOT DONE but results
} else if(nrow(mydf)>0){
fail(paste0("SS (LTFU) has ", nrow(mydf), " record(s) for ", length(unique(mydf$USUBJID)),
" unique patient(s) with non-missing SSORRES when SSSTAT=NOT DONE (no contact). ",sep=" "),
mydf)
}
}
}