Skip to main content

Pandas DataFrame templates for REDCap instruments, with stacking and upload functionality.

Project description

rcol

rcol (RedCap Uni Oldenburg) is a Python package that provides Pandas DataFrame templates for REDCap instruments with stacking and upload functionality.

Installation

pip install rcol

Quick Start

from rcol.instruments import fal, ehi, bdi_ii
import pandas as pd

# Use individual instruments
print(f"FAL has {len(fal)} fields")
print(f"EHI has {len(ehi)} fields") 
print(f"BDI-II has {len(bdi_ii)} fields")

# Stack multiple instruments for REDCap upload
all_instruments = pd.concat([fal, ehi, bdi_ii], ignore_index=True)
print(f"Combined: {len(all_instruments)} total fields")

# Upload to REDCap (requires PyCap and API credentials)
from redcap import Project
project = Project(api_url, api_token)
project.import_metadata(all_instruments, import_format='df')

Available Instruments

  • fal: Fragebogen zur Allgemeinen Leistungsfähigkeit (General Performance Questionnaire)
  • ehi: Edinburgh Handedness Inventory
  • bdi_ii: Beck Depression Inventory II
  • moca: Montreal Cognitive Assessment

Creating Custom Instruments

You can create custom instruments or extend existing ones without contributing to the package:

import pandas as pd
from rcol.instruments import fal, ehi
from redcap import Project

# Create a custom instrument from scratch
custom_instrument = pd.DataFrame({
    'field_name': ['record_id', 'custom_field_1', 'custom_field_2'],
    'field_label': ['Record ID', 'Custom Field 1', 'Custom Field 2'],
    'field_type': ['text', 'text', 'radio'],
    'form_name': ['custom_form', 'custom_form', 'custom_form'],
    'choices': ['', '', '1, Yes | 0, No']
})

# Add a new question to an existing instrument
fal_new_question = pd.DataFrame({
    'field_name': ['fal_like_redcap'],
    'field_label': ['Do you like REDCap?'],
    'field_type': ['radio'],
    'form_name': ['fal'],
    'choices': ['1, Yes | 0, No']
})

fal_extended = pd.concat([fal, fal_new_question], ignore_index=True)

# Combine everything and upload to REDCap
all_instruments = pd.concat([fal_extended, ehi, custom_instrument], ignore_index=True)

project = Project(api_url, api_token)
project.import_metadata(all_instruments, import_format='df')

See tutorial_custom_instruments.py for a complete guide with all REDCap metadata fields.

Contributing a New Instrument

  1. Fork this repository

  2. Add your instrument data in src/rcol/instruments.py:

    # Define your instrument fields
    my_instrument_data = [
        {
            "field_name": "record_id",
            "form_name": "my_instrument", 
            "field_type": "text",
            "field_label": "Record ID",
            # ... other REDCap metadata fields
        },
        # ... more fields
    ]
    
    # Create DataFrame
    my_instrument = pd.DataFrame(my_instrument_data)
    
  3. Run the instrument test suite to validate your template. The shared tests automatically pick up every pandas.DataFrame exported from rcol.instruments and check for required REDCap metadata, non-empty field names, and duplicate protection:

    uv run --with pytest pytest -k instrument
    

    If you add custom validation that needs extra assertions, extend tests/test_templates.py accordingly.

  4. Preview the documentation (optional). The MkDocs site renders the instrument tables directly from rcol.instruments. To check the output locally:

    uv run --group docs mkdocs serve
    
  5. Submit a pull request. Every PR triggers the GitHub Actions CI workflow, which runs the same instrument tests on Ubuntu with Python 3.11. Make sure the workflow badge stays green before requesting review.

Development

# Clone and install for development
git clone https://github.com/JuliusWelzel/rcol.git
cd rcol
uv sync

# Run tests
uv run pytest

# Build package
uv build

Documentation

The documentation site is powered by MkDocs and mkdocstrings, so instrumentation tables are rendered directly from rcol.instruments at build time.

# Serve docs locally
uv run --group docs mkdocs serve

# Build static site
uv run --group docs mkdocs build

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rcol-0.0.3.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rcol-0.0.3-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file rcol-0.0.3.tar.gz.

File metadata

  • Download URL: rcol-0.0.3.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for rcol-0.0.3.tar.gz
Algorithm Hash digest
SHA256 1a9a5ab9ef978c76d7f85fb4d90dd63c8514df5fcb7436cebae9d21aa12d93d6
MD5 c331cdc901bc55080de57282c2e58b6f
BLAKE2b-256 facb8118c18065c8635d27510e19b61cd848ead17b40a8b3631dd2f49824fea8

See more details on using hashes here.

File details

Details for the file rcol-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: rcol-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for rcol-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6251401397fbae90cb56e6b098a12fa06c4d897e650245151c5f98a014d218cf
MD5 8878e023ecd7ab5f13b25b890a129829
BLAKE2b-256 ecb344c2d73d55f340f029b66d41ea3aa6213500d1f5e5755563a1017deef92c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page