redcap_bridge package
Submodules
redcap_bridge.cli module
Provide CLI for the main functionalities of the redcap bridge
- redcap_bridge.cli.main(command_line=None)
redcap_bridge.project_building module
- redcap_bridge.project_building.build_project(project_csv, output_file=None, include_provenance=True)
Build a complete RedCap Instrument CSV from a set of template_parts and a project csv file.
- Parameters:
project_csv (str) – Filepath of the project csv file
output_file (str, None) – Filepath of the resulting, complete project csv (with inserted template_parts. If None, the content is only returned and not saved. Default: None
include_provenance (bool) – If True, include hidden fields in the project csv that contain git commits of source files Default: True
- Returns:
(list) list containing the lines of the complete project definition
including the template content
- redcap_bridge.project_building.customize_project(project_built_csv, customization_csv, output_file=None)
Fill in a built project csv with project specific customizations.
This can be used to e.g. change the default values of fields or customize the list of experimenters to be selected
- Parameters:
project_built_csv (str) – The filepath to the csv containing the built project (see also build_project)
customization_csv (str) – The filepath to the csv containing the project customizations
output_file (str) – The path to save the combined csv. Default: None
- Returns:
pandas dataframe csv representation of the customized project definition
- Return type:
dataframe
- redcap_bridge.project_building.extract_customization(project_csv, export_custom_csv, *template_parts)
Extract custom parts of a project data dict by subtracting template parts
- Parameters:
project_csv (path) – path to the complete project csv file
export_custom_csv (path) – path to store the resulting customization csv file
*template_parts ((list)) – list of template parts included in the project
redcap_bridge.project_control module
- redcap_bridge.project_control.setup_project(proj_folder, working_dir=None, include_provenance=True)
Build a project csv from its specifications and setup on the server
- Parameters:
proj_folder ((path)) – folder containing the project specification files project.json, structure.csv and customizations.csv
working_dir ((path)) – directory in which to store temporarily generated project files
include_provenance ((bool)) – include hidden provenance information in project csv. Default: True
redcap_bridge.project_validation module
- redcap_bridge.project_validation.validate_project_against_template_parts(project, *templates)
Validate a built project csv
- Parameters:
project (str, buffer) – Filepath of the csv file or csv buffer of the built project
templates (str, list) – List of file paths of the template part csvs.
- Returns:
True if the validation was successful
- Return type:
bool
- redcap_bridge.project_validation.validate_record_against_template(record_csv, template_csv)
Validate a RedCap record against a template instrument
- Parameters:
record_csv (path) – path to the record csv of that instrument
template_csv (path) – path to the template csv of an instrument
- Return type:
True
- Raises:
ValueError in case of failing validation –
redcap_bridge.server_interface module
- redcap_bridge.server_interface.check_external_modules(server_config_json)
Download records from the redcap server.
- Parameters:
server_config_json (str) – Path to the json file containing the redcap url, api token and required external modules
- Returns:
bool
- Return type:
True if required external modules are present
- redcap_bridge.server_interface.configure_project_settings(server_config_json)
Setting project specific settings on server
- Parameters:
server_config_json (str) – Path to the json file containing the redcap url, api token and required external modules
- redcap_bridge.server_interface.download_datadict(save_to, server_config_json, format='csv')
- Parameters:
save_to (str) – Path where to save the retrieved data dictionary
server_config_json (str) – Path to the json file containing the redcap url and api token
format ('csv', 'json', 'df') – Format of the retrieved data dictionary
- redcap_bridge.server_interface.download_project_settings(server_config_json, format='json')
Get project specific settings from server
- Parameters:
server_config_json (str) – Path to the json file containing the redcap url, api token and required external modules
format (str) – Return format to use (json, csv, xml, df)
- Returns:
(dict|list|xml|df)
- Return type:
The project settings in the corresponding format
- redcap_bridge.server_interface.download_records(save_to, server_config_json, format='csv', compressed=False, **kwargs)
Download records from the redcap server.
- Parameters:
save_to (str) – Path where to save the retrieved records csv
server_config_json (str) – Path to the json file containing the redcap url and api token
format ('csv', 'json') – Format of the retrieved records
kwargs (dict) – Additional arguments passed to PyCap export_records
- redcap_bridge.server_interface.get_json_csv_header_mapping(server_config_json)
- Returns:
Mapping of json to csv headers
- Return type:
dict
- redcap_bridge.server_interface.get_redcap_project(server_config_json)
Initialize a pycap project based on the provided server configuration :param server_config_json: json file containing the api_url and api_token :return: pycap project
- redcap_bridge.server_interface.upload_datadict(csv_file, server_config_json)
- Parameters:
csv_file (str) – Path to the csv file to be used as data dictionary
server_config_json (str) –
Path to the json file containing the redcap url and api token
- returns:
(int)
- rtype:
The number of uploaded fields
- redcap_bridge.server_interface.upload_records(csv_file, server_config_json)
- Parameters:
csv_file (str) – Path to the csv file to be used as records
server_config_json (str) –
Path to the json file containing the redcap url and api token
- returns:
(int)
- rtype:
Number of uploaded records
redcap_bridge.utils module
- redcap_bridge.utils.compress_record(csv_file, compressed_file=None)
- redcap_bridge.utils.exportCSVtoXLS(csv_file, compressed_file=None)
- redcap_bridge.utils.remove_columns(csv_file, compressed_file=None)