Skip to content
Draft
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: clinsight
Title: ClinSight
Version: 0.2.0.9005
Version: 0.2.0.9006
Authors@R: c(
person("Leonard Daniël", "Samson", , "lsamson@gcp-service.com", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-6252-7639")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ Here is `calculate_subject_status` a function with custom logic that calculates
- Removed the requirement for common_forms to have a 'Name' column. In addition, a 'Name' column can be provided in study data tabs, indicating a common name per row, which will improve the query selector items (#207).
- Improved branding with new ClinSight Logo, added favicon, and allowed for study logos, when available (#214).
- Added options to review on form level. With form-level review, subject-level graphics and tiles will be hidden, and all data will be shown in the tables, and review is enable on all rows. All data in a form can be reviewed at once; if a user tries to do so, an additional confirmation will be requested (#198).
- Added path that updates db's `query_data` table with existing EDC queries upon initialization & update.

## Bug fixes

- The event label order calculation is now calculated as intended in the rare cases where it needs to be estimated (for example when the order of occurrence of the events differs per patient) (#225).






# clinsight 0.2.0

## Changed
Expand Down
85 changes: 82 additions & 3 deletions R/fct_SQLite.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
#' Check Query Path
#'
#' Verify that the query_path supplied is in the correct format, and if it
#' isn't, fall back on the internal query_data_skeleton. If it is, then read
#' the rds file in as a data.frame
#'
#' @param query_path If it exists, provide a file.path to an RDS file,
#' containing data.frame with the same schema as `query_data_skeleton`, used
#' to populate a new database with existing queries from the EDC.
#'
#' @keywords internal
#' @return a data.frame containing EDC queries
#'
check_query_path <- function(query_path) {

# verify that the query_path points at something that exists and is usable
query_df <-
if(is.null(query_path)) {

# when null (the default): use skeleton
query_data_skeleton

} else if(!file.exists(query_path)) {

# when file doesn't exist: use skeleton
warning(paste0("Cannot find '", query_path,"'"))
query_data_skeleton

Check warning on line 27 in R/fct_SQLite.R

View check run for this annotation

Codecov / codecov/patch

R/fct_SQLite.R#L26-L27

Added lines #L26 - L27 were not covered by tests

} else if(tolower(tools::file_ext(query_path)) != "rds") {

# when file exists, but it's not an .rds: use skeleton
warning("Invalid data format. Expecting a .rds format.")
query_data_skeleton

Check warning on line 33 in R/fct_SQLite.R

View check run for this annotation

Codecov / codecov/patch

R/fct_SQLite.R#L32-L33

Added lines #L32 - L33 were not covered by tests

} else {

# read in the query data found at 'query_path'
readRDS(query_path)

Check warning on line 38 in R/fct_SQLite.R

View check run for this annotation

Codecov / codecov/patch

R/fct_SQLite.R#L38

Added line #L38 was not covered by tests

}

# It query_df doesn't follow the same structure as the skeleton, dump it
qcols <- colnames(query_data_skeleton)
if(!identical(qcols, colnames(query_df))) {
warning(paste0("Data.frame read from '", query_path,
"'does match expected columns: ", paste(qcols, collapse = ", ")))
query_df <- query_data_skeleton

Check warning on line 47 in R/fct_SQLite.R

View check run for this annotation

Codecov / codecov/patch

R/fct_SQLite.R#L45-L47

Added lines #L45 - L47 were not covered by tests
}
return(query_df)
}

#' Connect to database
#'
#' Small helper function to connect to database. This way, the connection
Expand Down Expand Up @@ -59,6 +110,9 @@
#' @param reviewer Character vector. Sets the reviewer in the review database.
#' @param status Character vector. Sets the status in the review database.
#' Defaults to `new`.
#' @param query_path If it exists, provide a file.path to an RDS file,
#' containing data.frame with the same schema as `query_data_skeleton`, used
#' to populate a new database with existing queries from the EDC.
#'
#' @return A database will be created. Nothing else will be returned.
#' @export
Expand All @@ -70,7 +124,8 @@
db_path,
reviewed = "No",
reviewer = "",
status = "new"
status = "new",
query_path = NULL
){
stopifnot(!file.exists(db_path))
stopifnot(reviewed %in% c("Yes", "No", ""))
Expand All @@ -93,9 +148,14 @@
status = status
)

# verify that the query_path points at something that exists and is usable. If
# it passes all the checks, read in the data.frame to 'query_df'. If it
# doesn't, use the query_data_skeleton
query_df <- check_query_path(query_path = query_path)

new_pk_data <- list(
"all_review_data" = df,
"query_data" = query_data_skeleton
"query_data" = query_df
)
idx_pk_cols <- list(
all_review_data = idx_cols
Expand Down Expand Up @@ -230,6 +290,10 @@
#' @param common_vars A character vector containing the common key variables.
#' @param edit_time_var A character vector with the column name of the edit-time
#' variable.
#' @param query_path If it exists, provide a file.path to an RDS file,
#' containing data.frame with the same schema as `query_data_skeleton`, used
#' to populate a new database with existing queries from the EDC.
#'
#'
#' @return Nothing will be returned.
#' @export
Expand All @@ -239,7 +303,8 @@
db_path,
common_vars = c("subject_id", "event_name", "item_group",
"form_repeat", "item_name"),
edit_time_var = "edit_date_time"
edit_time_var = "edit_date_time",
query_path = NULL
){
stopifnot(file.exists(db_path))
con <- get_db_connection(db_path)
Expand Down Expand Up @@ -276,6 +341,20 @@
data.frame("synch_time" = data_synch_time),
overwrite = TRUE
)

# If applicable, Dump old query table & inject it with fresh query info
query_df <- check_query_path(query_path = query_path)

if(nrow(query_df) > 0){
con <- get_db_connection(db_path)
rs <- DBI::dbSendStatement(con, "DELETE FROM query_data")
DBI::dbClearResult(rs)
DBI::dbAppendTable(con, "query_data", query_df)
cat("Finished updating 'query_data' table in user_db.\n\n")

Check warning on line 353 in R/fct_SQLite.R

View check run for this annotation

Codecov / codecov/patch

R/fct_SQLite.R#L349-L353

Added lines #L349 - L353 were not covered by tests
} else {
cat("Did not update 'query_data' table in user_db.\n\n")
}

cat("Finished updating review data\n")
}

Expand Down
5 changes: 3 additions & 2 deletions R/run_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ run_app <- function(
data <- get_golem_config("study_data")
meta <- get_golem_config("meta_data")
user_db <- get_golem_config("user_db")
query_path <- get_golem_config("query_data")
use_shinymanager <- isTRUE(get_golem_config("user_identification") == "shinymanager")
credentials_db <- get_golem_config("credentials_db")

Expand Down Expand Up @@ -72,13 +73,13 @@ run_app <- function(
is.character(user_db))
if(!file.exists(user_db)){
warning("No user database found. New database will be created")
db_create(get_review_data(data), db_path = user_db)
db_create(get_review_data(data), db_path = user_db, query_path = query_path)
} else{
stopifnot("user_db version is not up to date" =
identical(db_version, db_get_version(user_db)))
# Skip if not needed for faster testing:
if(isTRUE(get_golem_config("app_prod"))){
db_update(get_review_data(data), db_path = user_db)
db_update(get_review_data(data), db_path = user_db, query_path = query_path)
}
}

Expand Down
3 changes: 2 additions & 1 deletion inst/golem-config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
default:
golem_name: clinsight
golem_version: 0.2.0.9005
golem_version: 0.2.0.9006
app_prod: no
user_identification: test_user
study_data: !expr clinsight::clinsightful_data
meta_data: !expr clinsight::metadata
user_db: user_db.sqlite
query_data: null
user_roles:
Administrator: admin
Medical Monitor: medical_monitor
Expand Down
22 changes: 22 additions & 0 deletions man/check_query_path.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion man/db_create.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/db_update.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.