Files
clinicpro/tests/Patient/PatientListNationalCodeTest.php
T
hamedandClaude Opus 4.8 3e8126c520 fix: return patient national code from profile in patients list
National code is stored on the profiles table, not users, so the patients
search returned null user_national_code for patients that actually have one
— which blocked selecting an existing patient on the appointment create
form. Backfill user_national_code from the profile (batch query) in the
list endpoint. On the create page, show a picked patient's stored national
code read-only and only prompt for input when the record genuinely lacks
one. Add backend tests and update docs/api/patient.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-16 09:57:03 +03:30

60 lines
2.1 KiB
PHP

<?php
namespace App\Tests\Patient;
use App\Doctor\Entity\Doctor;
use App\Patient\Entity\PatientRecord;
use App\Tests\ApiTestCase;
use App\UserProfile\Entity\UserProfile;
/**
* کد ملی روی جدول profiles ذخیره می‌شود نه users؛ لیست بیماران باید آن را
* در فیلد user_national_code برگرداند تا فرم ثبت نوبت بتواند از بیمار موجود استفاده کند.
*/
class PatientListNationalCodeTest extends ApiTestCase
{
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 testNationalCodeFromProfileIsReturned(): void
{
[$owner, $doctor] = $this->doctor();
$patient = $this->createUser(['ROLE_USER']);
// کد ملی فقط روی پروفایل، نه روی خود کاربر
$profile = new UserProfile($patient);
$profile->setNationalCode('0012345675');
$this->em->persist($profile);
$record = new PatientRecord('doctor', $doctor->getId(), $patient, 'doctor', $doctor->getId());
$this->em->persist($record);
$this->em->flush();
$res = $this->authJson('GET', '/api/v1/patients', $owner);
self::assertSame(200, $this->responseCode());
self::assertSame($record->getUuid(), $res['data'][0]['uuid']);
self::assertSame('0012345675', $res['data'][0]['user_national_code']);
}
public function testNullWhenNoNationalCodeAnywhere(): void
{
[$owner, $doctor] = $this->doctor();
$patient = $this->createUser(['ROLE_USER']);
$record = new PatientRecord('doctor', $doctor->getId(), $patient, 'doctor', $doctor->getId());
$this->em->persist($record);
$this->em->flush();
$res = $this->authJson('GET', '/api/v1/patients', $owner);
self::assertSame(200, $this->responseCode());
self::assertNull($res['data'][0]['user_national_code']);
}
}