Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -38,6 +38,7 @@ class BillingController extends BaseController
|
||||
private readonly InsuranceRepository $insuranceRepo,
|
||||
private readonly ClaimStatusLogRepository $statusLogRepo,
|
||||
private readonly PatientRecordScopeResolver $scopeResolver,
|
||||
private readonly \App\UserProfile\Repository\UserProfileRepository $profileRepo,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -237,12 +238,14 @@ class BillingController extends BaseController
|
||||
|
||||
$result = $this->invoiceService->patientInvoiceList($entityType, $entityId, $record->getId(), $page, $limit);
|
||||
$patient = $record->getUser();
|
||||
// کد ملی روی پروفایل ذخیره میشود؛ users.national_code برای بیمارِ ساختهشده در نوبتدهی خالی است.
|
||||
$nationalCode = $this->profileRepo->findByUser($patient)?->getNationalCode() ?? $patient->getNationalCode();
|
||||
|
||||
return $this->success([
|
||||
'patient' => [
|
||||
'uuid' => $record->getUuid(),
|
||||
'name' => $patient->getRealName(),
|
||||
'national_code' => $patient->getNationalCode(),
|
||||
'national_code' => $nationalCode,
|
||||
],
|
||||
'data' => $result['items'],
|
||||
'summary' => $result['summary'],
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Billing\Entity\Invoice;
|
||||
use App\Billing\Service\InvoicePaymentStatus;
|
||||
use App\Patient\Entity\PatientRecord;
|
||||
use App\Patient\Entity\SessionPayment;
|
||||
use App\UserProfile\Entity\UserProfile;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
@@ -41,7 +42,7 @@ class InvoiceRepository extends ServiceEntityRepository
|
||||
$rows = $this->tenantInvoicesQuery($entityType, $entityId, $filters)
|
||||
->select(
|
||||
'i.uuid AS invoice_uuid', 'r.uuid AS patient_uuid', 'u.realName AS patient_name',
|
||||
'u.nationalCode AS national_code', 'i.issuedAt AS issued_at',
|
||||
'COALESCE(p.nationalCode, u.nationalCode) AS national_code', 'i.issuedAt AS issued_at',
|
||||
'i.patientRials AS amount_rials',
|
||||
sprintf('%s AS paid_rials', self::paidSumDql('sp_row')),
|
||||
)
|
||||
@@ -198,6 +199,9 @@ class InvoiceRepository extends ServiceEntityRepository
|
||||
$qb = $this->createQueryBuilder('i')
|
||||
->innerJoin(PatientRecord::class, 'r', Join::WITH, 'r.id = i.patientRecordId')
|
||||
->innerJoin('r.user', 'u')
|
||||
// کد ملی روی پروفایل ذخیره میشود (profiles.national_code)؛ users.national_code
|
||||
// برای بیمارانِ ساختهشده در نوبتدهی خالی میماند.
|
||||
->leftJoin(UserProfile::class, 'p', Join::WITH, 'p.user = u')
|
||||
->where('i.entityType = :type')
|
||||
->andWhere('i.entityId = :id')
|
||||
->andWhere('i.status IN (:active)')
|
||||
@@ -206,7 +210,8 @@ class InvoiceRepository extends ServiceEntityRepository
|
||||
->setParameter('active', [Invoice::STATUS_FINALIZED, Invoice::STATUS_PAID]);
|
||||
|
||||
if (!empty($filters['national_code'])) {
|
||||
$qb->andWhere('u.nationalCode LIKE :nc')->setParameter('nc', '%' . $filters['national_code'] . '%');
|
||||
$qb->andWhere('(p.nationalCode LIKE :nc OR u.nationalCode LIKE :nc)')
|
||||
->setParameter('nc', '%' . $filters['national_code'] . '%');
|
||||
}
|
||||
if (!empty($filters['from'])) {
|
||||
$qb->andWhere('i.issuedAt >= :from')->setParameter('from', (int) $filters['from']);
|
||||
|
||||
Reference in New Issue
Block a user