nanosanteservice/app/Http/Controllers/InsuranceController.php

99 lines
3.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use App\Events\InsuranceEvent;
use App\InsuranceSubscriptionAffiliation;
use App\InsuranceSubscriptionState;
use App\Models\CountriesCurrency;
use App\Models\Identification;
use App\Models\NhInsurance;
use App\Models\NhInsurancesHavingRight;
use App\Models\NhInsurancesSubscription;
use App\Models\NhInsurancesSubscriptionsHistory;
2021-10-20 13:05:23 +00:00
use App\Models\NhMonthsPricesGrid;
use App\Models\NhNetworksConfig;
2021-11-01 14:26:21 +00:00
use App\Models\User;
use App\Traits\Helper;
2021-10-20 13:05:23 +00:00
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
2021-10-21 12:07:35 +00:00
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Throwable;
class InsuranceController extends Controller
{
use Helper;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* @OA\Get(
* path="/insurances",
* summary="Afficher la liste des assurances ( par pays )",
* tags={"Assurances"},
* security={{"api_key":{}}},
* @OA\Parameter(
* parameter="country_id",
* name="country_id",
* description="ID du pays",
* in="query",
* required=true,
* @OA\Schema(
* type="integer",
* default=78
* )
* ),
* @OA\Response(
* response=200,
* description="OK",
* @OA\JsonContent(
* ref="#/components/schemas/ApiResponse",
* example = {
* "status" : 200,
2021-10-20 13:05:23 +00:00
* "response" : {{"id":250,"name":"Cnamgs-pharmacies", "age_limit_of_insured_and_spouse" : 30 ,
* "age_limit_of_child_beneficiary": 25 , "max_number_of_beneficiaries":"5", "months_prices":{{"id": 1,"number_of_months":"3","min_amount":"150000 XAF"}}}},
* "error":null
* }
* )
* )
* )
*/
public function getInsurances(Request $request)
{
$this->validate($request, [
'country_id' => 'nullable|integer|exists:countries,id'
]);
$country = CountriesCurrency::findOrFail($request->input('country_id'));
2021-10-20 13:05:23 +00:00
$insurances = DB::select("SELECT n.id , n.name , nhc.age_limit_of_insured_and_spouse, nhc.age_limit_of_child_beneficiary, nhc.max_number_of_beneficiaries, nhc.id as nhc_id
FROM networks n JOIN configWallet cw ON cw.id_network = n.id JOIN nh_networks_configs nhc
ON nhc.network_id = n.id WHERE n.country_id = :countryId AND cw.type = 'ilink_sante' AND n.status = 1", ['countryId' => $request->input('country_id')]);
foreach ($insurances as $insurance) {
$months_prices = DB::select("SELECT id, number_of_months , min_amount FROM nh_months_prices_grid WHERE nh_network_config_id = :nhc_id",
['nhc_id' => $insurance->nhc_id]);
foreach ($months_prices as $mp) {
$mp->min_amount = $this->toMoneyWithCurrencyCode($mp->min_amount, $country->currency_code ?? 'XAF');
}
$insurance->months_prices = $months_prices;
unset($insurance->nhc_id);
}
return $this->successResponse($insurances);
}
}