# Case #3: Two patients can be booked into the same appointment slot

**CASE CLOSED** · Clinic Records · opened 2026-11-13 12:43 · report 20261113-124324-d930

## The report

> we have 2 patients booked at 10:00 tomorrow?? how did the system allow that. sunrise clinic. the 2nd one should be blocked

**What the user most likely did:** A Sunrise Clinic user booked one patient at 10:00 tomorrow, then booked a second patient at the same 10:00 slot, and the app accepted both instead of blocking the second one.

**What should happen:** Once a 10:00 appointment exists for tomorrow, the app should refuse to book another patient at that same date and time and show an error saying the slot is already taken.

## What Kane did, in a real browser

1. I went to http://127.0.0.1:8001/login.
2. I typed the test email into Email.
3. I typed the test password into Password.
4. I clicked Log in button.
5. I clicked Appointments in the top navigation.
6. I clicked Book appointment in the top-right corner.
7. I picked Aisha Rahman in the patient dropdown.
8. I typed 2026-11-14 into the Date field.
9. I typed appointment time 10:00.
10. I clicked Book appointment for tomorrow 10:00 for the first patient.
11. I waited to see what the page did.
12. I clicked + Book to open the appointment booking page again.
13. I picked James Carter in Patient.
14. I typed 2026-11-14 into Date.
15. I typed 10:00 into Time.
16. I clicked Book appointment.
17. I waited to see what the page did.
18. I checked: The second booking was refused with a message that the 10:00 slot tomorrow is already taken.

## Verdict

**Confirmed.** The agent booked Aisha Rahman for tomorrow at 10:00, then booked James Carter for the same date and time. The app accepted the second booking and opened James Carter's patient page, the same thing it did after the first booking, and no 'slot taken' message appeared, so the double booking the user reported happened again.

## The repair

The booking form never checked whether the clinic already had an appointment at the chosen date and time, so a second 10:00 booking for tomorrow was saved. In `app.py` (`appointment_create`), the app now looks for an existing appointment at that slot before saving. If it finds one, it doesn't save and shows the form again with "The 10:00 slot on <date> is already taken. Please choose another time. The appointment was not saved."

I haven't run it: the syntax check needed your approval and didn't go through, so Kane's re-run will be the first real test.

```diff
diff --git a/clinic/app.py b/clinic/app.py
index 269425d..eb84bd8 100644
--- a/clinic/app.py
+++ b/clinic/app.py
@@ -606,6 +606,14 @@ def appointment_create(
             errors.insert(0, "Please choose a patient.")
         else:
             form["patient_id"] = patient["id"]
+        if not errors and conn.execute(
+            "SELECT 1 FROM appointments WHERE clinic_id = ? AND date = ? AND time = ?",
+            (clinic["id"], form["date"], form["time"]),
+        ).fetchone():
+            errors.append(
+                f"The {form['time']} slot on {form['date']} is already taken. "
+                "Please choose another time. The appointment was not saved."
+            )
         if errors:
             ctx = _appointment_form_context(conn, clinic, form, errors)
             return render(request, "appointment_form.html", status_code=400, **ctx)
```

**Kane went back and repeated the same steps:** passed. You asked to schedule the first and second patients for tomorrow at 10:00.
The first patient’s appointment was submitted for 10:00 on 2026-11-14.
When the same 10:00 time was submitted for the second patient, the booking was refused because that slot was already taken.
The page displayed: “The 10:00 slot on 2026-11-14 is already taken. Please choose another time. The appointment was not saved.”

**Kept on file as a regression test:** `bug-20261113-124324-d930-fixed-date`

## Bug ticket

### Two patients can be booked into the same appointment slot

**Steps**
1. Log in to Sunrise Clinic
2. Go to Appointments and click Book appointment
3. Pick the first patient (Aisha Rahman), set tomorrow's date (2026-11-14) and 10:00, then click Book appointment
4. Open the booking page again
5. Pick the second patient (James Carter), set the same date (2026-11-14) and 10:00, then click Book appointment

**Expected:** The second booking is refused, with a message saying the 10:00 slot tomorrow is already taken.

**Actual:** The second booking is saved and the app opens James Carter's patient page with no error, so two patients now share the 10:00 slot tomorrow.

Reproduced by Kane CLI (Bug Whisperer report 20261113-124324-d930).

---
Proved by Kane CLI: 2 run(s), about 312 s, 85.0 credits. Generated by Bug Whisperer on 2026-12-03 23:08.
