Skip to content

Commit

Permalink
account for field [event-name] in branching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbarks committed Sep 25, 2023
1 parent a3e0385 commit 51382f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export(translate_logic)
importFrom(chron,times)
importFrom(dplyr,`%>%`)
importFrom(dplyr,across)
importFrom(dplyr,add_row)
importFrom(dplyr,all_of)
importFrom(dplyr,anti_join)
importFrom(dplyr,any_of)
Expand Down
22 changes: 19 additions & 3 deletions R/generate_queries.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#' }
#'
#' @importFrom dplyr `%>%` filter mutate select left_join if_else n rename
#' arrange all_of bind_rows group_by ungroup summarize across case_when
#' arrange all_of bind_rows group_by ungroup summarize across case_when add_row
#' @importFrom rlang .data .env
#' @export generate_queries
generate_queries <- function(conn,
Expand All @@ -64,7 +64,6 @@ generate_queries <- function(conn,
drop_redundant = FALSE,
on_error = "warn") {


## validate argument lang
lang <- match.arg(lang, c("en", "fr"))

Expand All @@ -80,9 +79,26 @@ generate_queries <- function(conn,
## validate argument query_types
query_types <- match.arg(query_types, c("missing", "not missing", "both"))

## fetch metadata events
m_events <- meta_events(conn)

event_choices <- paste(
m_events$unique_event_name,
m_events$event_name,
sep = ", ",
collapse = " | "
)

## fetch metadata dictionary
dict$field_label <- string_squish(dict$field_label)
dict_check <- expand_checkbox(dict)

dict_check <- expand_checkbox(dict) %>%
add_row(
field_name = "redcap_event_name",
field_label = "Event Name",
field_type = "radio",
choices = event_choices
)

## fetch metadata exported fields
exported_fields <- meta_fields(conn)
Expand Down
1 change: 1 addition & 0 deletions R/translate_logic.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ translate_prep <- function(x) {
x <- gsub("[[:space:]]*<>[[:space:]]*", " != ", x)
x <- gsub("[[:space:]]*>(?![=])[[:space:]]*", " > ", x, perl = TRUE)
x <- gsub("[[:space:]]*<(?![=])[[:space:]]*", " < ", x, perl = TRUE)
x <- gsub("\\[event\\-name\\]", "[redcap_event_name]", x)
x <- gsub("([[]|[]])", "", x)
x <- gsub("\"", "\'", x)
str2lang(x)
Expand Down

0 comments on commit 51382f9

Please sign in to comment.