Add endpoint to calculate performance

This commit is contained in:
Djery-Tom 2021-11-29 13:02:14 +01:00
parent 6e99bd4e51
commit 4956227c37
2 changed files with 105 additions and 23 deletions

View File

@ -29,6 +29,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use stdClass;
use Throwable;
class HealthCareSheetController extends Controller
@ -146,7 +147,7 @@ class HealthCareSheetController extends Controller
* ref="#/components/schemas/ApiResponse",
* example = {
* "status" : 200,
* "response" : "Médicament / Appareillage enregistré",
* "response" : {"network_id":250,"code":"ABD","name":"Nivaquine","type":"COMPRESSED","on_prescription":false,"updated_at":"2021-11-29T11:32:31.000000Z","created_at":"2021-11-29T11:32:31.000000Z","id":4},
* "error":null
* }
* )
@ -168,9 +169,8 @@ class HealthCareSheetController extends Controller
if (isset($drug)) {
return $this->errorResponse(trans('errors.drug_device_already_exists'));
}
NhDrugsAndDevice::create($request->all());
return $this->successResponse(trans('messages.drug_device_saved'));
$drug = NhDrugsAndDevice::create($request->all());
return $this->successResponse($drug);
}
/**
@ -284,6 +284,79 @@ class HealthCareSheetController extends Controller
return $this->successResponse($classes);
}
/**
* @OA\Post(
* path="/health-care-sheets/performances-amount",
* summary="Calculer le montant des prestations lors d'une consulation",
* tags={"Feuilles de soins"},
* security={{"api_key":{}}},
* @OA\RequestBody(
* description="Corps de la requete",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="network_id",
* type="integer",
* example = 250,
* description="ID du reseau de l'assureur"
* ),
* @OA\Property(property="care_condition",
* description = "Condition de prise en charge",
* type="string",
* enum={"CURRENT_AFFECTION","LONG_TERM_AFFECTION","EXONERATION"},
* example= "CURRENT_AFFECTION"
* ),
* @OA\Property(
* property="performances",
* description="Listes des montants des prestations",
* example = {{"amount":20000}}
* ),
* ),
* example = {"network_id":250,"care_condition":"CURRENT_AFFECTION","performances":{{"amount":20000}}}
* )
* ),
* @OA\Response(
* response=200,
* description="OK",
* @OA\JsonContent(
* ref="#/components/schemas/ApiResponse",
* example = {"status":200,"response":{{"moderator_ticket":4000,"moderator_ticket_formatted":"4\u202f000 FCFA","insurance_amount":16000,
* "insurance_amount_formatted":"16\u202f000 FCFA"}},"error":null},
* )
* )
* )
*/
public function calculateConsultationPerformancesAmount(Request $request)
{
$this->validate($request, [
'network_id' => 'required|integer|exists:networks,id',
'care_condition' => 'required|in:CURRENT_AFFECTION,LONG_TERM_AFFECTION,EXONERATION',
'performances' => 'required|array',
'performances.*.amount' => 'required|numeric',
]);
$nhConfig = NhNetworksConfig::where('network_id', $request->input('network_id'))->first();
if (!isset($nhConfig)) {
return $this->errorResponse(trans('errors.nano_health_not_activated'));
}
$currency_code = $this->getNetworkCurrency($request->input('network_id'));
$parts = $this->getConfigInsuranceParts($nhConfig, $request->input('care_condition'));
$result = [];
foreach ($request->input('performances') as $p) {
array_push($result, [
'moderator_ticket' => $parts->insured_part * $p['amount'],
'moderator_ticket_formatted' => $this->toMoneyWithCurrencyCode($parts->insured_part * $p['amount'], $currency_code),
'insurance_amount' => $parts->insurer_part * $p['amount'],
'insurance_amount_formatted' => $this->toMoneyWithCurrencyCode($parts->insurer_part * $p['amount'], $currency_code), //
]);
}
return $this->successResponse($result);
}
/**
* @OA\Post(
* path="/health-care-sheets/consultation",
@ -513,23 +586,7 @@ class HealthCareSheetController extends Controller
return $this->errorResponse(trans('errors.nano_health_not_activated'));
}
$insuredPart = 0;
$insurerPart = 0;
switch ($request->input('care_condition')) {
case 'CURRENT_AFFECTION':
$insurerPart = $nhConfig->current_affection_percentage_insurer / 100;
$insuredPart = $nhConfig->current_affection_percentage_insured / 100;
break;
case 'LONG_TERM_AFFECTION':
$insurerPart = $nhConfig->long_term_affection_percentage_insurer / 100;
$insuredPart = $nhConfig->long_term_affection_percentage_insured / 100;
break;
case 'EXONERATION':
$insurerPart = $nhConfig->exoneration_percentage_insurer / 100;
$insuredPart = $nhConfig->exoneration_percentage_insured / 100;
break;
}
$parts = $this->getConfigInsuranceParts($nhConfig, $request->input('care_condition'));
try {
DB::beginTransaction();
@ -551,8 +608,8 @@ class HealthCareSheetController extends Controller
'act_id' => $p['act_id'],
'amount' => $p['amount'],
'home_visit_fees' => $p['home_visit_fees'] ?? null,
'moderator_ticket' => $insuredPart * $p['amount'], // to calculate,
'insurance_amount' => $insurerPart * $p['amount'], // to calculate, montant de l'assurance
'moderator_ticket' => $parts->insured_part * $p['amount'], // to calculate,
'insurance_amount' => $parts->insurer_part * $p['amount'], // to calculate, montant de l'assurance
'created_at' => $datetime, 'updated_at' => $datetime,
]);
@ -775,6 +832,30 @@ class HealthCareSheetController extends Controller
}
}
private function getConfigInsuranceParts(NhNetworksConfig $nhConfig, $care_condition): stdClass
{
$insuredPart = 0;
$insurerPart = 0;
switch ($care_condition) {
case 'CURRENT_AFFECTION':
$insurerPart = $nhConfig->current_affection_percentage_insurer / 100;
$insuredPart = $nhConfig->current_affection_percentage_insured / 100;
break;
case 'LONG_TERM_AFFECTION':
$insurerPart = $nhConfig->long_term_affection_percentage_insurer / 100;
$insuredPart = $nhConfig->long_term_affection_percentage_insured / 100;
break;
case 'EXONERATION':
$insurerPart = $nhConfig->exoneration_percentage_insurer / 100;
$insuredPart = $nhConfig->exoneration_percentage_insured / 100;
break;
}
$result = new stdClass();
$result->insured_part = $insuredPart;
$result->insurer_part = $insurerPart;
return $result;
}
public function generateSheetID(): string
{
do {

View File

@ -44,6 +44,7 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
$router->get('health-care-sheets', 'HealthCareSheetController@getHealthCareSheets');
$router->put('health-care-sheets', 'HealthCareSheetController@treatHealthCareSheet');
$router->post('health-care-sheets/performances-amount', 'HealthCareSheetController@calculateConsultationPerformancesAmount');
$router->post('health-care-sheets/consultation', 'HealthCareSheetController@storeHealthCareSheetConsultation');
$router->post('health-care-sheets/execution', 'HealthCareSheetController@storeHealthCareSheetExecution');