Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions docs/user_guide/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# User Guide

This section provides a detailed guide to using the `reproschema` command-line interface (CLI).

It covers the following topics:
- [Reproschema to REDCap](reproschema2redcap.md)
- [REDCap to Reproschema](redcap2reproschema.md)
- [LORIS to Reproschema](loris2reproschema.md)
- [Output to REDCap](output2redcap.md)
- [Reproschema to FHIR](reproschema2fhir.md)
55 changes: 55 additions & 0 deletions docs/user_guide/loris2reproschema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# LORIS to ReproSchema Conversion

The `reproschema loris2reproschema` command converts a LORIS data dictionary in CSV format to the ReproSchema format.

## Usage

```bash
reproschema loris2reproschema [OPTIONS] CSV_FILE CONFIG_FILE
```

### Arguments

- `CSV_FILE`: Path to the LORIS data dictionary CSV file. (Required)
- `CONFIG_FILE`: Path to the YAML configuration file. (Required)

### Options

- `--output-path PATH`: Path to the output directory. Defaults to the current directory.
- `--encoding TEXT`: Encoding to use for reading the CSV file (e.g., `utf-8`, `latin-1`).
- `--analyze`: Only analyze the CSV file structure and exit without conversion.
- `--verbose`: Enable verbose logging.
- `--help`: Show the help message and exit.

## Configuration File

The conversion process is controlled by a YAML configuration file. This file specifies how to map the columns in your LORIS CSV to ReproSchema fields, and provides metadata for the protocol.

Here is an example of a configuration file:

```yaml
# Protocol information
protocol_name: "HBCD_LORIS"
protocol_display_name: "HEALthy Brain and Child Development Study"
protocol_description: "Protocol for the HBCD study using LORIS data dictionary"
loris_version: "1.0.0"

# Column mappings from LORIS CSV to ReproSchema
column_mappings:
activity_name: "full_instrument_name"
item_name: "name"
question: "question"
field_type: "field_type"
response_option_labels: "option_labels"
response_option_values: "option_values"
```

## Example

To convert a LORIS CSV file named `HBCD_LORIS.csv` using a configuration file `hbcd-loris.yml`, you would run:

```bash
reproschema loris2reproschema HBCD_LORIS.csv hbcd-loris.yml --output-path my-protocol
```

This will create a new directory named `my-protocol/HBCD_LORIS` containing the ReproSchema representation of your protocol.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ nav:
- CLI Usage: user_guide/cli_usage.md
- Reproschema to REDCap: user_guide/reproschema2redcap.md
- REDCap to Reproschema: user_guide/redcap2reproschema.md
- LORIS to Reproschema: user_guide/loris2reproschema.md
- Output to REDCap: user_guide/output2redcap.md
- Reproschema to FHIR: user_guide/reproschema2fhir.md
- About: about.md
Expand Down
44 changes: 44 additions & 0 deletions reproschema/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,50 @@ def redcap2reproschema(csv_path, yaml_path, output_path):
raise click.ClickException(f"Error during conversion: {e}")


@main.command()
@click.argument("csv_file", type=click.Path(exists=True, dir_okay=False))
@click.argument("config_file", type=click.Path(exists=True, dir_okay=False))
@click.option(
"--output-path",
type=click.Path(dir_okay=True, writable=True, resolve_path=True),
default=".",
show_default=True,
help="Path to the output directory, defaults to the current directory.",
)
@click.option(
"--encoding",
help="Encoding to use for reading the CSV file (e.g., utf-8, latin-1).",
)
@click.option(
"--analyze",
is_flag=True,
help="Only analyze the CSV file structure and exit without conversion.",
)
@click.option(
"--verbose",
is_flag=True,
help="Enable verbose logging.",
)
def loris2reproschema(
csv_file, config_file, output_path, encoding, analyze, verbose
):
"""
Converts LORIS CSV files to Reproschema format.
"""
from .loris2reproschema import loris2reproschema as loris2rs

try:
loris2rs(
csv_file, config_file, output_path, encoding, analyze, verbose
)
if not analyze:
click.echo(
"Converted LORIS data dictionary to Reproschema format."
)
except Exception as e:
raise click.ClickException(f"Error during conversion: {e}")


@main.command()
@click.argument("input_path", type=click.Path(exists=True, dir_okay=True))
@click.argument("output_csv_path", type=click.Path(writable=True))
Expand Down
13,823 changes: 13,823 additions & 0 deletions reproschema/example/loris/HBCD_LORIS.csv

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions reproschema/example/loris/hbcd-loris.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# HBCD LORIS Configuration

# Protocol information
protocol_name: "HBCD_LORIS"
protocol_display_name: "HEALthy Brain and Child Development Study"
protocol_description: "Protocol for the HBCD study using LORIS data dictionary"
loris_version: "1.0.0"
protocol_preamble: "This protocol contains the HBCD assessment instruments from the LORIS data dictionary"

# Domain/instrument column settings
domain_column: "full_instrument_name"
fallback_domain_column: "domain"
default_domain: "General"

# Schema context URL (defaults to ReproSchema standard URL if not specified)
schema_context_url: "https://raw.githubusercontent.com/ReproNim/reproschema/main/releases/1.0.0/reproschema"

# Column mappings - customized based on HBCD LORIS CSV format
column_mappings:
# Main identifiers and structure
activity_name: "full_instrument_name" # Primary grouping field
item_name: "name" # Field identifier
question: "question" # Question text

# Input type and validation
field_type: "field_type" # Type of input (dropdown, text, etc.)
validation: "data_type" # Data type validation
required: "loris_required" # If field is required

# Response options
response_option_labels: "option_labels" # Labels for choices
response_option_values: "option_values" # Values for choices

# Additional metadata
description: "description" # Field description
min_value: "redcap_text_validation_min" # Min value if applicable
max_value: "redcap_text_validation_max" # Max value if applicable
visibility: "redcap_branching_logic" # Conditional display logic
annotation: "redcap_field_annotation" # Additional annotations
matrix_group: "redcap_matrix_group_name" # Matrix group name

# Additional columns to include as notes in the schema
additional_notes_fields:
- "source_field"
- "source_from"
- "source_respondent"
- "study"
- "data_type"
- "data_scope"
- "field_category"
- "field_class"
- "coding_format"
- "collection_platform"
- "collection_required"
- "description_status"

# Field type overrides - map specific HBCD types to correct ReproSchema input types
field_type_overrides:
"Dropdown": "select"
"Multi-select": "selectMultiple"
"Text": "text"
"Dropdown, Multi-select": "selectMultiple"

# Enable verbose logging
verbose: true
Loading
Loading