feat(appointments): resources share the doctors' timeline

Three views become two. The resource lanes were a separate tab, which meant
reading a doctor's free hour on one screen and the laser's on another and
matching them by eye — while in the resource-first model it is the device and
the room that decide whether that hour is really free. They now sit under the
same "زمانبندی" view, below the doctor's slots.

Each lane says how much of its shift is still free, and that number respects
capacity: a minute counts as busy only once the overlapping bookings reach
the resource's capacity, so a three-bed room with two appointments is still
open. Treating it otherwise would silently turn every multi-capacity resource
into a single-capacity one. ResourceFreeTimeCalculator does the sweep and
carries nine cases of its own.

only_bookable=1 keeps resources with no service offering out of the view;
they could only ever render an empty lane. On the seeded clinic that is five
resources down to two.

Two ruler defects the screenshot caught: hours rendered in Latin digits, and
the last label was half-clipped by the container so 21 read as 2.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-02 16:14:04 +03:30
co-authored by Claude Opus 5
parent b8e8580867
commit 5e87bbc18b
12 changed files with 455 additions and 46 deletions
@@ -158,4 +158,42 @@ class ResourceTimelineEndpointTest extends ApiTestCase
self::assertCount(1, $body['data']['resources']);
self::assertSame([], $body['data']['resources'][0]['items']);
}
// ── وقت آزاد و فیلتر «قابل رزرو» ────────────────────────────────────────
/** ردیف تایم‌لاین باید بگوید چقدر از شیفت هنوز جا دارد، نه فقط چه چیزی گرفته است. */
public function testTheLaneReportsHowMuchOfTheShiftIsStillFree(): void
{
[$user, $resource] = $this->clinicWithResource();
$midnight = (int) strtotime('today midnight');
$this->shift($resource, $this->dayOfWeek($midnight), 540, 1020); // ۸ ساعت
$this->occupy($resource, $midnight + 10 * 3600, $midnight + 11 * 3600, 'لیزر');
$row = $this->authJson('GET', '/api/v1/resources/timeline?date=' . date('Y-m-d', $midnight), $user)
['data']['resources'][0];
self::assertSame(480, $row['shift_minutes']);
self::assertSame(60, $row['busy_minutes']);
self::assertSame(420, $row['free_minutes']);
}
/** منبعی که به هیچ سرویسی وصل نیست، ردیفِ همیشه‌خالی در تایم‌لاین نمی‌سازد. */
public function testOnlyBookableHidesResourcesWithNoService(): void
{
[$user, $resource] = $this->clinicWithResource();
$midnight = (int) strtotime('today midnight');
$this->shift($resource, $this->dayOfWeek($midnight), 540, 1020);
$all = $this->authJson('GET', '/api/v1/resources/timeline?date=' . date('Y-m-d', $midnight), $user);
self::assertCount(1, $all['data']['resources']);
$bookable = $this->authJson(
'GET',
'/api/v1/resources/timeline?only_bookable=1&date=' . date('Y-m-d', $midnight),
$user,
);
self::assertSame([], $bookable['data']['resources'], 'بدون ResourceServiceOffering فعال، قابل رزرو نیست');
}
}