feat(claims): enhance claims filtering with insurance, date range, and patient search
This commit is contained in:
@@ -18,8 +18,11 @@ class ClaimRepository extends ServiceEntityRepository
|
||||
return $this->findOneBy(['uuid' => $uuid]);
|
||||
}
|
||||
|
||||
/** @return Claim[] */
|
||||
public function findByTenant(string $entityType, int $entityId, ?string $status = null): array
|
||||
/**
|
||||
* @param array{status?:?string, insurance_id?:?int, from?:?int, to?:?int, q?:?string} $filters
|
||||
* @return Claim[]
|
||||
*/
|
||||
public function findByTenant(string $entityType, int $entityId, array $filters = []): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('c')
|
||||
->where('c.entityType = :type')
|
||||
@@ -28,8 +31,34 @@ class ClaimRepository extends ServiceEntityRepository
|
||||
->setParameter('id', $entityId)
|
||||
->orderBy('c.id', 'DESC');
|
||||
|
||||
if ($status !== null) {
|
||||
$qb->andWhere('c.status = :status')->setParameter('status', $status);
|
||||
if (!empty($filters['status'])) {
|
||||
$qb->andWhere('c.status = :status')->setParameter('status', $filters['status']);
|
||||
}
|
||||
if (!empty($filters['insurance_id'])) {
|
||||
$qb->andWhere('c.insuranceId = :insId')->setParameter('insId', (int) $filters['insurance_id']);
|
||||
}
|
||||
if (!empty($filters['from'])) {
|
||||
$qb->andWhere('c.createdAt >= :from')->setParameter('from', (int) $filters['from']);
|
||||
}
|
||||
if (!empty($filters['to'])) {
|
||||
$qb->andWhere('c.createdAt <= :to')->setParameter('to', (int) $filters['to']);
|
||||
}
|
||||
|
||||
// فیلتر بیمار: مطالباتی که آیتمشان به صورتحساب پروندهی همان کاربر اشاره دارد (موبایل/کدملی/نام).
|
||||
if (!empty($filters['q'])) {
|
||||
$q = trim((string) $filters['q']);
|
||||
$qb->andWhere(
|
||||
'EXISTS (' .
|
||||
'SELECT 1 FROM App\Billing\Entity\ClaimItem ci2 ' .
|
||||
'JOIN App\Billing\Entity\InvoiceItem ii2 WITH ii2.id = ci2.invoiceItemId ' .
|
||||
'JOIN App\Billing\Entity\Invoice inv2 WITH inv2 = ii2.invoice ' .
|
||||
'JOIN App\Patient\Entity\PatientRecord pr2 WITH pr2.id = inv2.patientRecordId ' .
|
||||
'JOIN App\Auth\Entity\User u2 WITH u2 = pr2.user ' .
|
||||
'WHERE ci2.claim = c AND (' .
|
||||
'u2.mobileNumber LIKE :q OR u2.nationalCode LIKE :q OR u2.realName LIKE :q' .
|
||||
')' .
|
||||
')'
|
||||
)->setParameter('q', '%' . $q . '%');
|
||||
}
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
|
||||
Reference in New Issue
Block a user