Add endpoints to treat health care sheet

This commit is contained in:
Djery-Tom 2021-11-29 08:34:35 +01:00
parent 421d420e0a
commit ea1621d5d8
8 changed files with 105 additions and 7 deletions

View File

@ -392,7 +392,7 @@ class HealthCareSheetController extends Controller
* ref="#/components/schemas/ApiResponse",
* example = {
* "status" : 200,
* "response" : "Médicament / Appareillage enregistré",
* "response" : "Consultation ou prescription effectuée",
* "error":null
* }
* )
@ -500,8 +500,9 @@ class HealthCareSheetController extends Controller
if (!checkPassword($request->input('password'), $agent->encrypted_password, $agent->salt))
return $this->errorResponse(trans('messages.incorrect_user_password'));
if ($request->has('beneficiary_id')) {
$beneficiary = $insurance->beneficiaries()->where('nh_having_rights.id', $request->input('beneficiary_id'))->first();
$beneficiary_id = $request->input('beneficiary_id');
if (isset($beneficiary_id)) {
$beneficiary = $insurance->beneficiaries()->where('nh_having_rights.id', $beneficiary_id)->first();
if (!isset($beneficiary)) {
return $this->errorResponse(trans('errors.beneficiary_not_found'));
}
@ -686,6 +687,89 @@ class HealthCareSheetController extends Controller
$e->insurer_paid_amount = isset($e->insurer_paid_amount) ? $this->toMoneyWithCurrencyCode($e->insurer_paid_amount, $sheet->currency_code) : null;
}
/**
* @OA\Put(
* path="/health-care-sheets",
* summary="Accepter ou Rejeter une feuille de soins",
* tags={"Feuilles de soins"},
* security={{"api_key":{}}},
* @OA\RequestBody(
* description="Corps de la requete",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* required={"health_care_sheet_id", "user_id", "action"},
* @OA\Property(
* property="health_care_sheet_id",
* description = "ID de la feuille de soins",
* type="integer",
* example= 4
* ),
* @OA\Property(
* property="user_id",
* description = "ID de l'utilisateur",
* type="integer",
* example= 349
* ),
* @OA\Property(
* property="action",
* description = "Action à effectuer",
* enum={"ACCEPT","REJECT"},
* example= "ACCEPT"
* ),
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="OK",
* @OA\JsonContent(
* ref="#/components/schemas/ApiResponse",
* example = {
* "status" : 200,
* "response" : "La feuille de soins a été acceptée",
* "error":null
* }
* )
* )
* )
*/
public function treatHealthCareSheet(Request $request)
{
$this->validate($request, [
'health_care_sheet_id' => 'required|integer|exists:nh_health_care_sheets,id',
'user_id' => 'required|integer|exists:users,id',
'action' => 'required|in:ACCEPT,REJECT'
]);
$action = $request->input('action');
$user_id = $request->input('user_id');
$sheet = NhHealthCareSheet::findOrFail($request->input('health_care_sheet_id'));
if ($sheet->insurance->user_id != $user_id) {
return $this->errorResponse(trans('errors.unauthorized'));
}
if ($sheet->state != InsuranceSubscriptionState::UNDER_VALIDATION) {
return $this->errorResponse(trans('errors.care_sheet_already_been_processed'));
}
$datetime = $this->getCurrentTimeByCountryCode($sheet->insurance->network->country->code_country);
if ($action == 'ACCEPT') {
$sheet->state = InsuranceSubscriptionState::ACCEPTED;
$sheet->updated_at = $datetime;
$sheet->save();
return $this->successResponse(trans('messages.care_sheet_accepted'));
} else {
$sheet->state = InsuranceSubscriptionState::REJECTED;
$sheet->updated_at = $datetime;
$sheet->save();
return $this->successResponse(trans('messages.care_sheet_rejected'));
}
}
public function generateSheetID(): string
{
do {

View File

@ -101,7 +101,8 @@ class InsuranceSubscriptionController extends Controller
'beneficiaries.*.affiliation' => 'required|in:CHILD,SPOUSE'
]);
if ($request->has('subscription_id')) {
$subscription_id = $request->has('subscription_id');
if (isset($subscription_id)) {
$subscription = NhInsurancesSubscription::findOrFail($request->input('subscription_id'));
$networkConfig = $subscription->nhNetworkConfig;
$monthPrice = $networkConfig->monthsPricesGrid()->where('number_of_months', $subscription->number_of_months)->first();

View File

@ -70,4 +70,9 @@ class NhHealthCareSheet extends Model
{
return $this->belongsTo(AgentPlus::class, 'network_agent_id', 'network_agent_id');
}
public function insurance()
{
return $this->belongsTo(NhInsurance::class, 'insurance_id');
}
}

View File

@ -33,5 +33,7 @@ return [
"subscription_cannot_be_submitted" => "Your previous application :state . You cannot submit another one at this time",
"not_insured" => "You are not insured",
'drug_device_already_exists' => "This drug / device code already exists",
"beneficiary_not_found" => "This beneficiary does not exist"
"beneficiary_not_found" => "This beneficiary does not exist",
"care_sheet_already_been_processed" => "This care sheet has already been processed",
"unauthorized" => "You are not authorized to perform this operation"
];

View File

@ -109,4 +109,6 @@ A new consultation or prescription has been made with your insurance company.
Log in to the application to have more details and validate this operation.
",
'consultation_or_prescription_carried_out_notification' => "A new consultation or prescription has just been made with your insurance company",
"care_sheet_accepted" => "The care sheet has been accepted",
"care_sheet_rejected" => "The care sheet has been rejected"
];

View File

@ -33,5 +33,7 @@ return [
"subscription_cannot_be_submitted" => "Votre demande précédente :state. Vous ne pouvez pas en soumettre une autre pour l'instant",
"not_insured" => "Vous n'êtes pas assuré",
'drug_device_already_exists' => "Ce code médicament / appareillage existe deja",
"beneficiary_not_found" => "Ce bénéficiaire n'existe pas"
"beneficiary_not_found" => "Ce bénéficiaire n'existe pas",
"care_sheet_already_been_processed" => "Cette feuille de soins a deja été traitée",
"unauthorized" => "Vous n'etes pas autorisé à effectuer cette operation"
];

View File

@ -109,5 +109,6 @@ Une nouvelle consultation ou prescription vient d'etre effectuée auprès de vot
Connectez-vous à l'application pour avoir plus de details et valider cette opération.
",
'consultation_or_prescription_carried_out_notification' => "Une nouvelle consultation ou prescription vient d'etre effectuée auprès de votre assurance",
"care_sheet_accepted" => "La feuille de soins a été acceptée",
"care_sheet_rejected" => "La feuille de soins a été rejetée"
];

View File

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