Add insurance coverage limit verification while accept health care sheet

This commit is contained in:
Djery-Tom 2022-02-17 15:55:14 +01:00
parent 6af9b094e7
commit c5452710b4
1 changed files with 10 additions and 1 deletions

View File

@ -1433,9 +1433,16 @@ class HealthCareSheetController extends Controller
try { try {
DB::beginTransaction(); DB::beginTransaction();
if ($action == 'ACCEPT') { if ($action == 'ACCEPT') {
$nhConfig = NhNetworksConfig::where('network_id', $sheet->insurance->network_id)->first();
if (!isset($nhConfig)) {
return $this->errorResponse(trans('errors.nano_health_not_activated'));
}
// Verification de la limite de couverture
$this->verifyInsuranceCoverageAmount($nhConfig, $sheet->insurance, $sheet, $sheet->beneficiary);
$sheet->state = InsuranceSubscriptionState::ACCEPTED; $sheet->state = InsuranceSubscriptionState::ACCEPTED;
$message = trans('messages.care_sheet_accepted'); $message = trans('messages.care_sheet_accepted');
// Mettre à jour lq couverture d'assurance de chaque assuré // Mettre à jour la couverture d'assurance de chaque assuré
$sheet->insurance_consumed_at = $datetime; $sheet->insurance_consumed_at = $datetime;
if (!empty($sheet->beneficiary)) { if (!empty($sheet->beneficiary)) {
$sheet->beneficiary->insurance_coverage_amount += $sheet->insurance_amount; $sheet->beneficiary->insurance_coverage_amount += $sheet->insurance_amount;
@ -1457,6 +1464,8 @@ class HealthCareSheetController extends Controller
DB::commit(); DB::commit();
return $this->successResponse($message); return $this->successResponse($message);
} catch (AppException $e) {
return $this->errorResponse($e->getMessage(), $e->getCode());
} catch (Throwable $e) { } catch (Throwable $e) {
Log::error($e->getMessage() . '\n' . $e->getTraceAsString()); Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
DB::rollBack(); DB::rollBack();