Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
Merge branch '59-question-can-users-customize-the-listing-columns' of https://github.com/Merck/metalite.sl into 59-question-can-users-customize-the-listing-columns

# Conflicts:
#	R/react_disposition.R
  • Loading branch information
niup0 committed Jan 23, 2025
2 parents 22e3523 + 43339a7 commit 79ade44
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions R/react_disposition.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#' metadata_ae = metalite.ae::meta_ae_example()
#' )
#' }

react_disposition <- function(
metadata_sl
,metadata_ae
Expand All @@ -66,19 +67,20 @@ react_disposition <- function(
,width = 1200
)
{

# ----------------------------------------- #
# default columns #
# ----------------------------------------- #
if (is.null(sl_col_selected)) {
sl_col_selected <- c("trt01a", "siteid", "subjid", "sex", "age", "weightbl")
sl_col_names <- c("Treatment", "Site", "Subject ID", "Sex", "Age (Year)", "Weight (kg)")
}
if (is.null(ae_col_selected)){
sl_col_names <- c("Treatment", "Site", "Subject ID", "Sex", "Age (Year)", "Weight (kg)")
}

if (is.null(ae_col_selected)) {
ae_col_selected <- c("AESOC", "ASTDT", "AENDT", "AETERM", "duration", "AESEV", "AESER", "related", "AEACN", "AEOUT")
ae_col_names <- c("SOC", "Onset Date", "End Date", "AE", "Duraion", "Intensity", "Serious", "Related", "Action Taken", "Outcome")
ae_col_names <- c("SOC", "Onset Date", "End Date", "AE", "Duraion", "Intensity", "Serious", "Related", "Action Taken", "Outcome")
}

# ----------------------------------------- #
# total setting #
# ----------------------------------------- #
Expand All @@ -90,7 +92,7 @@ react_disposition <- function(
}

# ----------------------------------------- #
# prepare the baseline char table numbers #
# prepare the disposition table numbers #
# ----------------------------------------- #
x_sl <- metadata_sl |>
prepare_disposition(
Expand All @@ -103,11 +105,6 @@ react_disposition <- function(
tbl_sl <- x_sl$tbl
tbl_sl$var_label[tbl_sl$name == "Participants in population"] <- "Participants in population"

# get AE listing
ae_listing_outdata <-
metalite.ae::prepare_ae_listing(meta = metadata_ae, population = ae_population, analysis='ae_specific', observation = ae_observation, parameter = 'any')
ae_list <- ae_listing_outdata$meta$data_observation

# Define Column
col_defs <- list()
for (sl_name in names(tbl_sl)) {
Expand Down Expand Up @@ -144,17 +141,29 @@ react_disposition <- function(

# Define columns for subject list
sl_col_selected <- toupper(sl_col_selected)
if (!('USUBJID' %in% sl_col_selected)) u_sl_col_selected <- c('USUBJID', sl_col_selected)
if (!("USUBJID" %in% sl_col_selected)) u_sl_col_selected <- c("USUBJID", sl_col_selected)
if (is.null(sl_col_names)) sl_col_names <- sl_col_selected
sl_col_def <- list()
for (i in 1:length(sl_col_selected)) sl_col_def[[sl_col_selected[i]]] <- reactable::colDef(sl_col_names[i])


# ----------------------------------------- #
# get AE listing #
# ----------------------------------------- #
ae_listing_outdata <-
metalite.ae::prepare_ae_listing(meta = metadata_ae, population = ae_population, analysis='ae_specific', observation = ae_observation, parameter = 'any')
ae_list <- ae_listing_outdata$meta$data_observation

# Define columns for AE list
if (is.null(ae_col_names)) ae_col_names <- ae_col_selected
ae_col_def <- list()
for (i in 1:length(ae_col_selected)) ae_col_def[[ae_col_selected[i]]] <- reactable::colDef(ae_col_names[i])


# ----------------------------------------- #
# making react table #
# ----------------------------------------- #
trt_grp <- toupper(trtvar)
# show participant details when category not in "participants in population", "discontinued", "participants ongoing", "completed"
details <- function(index) {
dcsreas <- stringr::str_trim(tolower(tbl_sl$name[index]))
if (!is.na(tbl_sl$name[index]) & !(dcsreas %in% c("participants in population", "discontinued", "participants ongoing", "completed"))) {
Expand All @@ -170,13 +179,13 @@ react_disposition <- function(
subset = metadata_sl$data_population$USUBJID %in% usubjids,
select = u_sl_col_selected
)
subj_list[,sl_col_selected] |>
subj_list[, sl_col_selected] |>
reactable::reactable(
filterable = TRUE, defaultExpanded = FALSE, striped = TRUE, groupBy = trt_grp,
columns = sl_col_def,
details = function(index) {
usubjid <- subj_list$USUBJID[index]
# get AE list of a subject
# get AE list of a subject if discontinued because of AE
if (dcsreas %in% c("adverse event")) {
sub_ae_listing <- ae_list |> subset(
subset = ae_list$USUBJID %in% usubjid,
Expand Down

0 comments on commit 79ade44

Please sign in to comment.