-
Notifications
You must be signed in to change notification settings - Fork 7
/
check_dv_covid.R
63 lines (55 loc) · 1.97 KB
/
check_dv_covid.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
#' @title Check for consistency in COVID-19 DV variables, DVREAS and DVEPRELI
#'
#' @description This check looks for inconsistency between DVREAS and DVEPRELI.
#' If DVREAS indicates a COVID-19 related deviation, then DVEPRELI should not be
#' missing and vice versa. This check applies to studies using the Protocol
#' Deviation Management System (PDMS).
#'
#' @param DV Protocol Deviations SDTM dataset with variables USUBJID, DVREAS,
#' DVEPRELI
#'
#' @return boolean value if check failed or passed with 'msg' attribute if the
#' test failed
#'
#' @importFrom dplyr %>% filter select
#'
#' @export
#'
#' @author Mij Rahman
#'
#' @family COVID
#'
#' @keywords COVID
#'
#' @examples
#'
#' DV <- data.frame(
#' USUBJID = 1:3,
#' DVEPRELI = c("Y","N","Y"),
#' DVREAS=c("EPIDEMIC/PANDEMIC INFECTION","EPIDEMIC/PANDEMIC INFECTION",""),
#' stringsAsFactors=FALSE
#' )
#'
#' check_dv_covid(DV)
#'
check_dv_covid <- function(DV){
###First check that required variables exist and return a message if they don't
if(DV %lacks_any% c("USUBJID","DVREAS","DVEPRELI")){
fail(lacks_msg(DV, c("USUBJID","DVREAS","DVEPRELI")))
}else{
# Select DV recs where DVREAS='CONFIRMED OR SUSPECTED EPIDEMIC/PANDEMIC INFECTION' or DVEPRELI=Y and check consistency
mydf <- DV %>%
select(c("USUBJID","DVREAS","DVEPRELI")) %>%
filter( ( DVEPRELI != "Y" & !is_sas_na(DVREAS)) | (DVEPRELI=="Y" & is_sas_na(DVREAS) ) )
###Print to report
### Return pass if all records with COVID-related DV.DVREAS had corresponding DV.DVEPRELI or vice versa
if(nrow(mydf)==0){
pass()
### Return subset /message if there are records with COVID-related inconsistencies with DV.DVREAS/DVEPRELI
}else if(nrow(mydf)>0){
fail( (paste("Found ", length(unique(mydf$USUBJID)),
"patient(s) with COVID-related Protocol Deviation inconsistencies. ")),
mydf)
}
}
}