added validation for group to have atleast 1 sub question
Proposed Changes
- Add validation in questionnaire create to raise error if a group is without any sub questions
- Updated submit endpoint to ignore group questions with no sub questions
Merge Checklist
- [ ] Tests added/fixed
- [ ] Update docs in
/docs - [ ] Linting Complete
- [ ] Any other necessary step
Only PR's with test cases included and passing lint and test pipelines will be reviewed
@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins
Summary by CodeRabbit
- Bug Fixes
- Improved validation for questionnaire questions, ensuring group-type questions cannot be empty and preventing errors when "questions" are missing.
- Enhanced robustness by safely handling missing or empty question groups during validation and processing.
π Walkthrough
Walkthrough
The updates rename a validation method in the Question class and expand its logic to include checks for empty group questions. Additionally, dictionary access in two utility functions is made safer and more robust by using .get() and by adding guards to skip empty groups during recursion.
Changes
| File(s) | Change Summary |
|---|---|
| care/emr/resources/questionnaire/spec.py | Renamed validate_value_set_or_options to validate_choice_and_group_questions; added validation for empty groups. |
| care/emr/resources/questionnaire/utils.py | Replaced direct key access with .get() for "questions"; added guard to skip empty groups in recursion. |
Suggested reviewers
- vigneshhari
Poem
Oh, questions with options, or groups with none,
Now error will catch youβno place to run!
With.get()in hand, and recursion so neat,
Empty groups no longer make code admit defeat.
A tiny tweak here, a rename thereβ
Robustness, at last, is floating in air!
π Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
π₯ Commits
Reviewing files that changed from the base of the PR and between 78449985d0bdef42fb1ac543c139fee1991063d4 and ee7e360ec0f3ac5b347975b1c4081f7860e38b49.
π Files selected for processing (2)
care/emr/resources/questionnaire/spec.py(1 hunks)care/emr/resources/questionnaire/utils.py(2 hunks)
β° Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Test / Test
π Additional comments (5)
care/emr/resources/questionnaire/spec.py (3)
166-166: Method name better reflects its expanded scope.The rename from
validate_value_set_or_optionstovalidate_choice_and_group_questionsmakes the method's purpose clearer now that it handles both choice and group validations.
170-172: Error message clarity improved.The error message is now more specific about what's required for choice type questions.
174-176: Group validation correctly implemented.The validation properly checks that group type questions have at least one sub-question, which aligns perfectly with the PR objective. The error message is clear and actionable.
care/emr/resources/questionnaire/utils.py (2)
212-212: Defensive programming improvement.Using
.get("questions")instead of direct dictionary access prevents potential KeyError exceptions. This is a sensible safety improvement, though one might wonder why groups without questions would exist in the first place given the new validation.
488-490: Consistent safe access pattern with helpful comment.The change to use
.get("questions")maintains consistency with the previous change, and the comment helpfully explains the behavior of ignoring groups with no questions. This aligns well with the validation logic that now prevents such groups from being created.
β¨ Finishing Touches
- [ ] π Generate Docstrings
π§ͺ Generate Unit Tests
- [ ] Create PR with Unit Tests
- [ ] Post Copyable Unit Tests in Comment
- [ ] Commit Unit Tests in branch
prafful/bugs/questionnaire-create-empty-groups
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
πͺ§ Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai auto-generate unit teststo generate unit tests for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Codecov Report
:x: Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 51.21%. Comparing base (7844998) to head (ee7e360).
:warning: Report is 333 commits behind head on develop.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| care/emr/resources/questionnaire/spec.py | 25.00% | 3 Missing :warning: |
| care/emr/resources/questionnaire/utils.py | 0.00% | 2 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## develop #3084 +/- ##
===========================================
- Coverage 51.21% 51.21% -0.01%
===========================================
Files 251 251
Lines 11383 11384 +1
Branches 1282 1283 +1
===========================================
Hits 5830 5830
- Misses 5532 5533 +1
Partials 21 21
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.