Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3503d12
Increment version number to 0.3.0.9001
aclark02-arcus Sep 10, 2025
56c7402
export 'get_available_data()' & update docs
aclark02-arcus Sep 10, 2025
46cdfd1
add news
aclark02-arcus Sep 10, 2025
7daef86
export check_appdata() and get_meta_vars() & update docs
aclark02-arcus Sep 10, 2025
aa1565b
setup clinsight to use other objects besides
aclark02-arcus Sep 10, 2025
95f9f11
move a comment
aclark02-arcus Sep 10, 2025
bf173dd
remove unneccessary comments
aclark02-arcus Sep 10, 2025
776727b
Merge branch 'dev' into ac-223
aclark02-arcus Dec 30, 2025
7caa754
Merge branch 'ac-223' of https://github.com/openpharma/clinsight into…
aclark02-arcus Dec 30, 2025
a8fbcb1
extract creation of timeline_data outside of the app & remove app_tab…
aclark02-arcus Dec 30, 2025
b5d631f
removed duplicate str(metadata)
aclark02-arcus Dec 30, 2025
cfe7130
fixed creation of 'cs_available_data'
aclark02-arcus Dec 30, 2025
2ee494d
Update R/run_app.R to check for character timeline_data object before…
aclark02-arcus Dec 30, 2025
7f84adc
fix typo in Rd
aclark02-arcus Dec 30, 2025
e4be379
Merge branch 'ac-223' of https://github.com/openpharma/clinsight into…
aclark02-arcus Dec 30, 2025
cd8b547
Update R/fct_test_clinsight.R to use 'meta_data' instead of 'meta'
aclark02-arcus Dec 30, 2025
d0403fd
whoops, fix a couple of issues copilot caught
aclark02-arcus Dec 30, 2025
212a90b
Merge branch 'ac-223' of https://github.com/openpharma/clinsight into…
aclark02-arcus Dec 30, 2025
72fe125
Merge branch 'dev' into ac-223
aclark02-arcus Feb 2, 2026
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
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ S3method(create_table,default)
S3method(create_table,general)
S3method(create_table,medical_history)
S3method(create_table,medication)
export(check_appdata)
export(collapse_column_vals)
export(create_clinsight_config)
export(create_clinsight_metadata)
Expand All @@ -17,12 +18,15 @@ export(db_create)
export(db_get_query)
export(db_update)
export(get_appdata)
export(get_available_data)
export(get_base_value)
export(get_db_connection)
export(get_meta_vars)
export(get_metadata)
export(get_raw_csv_data)
export(get_review_data)
export(get_test_results)
export(get_timeline_data)
export(key_columns)
export(merge_meta_with_data)
export(run_app)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
- Added additional navigation buttons next to the tabs to easier navigate between common forms and study forms (#255).
- Add toggle to enable text wrapping in tables.
- The timeline is now available in all forms, and can be toggled on or off (#1007).
- - Moved `app_data`, `app_vars`, `timeline_data` & `available_data` to pre-processing step so that doesn't need to compute every session.
- Export functions used to create the data objects above ^^^.
- Started using parquet read / writes for `merged_data`, `timeline_data` & `available_data` to speed startup time.


## Bug fixes

Expand Down
47 changes: 30 additions & 17 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ app_server <- function(
output,
session
){

# Read in pre-processed R objects
# merged_data <- golem::get_golem_options("data")
meta <- golem::get_golem_options("meta")
merged_data <- golem::get_golem_options("data")
app_data <- golem::get_golem_options("app_data")
app_vars <- golem::get_golem_options("app_vars")
# app_tables <- golem::get_golem_options("app_tables")
timeline_data <- golem::get_golem_options("timeline_data")
available_data <- golem::get_golem_options("available_data")
user_db <- golem::get_golem_options("user_db")
credentials_db <- golem::get_golem_options("credentials_db")

app_data <- get_appdata(merged_data, meta = meta)
app_vars <- get_meta_vars(data = app_data, meta = meta)
check_appdata(app_data, meta)
# app_data <- get_appdata(merged_data, meta = meta)
# app_vars <- get_meta_vars(data = app_data, meta = meta)
# app_tables <- lapply(
# setNames(names(app_data), names(app_data)), \(x){
# create_table(app_data[[x]], expected_columns = names(app_vars$items[[x]]))
# })
# check_appdata(app_data, meta)

session$userData$pending_review_records <- reactiveValues()
session$userData$pending_form_review_status <- reactiveValues()
Expand All @@ -39,14 +50,16 @@ app_server <- function(
)

# For query item selector drop-down menus:
available_data <- get_available_data(
data = app_data,
form_repeat_name = with(
meta[["table_names"]],
table_name[raw_name == "form_repeat"]
) |>
tryCatch(error = \(e) "N")
)
# available_data <- get_available_data(
# data = app_data,
# tables = app_tables, # outdated arg
# all_forms = app_vars$all_forms, # outdated arg
# form_repeat_name = with(
# meta[["table_names"]],
# table_name[raw_name == "form_repeat"]
# ) |>
# tryCatch(error = \(e) "N")
# )

# For summary review data:
static_overview_data <- get_static_overview_data(
Expand All @@ -58,11 +71,11 @@ app_server <- function(
)

# For timeline data
timeline_data <-get_timeline_data(
app_data,
available_data = available_data,
treatment_label = meta$settings$treatment_label %||% "\U1F48A T\U2093"
)
# timeline_data <- get_timeline_data(
# app_data,
# available_data = available_data,
# treatment_label = meta$settings$treatment_label %||% "\U1F48A T\U2093"
# )

# think of using the pool package, but functions such as row_update are not yet supported.
r <- reactiveValues(
Expand Down
94 changes: 94 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,100 @@
#' system.file("raw_data", package = "clinsight")))`.
"clinsightful_data"


#' Application Metadata
#'
#' A list of data frames and settings containing metadata that will be used for
#' the application. The metadata will be merged with raw data. It controls
#' the variables that will be used in the application, and in which tab the
#' variables will be shown. The goal is that most, if not all, study-specific
#' data will be captured in the metadata, leaving the scripts to run the
#' application largely unaltered between studies. See `vignette("Metadata")` for
#' in-depth information.
#'
#' @format `metadata`: A list with `r length(metadata)` objects.
#'
#' @source Can be created with an Excel file. The Excel file format is chosen so
#' that the metadata can be changed easily per study. See
#' `raw-data/metadata.R` for details.
"metadata"


#' Application Data
#'
#' A list of data frames split by `item_group`. It is currently
#' not needed to provide the application data in this format. However, the
#' function can be useful for clinsight data customization, especially in
#' combination with [create_table()]. It creates table classes of the
#' `item_group` name (in lower case letters, and all punctuation replaced by an
#' underscore), as long as there is a method available with the corresponding
#' item_group name for the function [create_table()]. If all data is of type
#' 'continuous', then laboratory values such as lab limits and units are
#' cleaned.
#'
#' @format ## `cs_app_data`: A list with `r length(cs_app_data)` objects.
#'
#' ```{r }
#' str(cs_app_data)
#' ```
#'
#' @source See `raw-data/clinsightful_data.R` for details.
#'
"cs_app_data"


#' Application Variables
#'
#' Named list version of `metadata` object.
#'
#' @format ## `cs_app_vars`: A list with `r length(cs_app_vars)` objects.
#'
#' ```{r }
#' str(cs_app_vars)
#' ```
#'
#' @source See `raw-data/clinsightful_data.R` for details.
#'
"cs_app_vars"


#' Application Timeline Data
#'
#' A data.frame containing timeline data.
#'
#' @format ## `cs_timeline_data`: data.frame formatted for consumption by
#' `timevis` package.
#'
#' ```{r }
#' str(cs_timeline_data)
#' ```
#'
#' @source See `raw-data/clinsightful_data.R` for details.
#'
"cs_timeline_data"


#' Application 'Available Data'
#'
#' Data frame containing info about available data per individual,
#' such as visits, adverse events, etc. Will be used in module
#' [mod_queries_server()], to select available items to create a query for per
#' individual and per form. Required columns are the ones distinctively
#' identifying an item. For now that are site_code, event_name, subject_id,
#' event_label, item_group, item_name.
#'
#' @format a data.frame with `r nrow(cs_available_data)` rows and
#' `r ncol(cs_available_data)` variables.
#'
#' ```{r }
#' str(cs_available_data)
#' ```
#'
#' @source See `raw-data/clinsightful_data.R` for details.
#'
"cs_available_data"


#' ClinSight key columns
#'
#' A character string containing the names of the columns that are needed to
Expand Down
4 changes: 2 additions & 2 deletions R/fct_appdata_summary_tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' treatment item in the timeline.
#'
#' @return A data frame with timeline data.
#' @keywords internal
#' @export
#'
get_timeline_data <- function(
data,
Expand Down Expand Up @@ -182,7 +182,7 @@ get_timeline_data <- function(
#' duplicate names exist for each participant.
#'
#' @return A data frame with available data points per form.
#' @keywords internal
#' @export
#'
get_available_data <- function(
data,
Expand Down
2 changes: 1 addition & 1 deletion R/fct_data_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fix_multiple_choice_vars <- function(
#' @param meta List. metadata to use.
#'
#' @return a list with all important names to be used in a clinical trial.
#' @keywords internal
#' @export
#'
get_meta_vars <- function(data = appdata, meta = metadata){
stopifnot(inherits(data, "list"))
Expand Down
2 changes: 1 addition & 1 deletion R/fct_data_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param required_cols Character vector, containing the column names that are
#' required for the application to run appropriately.
#'
#' @keywords internal
#' @export
#'
check_appdata <- function(
data = appdata,
Expand Down
60 changes: 55 additions & 5 deletions R/fct_test_clinsight.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,67 @@ test_clinsight <- function(
meta_data_path <- get_golem_config("meta_data", config = clinsight_config)
if (
clinsight_config %in% c("default", "dev") |
!is.character(study_data_path) | !is.character(meta_data_path)
!is.character(study_data_path) |
!is.character(meta_data_path) #|
){
stop("The 'default' or 'dev' config cannot be used with custom data, ",
"and study_data and meta_data in the config file ",
"should be character vectors.")
"and meta_data, app_data, app_vars, timeline_data, & available_data ",
"in the config file should be character vectors.")
}
# Build a version of `app_data` & app_vars
app_data <- get_appdata(data = clinsight_data, meta = meta_data)
app_vars <- get_meta_vars(data = app_data, meta = meta_data)

# Build a 'app_tables'
# app_tables <- lapply(
# setNames(names(app_data), names(app_data)), \(x){
# create_table(app_data[[x]], expected_columns = names(app_vars$items[[x]]))
# })

# Build a 'available_data'
available_data <- get_available_data(
data = app_data,
# tables = app_tables, # outdated arg
# all_forms = app_vars$all_forms, # outdated arg
form_repeat_name = with(
meta_data[["table_names"]],
table_name[raw_name == "form_repeat"]
) |>
tryCatch(error = \(e) "N")
)

# For timeline data
timeline_data <- get_timeline_data(
app_data,
available_data = available_data,
treatment_label = meta_data$settings$treatment_label %||% "\U1F48A T\U2093"
)

temp_folder <- tempfile(tmpdir = tempdir())
dir.create(temp_folder, recursive = TRUE)
saveRDS(clinsight_data, file.path(temp_folder, basename(study_data_path)))
saveRDS(meta_data, file.path(temp_folder, basename(meta_data_path)))
# saveRDS(clinsight_data, file.path(temp_folder, basename(study_data_path)))
# saveRDS(meta_data, file.path(temp_folder, basename(meta_data_path)))
db_path <- file.path(temp_folder, "user_db.sqlite")
if(file.exists(db_path)) file.remove(db_path)
db_create(get_review_data(clinsight_data),
db_path = db_path
)
save_objs <- c(
"clinsight_data",
"meta_data",
"app_data",
"app_vars",
# "app_tables",
"timeline_data",
"available_data")
purrr::walk(save_objs, function(x){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that purrr is currently only in suggests in the description. We should either use base R or move the package to Imports.

rds_file <- file.path(temp_folder, paste0(x, ".rds"))
saveRDS(get(x), rds_file)
if(inherits(get(x), "data.frame")) {
pq_file <- file.path(temp_folder, paste0(x, ".parquet"))
arrow::write_parquet(get(x), pq_file)
}
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding parquet files here will make it significantly slower to test clinsight with this function because it is fairly slow to write parquet files. Can this be changed/removed here?

old_config <- Sys.getenv("GOLEM_CONFIG_ACTIVE")
Sys.setenv("GOLEM_CONFIG_ACTIVE" = clinsight_config)
run_app(
Expand Down
Loading
Loading