Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

415 visit logic unit tests #424

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sdtmchecks
Title: Data Quality Checks for Study Data Tabulation Model (SDTM) Datasets
Version: 1.0.0
Version: 1.0.0.9001
Authors@R: c(
person(given="Will",
family="Harris",
Expand Down
14 changes: 11 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# sdtmchecks 1.0.0.9001 "CRAN Try"


## Refinements of existing data check functions
* Add more logic to check missing visit post-subsetting the dataframe:
[`check_lb_lbdtc_visit_ordinal_error`](https://pharmaverse.github.io/sdtmchecks/reference/check_lb_lbdtc_visit_ordinal_error.html), [`check_rs_rsdtc_visit_ordinal_error`](https://pharmaverse.github.io/sdtmchecks/reference/check_rs_rsdtc_visit_ordinal_error.html), [`check_tr_trdtc_visit_ordinal_error`](https://pharmaverse.github.io/sdtmchecks/reference/check_tr_trdtc_visit_ordinal_error.html), [`check_tu_tudtc_visit_ordinal_error`](https://pharmaverse.github.io/sdtmchecks/reference/check_tu_tudtc_visit_ordinal_error.html)


# sdtmchecks 1.0.0 "CRAN Try"


## Refinements of existing data check functions

* Covid related checks have been updated to expect a character vector of terms identifying covid related AEs. Specifically [`check_ae_aeacn_ds_disctx_covid`](https://pharmaverse.github.io/sdtmchecks/reference/check_ae_aeacn_ds_disctx_covid.html), [`check_ae_aeacnoth_ds_stddisc_covid`](https://pharmaverse.github.io/sdtmchecks/reference/check_ae_aeacnoth_ds_stddisc_covid.html), [`check_dv_ae_aedecod_covid`](https://pharmaverse.github.io/sdtmchecks/reference/check_dv_ae_aedecod_covid.html) are affected.
* Covid-19 related checks have been updated to expect a character vector of terms identifying Covid related AEs. Specifically [`check_ae_aeacn_ds_disctx_covid`](https://pharmaverse.github.io/sdtmchecks/reference/check_ae_aeacn_ds_disctx_covid.html), [`check_ae_aeacnoth_ds_stddisc_covid`](https://pharmaverse.github.io/sdtmchecks/reference/check_ae_aeacnoth_ds_stddisc_covid.html), [`check_dv_ae_aedecod_covid`](https://pharmaverse.github.io/sdtmchecks/reference/check_dv_ae_aedecod_covid.html) are affected.
* [`check_vs_height`](https://pharmaverse.github.io/sdtmchecks/reference/check_vs_height.html) minor update to return message [#379](https://github.com/pharmaverse/sdtmchecks/issues/379)
* [`check_lb_missing_month`](https://pharmaverse.github.io/sdtmchecks/reference/check_lb_missing_month.html) and [`check_mh_missing_month`](https://pharmaverse.github.io/sdtmchecks/reference/check_mh_missing_month.html) were both updated to have flexibility for Roche functions parsing `--SPID`

## Misc package updates

* General updates for CRAN compliance, e.g. to DESCRIPTION file, Roxygen headers, etc.
* Remove `rm(list=ls())` from sdtmchecksmeta.R ([#375](https://github.com/pharmaverse/sdtmchecks/issues/375))
* Removed `xls2list()` function. If working with the results of `run_all_checks()` it's recommended to output results to to .rds instead of parsing .xlsx files.
* Removed `xls2list()` function. If working with the results of `run_all_checks()` it's recommended to output results to .rds instead of parsing .xlsx files.


# sdtmchecks 0.1.11.9008 "Light Ice"
# sdtmchecks 0.1.12 "Light Ice"


## Refinements of existing data check functions
Expand Down
11 changes: 10 additions & 1 deletion R/check_lb_lbdtc_visit_ordinal_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ check_lb_lbdtc_visit_ordinal_error <- function(LB){
subsetdf = subset(LB, LB$LBSTAT != "NOT DONE" & !grepl("UNSCHEDU|TREATMENT OR OBSERVATION FU COMP EARLY DISC", toupper(LB$VISIT)))


if(nrow(subsetdf)>0){
### re-check if the subset has VISITNUM all missing
if (length(unique(subsetdf[["VISITNUM"]]))<=1) {

fail(msg="VISITNUM exists but only a single value. ")

}



else if(nrow(subsetdf)>0){

mydf2 <- dtc_dupl_early(
dts = subsetdf,
Expand Down
9 changes: 8 additions & 1 deletion R/check_rs_rsdtc_visit_ordinal_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ check_rs_rsdtc_visit_ordinal_error <- function(RS){
#only keep INV overall responses not indicated as Not Done
subsetdf = subset(RS,RS$RSTESTCD=="OVRLRESP" & RS$RSEVAL=="INVESTIGATOR" & RS$RSSTAT != "NOT DONE" & !grepl("UNSCHEDU",toupper(RS$VISIT)),)

if(nrow(subsetdf)>0){
### re-check if the subset has VISITNUM all missing
if (length(unique(subsetdf[["VISITNUM"]]))<=1) {

fail("VISITNUM exists but only a single value. ")

}

else if(nrow(subsetdf)>0){

mydf2 <- dtc_dupl_early(dts = subsetdf, vars = vars,
### groupby variables used for grouping and visit.order derivation
Expand Down
11 changes: 10 additions & 1 deletion R/check_tr_trdtc_visit_ordinal_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ check_tr_trdtc_visit_ordinal_error <- function(TR){
} else {

subsetdf = subset(TR, TR$TREVAL=="INVESTIGATOR" & TR$TRSTAT !="NOT DONE" & !grepl("UNSCHEDU",toupper(TR$VISIT)),)

### re-check if the subset has VISITNUM all missing
if (length(unique(subsetdf[["VISITNUM"]]))<=1) {

fail(msg="VISITNUM exists but only a single value. ")

}



if(nrow(subsetdf)>0){
else if(nrow(subsetdf)>0){

mydf2 <- dtc_dupl_early(dts = subsetdf, vars = vars,
### groupby variables used for grouping and visit.order derivation
Expand Down
11 changes: 10 additions & 1 deletion R/check_tu_tudtc_visit_ordinal_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ check_tu_tudtc_visit_ordinal_error <- function(TU){

subsetdf = subset(TU, TU$TUEVAL=="INVESTIGATOR" & !grepl("UNSCHEDU",toupper(TU$VISIT)),)

if(nrow(subsetdf)>0){
### re-check if the subset has VISITNUM all missing
if (length(unique(subsetdf[["VISITNUM"]]))<=1) {

fail(msg="VISITNUM exists but only a single value. ")

}



else if(nrow(subsetdf)>0){

mydf2 <- dtc_dupl_early(
dts = subsetdf,
Expand Down
6 changes: 4 additions & 2 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ reference:
# - convert_var_to_ascii
# - truncate_var_strings
# - create_R_script
# - xlsx2list
# - xlsx2list (no longer in the package)

- title: "Company-specific utility functions"
desc: Helper functions for data checks tailored to company-specific data inputs.
Expand All @@ -79,8 +79,10 @@ reference:

news:
releases:
- text: "sdtmchecks 1.0.0"
href: news/index.html#sdtmchecks-100-cran-try
- text: "sdtmchecks 0.1.12"
href: news/index.html#sdtmchecks-0112-cran-try
href: news/index.html#sdtmchecks-0112-light-ice
- text: "sdtmchecks 0.1.11"
href: news/index.html#sdtmchecks-0111-light-ice
- text: "sdtmchecks 0.1.10"
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/test-check_lb_lbdtc_visit_ordinal_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,28 @@ test_that("Function returns false when expected column not present", {
expect_false(check_lb_lbdtc_visit_ordinal_error(LB1))
})



test_that("Function returns false when subset has VISITNUM all missing ", {

LB2 <- data.frame(USUBJID = c(rep("101", 5), rep("102", 5)),
LBCAT = "Hematology",
LBDTC = 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(c(rep(1, 4), 2),2),
VISIT = rep(c(
"Visit 1",
"Visit 2",
"Visit 3",
"VIsit 5",
"UNSCheduled!!!"), 2),
LBSTAT = c(rep("", 9), "NOT DONE"),
stringsAsFactors = FALSE)


expect_false(check_lb_lbdtc_visit_ordinal_error(LB2))
})
16 changes: 16 additions & 0 deletions tests/testthat/test-check_rs_rsdtc_visit_ordinal_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,19 @@ test_that("Function returns false when Investigator (INV) records but not OVRLRE
expect_false(check_rs_rsdtc_visit_ordinal_error(RS))
})



test_that("Function returns false when subset has VISITNUM all missing", {

RS2<- data.frame(USUBJID = 101:102,
RSDTC=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(c(rep(1, 4), 2),2),
VISIT=rep(c("Screening", "Cycle 1", "Cycle 2","Cycle 3","UNSCHEDULED"),2),
RSTESTCD="OVRLRESP",
RSEVAL="INVESTIGATOR",
RSSTAT="",
stringsAsFactors=FALSE)

expect_false(check_rs_rsdtc_visit_ordinal_error(RS2))
})
17 changes: 17 additions & 0 deletions tests/testthat/test-check_tr_trdtc_visit_ordinal_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,20 @@ test_that("Returns false when VISITNUM exists but only a single non-missing valu
})



test_that("Function returns false when subset has VISITNUM all missing", {

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(c(rep(1, 4), 2),2),
VISIT = rep(c( "Visit 1", "Visit 2", "Visit 3", "Visit 4","Unscheduled"), 2),
TREVAL="INVESTIGATOR",
TRSTAT = "",
stringsAsFactors = FALSE)

expect_false(check_tr_trdtc_visit_ordinal_error(TR))
})


15 changes: 15 additions & 0 deletions tests/testthat/test-check_tu_tudtc_visit_ordinal_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,18 @@ test_that("Returns false when VISITNUM exists but only a single non-missing valu
})



test_that("Function returns false when subset has VISITNUM all missing", {

TU <- data.frame(USUBJID = 101:102,
TUORRES = rep(c("NEW", "TARGET"), 5),
TULOC=rep(c("BONE","LIVER"),5),
TUDTC = 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(c(rep(1, 4), 2),2),
VISIT = rep(c( "Visit 1", "Visit 2", "Visit 3", "Visit 4","UNSCHEDULED"), 2),
TUEVAL="INVESTIGATOR",
stringsAsFactors = FALSE)

expect_false(check_tu_tudtc_visit_ordinal_error(TU))
})
Loading