fix(appointment): make resource bookings independent of the doctor's calendar
Booking a device is not booking its doctor: the operator runs it and the doctor only supervises. But bookAtomically locked the doctor row and isSlotTaken checked overlap against the doctor alone, ignoring which resource was chosen, so a clinic whose devices share one supervisor could not run two of them at once. Every tenant in the database is in that position — clinic 2's six resources all point at doctor 6. Resource bookings now skip the doctor lock and carry no active_slot_key; their guarantee comes from resource_occupancy, which understands capacity and seats. Both direct paths write occupancy rows the way the hold engine already did, so ResourceBookingSlotService stops being the only thing holding two sources of truth together, and cancelling releases the seat. Occupancy is bucketed in five-minute slices, which is coarser than a booking time: a booking ending 12:35:04 spilled four seconds into the 12:35 bucket and collided with the next one starting at that same second, despite zero real overlap. This surfaced on real rows 76 and 77 during backfill. Resource bookings now snap both ends of their window down to the bucket grid — schedule-driven slots are already aligned, so only manually entered times move. The seat is claimed after persist because it needs the appointment id; losing the race removes the appointment rather than leaving a booking with no device behind it. app:appointment:backfill-resource-occupancy gives existing resource-backed appointments their missing occupancy and clears the doctor keys that no longer mean anything. It reports conflicts between two old bookings instead of picking a loser. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -275,6 +275,22 @@ Book an appointment slot.
|
||||
> مسیر پنل (`POST /api/v1/my/appointment`) این رفتار را از قبل داشت؛ این تغییر مسیر
|
||||
> عمومی را با آن همتراز کرد.
|
||||
>
|
||||
> **رزرو منبع از تقویم پزشک مستقل است.** وقتی `resource_uuid` داده شود:
|
||||
>
|
||||
> - قفل و بررسی تداخلِ per-doctor اعمال **نمیشود** و `active_slot_key` نال میماند.
|
||||
> پیش از این کلینیکی که چند دستگاه زیر نظر یک پزشک داشت نمیتوانست دوتایشان را
|
||||
> همساعت رزرو کند.
|
||||
> - تضمینِ یکتایی از `resource_occupancy` میآید که ظرفیت (`capacity`) را میفهمد؛
|
||||
> اتاق سهنفره سه رزرو همزمان میپذیرد و چهارمی `409` میگیرد.
|
||||
> - شعبهٔ نوبت از خودِ منبع برداشته میشود، نه از برنامهٔ هفتگی پزشک.
|
||||
> - **ساعت نوبت به مرز پنجدقیقهای گرد میشود** (هر دو سر رو به پایین). اسلاتهای
|
||||
> برنامهٔ هفتگی از قبل ترازند و تغییری نمیکنند؛ فقط «ثبت خارج از برنامه (ورود دستی
|
||||
> ساعت)» جابهجا میشود. بدون این، دو نوبتِ پشتسرهم سطلِ اشغالِ مشترک پیدا میکردند و
|
||||
> دومی `409` میگرفت با اینکه یک ثانیه هم روی هم نبودند.
|
||||
> - لغو نوبت، اشغال منبع را آزاد میکند.
|
||||
>
|
||||
> نوبت بدون منبع دقیقاً مثل قبل با کلید و قفل پزشک محافظت میشود.
|
||||
>
|
||||
> **پاسخ:** علاوه بر فیلدهای قبلی، `resource` (`uuid`, `name`, `type`) و `service_option`
|
||||
> (`uuid`, `name`) برمیگردند. نوبتهای پیش از مدل منبعمحور هر دو را `null` دارند، پس
|
||||
> کلاینت باید با `null` کنار بیاید.
|
||||
|
||||
Reference in New Issue
Block a user