feat(claims): add insurance_name field to claims and update API responses
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Billing\Service\ClaimService;
|
||||
use App\Billing\Service\InvoiceService;
|
||||
use App\Clinic\Repository\ClinicRepository;
|
||||
use App\Doctor\Repository\DoctorRepository;
|
||||
use App\Insurance\Repository\InsuranceRepository;
|
||||
use App\Patient\Repository\PatientSessionRepository;
|
||||
use App\Shared\Constant\ErrorCodes;
|
||||
use App\Shared\Controller\BaseController;
|
||||
@@ -32,8 +33,16 @@ class BillingController extends BaseController
|
||||
private readonly PatientSessionRepository $sessionRepo,
|
||||
private readonly DoctorRepository $doctorRepo,
|
||||
private readonly ClinicRepository $clinicRepo,
|
||||
private readonly InsuranceRepository $insuranceRepo,
|
||||
) {}
|
||||
|
||||
private function claimArray(Claim $claim): array
|
||||
{
|
||||
$data = $claim->toArray();
|
||||
$data['insurance_name'] = $this->insuranceRepo->find($claim->getInsuranceId())?->getName();
|
||||
return $data;
|
||||
}
|
||||
|
||||
#[Route('/api/v1/billing/invoices', methods: ['POST'])]
|
||||
public function create(Request $request, #[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
@@ -107,7 +116,7 @@ class BillingController extends BaseController
|
||||
|
||||
$claims = $this->claimService->createFromInvoice($invoice);
|
||||
|
||||
return $this->success(['data' => array_map(fn(Claim $c) => $c->toArray(), $claims)], 201);
|
||||
return $this->success(['data' => array_map(fn(Claim $c) => $this->claimArray($c), $claims)], 201);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/billing/claims', methods: ['GET'])]
|
||||
@@ -121,7 +130,7 @@ class BillingController extends BaseController
|
||||
$status = $request->query->get('status') ?: null;
|
||||
$claims = $this->claimRepo->findByTenant($entityType, $entityId, $status);
|
||||
|
||||
return $this->success(['data' => array_map(fn(Claim $c) => $c->toArray(), $claims)]);
|
||||
return $this->success(['data' => array_map(fn(Claim $c) => $this->claimArray($c), $claims)]);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/billing/claims/{uuid}/{action}', methods: ['POST'], requirements: ['action' => 'submit|approve|reject|pay'])]
|
||||
@@ -151,7 +160,7 @@ class BillingController extends BaseController
|
||||
'reason' => trim($data['reason'] ?? ''),
|
||||
]);
|
||||
|
||||
return $this->success(['data' => $claim->toArray()]);
|
||||
return $this->success(['data' => $this->claimArray($claim)]);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/billing/reports/insurance-debt', methods: ['GET'])]
|
||||
@@ -162,7 +171,12 @@ class BillingController extends BaseController
|
||||
return $this->error(ErrorCodes::ERR_FORBIDDEN_001, 'پروفایل یافت نشد', 403);
|
||||
}
|
||||
|
||||
return $this->success(['data' => $this->claimRepo->debtReport($entityType, $entityId)]);
|
||||
$rows = array_map(function (array $row) {
|
||||
$row['insurance_name'] = $this->insuranceRepo->find($row['insurance_id'])?->getName();
|
||||
return $row;
|
||||
}, $this->claimRepo->debtReport($entityType, $entityId));
|
||||
|
||||
return $this->success(['data' => $rows]);
|
||||
}
|
||||
|
||||
private function ownsSession($session, string $entityType, int $entityId): bool
|
||||
|
||||
Reference in New Issue
Block a user