Skip to content

feat(#833): error when forms reference CSV external datasets - #839

Open
yasumorishima wants to merge 1 commit into
medic:mainfrom
yasumorishima:feat/833-csv-external-datasets
Open

yasumorishima wants to merge 1 commit into
medic:mainfrom
yasumorishima:feat/833-csv-external-datasets

Conversation

@yasumorishima

Copy link
Copy Markdown

Description

Adds a form validation that fails when a form references an external dataset stored in a CSV file.

Since select_*_from_file support landed (medic/cht-core#10971), only XML datasets are supported. A form whose secondary instance uses src="jr://file-csv/..." uploads and loads without any error, but the question simply has no data. This catches that before the form reaches the server.

  • src/lib/validation/form/no-csv-external-datasets.js: errors for every model/instance node whose src starts with jr://file-csv/. requiresInstance: false and skipFurtherValidation: false, as suggested in the issue. All offending sources are listed in a single message, with a link to the docs.
  • test/lib/validation/form/no-csv-external-datasets.spec.js: 7 unit tests (no external data, XML source, one CSV source, several CSV sources, mixed XML/CSV, a jr://file-csv-backup/... near match, and a whitespace padded src).
  • test/lib/validate-forms.spec.js: added the new validation to the expected load order.

No documentation change looked necessary: the docs already state that only XML files are supported. Note this is a behaviour change for existing configs that reference a CSV dataset - they will now fail validation instead of uploading a form that quietly shows no choices.

AI Disclosure: this PR was written primarily with Claude Code. It explored the codebase, drafted the validation following the existing ones and wrote the tests. I reviewed the result, verified the error message against the docs, and confirmed lint, unit tests (Node 20/22/24) and the e2e suite pass.

#833

Code review items

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or integration tests where appropriate
  • Backwards compatible: Works with existing data and configuration. Any breaking changes documented in the release notes.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants