fix(appointment): fall back to the resource's supervising doctor on public booking

A laser device is not a doctor, so booking one from the public site sent
resource_uuid and no doctor_uuid and got back "doctor_uuid یا resource_uuid
الزامی است" — a message telling the caller to send something it had already
sent. The panel path had resolved this from ClinicResource.supervisor since it
was written; only the public path had not, and the field was defined but never
read there.

A resource with no supervisor now gets its own message pointing at the actual
fix, instead of the generic one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-06 17:31:21 +03:30
co-authored by Claude Opus 5
parent 252e20bfe9
commit 12c1d2cbf4
3 changed files with 64 additions and 2 deletions
@@ -456,7 +456,9 @@ class AppointmentController extends BaseController
/**
* منبع می‌تواند جای پزشک بنشیند: نوبتِ «دستگاه لیزر ۲» پزشکی ندارد که uuidش
* فرستاده شود. اگر منبع خودش پزشک باشد، پزشک از آن استنتاج می‌شود.
* فرستاده شود. اگر منبع خودش پزشک باشد، پزشک از آن استنتاج می‌شود؛ وگرنه
* پزشکِ ناظرِ همان منبع می‌نشیند — دستگاه را اپراتور کار می‌کند و پزشک فقط
* پاسخگوی بالینی است.
*/
$resourceUuid = trim((string) ($data['resource_uuid'] ?? ''));
$resource = null;
@@ -472,6 +474,21 @@ class AppointmentController extends BaseController
$doctorUuid = $resource->subject()->getUuid();
}
if ($doctorUuid === '' && $resource->getSupervisor() !== null) {
$doctorUuid = $resource->getSupervisor()->getUuid();
}
// پیام عمومیِ «doctor_uuid یا resource_uuid لازم است» اینجا گمراه‌کننده بود:
// کلاینت هر دو را فرستاده و مشکل نبودِ ناظر روی خودِ منبع است.
if ($doctorUuid === '') {
return $this->error(
ErrorCodes::ERR_VALIDATION_002,
'این منبع پزشک ناظر ندارد؛ ابتدا در تنظیمات منابع پزشک ناظر را مشخص کنید',
422,
'resource_uuid',
);
}
// رزرو **برای یک منبع** یعنی رزرو در شعبهٔ همان منبع؛ فرستادن جداگانهٔ
// `clinic_uuid` فقط راهی برای ناسازگار کردن این دو بود.
if ($clinicUuid === null && $resource->getAddress()->getClinicId() !== null) {