# Flow: Clinic Setup

**Actors**: Super Admin, Clinic Admin
**Phase**: 1 (`04-early-pages.md`)

## Steps

1. **Super Admin creates a clinic.**
   `Admin\Clinic\ClinicController::store()` → `ClinicService::create()` — in one transaction,
   creates a `Core\Branch` row and its `ClinicProfile` row, plus the clinic's first `Admin`
   account (role `Clinic Admin`, `admins.branch_id` = the new branch's id).

2. **Clinic Admin adds specialties (if a needed one doesn't already exist).**
   `Admin\Clinic\SpecialtyController::store()` — Super Admin only per permissions
   (`clinic.specialties.create`); a Clinic Admin picks from the existing global list.

3. **Clinic Admin adds doctors.**
   `Admin\Clinic\DoctorController::store()` → `DoctorService::create()` — creates (or links an
   existing) `Doctor` row plus one `DoctorClinic` (`clinic_doctor_branch`) pivot row scoped to
   the acting admin's `branch_id`, with `visit_price`, `consultation_price`,
   `slot_duration_minutes`.

4. **Clinic Admin configures the doctor's weekly schedule for this branch.**
   `Admin\Clinic\DoctorScheduleController::store()` → `DoctorScheduleService::create()` — one or
   more `DoctorSchedule` rows (day of week + start/end time) under the `DoctorClinic` pairing
   from step 3.

5. **(Optional, any time later) Clinic Admin adds a Receptionist.**
   `Admin\Clinic\...` (staff management, `clinic.staff.create`) — creates a new `Admin` account,
   role `Receptionist`, `branch_id` copied from the creating Clinic Admin.

## System effects

- Steps 1–4 touch no patient-facing or doctor-facing code at all — this flow is entirely inside
  `routes/admin.php`.
- After step 4, the doctor is bookable: `BookingService::availableSlots()` (Phase 2) can compute
  open slots for this doctor at this branch from the `DoctorSchedule` rows just created.

## Business rules from the brief

- A doctor working at two branches has **one** `Doctor` row and **two** `DoctorClinic` rows, each
  with independent pricing/schedule (see `models/DoctorClinic.md` and
  `plan_Clinics/../` — the concrete example: Dr. Ahmed at Nasr City + Mohandessin with two
  different weekly schedules).
- Specialties are managed once, globally, by Super Admin — never duplicated per clinic.
