Improve pagination
This commit is contained in:
parent
b938338627
commit
23f8d79ff9
|
@ -1017,6 +1017,16 @@ class HealthCareSheetController extends Controller
|
||||||
* type="integer"
|
* type="integer"
|
||||||
* )
|
* )
|
||||||
* ),
|
* ),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* parameter="pagination",
|
||||||
|
* name="pagination",
|
||||||
|
* description="pagination",
|
||||||
|
* in="query",
|
||||||
|
* required=false,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="boolean",
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
* @OA\Response(
|
* @OA\Response(
|
||||||
* response=200,
|
* response=200,
|
||||||
* description="OK",
|
* description="OK",
|
||||||
|
@ -1044,7 +1054,8 @@ class HealthCareSheetController extends Controller
|
||||||
'beneficiary_id' => 'nullable|integer|exists:nh_having_rights,id',
|
'beneficiary_id' => 'nullable|integer|exists:nh_having_rights,id',
|
||||||
'network_agent_id' => 'required_without:user_id|integer|exists:networks_agents,id',
|
'network_agent_id' => 'required_without:user_id|integer|exists:networks_agents,id',
|
||||||
'type' => 'nullable|in:CONSULTATION,EXECUTION',
|
'type' => 'nullable|in:CONSULTATION,EXECUTION',
|
||||||
'state' => 'nullable|in:UNTREATED,TREATED,ACCEPTED,TO_BILL,ALL'
|
'state' => 'nullable|in:UNTREATED,TREATED,ACCEPTED,TO_BILL,ALL',
|
||||||
|
'pagination' => 'nullable|boolean'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$type = $request->input('type');
|
$type = $request->input('type');
|
||||||
|
@ -1052,6 +1063,7 @@ class HealthCareSheetController extends Controller
|
||||||
$user_id = $request->input('user_id');
|
$user_id = $request->input('user_id');
|
||||||
$beneficiary_id = $request->input('beneficiary_id');
|
$beneficiary_id = $request->input('beneficiary_id');
|
||||||
$network_agent_id = $request->input('network_agent_id');
|
$network_agent_id = $request->input('network_agent_id');
|
||||||
|
$pagination = $request->input('pagination');
|
||||||
|
|
||||||
if (!empty($user_id)) {
|
if (!empty($user_id)) {
|
||||||
$query = NhInfosHealthCareSheets::where('user_id', $user_id);
|
$query = NhInfosHealthCareSheets::where('user_id', $user_id);
|
||||||
|
@ -1107,23 +1119,34 @@ class HealthCareSheetController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sheets = $query->orderBy('created_at', 'DESC')->paginate($request->input('perPage', 10));
|
$query = $query->orderBy('created_at', 'DESC');
|
||||||
|
if ($pagination) {
|
||||||
|
$sheets = $query->paginate($request->input('perPage', 10));
|
||||||
|
} else {
|
||||||
|
$sheets = $query->get();
|
||||||
|
}
|
||||||
if (!empty($state) && $state == 'TO_BILL') {
|
if (!empty($state) && $state == 'TO_BILL') {
|
||||||
// Liste des feuilles de soins a afficher pour l'execution ,
|
// Liste des feuilles de soins a afficher pour l'execution ,
|
||||||
// Retirer les feuilles de soins qui n'ont ni exams ou prescriptions non soldes
|
// Retirer les feuilles de soins qui n'ont ni exams ou prescriptions non soldes
|
||||||
$notEmptySheets = [];
|
$notEmptySheets = [];
|
||||||
foreach ($sheets->items() as $s) {
|
$array = $pagination ? $sheets->items() : $sheets;
|
||||||
|
foreach ($array as $s) {
|
||||||
if (sizeof($s->exams) == 0 && sizeof($s->prescriptions) == 0) {
|
if (sizeof($s->exams) == 0 && sizeof($s->prescriptions) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$notEmptySheets[] = $s;
|
$notEmptySheets[] = $s;
|
||||||
}
|
}
|
||||||
// $sheets = $notEmptySheets;
|
|
||||||
$sheets->setCollection(collect($notEmptySheets));
|
if ($pagination) {
|
||||||
|
$sheets->setCollection(collect($notEmptySheets));
|
||||||
|
} else {
|
||||||
|
$sheets = $notEmptySheets;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($sheets->items() as $sheet) {
|
$array = $pagination ? $sheets->items() : $sheets;
|
||||||
|
foreach ($array as $sheet) {
|
||||||
$this->formalizeHealthCareSheet($sheet);
|
$this->formalizeHealthCareSheet($sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -703,6 +703,16 @@ class InsuranceSubscriptionController extends Controller
|
||||||
* type="integer"
|
* type="integer"
|
||||||
* )
|
* )
|
||||||
* ),
|
* ),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* parameter="pagination",
|
||||||
|
* name="pagination",
|
||||||
|
* description="pagination",
|
||||||
|
* in="query",
|
||||||
|
* required=false,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="boolean",
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
* @OA\Response(
|
* @OA\Response(
|
||||||
* response=200,
|
* response=200,
|
||||||
* description="OK",
|
* description="OK",
|
||||||
|
@ -727,10 +737,12 @@ class InsuranceSubscriptionController extends Controller
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'user_id' => 'nullable|integer|exists:users,id',
|
'user_id' => 'nullable|integer|exists:users,id',
|
||||||
'type' => 'nullable|in:ALL,ACCEPTED'
|
'type' => 'nullable|in:ALL,ACCEPTED',
|
||||||
|
'pagination' => 'nullable|boolean'
|
||||||
]);
|
]);
|
||||||
$user = User::findOrFail($request->input('user_id'));
|
$user = User::findOrFail($request->input('user_id'));
|
||||||
$currency_code = $user->network->country->currency_code;
|
$currency_code = $user->network->country->currency_code;
|
||||||
|
$pagination = $request->input('pagination');
|
||||||
|
|
||||||
$query = NhInsurancesSubscription::with(['network:id,name', 'beneficiaries']);
|
$query = NhInsurancesSubscription::with(['network:id,name', 'beneficiaries']);
|
||||||
|
|
||||||
|
@ -745,8 +757,14 @@ class InsuranceSubscriptionController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscriptions = $query->paginate($request->input('perPage', 10));;
|
if ($pagination) {
|
||||||
foreach ($subscriptions->items() as $subscription) {
|
$subscriptions = $query->paginate($request->input('perPage', 10));
|
||||||
|
} else {
|
||||||
|
$subscriptions = $query->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
$array = $pagination ? $subscriptions->items() : $subscriptions;
|
||||||
|
foreach ($array as $subscription) {
|
||||||
$subscription->state = trans('states.' . $subscription->state);
|
$subscription->state = trans('states.' . $subscription->state);
|
||||||
$subscription->insurance_action = trans('states.' . $subscription->insurance_action);
|
$subscription->insurance_action = trans('states.' . $subscription->insurance_action);
|
||||||
$subscription->bonus_amount = $this->toMoneyWithCurrencyCode($subscription->bonus_amount, $currency_code);
|
$subscription->bonus_amount = $this->toMoneyWithCurrencyCode($subscription->bonus_amount, $currency_code);
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class BooleanMiddleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @param string|null $guard
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
$request->replace($this->transform($request->all()));
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform boolean strings to boolean
|
||||||
|
* @param array $parameters
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function transform(array $parameters): array
|
||||||
|
{
|
||||||
|
return collect($parameters)->map(function ($param) {
|
||||||
|
if ($param == 'true' || $param == 'false') {
|
||||||
|
return filter_var($param, FILTER_VALIDATE_BOOLEAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $param;
|
||||||
|
})->all();
|
||||||
|
}
|
||||||
|
}
|
|
@ -82,6 +82,7 @@ $app->alias('mailer', Illuminate\Contracts\Mail\MailQueue::class);
|
||||||
|
|
||||||
$app->middleware([
|
$app->middleware([
|
||||||
App\Http\Middleware\Localization::class,
|
App\Http\Middleware\Localization::class,
|
||||||
|
App\Http\Middleware\BooleanMiddleware::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$app->routeMiddleware([
|
$app->routeMiddleware([
|
||||||
|
|
Loading…
Reference in New Issue