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

convert Redcap2ReproSchema.js to redcap2reproschema.py #30

Merged
merged 26 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ef27982
convert js to python
yibeichan Dec 25, 2023
142089e
add redcap2rs yaml template
yibeichan Dec 25, 2023
abd9c48
update yaml template
yibeichan Dec 25, 2023
675a4b2
update instruction to use redcap2reproschema.py
yibeichan Dec 25, 2023
1f8746d
add additional python package
yibeichan Dec 25, 2023
550db35
convert redcap2rs too from js to python
yibeichan Dec 25, 2023
7881305
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 25, 2023
a3606fb
integrate redcap2rs in cli.py
yibeichan Dec 26, 2023
73da571
rewrite main() for cli use
yibeichan Dec 26, 2023
4906d76
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 26, 2023
25932f8
update the template
yibeichan Dec 27, 2023
451af3c
major updates for converting
yibeichan Dec 27, 2023
5582c74
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 27, 2023
8739b10
Merge branch 'master' into redcap2reproschema
yibeichan Dec 27, 2023
14976ec
merge from master
yibeichan Dec 27, 2023
47fb76b
Merge branch 'master' into redcap2reproschema
yibeichan Dec 27, 2023
b6685e0
remove the github part
yibeichan Dec 28, 2023
3e72f25
add test for redcap2reproschema
yibeichan Dec 28, 2023
587b388
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 28, 2023
a4e21a1
missing commits fpr cli
yibeichan Dec 28, 2023
0c96d56
fix the missing commit for cli
yibeichan Dec 28, 2023
8838e06
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 28, 2023
ad7191a
remove protocol_variable_map
yibeichan Dec 28, 2023
163316c
Merge branch 'redcap2reproschema' of https://github.com/yibeichan/rep…
yibeichan Dec 28, 2023
e5e6091
fix protocol path
yibeichan Dec 28, 2023
f5dd9c5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,57 @@ Commands:
validate
```

## redcap2reproschema Usage
The `redcap2reproschema` function is designed to process a given REDCap CSV file and YAML configuration to generate the output in the reproschema format.

### Prerequisites
Before the conversion, ensure you have the following:

**YAML Configuration File**:
- Download [templates/redcap2rs.yaml](templates/redcap2rs.yaml) and fill it out with your protocol details.

### YAML File Configuration
In the `templates/redcap2rs.yaml` file, provide the following information:

- **protocol_name**: This is a unique identifier for your protocol. Use underscores for spaces and avoid special characters.
- **protocol_display_name**: The name that will appear in the application.
- **protocol_description**: A brief description of your protocol.

Example:
```yaml
protocol_name: "My_Protocol"
protocol_display_name: "Assessment Protocol"
protocol_description: "This protocol is for assessing cognitive skills."
```
### Command-Line Usage

The `redcap2reproschema`` function has been integrated into a CLI tool, use the following command:
```bash
reproschema redcap2reproschema path/to/your_redcap_data_dic.csv path/to/your_redcap2rs.yaml
```

### Python Function Usage

You can also use the `redcap2reproschema` function from the `reproschema-py` package in your Python code.

```python
from reproschema import redcap2reproschema

csv_path = "path-to/your_redcap_data_dic.csv"
yaml_path = "path-to/your_redcap2rs.yaml"

reproschema2redcap(input_dir_path, output_csv_filename)
```

After configuring the YAML file:

1. Run the Python script with the paths to your CSV file and the YAML file as arguments.
2. Command Format: `python script_name.py path/to/your_redcap_data_dic.csv path/to/your_redcap2rs.yaml`

### Notes
1. The script requires an active internet connection to access the GitHub repository.
2. Make sure you use `git add`, `git commit`, `git push` properly afterwards to maintain a good version control for your converted data.

## Developer installation

Install repo in developer mode:
Expand Down
15 changes: 15 additions & 0 deletions reproschema/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from . import get_logger, set_logger_level
from . import __version__
from .redcap2reproschema import redcap2reproschema as redcap2rs

lgr = get_logger()

Expand Down Expand Up @@ -95,3 +96,17 @@ def serve(port):
from .utils import start_server

start_server(port=port)


@main.command()
@click.argument("csv_path", type=click.Path(exists=True, dir_okay=False))
@click.argument("yaml_path", type=click.Path(exists=True, dir_okay=False))
def redcap2reproschema(csv_path, yaml_path):
"""
Convert REDCap CSV files to Reproschema format.
"""
try:
redcap2rs(csv_path, yaml_path)
click.echo("Converted REDCap data dictionary to Reproschema format.")
except Exception as e:
raise click.ClickException(f"Error during conversion: {e}")
Loading
Loading