Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update proof_of_concept.R #25

Open
pbchase opened this issue Feb 13, 2025 · 0 comments
Open

Update proof_of_concept.R #25

pbchase opened this issue Feb 13, 2025 · 0 comments

Comments

@pbchase
Copy link
Contributor

pbchase commented Feb 13, 2025

Edit proof_of_concept.R removing these lines

metadata <- REDCapR::redcap_metadata_read(
token = credentials$token,
redcap_uri = credentials$redcap_uri
)$data
# identify the record_id column
record_id_name <- metadata |>
filter(row_number() == 1) |>
pull(field_name)
# identify the forms to fill
forms_to_fill <- metadata |>
distinct(form_name) |>
filter(!form_name %in% c("randomization")) |>
pull(form_name)
field_types_we_know_how_to_fill <- c(
"checkbox",
"dropdown",
"notes",
"radio",
"text",
"yesno",
"truefalse",
"slider"
)
metadata_to_populate <-
metadata |>
# exclude the record_id field from filling
filter(field_name != record_id_name) |>
# Filter for forms we want to fill
filter(form_name %in% forms_to_fill) |>
# Exclude descriptive fields because they are not fillable
filter(field_type != "descriptive") |>
# Exclude calc fields because we don't control them
# (though we might strobe them to trigger writes in a future version)
filter(field_type != "calc") |>
# Exclude file fields
# (Eventually we'll add an option to populate them with a dummy file)
filter(field_type != "file") |>
# Filter for fields not hidden via branching logic.
filter(is.na(branching_logic)) |>
# filter for fields we no how to fill
filter(field_type %in% field_types_we_know_how_to_fill)
# Make a vector of record IDs to populate
# Get highest existing id
read_result <- REDCapR::redcap_read(
token = credentials$token,
redcap_uri = credentials$redcap_uri
)
if (nrow(read_result$data) > 0) {
max_existing_id <- max(read_result$data$record_id)
} else {
max_existing_id <- 0
}
# choose which IDs to use
first_id <- max_existing_id + 1
number_of_records_to_populate <- 5
record_ids <- seq(first_id, first_id + number_of_records_to_populate)
# get the categorical field responses in a long table and populate them
long_categorical_field_responses <- get_long_categorical_field_responses(metadata_to_populate)
long_text_fields <- get_long_text_fields(metadata_to_populate)
long_slider_fields <- get_long_slider_fields(metadata_to_populate)
long_notes_fields <- get_long_notes_fields(metadata_to_populate)
long_fields_and_responses <- bind_rows(
long_categorical_field_responses,
long_text_fields,
long_slider_fields,
long_notes_fields
)
picked_values <-
purrr::map(
record_ids,
get_one_rectangle_of_values,
record_id_name,
forms_to_fill,
long_fields_and_responses
) |>
bind_rows()

Replace them with a call to get_project_values(), created in issue #24. Write the result to generated_values.

Replace

picked_values |> REDCapR::redcap_write(
token = credentials$token,
redcap_uri = credentials$redcap_uri
)

...with code to iterate over generated_values writing each dataframe of generated data to REDCap.

@pbchase pbchase added this to the Add longitudinal support milestone Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant