Admin-side booking (POST /api/v1/my/appointment and /api/v1/admin/appointment) resolved the patient User by mobile only, so one person booked under two mobiles produced two User rows — and two case-files, since PatientRecord is keyed on user_id. National code is the real unique identity (User.national_code is already unique); a person may have several mobiles. Booking now requires + validates patient_national_code and resolves the patient national-code-first (then mobile) via a shared PatientResolver, so the case-file stays unique per national code even across mobiles. Reusing a mobile already bound to a different national code returns 422 ERR_PROFILE_MOBILE_TAKEN. The admin create form and NewAppointmentDrawer gain a national-code field and send it; both had a dead patient-picker URL (/api/v1/patient) fixed to the real /api/v1/patients, whose payload already carries user_national_code for autofill. Docs (appointment.md, admin.md) and tests updated; new AppointmentNationalCodeTest covers success, single-file reuse, missing, invalid, and identity-conflict cases. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
109 lines
4.4 KiB
PHP
109 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Appointment;
|
|
|
|
use App\ClinicService\Entity\ServiceItem;
|
|
use App\ClinicService\Entity\ServiceSection;
|
|
use App\Doctor\Entity\Doctor;
|
|
use App\Staff\Entity\ClinicStaff;
|
|
use App\Tests\ApiTestCase;
|
|
|
|
/**
|
|
* POST /api/v1/my/appointment extensions (workflow fields + reserve entries)
|
|
* and the GET /api/v1/my/appointments ?reserve list split.
|
|
*/
|
|
class AppointmentCreateReserveTest extends ApiTestCase
|
|
{
|
|
/** @return array{0: \App\Auth\Entity\User, 1: Doctor} */
|
|
private function doctor(): array
|
|
{
|
|
$owner = $this->createUser(['ROLE_DOCTOR']);
|
|
$doctor = new Doctor($owner, 'دکتر');
|
|
$this->em->persist($doctor);
|
|
$this->em->flush();
|
|
|
|
return [$owner, $doctor];
|
|
}
|
|
|
|
public function testCreateWithWorkflowFields(): void
|
|
{
|
|
[$owner, $doctor] = $this->doctor();
|
|
|
|
$section = new ServiceSection('doctor', $doctor->getId(), 'زیبایی');
|
|
$item = new ServiceItem($section, 'لیزر فول بادی');
|
|
$staff = new ClinicStaff('doctor', $doctor->getId(), 'سحر ایمانی');
|
|
$this->em->persist($section);
|
|
$this->em->persist($item);
|
|
$this->em->persist($staff);
|
|
$this->em->flush();
|
|
|
|
$start = time() + 86_400;
|
|
$res = $this->authJson('POST', '/api/v1/my/appointment', $owner, [
|
|
'doctor_uuid' => $doctor->getUuid(),
|
|
'slot_start' => $start,
|
|
'slot_end' => $start + 2_400,
|
|
'patient_mobile' => '09' . random_int(100000000, 999999999),
|
|
'patient_name' => 'مریم اسکندری',
|
|
'patient_national_code' => '00' . str_pad((string) random_int(0, 99_999_999), 8, '0', STR_PAD_LEFT),
|
|
'service_section_uuid' => $section->getUuid(),
|
|
'service_item_uuid' => $item->getUuid(),
|
|
'staff_uuid' => $staff->getUuid(),
|
|
'deposit_required' => true,
|
|
'deposit_amount_rials' => 5_000_000,
|
|
]);
|
|
self::assertSame(201, $this->responseCode());
|
|
self::assertFalse($res['data']['is_reserve']);
|
|
|
|
$list = $this->authJson('GET', '/api/v1/my/appointments?limit=50', $owner);
|
|
$row = $list['data'][0];
|
|
self::assertSame('لیزر فول بادی', $row['service_item']['name']);
|
|
self::assertSame('سحر ایمانی', $row['staff']['full_name']);
|
|
self::assertTrue($row['deposit_required']);
|
|
}
|
|
|
|
public function testReserveEntriesSkipSlotRulesAndAreListedSeparately(): void
|
|
{
|
|
[$owner, $doctor] = $this->doctor();
|
|
$day = strtotime('today midnight'); // past for a slot booking — fine for a reserve
|
|
|
|
// two reserves on the same day must both succeed (no slot occupation)
|
|
foreach (['ساغر صابری', 'پریسا همتی'] as $name) {
|
|
$this->authJson('POST', '/api/v1/my/appointment', $owner, [
|
|
'doctor_uuid' => $doctor->getUuid(),
|
|
'slot_start' => $day,
|
|
'slot_end' => $day,
|
|
'patient_mobile' => '09' . random_int(100000000, 999999999),
|
|
'patient_name' => $name,
|
|
'patient_national_code' => '00' . str_pad((string) random_int(0, 99_999_999), 8, '0', STR_PAD_LEFT),
|
|
'is_reserve' => true,
|
|
]);
|
|
self::assertSame(201, $this->responseCode());
|
|
}
|
|
|
|
$reserves = $this->authJson('GET', '/api/v1/my/appointments?reserve=1&limit=50', $owner);
|
|
self::assertCount(2, $reserves['data']);
|
|
self::assertTrue($reserves['data'][0]['is_reserve']);
|
|
|
|
// the regular list must not contain reserve entries
|
|
$regular = $this->authJson('GET', '/api/v1/my/appointments?limit=50', $owner);
|
|
self::assertCount(0, $regular['data']);
|
|
}
|
|
|
|
public function testUnknownServiceUuidIs422(): void
|
|
{
|
|
[$owner, $doctor] = $this->doctor();
|
|
$start = time() + 86_400;
|
|
|
|
$this->authJson('POST', '/api/v1/my/appointment', $owner, [
|
|
'doctor_uuid' => $doctor->getUuid(),
|
|
'slot_start' => $start,
|
|
'slot_end' => $start + 1_800,
|
|
'patient_mobile' => '09' . random_int(100000000, 999999999),
|
|
'patient_name' => 'x',
|
|
'patient_national_code' => '00' . str_pad((string) random_int(0, 99_999_999), 8, '0', STR_PAD_LEFT),
|
|
'service_item_uuid' => 'missing-uuid',
|
|
]);
|
|
self::assertSame(422, $this->responseCode());
|
|
}
|
|
}
|