feat(treatment): filter treatment cases by patient record
The list could be narrowed by status, search and open-date, but not by patient — so a patient's own file had no way to ask which courses belong to them. `?record=` adds that bound. patientRecord is joined once and shared with the search branch; joining it twice under the same alias is a DQL error, and search already needed it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -40,9 +40,10 @@ class TreatmentCaseRepository extends ServiceEntityRepository
|
||||
|
||||
/** @return TreatmentCase[] */
|
||||
/**
|
||||
* @param ?string $q جستجو روی نام بیمار، موبایل، کد ملی، شمارهٔ پرونده و نام سرویس.
|
||||
* منشی همان کلیدی را میزند که در فرم نوبت میزند، پس هر چهار
|
||||
* شناسهٔ بیمار باید بگیرد نه فقط نام.
|
||||
* @param ?string $q جستجو روی نام بیمار، موبایل، کد ملی، شمارهٔ پرونده و نام سرویس.
|
||||
* منشی همان کلیدی را میزند که در فرم نوبت میزند، پس هر چهار
|
||||
* شناسهٔ بیمار باید بگیرد نه فقط نام.
|
||||
* @param ?string $recordUuid فقط دورههای همین بیمار — نمای «پروندهٔ بیمار».
|
||||
*/
|
||||
public function findForTenant(
|
||||
string $entityType,
|
||||
@@ -51,6 +52,7 @@ class TreatmentCaseRepository extends ServiceEntityRepository
|
||||
?string $q = null,
|
||||
?int $openedFrom = null,
|
||||
?int $openedTo = null,
|
||||
?string $recordUuid = null,
|
||||
): array {
|
||||
$qb = $this->createQueryBuilder('c')
|
||||
->where('c.entityType = :type')
|
||||
@@ -59,6 +61,18 @@ class TreatmentCaseRepository extends ServiceEntityRepository
|
||||
->setParameter('id', $entityId)
|
||||
->orderBy('c.openedAt', 'DESC');
|
||||
|
||||
$hasSearch = $q !== null && $q !== '';
|
||||
|
||||
// `patientRecord` را یک بار join میکنیم؛ هم فیلتر بیمار و هم جستجو لازمش
|
||||
// دارند و دو join با یک alias خطای DQL است.
|
||||
if ($hasSearch || ($recordUuid !== null && $recordUuid !== '')) {
|
||||
$qb->join('c.patientRecord', 'pr');
|
||||
}
|
||||
|
||||
if ($recordUuid !== null && $recordUuid !== '') {
|
||||
$qb->andWhere('pr.uuid = :record')->setParameter('record', $recordUuid);
|
||||
}
|
||||
|
||||
if ($status !== null) {
|
||||
$qb->andWhere('c.status = :status')->setParameter('status', $status);
|
||||
}
|
||||
@@ -73,7 +87,7 @@ class TreatmentCaseRepository extends ServiceEntityRepository
|
||||
$qb->andWhere('c.openedAt <= :to')->setParameter('to', $openedTo);
|
||||
}
|
||||
|
||||
if ($q !== null && $q !== '') {
|
||||
if ($hasSearch) {
|
||||
/**
|
||||
* پرسنل از دو راه میآید: کسی که به پرونده اختصاص یافته، و کسی که واقعاً
|
||||
* جلسهای از آن را انجام داده. مدیر که نام اپراتور را میزند هر دو را
|
||||
@@ -95,8 +109,7 @@ class TreatmentCaseRepository extends ServiceEntityRepository
|
||||
)
|
||||
DQL;
|
||||
|
||||
$qb->join('c.patientRecord', 'pr')
|
||||
->join('pr.user', 'u')
|
||||
$qb->join('pr.user', 'u')
|
||||
->join('c.serviceItem', 'si')
|
||||
->andWhere(
|
||||
'u.realName LIKE :q OR u.mobileNumber LIKE :q OR u.nationalCode LIKE :q'
|
||||
|
||||
Reference in New Issue
Block a user