Files
clinicpro/docs/new_feture/taskes
hamedandClaude Opus 5 24534ec483 feat(availability): multi-resource availability engine
Section 10 of the design document, and the payoff for tasks 01–05. The engine slides
a multi-segment plan across resource calendars and answers which times are actually
possible, with a suggested resource for each role. Until now the only conflict the
system checked was the doctor's; rooms, devices and operators did not exist.

Allocation is per *role*, not per segment, and that is what returns the wasted
capacity. An operator with no requirement during "waiting for the cream" is simply
not examined for those minutes, so another patient can use them. The reference test
encodes exactly that: patient A holds 10:00–11:00 while the operator is only busy
10:00–10:05 and 10:35–11:00, and patient B is offered a slot inside the gap with the
second room assigned. The spec says the task is not verified without that scenario.

One resource is chosen for every segment that needs its role, not independently per
segment — otherwise the operator in segment 1 and segment 3 could be two different
people and the patient would change hands mid-treatment.

Occupancy is stored one row per (segment × resource) rather than one per appointment.
The granularity is the whole point; a row per appointment would re-create the
single-interval model the design rejects. Reserved intervals are widened by each
resource's setup/cleanup, because the resource genuinely is not available then.

booking_mode gains a third value, resource, alongside slot and service. It is purely
additive: the default stays slot, no environment moves on its own, and a location
that has not opted in keeps the untouched legacy path. The frozen slot-mode contract
stays green.

Performance is a test, not a hope: 30 days, 20 resources and 500 existing bookings
complete well inside the 500ms budget. Every input is read once and the rest is in
memory — no query inside the day or candidate loop — and candidates are generated
only from the free windows of the scarcest role, which turns tens of thousands of
candidates into a few hundred.

An empty result is not an error and not a 404: it carries
reason: "no_capacity_in_range" so the caller does not have to infer meaning from
emptiness.

Also fixed a genuinely intermittent test defect: NumericFieldNormalizerTest padded a
random number with the three-byte Persian "۰" using byte-based str_pad, producing
broken UTF-8 whenever the number was short. It failed roughly at random. The improved
assertion message added earlier is what identified it immediately.

1196 tests / 3414 assertions. phpstan at its 14-error baseline.

Resource-picking strategies, the availability cache and the settings UI are recorded
as outstanding in the checklist with reasons — the cache in particular would be
premature while the performance test passes comfortably without it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 21:21:33 +03:30
..

تسک‌های موتور نوبت‌دهی چندمنبعی Clinic Pro

پیاده‌سازی تدریجی clinic-pro-mostanad-sade.md روی کد موجود. گزارش وضعیت فعلی و تحلیل شکاف: 00-current-state-report.md


سه قاعده‌ای که پیش از هر تسکی باید بخوانی

سند چه می‌گوید
_shared/red-lines.md منطق اسلاتی به هیچ عنوان دست‌کاری نمی‌شود · نوبت‌دهی سرویسی در همین فاز کامل می‌شود
_shared/ui-conventions.md هر صفحه یا بخش جدید عیناً با دیزاین‌سیستم موجود — هیچ طراحی جدید
_shared/definition-of-done.md هیچ تسکی بدون تکمیل چک‌لیستش تمام نیست 🔄 ⚠️

در تناقض، این سه سند بر متن تسک‌ها برنده‌اند.


لیست تسک‌ها

فاز ۰ — تثبیت وضعیت فعلی (پیش‌نیاز بقیه)

تسک ماژول پروژه Endpoint وابستگی زمان
۰۰ تکمیل نوبت‌دهی سرویسی clinicpro ۴ ۱۴-۱۸h
۰۰ب سازگارسازی سایت عمومی nobat724_front ۰۰ ۱۰-۱۴h

فاز ۱ — هستهٔ چندمنبعی

تسک ماژول Endpoint وابستگی زمان
۰۱ شعبه و اتاق ۸ ۰۰ ۱۰-۱۲h
۰۲ منبع، نوع منبع، مهارت، استخر ۱۴ ۰۱ ۱۴-۱۸h
۰۳ تقویم منبع، مرخصی، تعطیلات ملی ۹ ۰۱، ۰۲ ۱۲-۱۴h
۰۴ کاتالوگ خدمات v2 (گروه آیتم، دو نوع زمان) ۱۰ ۰۱ ۱۴-۱۶h
۰۵ بخش‌های نوبت و سازندهٔ برنامه ۳ ۰۲، ۰۴ ۱۶-۲۰h
۰۶ موتور جستجوی وقت چندمنبعی ۲ ۰۳، ۰۵ ۲۰-۲۴h
۰۷ رزرو موقت و ثبت نهایی چندمنبعی ۴ ۰۶ ۱۶-۲۰h
۰۸ لیست قیمت بازه‌دار و snapshot فاکتور ۷ ۰۴، ۰۷ ۱۲-۱۴h

فاز ۲ — قوانین

تسک ماژول Endpoint وابستگی زمان
۰۹ موتور قوانین شش‌دسته‌ای ۶ ۰۵، ۰۶، ۰۸ ۲۰-۲۴h
۱۰ فرم ساخت قانون + محیط آزمایش ۲ ۰۹ ۱۰-۱۲h

فاز ۳ — کسب‌وکار

تسک ماژول Endpoint وابستگی زمان
۱۱ پکیج و دفتر اعتبار جلسات ۸ ۰۸ ۱۰-۱۲h
۱۲ دوره درمان ۹ ۰۷، ۱۱ ۱۶-۲۰h
۱۳ سیاست لغو، عدم حضور، لیست انتظار ۷ ۰۷ ۱۰-۱۲h

فاز ۴ — بهینه‌سازی

تسک ماژول Endpoint وابستگی زمان
۱۴ رویدادهای دامنه و گزارش بهره‌وری ۳ ۰۷ ۸-۱۰h

مجموع endpoint جدید: ~۹۶ · مجموع زمان: ۲۱۴ تا ۲۵۶ ساعت


ساختار هر تسک

task-XX-name/
├── task.md                 ← شرح، دامنه، endpoint ها، معیار پذیرش، زمان
├── architecture.md         ← فایل‌ها، entity ها، سرویس‌ها، لایه‌ها، قواعد UI
├── database.md             ← جداول، ستون‌ها، ایندکس‌ها، migration
├── implementation_notes.md ← نکات فنی، edge case، سازگاری عقب‌رو، تست
├── checklist.md            ← ☑️ وضعیت هر مورد: ✅ 🔄 ⏳ ⚠️
└── user_flow.md            ← (تسک‌های پیچیده) جریان کاربری

checklist.md اجباری است و ساختار ثابتی دارد:

۰. خط سرخ‌ها   ۱. بک‌اند   ۲. دیتابیس   ۳. UI   ۴. تست   ۵. مستندات   ۶. بازبینی پایانی

چک‌لیست — قواعد

نماد معنی اجازهٔ باقی‌ماندن در پایان تسک
انجام‌شده و تأییدشده بله
🔄 در حال انجام نه
انجام‌نشده نه — مگر با دلیل مکتوب و تسک مقصد
⚠️ نیازمند بررسی یا تست نه — باید تعیین تکلیف شود

پیش از پایان هر تسک، همهٔ ردیف‌های چک‌لیست بازبینی می‌شوند و وضعیت نهایی می‌گیرند. هر تسک بخش «۶. بازبینی پایانی» دارد که تست‌ها، مستندات، UI و دو کلاینت دیگر را می‌سنجد.


ترتیب پیشنهادی اجرا

۰۰ ── ۰۰ب
  │
  ├─ ۰۱ ─┬─ ۰۲ ── ۰۳ ─┐
  │      └─ ۰۴ ── ۰۵ ─┴─ ۰۶ ── ۰۷ ─┬─ ۰۸ ─┬─ ۰۹ ── ۱۰
  │                                │      └─ ۱۱ ── ۱۲
  │                                ├─ ۱۳
  │                                └─ ۱۴

فاز ۰ اختیاری نیست. اگر حالت resource (تسک ۰۶) روی حالت service نیمه‌کاره ساخته شود، هر باگ موجود سرویسی به موتور جدید ارث می‌رسد و تشخیص منبعش غیرممکن می‌شود.

فاز اول قابل عرضه: ۰۰ تا ۰۸ — بعد از آن یک کلینیک زیبایی با اتاق، دستگاه و اپراتور می‌تواند واقعاً نوبت بگیرد.


سه حالت نوبت‌دهی

حالت مقدار WeeklySchedule.meta.booking_mode وضعیت
اسلاتی slot قفل — پیش‌فرض، تولیدی، دست‌نخورده
سرویسی service 🔄 موجود ولی نیمه‌کاره → تسک ۰۰ و ۰۰ب کاملش می‌کنند
چندمنبعی resource جدید — تسک ۰۶ به بعد

booking_mode پس از اولین ثبت قفل می‌شود (WeeklySchedule::getStoredBookingMode()). تسک ۰۶ یک استثنای کنترل‌شده اضافه می‌کند: ارتقای یک‌طرفه از slot/service به resource، مشروط بر نبودِ نوبت فعال آینده. بازگشت ممنوع.

ماتریس کامل «کدام endpoint در کدام حالت» در docs/architecture/booking-modes.md (تسک ۰۰ می‌سازد، تسک ۰۶ حالت سوم را اضافه می‌کند).


اجبار خودکار خط سرخ

هر تسک باید این را سبز نگه دارد:

ddev exec php bin/phpunit --group=slot-mode-frozen

تسک ۰۰ این تست و سه fixture آن را می‌سازد. fixture ها بعد از آن read-only اند: اگر تستی قرمز شد، کد باید برگردد، نه fixture.


قواعد مشترک همهٔ تسک‌ها

از CLAUDE.md و docs/architecture/tenancy.md. فهرست کامل در _shared/definition-of-done.md:

  1. entity جدید یا TenantOwnedTrait می‌گیرد یا با دلیل در GlobalTables ثبت می‌شود
  2. entity_type, entity_id ستون‌های اول هر ایندکس ترکیبیِ لیست
  3. هر uuid از request با TenantOwnershipChecker سنجیده می‌شود
  4. timestamp ها int یونیکس؛ نمایش شمسی فقط در UI
  5. کنترلر نازک · BaseController · success/paginated/error
  6. API جدید فقط وقتی هیچ endpoint موجودی کافی نباشد — دلیلش نوشته شود
  7. تست موفق + خطا + مرزی؛ بدون اجرای موفق تست، تسک تمام نیست
  8. هر endpoint جدید یا تغییریافته → docs/api/* در همان نشست
  9. رشته‌های UI فارسی از i18n؛ کد و کامیت و مستندات انگلیسی
  10. سازگاری عقب‌رو: nobat724_front و clinic-pro-tauri در build خطا نمی‌دهند — بررسی دستی اجباری است (ردیف بازبینی پایانی هر تسک)
  11. اول commit، بعد graphify update .