I want to be able to find the number of available slots for a particular time duration for all locations and all days
For example: I have to know the number of available appointments before 10 AM in all locations from the below sample tables
I have looked at other answers in stack overflow, mine is peculiar in the sense it also involves data on multiple doctors/patients.
Doctor's time table
| Location | RESOURCE | Day | StartTime | EndTime |
|---|---|---|---|---|
| ABC | D1 | Mon | 8:00 AM | 12:00 PM |
| ABC | D1 | Tue | 8:00 AM | 12:00 PM |
| ABC | D2 | Mon | 9:00 AM | 01:00 PM |
| ABC | D2 | Tue | 8:00 AM | 12:00 PM |
| XYZ | D1 | Mon | 8:00 AM | 12:00 PM |
| XYZ | D1 | Tue | 8:00 AM | 12:00 PM |
| XYZ | D4 | Mon | 9:00 AM | 01:00 PM |
| XYZ | D4 | Tue | 8:00 AM | 12:00 PM |
Patient's appointment time table
| Location | Patient | Duration | StartTime | ApptDt |
|---|---|---|---|---|
| ABC | P1 | 15 | 8:00 AM | 10/4/2021 |
| ABC | P2 | 15 | 8:15 AM | 10/4/2021 |
| ABC | P3 | 15 | 9:00 AM | 10/4/2021 |
| ABC | P4 | 15 | 9:00 AM | 10/5/2021 |
| XYZ | P5 | 15 | 10:00 AM | 10/5/2021 |
| XYZ | P6 | 15 | 10:00 AM | 10/5/2021 |
| XYZ | P7 | 15 | 10:15 AM | 10/5/2021 |
| XYZ | P8 | 15 | 10:15 AM | 10/5/2021 |
Doctor's time table does not have dates as it is the same throughout the year.
On Mondays in ABC location, since there are 2 doctors overlapping the time between 9:00 AM to 12:00 noon, they can accept multiple appointments at the same time. ie, 2 patients from 9:00 am to 9:15 am can be served in location ABC.
A typical duration(Duration) for an appointment is 15 minutes as indicated in the patient's table.
Expected result set
| Location | Date | Available appts |
|---|---|---|
| ABC. | 10/4/2021 | 8 |
| XYZ | 10/4/2021 | 12 |
On 10/4/2021 there were 8 slots available for booking before 10 AM because there were no appointments between
- 8:30-8:45 for D1
- 8:45-9:00 for D1
- 9:00-9:15(2) for D1,D2
- 9:15-9:30(2) for D1,D2
- 9:30-9:45(2) for D1,D2
- 9:45-10:00(2) for D1,D2
I want to also know for a specific time slot how many appointments were booked vs available.