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

Add wrapper for Export Events API method to export event names #457

Closed
ezraporter opened this issue Dec 14, 2022 · 3 comments · Fixed by #460
Closed

Add wrapper for Export Events API method to export event names #457

ezraporter opened this issue Dec 14, 2022 · 3 comments · Fixed by #460
Assignees

Comments

@ezraporter
Copy link
Contributor

ezraporter commented Dec 14, 2022

Currently REDCapR only has wrappers for the Export Instrument-Event Mappings method redcap_event_instruments() which gives instrument-event-arm mappings and the Export Arms method redcap_arm_export() which gives arm names. For REDCapTidier, we'd like to access the event names to include as metadata. The Export Events method returns those.

Export Events functions almost identically to Export Arms so this new function (redcap_event_export()?) would be almost identical to redcap_arm_export() internally.

Happy to contribute a PR if this idea has your blessing!

@wibeasley
Copy link
Member

@ezraporter, sounds good. I was kinda surprised this function wasn't already in here. How about naming it redcap_event_read()? I'm trying to move everything to the read/write terminology (and away from export/import).

To make sure I understand, this would be a function that produces something like

enrollment_arm_1
dose_1_arm_1
visit_1_arm_1
dose_2_arm_1
visit_2_arm_1
final_visit_arm_1

where the mappings & arms look like this:

uri   <- "https://bbmc.ouhsc.edu/redcap/api/"
token <- "0434F0E9CF53ED0587847AB6E51DE762"
REDCapR::redcap_event_instruments(uri, token)$data
#> 15 event instrument metadata records were read from REDCap in 0.2 seconds.  The http status code was 200.
#> # A tibble: 15 × 3
#>    arm_num unique_event_name form                            
#>      <int> <chr>             <chr>                           
#>  1       1 enrollment_arm_1  demographics                    
#>  2       1 enrollment_arm_1  contact_info                    
#>  3       1 enrollment_arm_1  baseline_data                   
#>  4       1 dose_1_arm_1      patient_morale_questionnaire    
#>  5       1 visit_1_arm_1     visit_lab_data                  
#>  6       1 visit_1_arm_1     patient_morale_questionnaire    
#>  7       1 visit_1_arm_1     visit_blood_workup              
#>  8       1 visit_1_arm_1     visit_observed_behavior         
#>  9       1 dose_2_arm_1      patient_morale_questionnaire    
#> 10       1 visit_2_arm_1     visit_lab_data                  
#> 11       1 visit_2_arm_1     patient_morale_questionnaire    
#> 12       1 visit_2_arm_1     visit_blood_workup              
#> 13       1 visit_2_arm_1     visit_observed_behavior         
#> 14       1 final_visit_arm_1 completion_data                 
#> 15       1 final_visit_arm_1 completion_project_questionnaire
REDCapR::redcap_arm_export(       uri, token)$data
#> The list of arms was retrieved from the REDCap project in 0.1 seconds. The http status code was 200.
#> # A tibble: 2 × 2
#>   arm_number arm_name
#>        <int> <chr>   
#> 1          1 Drug A  
#> 2          2 Drug B

Created on 2022-12-14 with reprex v2.0.2

@ezraporter
Copy link
Contributor Author

How about naming it redcap_event_read()?

Sounds good to me!

To make sure I understand, this would be a function that produces something like

enrollment_arm_1
dose_1_arm_1
visit_1_arm_1
dose_2_arm_1
visit_2_arm_1
final_visit_arm_1

Slightly different. Those names are actually autogenerated by REDCap by massaging the user-defined event name and mashing it together with the arm number. Export Events gives you access to the actual user-defined event name. Here's some example output from one of our test REDCaps:

event_name, arm_num, unique_event_name, custom_event_label, event_id
"Event 1",  1,       event_1_arm_1,     ,                   471384
"Event 2",  1,       event_2_arm_1,     ,                   471385
"Event 1",  2,       event_1_arm_2,     ,                   471387
"Event 3",  2,       event_3_arm_2,     ,                   471388

redcap_event_read() would return a tibble of this in $data and we're particularly interested in the unedited event_name for REDCapTidieR.

@wibeasley
Copy link
Member

Beautiful. This looks useful, even beyond REDCapTidieR. Please tell me if I can help.

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

Successfully merging a pull request may close this issue.

2 participants