16  Data Access Groups (DAGs)

In addition to user roles for access control, DAGs control which records each user can access. Users assigned to a DAG can only access records assigned to that particular DAG, and are blinded to records outside of their group. DAGs are particularly useful in multi-site or multi-jurisdictional projects to restrict sites from viewing records from other sites.

Users can be assigned to a DAG after being added to the project. Users can be in multiple DAGs. Users not assigned to any DAG have global access and can see all records in the project.

Records are assigned to DAG’s using the ‘Record Status Dashboard’ in REDCap. In this project, one DAG group was created called ‘records1_2’ that contains Record IDs 1 & 2.

redcap_dag_read()

View the DAGs and their unique data_access_group_id:

%%capture
%%R 
dag <- redcap_dag_read(redcap_uri = url, token)$data

Use redcap_read_oneshot to view record DAG assignments:

%%capture
%%R
data_dag <- redcap_read_oneshot(
    redcap_uri = url, 
    token = token,
    export_data_access_groups = TRUE, 
    fields = "record_id")$data

For the REDCapR package, refer to the data_user table printed in Chapter 15 to see user DAG assignments.

export_dags(), export_user_dag_assignment()

View the DAGs and their unique data_access_group_id:

project.export_dags(format_type='df') 
data_access_group_name unique_group_name data_access_group_id
0 Limited Access limited_access 2707
1 records1_2 records1_2 2716

View users’ DAG assignments:

project.export_user_dag_assignment(format_type='df') #exports users and their assigned DAGs (username and DAG)
username redcap_data_access_group
0 alexey.gilman@doh.wa.gov records1_2
1 caitlin.drover@doh.wa.gov NaN
2 emily.pearman@doh.wa.gov NaN

Use export_records to view which records belong to which data access group.

dag = project.export_records(format_type = 'df', export_data_access_groups = True, fields = 'record_id')
dag.head()
redcap_repeat_instrument redcap_repeat_instance redcap_data_access_group
record_id redcap_event_name
1 personal_info_arm_1 NaN NaN records1_2
notifications_arm_1 NaN NaN records1_2
case_intake_arm_1 NaN 1.0 records1_2
2 personal_info_arm_1 NaN NaN records1_2
notifications_arm_1 NaN NaN records1_2

Note: Even though only record_id was specified for export under the fields argument, PyCap will automatically include all the variables that make the unique_key (record_id, redcap_event_name, redcap_repeat_instrument, redcap_repeat_instance).