-
Notifications
You must be signed in to change notification settings - Fork 0
feat: ✨ download REDCap data dictionary script #33
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
Changes from 3 commits
9abadc0
fd90c6c
9de023f
7c86fbc
c87d2af
cc05c21
dbd25c3
e589e8f
daa6828
f82fffd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| """Processing and build pipeline scripts.""" | ||
|
|
||
| from .redcap import save_data_dict | ||
|
|
||
| __all__ = [ | ||
| "save_data_dict", | ||
| ] | ||
|
martonvago marked this conversation as resolved.
Outdated
|
||
|
martonvago marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import json | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import requests | ||
| from dotenv import load_dotenv | ||
|
|
||
| load_dotenv() | ||
|
lwjohnst86 marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def get_data_dict_from_redcap() -> dict[str, str]: | ||
| """Gets the data dictionary from REDCap.""" | ||
| token = os.environ.get("REDCAP_TOKEN") | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the token has
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for the generic code we should use the more general name, for the implementation of this code on ON LiMiT Feasibility we'll need to know that this is the code for the instance on REDCap in Copenhagen. Later there will be tokens for Copenhagen, Aarhus and Odense.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will all the locations be in the same repo or different repos?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the REDCap locations will pull into this one Data Package repo, as far I know.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah okay! The metadata will be exactly the same, right (it's enough to get it from one location)? Then I will change the token name back to the CPH-specific one.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For feasibility the only instance that we will be pulling 'real' data from is the Copenhagen one, but for testing we should be able to use the Aarhus version. I'm not sure we should be testing the data transfer with real data to start with. It would have been easier if we had some time to run tests on the system in Cph before we went into production, hopefully we'll have that for the main study. The main study is still being designed, but it does look like we'll run several REDCap instances on the Aarhus server, each with slightly different data dictionaries... |
||
| if not token: | ||
| raise RuntimeError("REDCAP_TOKEN environment variable is not set.") | ||
|
|
||
| data = { | ||
| "token": token, | ||
| "content": "metadata", | ||
| "format": "json", | ||
| "returnFormat": "json", | ||
| } | ||
| response = requests.post("https://redcap.au.dk/api/", data=data, timeout=30) | ||
|
martonvago marked this conversation as resolved.
Outdated
|
||
| response.raise_for_status() | ||
| return response.json() | ||
|
|
||
|
|
||
| def save_data_dict(): | ||
| """Saves the data dictionary from REDCap to `scripts/data_dictionary.json`.""" | ||
| data_dict = get_data_dict_from_redcap() | ||
| file_path = Path("scripts") / "data_dictionary.json" | ||
| file_path.parent.mkdir(exist_ok=True) | ||
| with open(file_path, "w") as f: | ||
| json.dump(data_dict, f, indent=2, ensure_ascii=False) | ||
Uh oh!
There was an error while loading. Please reload this page.