test_that("combining SDTM with its supplemental data works", {
# Create prod dmsupp data frame using ru_addsupp() function.
# Create qc dmsupp data frame using independent code.
qlabs <- suppdm %>% dplyr::distinct(QNAM,QLABEL)
suppdm %>% dplyr::select(STUDYID, USUBJID, QNAM, QVAL) %>% tidyr::pivot_wider(names_from=QNAM, values_from=QVAL) -> suppdm_t
suppressMessages(dm %>% dplyr::full_join(suppdm_t)) -> qc_dm
# Create prod aesupp data frame using ru_addsupp() function.
# Create qc aesupp data frame using independent code.
qlabs <- suppae %>% dplyr::distinct(QNAM,QLABEL)
suppae %>% dplyr::select(STUDYID, USUBJID, IDVARVAL, QNAM, QVAL) %>% tidyr::pivot_wider(names_from=QNAM, values_from=QVAL) %>% dplyr::rename(AESEQ=IDVARVAL) %>% dplyr::mutate(AESEQ=as.numeric(AESEQ)) -> suppae_t
suppressMessages(ae %>% dplyr::full_join(suppae_t)) -> qc_ae

"combining SDTM with its supplemental data works"

combining SDTM with its supplemental data works

repfun::rs_setup(D_POP="SAFFL",D_POPLBL="Safety",D_POPDATA=repfun::adsl %>% dplyr::filter(SAFFL =='Y'), D_SUBJID=c("STUDYID","USUBJID"), R_ADAMDATA=".")
rfenv$G_POPDATA %>% dplyr::mutate(TRT01AN=ifelse(TRT01A=='Placebo',1,ifelse(TRT01A=='Xanomeline Low Dose',2,3))) -> G_POPDATA
adae <- rfenv$adamdata$adae.rda() %>% dplyr::select(-SAFFL) %>% repfun::ru_getdata(G_POPDATA, c("STUDYID", "USUBJID"), keeppopvars=c("TRT01AN", "TRT01A"))
aesum_t_a <- repfun::ru_align(aesum_t, "tt_ac:") %>% dplyr::select(-c('tt_p01','tt_p02','tt_p03','tt_p99'))
l1=nchar(tt_ac01), l2=nchar(tt_ac02), l3=nchar(tt_ac03), l9=nchar(tt_ac99)) %>% {. ->> QCINT} %>%
dplyr::summarize(m1=max(l1), m2=max(l2), m3=max(l3), m9=max(l9)) %>% tidyr::crossing(QCINT) %>%
tt_ac99=paste0(strrep(' ',m9-l9),tt_ac99),) %>% dplyr::select(-c(starts_with('m'),starts_with('l'))) %>%
rs_setup(D_POP="SAFFL",D_POPLBL="Safety",D_POPDATA=repfun::adsl %>% dplyr::filter(SAFFL =='Y'), D_SUBJID=c("STUDYID","USUBJID"), R_ADAMDATA=".")
statslist=c("n", "mean", "median", "sd", "min", "max")) %>%
repfun::ru_denorm(varstodenorm=c("tt_result"), groupbyvars=c("tt_avid", "tt_avnm", "tt_svid", "tt_svnm"),
demstats_t_a <- repfun::ru_align(demstats_t, "tt_ac:", ncspaces=10)
qcdemstats_t_a <- demstats_t %>% dplyr::mutate(b1=3 - nchar(trimws(gsub('\\..*$','',tt_ac01))),
dplyr::select(-c(starts_with('a'),starts_with('b'))) %>% repfun::ru_labels(varlabels=lapply(demstats_t, attr, "label"))