# BIDS Compliance Quick Reference **For Developers & Contributors** --- ## ๐ŸŽฏ At a Glance **What**: PRISM Studio now enforces BIDS compliance automatically **Where**: `app/templates/projects.html` (UI) + `app/src/web/blueprints/projects.py` (Backend) **How**: Form โ†’ dataset_description.json โ†’ CITATION.cff sync โ†’ Form reload **Why**: Ensures metadata consistency and BIDS-app compatibility --- ## ๐Ÿ“‹ Field Categories ### REQUIRED (โš ๏ธ Will fail validation if missing) - โœ… `Name`: Dataset name (MUST be provided by user) - โœ… `BIDSVersion`: Auto-set to "1.10.1" (no user input) ### RECOMMENDED (โš ๏ธ Will get auto-defaults) - ๐ŸŸก `DatasetType`: Auto-set to "raw" if missing - ๐ŸŸก `License`: Auto-set to "CC0" if missing (unless CITATION.cff exists) - ๐ŸŸก `HEDVersion`: Only include if you use HED tags - ๐ŸŸก `GeneratedBy`: API-only (preserved from existing) - ๐ŸŸก `SourceDatasets`: API-only (preserved from existing) ### OPTIONAL (No auto-defaults) - โšช `Authors`: Array of {name, email} - โšช `Keywords`: Array of strings (โ‰ฅ3 recommended) - โšช `Acknowledgements`: Free text - โšช `HowToAcknowledge`: Free text - โšช `Funding`: Array of strings - โšช `EthicsApprovals`: Array of {name, reference} - โšช `ReferencesAndLinks`: Array of URLs - โšช `DatasetDOI`: DOI URI - โšช `DatasetLinks`: Array of URLs (API-only) --- ## ๐Ÿ”„ CITATION.cff Precedence Rules ### If CITATION.cff EXISTS: ``` dataset_description.json will NOT contain: โŒ Authors โŒ HowToAcknowledge โŒ License โŒ ReferencesAndLinks BUT will still contain: โœ… Name โœ… DatasetDOI ``` ### If CITATION.cff NOT FOUND: ``` dataset_description.json will contain all fields: โœ… Authors โœ… License (defaults to CC0) โœ… HowToAcknowledge โœ… ReferencesAndLinks ``` **Why?**: Avoid duplication. BIDS spec says these fields belong in CITATION.cff when it exists. --- ## ๐Ÿ”ข Field Type Conversions ```text // USER INPUT in form (string) โ†’ STORAGE in JSON (array) "psychology, neuroscience, BIDS" โ†’ ["psychology", "neuroscience", "BIDS"] "NSF #123, Other Grant" โ†’ ["NSF #123", "Other Grant"] // RELOAD from JSON (array) โ†’ FORM DISPLAY (string) ["psychology", "neuroscience"] โ†’ "psychology, neuroscience" ``` **Fields that convert**: Keywords, Funding, ReferencesAndLinks **Fields that don't**: Name, License, DatasetType, DOI, etc. (stored as strings) --- ## ๐Ÿ› ๏ธ Code Locations ### Frontend Form Fields (HTML) **File**: `app/templates/projects.html` ```html ``` **Pattern**: `` or ` Description of this field. ``` ### 2. **Add to Save Function** (projects.html, line 2541-2565) ```javascript const description = { // ... existing fields ... NewField: document.getElementById('metadataNewField').value, }; ``` ### 3. **Add to Load Function** (projects.html, line 2472-2495) ```javascript document.getElementById('metadataNewField').value = desc.NewField || ''; ``` ### 4. **Update Backend** (projects.py, line 707+) - If REQUIRED: Add to validation check - If RECOMMENDED: Add logic to set default value - If OPTIONAL: No backend changes needed (just validate) ### 5. **Test** ```bash python3 scripts/ci/test_bids_compliance.py ``` --- ## ๐Ÿงช Testing Your Changes ### Unit Test ```bash python3 scripts/ci/test_bids_compliance.py ``` ### Manual Test 1. Open PRISM Studio 2. Create/select a project 3. Fill in the metadata form 4. Click Save 5. Verify `dataset_description.json` created correctly 6. Verify `CITATION.cff` generated correctly 7. Click form reload 8. Verify all fields repopulated ### Visual Check ```bash # Check dataset_description.json structure cat /dataset_description.json | python3 -m json.tool # Check CITATION.cff syntax cat /CITATION.cff ``` --- ## โš ๏ธ Common Issues & Solutions ### Issue: "REQUIRED FIELD: Dataset Name is mandatory" **Cause**: Name field is empty **Fix**: Enter a dataset name in the "Dataset Name" field ### Issue: Authors field in dataset_description.json when CITATION.cff exists **Cause**: Backend didn't apply precedence rules **Fix**: Ensure `citation_cff_path.exists()` check in `save_dataset_description()` ### Issue: Keywords not parsing correctly **Cause**: User entered "keyword1, keyword2" but it stored as string instead of array **Fix**: Check that `.split(',').map(s => s.trim()).filter(s => s)` is being applied ### Issue: CITATION.cff not updating **Cause**: `update_citation_cff()` not called or threw exception **Fix**: Check Flask logs for error; ensure `project_manager` is initialized ### Issue: Backend issues array shows "License is RECOMMENDED" **Cause**: This is just a warning, not an error **Fix**: This is expected behavior; you can ignore it or set a License value --- ## ๐Ÿ”— Related Documentation - **Full Spec**: See `docs/BIDS_COMPLIANCE_IMPLEMENTATION.md` (300+ lines) - **Field Audit**: See `docs/METADATA_AUDIT.md` (detailed mappings) - **Status Summary**: See `docs/BIDS_AUTO_MAPPING_COMPLETE.md` (overview) - **Official BIDS**: https://bids-specification.readthedocs.io/ --- ## ๐Ÿš€ Quick Debugging Commands ```bash # Check project structure ls -la / # View dataset_description.json cat /dataset_description.json | python3 -m json.tool # View CITATION.cff cat /CITATION.cff # Run validation tests python3 scripts/ci/test_bids_compliance.py # Check Flask logs grep -i "dataset_description\|citation" prism-studio.log ``` --- ## ๐Ÿ“Š Field Summary Table | Field | Type | Required | Default | Array | CITATION.cff | Notes | |-------|------|----------|---------|-------|-------------|-------| | Name | string | โœ… | - | โŒ | โœ… Synced | BIDS core identifier | | BIDSVersion | string | โœ… | "1.10.1" | โŒ | โŒ | Auto-set by backend | | DatasetType | string | โš ๏ธ | "raw" | โŒ | โŒ | raw, derivative, study | | License | string | โš ๏ธ | "CC0" | โŒ | **Omitted if CITATION.cff** | SPDX identifier | | Authors | array | โŒ | [] | โœ… | **Omitted if CITATION.cff** | {name, email} format | | Keywords | array | โŒ | [] | โœ… | โŒ | โ‰ฅ3 for FAIR | | Acknowledgements | string | โŒ | "" | โŒ | โŒ | Free text | | HowToAcknowledge | string | โŒ | "" | โŒ | **Omitted if CITATION.cff** | Citation instructions | | Funding | array | โŒ | [] | โœ… | โŒ | Free text | | EthicsApprovals | array | โŒ | [] | โœ… | โŒ | {name, reference} | | ReferencesAndLinks | array | โŒ | [] | โœ… | **Omitted if CITATION.cff** | URLs | | DatasetDOI | string | โŒ | "" | โŒ | โœ… Synced | DOI URI | | HEDVersion | string | โŒ | "" | โŒ | โŒ | If HED tags used | --- **Last Updated**: February 2025 **For questions**: See full documentation in `docs/BIDS_COMPLIANCE_IMPLEMENTATION.md`