hsx1 / redcap2json

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

redcap2json

Handling data dictionaries from REDCap. REDCap is used for electronic data collection.

Oftentimes, experimenters will only download a CSV will the raw data. To access the labels of many Recap question types. Download the code dictionary along with the raw data. This script allows to parse the data dictionary into an object that can either be used during data analysis or saved into a json structure.

Requirements

  • pandas
  • jsonpickle

Usage

Save answer as json

from redcap2json import Project

file_path = "/Users/Path/To/CivibeScreening_DataDictionary_2023-04-30.csv"
proj = Project(file_path)

json_path = "/Users/Path/To/CivibeScreening_DataDictionary_2023-04-30.json"
proj.save_as_json(json_path)

Use project object in script

# load data dictionary in object structure
file_path = "/Users/Path/To/CivibeScreening_DataDictionary_2023-04-30.csv"
proj = Project(file_path)

# get overview of all form/survey names
overview_forms = proj.get_forms()
print(overview_forms)

# overview of all item/question names
overview_items = proj.get_questions()
print(overview_items)

# options/content for one single item
# 
# option 1 - from specific form/survey
single_item = proj.forms["online_screening_consent_form"].get_content(
    content="screening_language")
print(single_item)
# option 2 - from whole project
single_item = proj.get_content("screening_language")
print(single_item)

Further Resources

About

License:MIT License


Languages

Language:Python 100.0%