fix(appointment): one weekly schedule per doctor, place chosen per shift

A doctor working both at their own practice and at a clinic had to write two
independent schedules and neither panel could see the other, so the clinic
showed an empty form even though the doctor had configured their practice.

The schedule is now a single record owned by the doctor. What varies between
days is the place: the context of a shift is read from its location_id, not
from the record it lives in. Booking in a context therefore sees only that
context's days, so a personal-practice secretary still cannot book a clinic
day. The caller's own context decides which addresses they may assign: the
doctor gets every place of theirs, a clinic manager only its own, and shifts
outside their reach are returned for display but preserved verbatim on save.

Existing per-clinic rows are merged by migration; location_id was already
stored on every shift, so no context information is lost.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-20 17:20:53 +03:30
co-authored by Claude Opus 5
parent 2f030edef1
commit a0b4a969fc
15 changed files with 789 additions and 84 deletions
@@ -80,7 +80,12 @@ class BookingLocationValidityTest extends ApiTestCase
self::assertSame([], $this->locations($doctor), 'محلی که آدرس ندارد نباید محل به حساب بیاید');
}
public function testLocationWhoseShiftsPointOutsideItsContextIsNotReturned(): void
/**
* برنامه یکی است و محیطِ هر شیفت از آدرسش خوانده می‌شود، پس شیفتی که روی آدرس
* کلینیک نشسته، محلِ کلینیک را می‌سازد و نه مطب شخصی را — حتی وقتی پزشک آدرس
* شخصی هم دارد. مطب شخصی که هیچ شیفتی رویش نیست، محل به حساب نمی‌آید.
*/
public function testShiftDecidesItsPlaceByItsAddressNotByTheRecord(): void
{
$doctor = $this->makeDoctor();
$clinic = $this->makeClinicWith($doctor);
@@ -91,10 +96,13 @@ class BookingLocationValidityTest extends ApiTestCase
$this->em->persist($personal);
$this->em->flush();
// برنامهٔ شخصی که شیفتش روی آدرس کلینیک نشسته — دقیقاً حالتی که در dev دیده شد.
$this->scheduleFor($doctor, null, $clinicAddress->getId());
self::assertSame([], $this->locations($doctor));
$locations = $this->locations($doctor);
self::assertCount(1, $locations);
self::assertSame('clinic', $locations[0]['type']);
self::assertSame($clinicAddress->getUuid(), $locations[0]['location_uuid']);
}
public function testValidLocationIsReturnedWithItsOpeningHours(): void