add request for authorization of care endpoint
This commit is contained in:
parent
89f4a8946e
commit
c3e69f71fc
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Events\InsuredConsultation;
|
||||
use App\HealthCareSheetType;
|
||||
use App\InsuranceState;
|
||||
use App\InsuranceSubscriptionState;
|
||||
use App\Models\AgentPlus;
|
||||
use App\Models\NhAuthorizationOfCareRequest;
|
||||
use App\Models\NhAct;
|
||||
use App\Models\NhDrugsAndDevice;
|
||||
use App\Models\NhExam;
|
||||
use App\Models\NhHealthCareSheet;
|
||||
use App\Models\NhHealthCareSheetsExam;
|
||||
use App\Models\NhHealthCareSheetsHistory;
|
||||
use App\Models\NhHealthCareSheetsPerformance;
|
||||
use App\Models\NhHealthCareSheetsPrescription;
|
||||
use App\Models\NhInfosHealthCareSheets;
|
||||
use App\Models\NhInsurance;
|
||||
use App\Models\NhMedicalPrescription;
|
||||
use App\Models\NhNetworksConfig;
|
||||
use App\Models\NhPerformance;
|
||||
use App\Models\NhProviderClass;
|
||||
use App\Models\NhValidatingAgent;
|
||||
use App\Models\User;
|
||||
use App\Traits\ApiResponser;
|
||||
use App\Traits\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use stdClass;
|
||||
use Throwable;
|
||||
|
||||
class AuthorizationCareRequestController extends Controller
|
||||
{
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/authorizations-care-requests",
|
||||
* summary="Demander une autorisation de soin",
|
||||
* tags={"Demandes d'autorisation de soins"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\RequestBody(
|
||||
* description="Corps de la requete",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(
|
||||
* schema="request_for_authorizations_of_care",
|
||||
* title = "Demande autorisation de soins",
|
||||
* required={"health_care_sheet_id", "network_agent_id", "password", "practitioner_lastname", "practitioner_provider_class_id",
|
||||
* "prescriptions" , "exams"},
|
||||
* @OA\Property(
|
||||
* property="act_id",
|
||||
* description = "ID de l'acte",
|
||||
* type="integer",
|
||||
* example= 5
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="user_id",
|
||||
* description = "ID de l'utilisateur",
|
||||
* type="integer",
|
||||
* example= 301
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="password",
|
||||
* description = "Mot de passe",
|
||||
* type="string",
|
||||
* example= "password"
|
||||
* )
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {
|
||||
* "status" : 200,
|
||||
* "response" : "Demande autorisation soin envoyée",
|
||||
* "error":null
|
||||
* }
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'act_id' => 'required|integer|exists:nh_acts,id',
|
||||
'user_id' => 'required|integer|exists:users,id',
|
||||
'password' => 'required|string'
|
||||
]);
|
||||
|
||||
$user = User::find($request->input('user_id'));
|
||||
$act_id = $request->input('act_id');
|
||||
$password = $request->input('password');
|
||||
if (!checkPassword($password, $user->encrypted_password, $user->salt))
|
||||
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
||||
|
||||
$act = NhAct::find($act_id);
|
||||
try {
|
||||
|
||||
DB::beginTransaction();
|
||||
NhAuthorizationOfCareRequest::create([
|
||||
'request_id' => $this->generateRequestID(),
|
||||
'user_id' => $user->id,
|
||||
'act_id' => $act_id,
|
||||
'state' => InsuranceSubscriptionState::UNDER_VALIDATION
|
||||
]);
|
||||
DB::commit();
|
||||
|
||||
$recipients = array_map(function ($email) {
|
||||
return preg_replace("/\s+/", "", $email);
|
||||
}, NhValidatingAgent::where('role', 'DOCTOR')->whereNotNull('password')->pluck('email')->toArray());
|
||||
|
||||
|
||||
$title = __('messages.new_care_authorisation');
|
||||
$message = __('messages.new_care_authorisation_email', ['insured' => $user->lastname . ' ' . $user->firstname, 'act' => $act->name]);
|
||||
|
||||
Mail::mailer('smtp')->raw($message, function ($message) use ($recipients, $title) {
|
||||
$message->subject($title)
|
||||
->to($recipients);
|
||||
});
|
||||
|
||||
} catch (Throwable $t) {
|
||||
DB::rollBack();
|
||||
Log::error('-------- Authorization of care error -----------');
|
||||
Log::error($t->getMessage() . " :\n" . $t->getTraceAsString());
|
||||
}
|
||||
|
||||
return $this->successResponse(__('messages.new_care_authorisation_sent'));
|
||||
}
|
||||
|
||||
private function generateRequestID(): string
|
||||
{
|
||||
do {
|
||||
$code = generateTransactionCode();
|
||||
$codeCorrect = NhAuthorizationOfCareRequest::where('request_id', $code)->count() < 0;
|
||||
} while ($codeCorrect);
|
||||
return $code;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -238,7 +238,17 @@ class HealthCareSheetController extends Controller
|
|||
* description="Code de l'acte",
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* default = "CODE1"
|
||||
* ),
|
||||
* in="query",
|
||||
* required=false
|
||||
* ),
|
||||
* @OA\Parameter(
|
||||
* parameter="authorization_type",
|
||||
* name="authorization_type",
|
||||
* description="Type d'autorisation",
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* enum = {"FREE","PRIOR"},
|
||||
* ),
|
||||
* in="query",
|
||||
* required=false
|
||||
|
@ -262,9 +272,11 @@ class HealthCareSheetController extends Controller
|
|||
$this->validate($request, [
|
||||
'network_id' => 'required|integer|exists:networks,id',
|
||||
'code' => 'nullable|string',
|
||||
'authorization_type' => 'nullable|in:FREE,PRIOR'
|
||||
]);
|
||||
|
||||
$network_id = $request->input('network_id');
|
||||
$authorization_type = $request->input('authorization_type');
|
||||
|
||||
$query = NhAct::whereHas('network_config', function ($query) use ($network_id) {
|
||||
return $query->where('network_id', $network_id);
|
||||
|
@ -275,6 +287,10 @@ class HealthCareSheetController extends Controller
|
|||
$query = $query->where('code', 'like', '%' . $code . '%');
|
||||
}
|
||||
|
||||
if (!empty($authorization_type)) {
|
||||
$query = $query->where('authorization_type', $authorization_type);
|
||||
}
|
||||
|
||||
$classes = $query->get(['id', 'code', 'name']);
|
||||
|
||||
return $this->successResponse($classes);
|
||||
|
@ -1767,7 +1783,7 @@ class HealthCareSheetController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
public function generateSheetID(): string
|
||||
private function generateSheetID(): string
|
||||
{
|
||||
do {
|
||||
$code = generateTransactionCode();
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class AuthorizationOfCareRequest
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $request_id
|
||||
* @property int $user_id
|
||||
* @property int $act_id
|
||||
* @property string $state
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class NhAuthorizationOfCareRequest extends Model
|
||||
{
|
||||
protected $table = 'nh_authorization_of_care_requests';
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'act_id' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'request_id',
|
||||
'user_id',
|
||||
'act_id',
|
||||
'state'
|
||||
];
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateNhAuthorizationOfCareRequestsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('nh_authorization_of_care_requests', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('request_id')->unique();
|
||||
$table->integer('user_id');
|
||||
$table->integer('act_id');
|
||||
$table->enum('state', ['UNDER_VALIDATION', 'ACCEPTED', 'REJECTED'])->default('UNDER_VALIDATION');
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('nh_authorization_of_care_requests');
|
||||
}
|
||||
}
|
|
@ -128,5 +128,8 @@ A new consultation or prescription has been made with your insurance.
|
|||
'institution_name' => "Institution name",
|
||||
'phone' => "Telephone",
|
||||
'transmitter' => "Transmitter",
|
||||
'recipient' => "Recipient"
|
||||
'recipient' => "Recipient",
|
||||
'new_care_authorisation' => "New care authorisation",
|
||||
'new_care_authorisation_email' => "Insured :insured requests new care authorisation for procedure :act",
|
||||
'new_care_authorisation_sent' => "New care authorisation request sent"
|
||||
];
|
||||
|
|
|
@ -144,5 +144,8 @@ Une nouvelle execution de prescription vient d'etre effectuée sur votre assuran
|
|||
'institution_name' => "Nom établissement",
|
||||
'phone' => "Téléphone",
|
||||
'transmitter' => "Émetteur",
|
||||
'recipient' => "Destinataire"
|
||||
'recipient' => "Destinataire",
|
||||
'new_care_authorisation' => "Nouvelle autorisation de soin",
|
||||
'new_care_authorisation_email' => "L'assuré :insured demande une nouvelle autorisation de soin pour l'acte :act",
|
||||
'new_care_authorisation_sent' => "Nouvelle demande autorisation soin envoyée"
|
||||
];
|
||||
|
|
|
@ -52,4 +52,6 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
|
|||
|
||||
$router->get('invoices', 'InvoiceController@getInvoices');
|
||||
$router->get('generate-invoice', 'InvoiceController@generateInvoice');
|
||||
|
||||
$router->post('authorizations-care-requests', 'AuthorizationCareRequestController@store');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue