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>
This commit is contained in:
@@ -29,6 +29,31 @@ class UserProfileRepository extends ServiceEntityRepository
|
||||
return $this->findOneBy(['nationalCode' => $nationalCode]);
|
||||
}
|
||||
|
||||
/**
|
||||
* نگاشتِ userId → کد ملیِ ذخیرهشده روی پروفایل، فقط برای پروفایلهایی که کد ملی دارند.
|
||||
* برای پر کردنِ گروهیِ کد ملی در لیست بیماران (کد ملی روی profiles است نه users).
|
||||
*
|
||||
* @param int[] $userIds
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function nationalCodesByUserIds(array $userIds): array
|
||||
{
|
||||
if ($userIds === []) {
|
||||
return [];
|
||||
}
|
||||
$rows = $this->createQueryBuilder('p')
|
||||
->select('IDENTITY(p.user) AS uid', 'p.nationalCode AS nc')
|
||||
->where('p.user IN (:ids)')->setParameter('ids', $userIds)
|
||||
->andWhere('p.nationalCode IS NOT NULL')
|
||||
->getQuery()->getArrayResult();
|
||||
|
||||
$map = [];
|
||||
foreach ($rows as $r) {
|
||||
$map[(int) $r['uid']] = (string) $r['nc'];
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
|
||||
public function save(UserProfile $profile, bool $flush = true): void
|
||||
{
|
||||
$this->getEntityManager()->persist($profile);
|
||||
|
||||
Reference in New Issue
Block a user