8000 Support for rescheduling booking to another schedulable user resource within same facility by rithviknishad · Pull Request #3063 · ohcnetwork/care · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support for rescheduling booking to another schedulable user resource within same facility #3063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

rithviknishad
Copy link
Member
@rithviknishad rithviknishad commented Jun 4, 2025

Proposed Changes

  • Removed restriction that prevented rescheduling bookings to another user.
  • Added restriction to prevent rescheduling bookings to users of different facility.

Associated Issue

Merge Checklist

  • Tests added/fixed
  • Linting Complete

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 booking rescheduling to allow selecting slots from any resource within the same facility, while preventing rescheduling to resources in other facilities.
  • Tests

    • Added tests to ensure bookings can be rescheduled to different resources within the same facility, and to confirm that cross-facility rescheduling is not permitted.
8000

@rithviknishad rithviknishad requested a review from a team as a code owner June 4, 2025 11:49
Copy link
Contributor
coderabbitai bot commented Jun 4, 2025
📝 Walkthrough

Walkthrough

The rescheduling logic in the booking API was updated to allow moving a booking to any resource within the same facility, rather than restricting it to the exact original resource. Corresponding tests were added to verify that rescheduling across resources within a facility is permitted, but rescheduling to a different facility is not.

Changes

File(s) Change Summary
care/emr/api/viewsets/scheduling/booking.py Modified slot lookup in the reschedule action to filter by facility rather than exact resource.
care/emr/tests/test_booking_api.py Added two tests: one for rescheduling within the same facility (different user resource), and one for cross-facility rescheduling (should fail).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BookingAPI
    participant TokenSlot
    participant Facility

    User->>BookingAPI: POST /reschedule (with new slot external_id)
    BookingAPI->>TokenSlot: Find slot by external_id and facility_id
    TokenSlot-->>BookingAPI: Return slot if facility matches
    BookingAPI->>BookingAPI: Update booking to new slot
    BookingAPI-->>User: Return success or error
Loading

Possibly related PRs

  • ohcnetwork/care#2738: Introduced the original reschedule method and related classes, which this PR directly builds upon by refining the resource filtering logic.

Suggested reviewers

  • vigneshhari

Poem

Oh, bookings now can freely roam,
Within their facility, they find a new home.
But cross the line to another’s land?
The API responds with a firm, guiding hand.
Tests were added, logic refined—
Booking reschedules, perfectly aligned!
🏥🔄

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

Copy link
codecov bot commented Jun 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.28%. Comparing base (c076917) to head (18713d4).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3063   +/-   ##
========================================
  Coverage    51.28%   51.28%           
========================================
  Files          251      251           
  Lines        11371    11371           
  Branches      1280     1280           
========================================
  Hits          5832     5832           
  Misses        5518     5518           
  Partials        21       21           

☔ 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: 0

🧹 Nitpick comments (1)
care/emr/tests/test_booking_api.py (1)

386-386: Address line length violations.

The static analysis tool flagged these lines for exceeding the 100-character limit. While functional, it would be... nice if we could keep our code formatting consistent with the project standards.

Apply these formatting improvements:

-    def test_reschedule_booking_to_another_user_resource_of_same_facility(self):
-        """Users can reschedule bookings via the re-schedule endpoint with another user resource of same facility."""
+    def test_reschedule_booking_to_another_user_resource_of_same_facility(self):
+        """Users can reschedule bookings via the re-schedule endpoint with 
+        another user resource of same facility."""

-    def test_reschedule_booking_to_another_user_resource_of_another_facility(self):
-        """Users cannot reschedule bookings via the re-schedule endpoint with another user resource of different facility."""
+    def test_reschedule_booking_to_another_user_resource_of_another_facility(self):
+        """Users cannot reschedule bookings via the re-schedule endpoint with 
+        another user resource of different facility."""

Also applies to: 412-412

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 386-386: Line too long (117/100)

(C0301)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c076917 and 18713d4.

📒 Files selected for processing (2)
  • care/emr/api/viewsets/scheduling/booking.py (1 hunks)
  • care/emr/tests/test_booking_api.py (1 hunks)
🧰 Additional context used
🧬 Code G A688 raph Analysis (1)
care/emr/tests/test_booking_api.py (4)
care/security/permissions/user_schedule.py (1)
  • UserSchedulePermissions (14-84)
care/security/authorization/user_schedule.py (3)
  • can_write_user_booking (64-78)
  • can_create_appointment (18-26)
  • can_reschedule_appointment (28-36)
care/utils/tests/base.py (2)
  • create_role_with_permissions (58-71)
  • attach_role_facility_organization_user (112-115)
care/emr/tests/test_schedule_api.py (3)
  • create_slot (90-99)
  • create_slot (823-832)
  • create_booking (101-113)
🪛 Pylint (3.3.7)
care/emr/tests/test_booking_api.py

[convention] 386-386: Line too long (117/100)

(C0301)


[convention] 412-412: Line too long (125/100)

(C0301)

🔇 Additional comments (3)
care/emr/api/viewsets/scheduling/booking.py (1)

146-146: LGTM! This change correctly implements facility-scoped rescheduling.

The modification from exact resource matching to facility-level filtering aligns perfectly with the PR objectives. The security is maintained since the facility is already validated and authorized earlier in the method.

care/emr/tests/test_booking_api.py (2)

385-410: Comprehensive test coverage for same-facility rescheduling.

The test properly validates that users can reschedule bookings to different resources within the same facility. The setup is thorough and the assertion is correct.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 386-386: Line too long (117/100)

(C0301)


411-437: Good test coverage for cross-facility rescheduling prevention.

The test correctly verifies that rescheduling across facilities is blocked with a 404 response. The test setup properly creates resources in different facilities to validate the boundary enforcement.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 412-412: Line too long (125/100)

(C0301)

@vigneshhari vigneshhari merged commit 79c41e9 into ohcnetwork:develop Jun 4, 2025
5 checks passed
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
0