Skip to content
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

Implement flexible slot duration based on service duration to prevent appointment overlaps #261

Open
adamspd opened this issue Sep 2, 2024 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@adamspd
Copy link
Owner

adamspd commented Sep 2, 2024

Currently, the appointment system uses a fixed slot duration for all services, which can lead to potential overlaps when service durations vary significantly. I need to implement a more flexible approach to slot duration that takes into account the actual service duration. Let's consider the following example to illustrate the problem:

Current system:

  • Default slot duration: 30 minutes
  • Service duration: 3 hours
  • Available slots start at 9:00 AM

Problem scenario:

  1. User 'A' books a 3-hour service at 9:30 AM (occupying 9:30 AM - 12:30 PM)
  2. The system still shows 9:00 AM as an available slot
  3. User B books the 3-hour service at 9:00 AM
  4. Result: The appointments overlap from 9:30 AM - 12:00 PM

This overlap occurs because the slot duration (30 minutes) doesn't match the service duration (3 hours), and the system doesn't consider the full duration of previously booked appointments when displaying available slots.

Proposed changes:

  1. Add a new field to the Service model:

    • use_service_duration_as_slot: BooleanField (default=True)
  2. Update the Config model with a new setting:

    • default_to_service_duration: BooleanField (default=True)
  3. Modify the slot calculation logic:

    • If Config.default_to_service_duration is True:
      • Use the service duration as the slot duration by default
    • If Config.default_to_service_duration is False:
      • Use the service's use_service_duration_as_slot field to determine whether to use service duration or the default slot duration
  4. Update the get_available_slots_for_staff function:

    • When calculating available slots, consider the service duration to prevent overlaps
    • If a slot is partially occupied by a longer service, mark it as unavailable
  5. Modify the appointment booking process:

    • When a user selects a slot, check if the entire duration of the service is available
    • If not, only display truly available slots
  6. Adjust the calendar view:

    • Display appointments with their actual duration rather than fixed-size slots

Example scenario:

  • Service A: 30 minutes
  • Service B: 3 hours
  • Default slot duration: 30 minutes

With the new system:

  1. If default_to_service_duration is True:
    • Service A slots will be 30 minutes
    • Service B slots will be 3 hours
  2. If default_to_service_duration is False:
    • Service A slots will be 30 minutes (or custom if set)
    • Service B slots will be 3 hours only if use_service_duration_as_slot is True for that service

This approach will prevent overlaps by ensuring that longer services block out the appropriate amount of time, while still allowing flexibility for services that can fit into smaller slots.

Additional considerations:

  • Performance impact of calculating available slots with variable durations
  • User interface changes to clearly display slot durations for different services
  • Backward compatibility with existing appointments and configurations

Note that this will be set by default but can still be disabled. If so, then the current behaviour will be applied.

If anyone is motivated to implement this, let me know, otherwise, I will implement it once I get a moment.

@adamspd adamspd added bug Something isn't working help wanted Extra attention is needed labels Sep 2, 2024
@adamspd
Copy link
Owner Author

adamspd commented Sep 2, 2024

Consider issue #57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant