diff --git a/app/Http/Controllers/HealthCareSheetController.php b/app/Http/Controllers/HealthCareSheetController.php index f61b7e9..b20526d 100755 --- a/app/Http/Controllers/HealthCareSheetController.php +++ b/app/Http/Controllers/HealthCareSheetController.php @@ -584,15 +584,27 @@ class HealthCareSheetController extends Controller $datetime = $this->getCurrentTimeByCountryCode($insurance->network->country->code_country); - $healthCareSheet = NhHealthCareSheet::create(array_merge($request->all(), [ + $accident_date = $request->input('accident_date'); + $pregnancy_start_at = $request->input('pregnancy_start_at'); + $pregnancy_end_at = $request->input('pregnancy_end_at'); + $healthCareSheet = NhHealthCareSheet::create([ 'health_care_sheet_id' => $this->generateSheetID(), + 'beneficiary_id' => $request->input('beneficiary_id'), + 'network_agent_id' => $request->input('network_agent_id'), + 'care_condition' => $request->input('care_condition'), + 'practitioner_lastname' => $request->input('practitioner_lastname'), + 'practitioner_firstname' => $request->input('practitioner_firstname'), + 'practitioner_provider_class_id' => $request->input('practitioner_provider_class_id'), 'insurance_id' => $insurance->id, - 'patient_lastname' => isset($beneficiary) ? $beneficiary->lastname : $insurance->user->lastname, - 'patient_firstname' => isset($beneficiary) ? $beneficiary->firstname : $insurance->user->firstname, + 'patient_lastname' => $request->input('patient_lastname'), + 'patient_firstname' => $request->input('patient_firstname'), 'patient_situation' => isset($beneficiary) ? 'HAVING_RIGHT' : 'INSURED', 'type' => HealthCareSheetType::CONSULTATION, - 'state' => InsuranceSubscriptionState::UNDER_VALIDATION - ])); + 'state' => InsuranceSubscriptionState::UNDER_VALIDATION, + 'accident_date' => (!empty($accident_date)) ? $accident_date : null, + 'pregnancy_start_at' => (!empty($pregnancy_start_at)) ? $pregnancy_start_at : null, + 'pregnancy_end_at' => (!empty($pregnancy_end_at)) ? $pregnancy_end_at : null, + ]); foreach ($request->input('performances', []) as $p) { $performance = NhPerformance::create([ @@ -1109,6 +1121,9 @@ class HealthCareSheetController extends Controller private function formatExamAndPrescriptionAmounts($e, $sheet): void { + $e->unit_price_non_formatted = $e->unit_price; + $e->insured_paid_amount_non_formatted = $e->insured_paid_amount; + $e->insurer_paid_amount_non_formatted = $e->insurer_paid_amount; $e->unit_price = isset($e->unit_price) ? $this->toMoneyWithCurrencyCode($e->unit_price, $sheet->currency_code) : null; $e->insured_paid_amount = isset($e->insured_paid_amount) ? $this->toMoneyWithCurrencyCode($e->insured_paid_amount, $sheet->currency_code) : null; $e->insurer_paid_amount = isset($e->insurer_paid_amount) ? $this->toMoneyWithCurrencyCode($e->insurer_paid_amount, $sheet->currency_code) : null; @@ -1684,9 +1699,11 @@ class HealthCareSheetController extends Controller $sheet->patient_situation = trans('states.' . $sheet->patient_situation); $sheet->care_condition = trans('states.' . $sheet->care_condition); foreach ($sheet->performances as $p) { + $p->amount_non_formatted = $p->amount; $p->amount = $this->toMoneyWithCurrencyCode($p->amount, $sheet->currency_code); $p->moderator_ticket = $this->toMoneyWithCurrencyCode($p->moderator_ticket, $sheet->currency_code); $p->insurance_amount = $this->toMoneyWithCurrencyCode($p->insurance_amount, $sheet->currency_code); + $p->home_visit_fees_non_formatted = $p->home_visit_fees; $p->home_visit_fees = isset($p->home_visit_fees) ? $this->toMoneyWithCurrencyCode($p->home_visit_fees, $sheet->currency_code) : null; } diff --git a/app/Http/Controllers/InsuredController.php b/app/Http/Controllers/InsuredController.php index 81187bd..2c54355 100755 --- a/app/Http/Controllers/InsuredController.php +++ b/app/Http/Controllers/InsuredController.php @@ -80,10 +80,21 @@ class InsuredController extends Controller $phone = $request->input('phone'); $network_id = $request->input('network_id'); - $insured = NhInsurance::with(['user:id,firstname,lastname,phone,email', 'network:id,name', 'beneficiaries'])->whereHas('user', function ($query) use ($name, $phone) { - $query->where('lastname', 'like', '%' . $name . '%')->orWhere('phone', 'like', '%' . $phone . '%'); - })->where('network_id', $network_id)->get(); + $q = NhInsurance::with(['user:id,firstname,lastname,phone,email', 'network:id,name', 'beneficiaries'])->where('network_id', $network_id); + if (!empty($name)) { + $q = $q->whereHas('user', function ($query) use ($name) { + return $query->where('lastname', 'like', '%' . $name . '%')->orWhere('firstname', 'like', '%' . $name . '%'); + }); + } + + if (!empty($phone)) { + $q = $q->whereHas('user', function ($query) use ($phone) { + return $query->where('phone', 'like', '%' . $phone . '%'); + }); + } + + $insured = $q->get(); return $this->successResponse($insured); } }