Skip to content

Appointments should have only healthcare service of type schedulable#3517

Open
praffq wants to merge 5 commits intodevelopfrom
prafful/validation-for-healthcare-system
Open

Appointments should have only healthcare service of type schedulable#3517
praffq wants to merge 5 commits intodevelopfrom
prafful/validation-for-healthcare-system

Conversation

@praffq
Copy link
Contributor

@praffq praffq commented Feb 5, 2026

Proposed Changes

  • added validation to healthcare system

Associated Issue

  • Link to issue here, explain how the proposed solution will solve the reported issue/ feature request.

Architecture changes

  • Remove this section if not used

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

    • Appointment creation now validates that only healthcare services designated as schedulable can be used. Non-schedulable service types will be rejected with a validation error.
  • Tests

    • Added test coverage for healthcare service type validation during appointment creation.

@praffq praffq requested a review from a team as a code owner February 5, 2026 18:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

Added validation in the appointment booking endpoint to enforce that healthcare services used for scheduling must have internal_type set to "scheduling". The change includes a pre-check before other validations and corresponding test cases covering both compliant and non-compliant healthcare service configurations.

Changes

Cohort / File(s) Summary
Scheduling Validation
care/emr/api/viewsets/scheduling/availability.py
Added pre-validation check in lock_create_appointment to ensure healthcare_service resources have internal_type equal to "scheduling" before proceeding with appointment creation logic.
Booking Tests
care/emr/tests/test_booking_api.py
Added three test cases validating appointment creation behavior with healthcare services: one confirming success with internal_type "scheduling", and two confirming 400 errors for non-scheduling types (internal_type "lab" and null).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete. While it mentions validation was added, it lacks essential details: no issue link, no explanation of the problem being solved, and minimal context about the changes. Add the associated issue link with explanation of how this validation solves it, and provide more specific details about what validation was implemented and why it matters.
Docstring Coverage ⚠️ Warning Docstring coverage is 73.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main validation being added - enforcing that appointments only use healthcare services with a schedulable type.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch prafful/validation-for-healthcare-system

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.54%. Comparing base (082769e) to head (ccec695).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3517      +/-   ##
===========================================
+ Coverage    75.51%   75.54%   +0.02%     
===========================================
  Files          473      473              
  Lines        21932    21936       +4     
  Branches      2286     2288       +2     
===========================================
+ Hits         16563    16571       +8     
+ Misses        4853     4850       -3     
+ Partials       516      515       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@care/emr/api/viewsets/scheduling/availability.py`:
- Around line 126-135: In lock_create_appointment, guard against a null
healthcare_service before accessing healthcare_service.internal_type: check
token_slot.resource.healthcare_service is not None (or use getattr) when
token_slot.resource.resource_type ==
SchedulableResourceTypeOptions.healthcare_service.value, and if it is None or
its internal_type is not "scheduling" raise the same ValidationError; update the
conditional that currently reads
token_slot.resource.healthcare_service.internal_type to first verify existence
and then evaluate internal_type so a missing FK yields the ValidationError
instead of an AttributeError.

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.

1 participant