Add endpoint to fetch user health care sheets
This commit is contained in:
parent
4ceddac738
commit
421d420e0a
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\NhHealthCareSheet;
|
||||
use App\Traits\Helper;
|
||||
|
||||
class InsuredConsultation extends Event
|
||||
{
|
||||
use Helper;
|
||||
|
||||
public $healthCareSheet;
|
||||
public $mailTitle;
|
||||
public $mailMessage;
|
||||
public $notification;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(NhHealthCareSheet $healthCareSheet, string $mailTitle, string $mailMessage,
|
||||
string $notification = null)
|
||||
{
|
||||
//
|
||||
$this->healthCareSheet = $healthCareSheet;
|
||||
$this->mailTitle = $mailTitle;
|
||||
$this->mailMessage = $mailMessage;
|
||||
$this->notification = $notification;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Events\InsuredConsultation;
|
||||
use App\HealthCareSheetType;
|
||||
use App\InsuranceState;
|
||||
use App\InsuranceSubscriptionState;
|
||||
|
@ -15,6 +16,7 @@ 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\NhInsurancesSubscription;
|
||||
use App\Models\NhMedicalPrescription;
|
||||
|
@ -25,6 +27,7 @@ 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 Throwable;
|
||||
|
||||
|
@ -84,6 +87,9 @@ class HealthCareSheetController extends Controller
|
|||
|
||||
$drugs = NhDrugsAndDevice::where('network_id', $request->input('network_id'))
|
||||
->where('name', 'like', '%' . $request->input('name') . '%')->get();
|
||||
foreach ($drugs as $drug) {
|
||||
$drug->type = trans('states.' . $drug->type);
|
||||
}
|
||||
return $this->successResponse($drugs);
|
||||
}
|
||||
|
||||
|
@ -281,7 +287,7 @@ class HealthCareSheetController extends Controller
|
|||
/**
|
||||
* @OA\Post(
|
||||
* path="/health-care-sheets/consultation",
|
||||
* summary="Consulter ou prescrire une feuille de soins",
|
||||
* summary="Consulter ou prescritpion d'un assuré",
|
||||
* tags={"Feuilles de soins"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\RequestBody(
|
||||
|
@ -292,7 +298,8 @@ class HealthCareSheetController extends Controller
|
|||
* @OA\Schema(
|
||||
* schema="consult_health_care_sheet",
|
||||
* title = "Consulter ou prescrire une feuille de soins",
|
||||
* required={"insured_id", "network_agent_id", "password", "practitioner_lastname", "practitioner_provider_class_id", "care_condition"},
|
||||
* required={"insured_id", "network_agent_id", "password", "practitioner_lastname", "practitioner_provider_class_id", "care_condition",
|
||||
* "performances"},
|
||||
* @OA\Property(
|
||||
* property="insured_id",
|
||||
* description = "Numéro immatriculation de l’assuré",
|
||||
|
@ -470,7 +477,7 @@ class HealthCareSheetController extends Controller
|
|||
'accident_date' => 'nullable|date_format:Y-m-d|before:today',
|
||||
'pregnancy_start_at' => 'nullable|date_format:Y-m-d|before:today',
|
||||
'pregnancy_end_at' => 'required_with:pregnancy_start_at|date_format:Y-m-d|after:pregnancy_start_at',
|
||||
'performances' => 'nullable|array',
|
||||
'performances' => 'required|array',
|
||||
'performances.*.act_id' => 'required|integer|exists:nh_acts,id',
|
||||
'performances.*.amount' => 'required|numeric',
|
||||
'performances.*.home_visit_fees' => 'nullable|numeric',
|
||||
|
@ -589,6 +596,12 @@ class HealthCareSheetController extends Controller
|
|||
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||
]);
|
||||
|
||||
$healthCareSheet->user = $insurance->user;
|
||||
Event::dispatch(new InsuredConsultation($healthCareSheet, trans('messages.consultation_or_prescription_carried_out'), trans('messages.consultation_or_prescription_carried_out_mail', ['name' => $insurance->user->lastname, 'insured_id' => $insurance->insured_id,
|
||||
'patient_name' => $healthCareSheet->patient_lastname . ' ' . $healthCareSheet->patient_firstname, 'patient_situation' => trans('states.' . $healthCareSheet->patient_situation), 'care_condition' => trans('states.' . $healthCareSheet->care_condition),
|
||||
'gender' => trans('states.' . $insurance->user->identification->gender), 'insurance_name' => $nhConfig->network->name, 'practitioner_name' => $healthCareSheet->practitioner_lastname . ' ' . $healthCareSheet->practitioner_firstname, 'institution_name' => $healthCareSheet->institution->lastname]),
|
||||
trans('messages.consultation_or_prescription_carried_out_notification')));
|
||||
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.consultation_or_prescription_carried_out'));
|
||||
} catch (Throwable $e) {
|
||||
|
@ -598,6 +611,81 @@ class HealthCareSheetController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/health-care-sheets",
|
||||
* summary="Obtenir les feuilles de soins d'un utilisateur",
|
||||
* tags={"Feuilles de soins"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\Parameter(
|
||||
* parameter="user_id",
|
||||
* name="user_id",
|
||||
* description="ID de l'utilisateur",
|
||||
* @OA\Schema(
|
||||
* type="integer",
|
||||
* default = 349
|
||||
* ),
|
||||
* in="query",
|
||||
* required=true
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {
|
||||
* "status" : 200,
|
||||
* "response" : {{"insured_id":"GJKS8ZGBEJTL","network_id":250,"user_id":349,"id":8,"health_care_sheet_id":"XLLLCY75OU8H","insurance_id":4,"network_agent_id":43510,"patient_lastname":"Dietchi",
|
||||
* "patient_firstname":"Djery","patient_situation":"AYANT DROIT","practitioner_lastname":"Dr Luc","practitioner_firstname":"Boris","practitioner_provider_class_id":"1","care_condition":"AFFECTION COURANTE",
|
||||
* "accident_date":null,"pregnancy_start_at":null,"pregnancy_end_at":null,"state":"EN COURS DE VALIDATION","created_at":"2021-11-25T04:39:06.000000Z","updated_at":"2021-11-25T04:39:06.000000Z","type":"CONSULTATION",
|
||||
* "practitioner_provider_class":"Chirugien","institution_name":"Agent 2 cnamgs fond 4","institution_code":"aon8K9BZOn","currency_code":"XAF","performances":{{"id":10,"act_id":5,"amount":"5 000 FCFA","moderator_ticket":"1 000 FCFA",
|
||||
* "insurance_amount":"4 000 FCFA","home_visit_fees":"2 000 FCFA","created_at":"2021-11-25T05:39:06.000000Z","updated_at":"2021-11-25T05:39:06.000000Z","act":{"id":5,"code":"CODE2","name":"Les actes infirmiers"}}},"exams":{{"id":2,"act_id":7,"description":"Une description de l'examen","quantity":5,"unit_price":null,"insured_paid_amount":null,"insurer_paid_amount":null,"created_at":"2021-11-25T04:39:06.000000Z",
|
||||
* "updated_at":"2021-11-25T04:39:06.000000Z","laravel_through_key":8,"act":{"id":7,"code":"CODE4","name":"Les analyses de biologie m\u00e9dicale"}}},"prescriptions":{{"id":4,"drug_or_device_id":1,"dosage":"3 fois\/jour","quantity":5,"unit_price":null,"insured_paid_amount":null,"insurer_paid_amount":null,"created_at":"2021-11-25T05:39:06.000000Z","updated_at":"2021-11-25T05:39:06.000000Z",
|
||||
* "drug_or_device":{"id":1,"name":"Paracetamol"}}}}},
|
||||
* "error":null
|
||||
* }
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function getHealthCareSheets(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'user_id' => 'required|integer|exists:users,id'
|
||||
]);
|
||||
|
||||
$sheets = NhInfosHealthCareSheets::with(['performances.act:id,code,name', 'exams.act:id,code,name', 'prescriptions.drug_or_device:id,name'])->where('user_id', $request->input('user_id'))->get();
|
||||
foreach ($sheets as $sheet) {
|
||||
$sheet->state = trans('states.' . $sheet->state);
|
||||
$sheet->patient_situation = trans('states.' . $sheet->patient_situation);
|
||||
$sheet->care_condition = trans('states.' . $sheet->care_condition);
|
||||
foreach ($sheet->performances as $p) {
|
||||
$p->amount = $this->toMoneyWithCurrencyCode($p->amount, $sheet->currency_code);
|
||||
$p->moderator_ticket = $this->toMoneyWithCurrencyCode($p->moderator_ticket, $sheet->currency_code);
|
||||
$p->insurance_amount = $this->toMoneyWithCurrencyCode($p->insurance_amount, $sheet->currency_code);
|
||||
$p->home_visit_fees = isset($p->home_visit_fees) ? $this->toMoneyWithCurrencyCode($p->home_visit_fees, $sheet->currency_code) : null;
|
||||
}
|
||||
|
||||
foreach ($sheet->exams as $e) {
|
||||
$this->formatExamAndPrescriptionAmounts($e, $sheet);
|
||||
}
|
||||
|
||||
foreach ($sheet->prescriptions as $p) {
|
||||
$this->formatExamAndPrescriptionAmounts($p, $sheet);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->successResponse($sheets);
|
||||
}
|
||||
|
||||
|
||||
private function formatExamAndPrescriptionAmounts($e, $sheet): void
|
||||
{
|
||||
$e->unit_price = isset($e->unit_price) ? $this->toMoneyWithCurrencyCode($e->unit_price, $sheet->currency_code) : null;
|
||||
$e->insured_paid_amount = isset($e->insured_paid_amount) ? $this->toMoneyWithCurrencyCode($e->insured_paid_amount, $sheet->currency_code) : null;
|
||||
$e->insurer_paid_amount = isset($e->insurer_paid_amount) ? $this->toMoneyWithCurrencyCode($e->insurer_paid_amount, $sheet->currency_code) : null;
|
||||
}
|
||||
|
||||
public function generateSheetID(): string
|
||||
{
|
||||
do {
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\ExampleEvent;
|
||||
use App\Events\InsuranceEvent;
|
||||
use App\Events\InsuredConsultation;
|
||||
use App\Traits\Helper;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use stdClass;
|
||||
use Throwable;
|
||||
|
||||
class InsuredConsultationNotification
|
||||
{
|
||||
use Helper;
|
||||
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param InsuredConsultation $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(InsuredConsultation $event)
|
||||
{
|
||||
//
|
||||
try {
|
||||
$client = new Client([
|
||||
'base_uri' => config('services.notification_service.base_uri'),
|
||||
]);
|
||||
$headers = [
|
||||
'Authorization' => config('services.notification_service.key'),
|
||||
];
|
||||
$body = new stdClass();
|
||||
$body->title = $event->mailTitle;
|
||||
$body->message = $event->mailMessage;
|
||||
$body->email = $event->healthCareSheet->user->email;
|
||||
|
||||
$client->request('POST', '/send-mail', ['json' => $body, 'headers' => $headers]);
|
||||
|
||||
if (isset($event->notification)) {
|
||||
$body = new stdClass();
|
||||
$body->user_code = $event->healthCareSheet->user->user_code;
|
||||
$body->message = $event->notification;
|
||||
$body->date = $event->healthCareSheet->created_at->format('Y-m-d H:i:s') ?? date('Y-m-d H:i:s');
|
||||
|
||||
$data = new stdClass();
|
||||
$data->screen = "notificationview";
|
||||
$data->data = new stdClass();
|
||||
$data->data->health_care_sheet_id = $data->data->id = $event->healthCareSheet->id;
|
||||
$body->data = $data;
|
||||
|
||||
$client->request('POST', '/onesignal/pushToUser', ['json' => $body, 'headers' => $headers]);
|
||||
}
|
||||
} catch (Throwable $t) {
|
||||
Log::error('-------- Insured Consultation notification not sent-----------');
|
||||
Log::error($t->getMessage() . '\n' . $t->getTraceAsString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,4 +44,9 @@ class NhExam extends Model
|
|||
'insured_paid_amount',
|
||||
'insurer_paid_amount'
|
||||
];
|
||||
|
||||
public function act()
|
||||
{
|
||||
return $this->belongsTo(NhAct::class, 'act_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,4 +65,9 @@ class NhHealthCareSheet extends Model
|
|||
'type',
|
||||
'state'
|
||||
];
|
||||
|
||||
public function institution()
|
||||
{
|
||||
return $this->belongsTo(AgentPlus::class, 'network_agent_id', 'network_agent_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NhInfosHealthCareSheets extends Model
|
||||
{
|
||||
protected $table = 'nh_infos_health_care_sheets';
|
||||
|
||||
// protected $dates = [
|
||||
// 'start_at',
|
||||
// 'end_at'
|
||||
// ];
|
||||
|
||||
public function network()
|
||||
{
|
||||
return $this->belongsTo(Network::class, 'network_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function performances()
|
||||
{
|
||||
return $this->hasManyThrough(NhPerformance::class, NhHealthCareSheetsPerformance::class,
|
||||
'sheet_id', 'id', 'id', 'performance_id');
|
||||
}
|
||||
|
||||
public function exams()
|
||||
{
|
||||
return $this->hasManyThrough(NhExam::class, NhHealthCareSheetsExam::class,
|
||||
'sheet_id', 'id', 'id', 'exam_id');
|
||||
}
|
||||
|
||||
public function prescriptions()
|
||||
{
|
||||
return $this->hasManyThrough(NhMedicalPrescription::class, NhHealthCareSheetsPrescription::class,
|
||||
'sheet_id', 'id', 'id', 'prescription_id');
|
||||
}
|
||||
}
|
|
@ -46,4 +46,9 @@ class NhMedicalPrescription extends Model
|
|||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
|
||||
public function drug_or_device()
|
||||
{
|
||||
return $this->belongsTo(NhDrugsAndDevice::class, 'drug_or_device_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,6 @@ class NhPerformance extends Model
|
|||
|
||||
protected $casts = [
|
||||
'act_id' => 'int',
|
||||
'amount' => 'float',
|
||||
'moderator_ticket' => 'float',
|
||||
'insurance_amount' => 'float',
|
||||
'home_visit_fees' => 'float'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
|
@ -44,4 +40,9 @@ class NhPerformance extends Model
|
|||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
|
||||
public function act()
|
||||
{
|
||||
return $this->belongsTo(NhAct::class, 'act_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Providers;
|
||||
|
||||
use App\Events\InsuranceEvent;
|
||||
use App\Events\InsuredConsultation;
|
||||
use App\Listeners\InsuredConsultationNotification;
|
||||
use App\Listeners\NotifyUser;
|
||||
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
|
@ -19,6 +21,9 @@ class EventServiceProvider extends ServiceProvider
|
|||
],
|
||||
InsuranceEvent::class => [
|
||||
NotifyUser::class
|
||||
],
|
||||
InsuredConsultation::class => [
|
||||
InsuredConsultationNotification::class
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
@ -91,5 +91,22 @@ Your request to add a beneficiary to your insurance is being validated.
|
|||
- Number of beneficiaries : :number_of_beneficiaries
|
||||
",
|
||||
'drug_device_saved' => "Drug / Device registered",
|
||||
'consultation_or_prescription_carried_out' => "Consultation or prescription carried out"
|
||||
'consultation_or_prescription_carried_out' => "Consultation or prescription carried out",
|
||||
'consultation_or_prescription_carried_out_mail' => ":gender :name ,
|
||||
|
||||
A new consultation or prescription has been made with your insurance company.
|
||||
Information about the consultation or prescription:
|
||||
- Insured number: :insured_id
|
||||
- Name of the insurance company: :insurance_name
|
||||
|
||||
- Patient name: :patient_name
|
||||
- Patient's situation: :patient_situation
|
||||
|
||||
- Institution name: :institution_name
|
||||
- Name of practitioner: :practitioner_name
|
||||
- Condition of care: :care_condition
|
||||
|
||||
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",
|
||||
];
|
||||
|
|
|
@ -22,5 +22,7 @@ return [
|
|||
"DEVICE" => "Device",
|
||||
'CURRENT_AFFECTION' => "CURRENT AFFECTION",
|
||||
'LONG_TERM_AFFECTION' => "LONG TERM AFFECTION",
|
||||
'EXONERATION' => "EXONERATION"
|
||||
'EXONERATION' => "EXONERATION",
|
||||
'HAVING_RIGHT' => "HAVING RIGHT",
|
||||
'INSURED' => 'INSURED'
|
||||
];
|
||||
|
|
|
@ -91,5 +91,23 @@ Votre demande d'ajout d'ayant droit à votre assurance est en cours de validatio
|
|||
- Nombre d'ayants droit : :number_of_beneficiaries
|
||||
",
|
||||
'drug_device_saved' => "Médicament / Appareillage enregistré",
|
||||
'consultation_or_prescription_carried_out' => "Consultation ou prescription effectuée"
|
||||
'consultation_or_prescription_carried_out' => "Consultation ou prescription effectuée",
|
||||
'consultation_or_prescription_carried_out_mail' => ":gender :name ,
|
||||
|
||||
Une nouvelle consultation ou prescription vient d'etre effectuée auprès de votre assurance.
|
||||
Informations de la consultation ou prescriptions :
|
||||
- Numéro d'assuré : :insured_id
|
||||
- Nom de l'assurance : :insurance_name
|
||||
|
||||
- Noms du patient : :patient_name
|
||||
- Situation du patient : :patient_situation
|
||||
|
||||
- Nom de l'établissement : :institution_name
|
||||
- Noms du praticien : :practitioner_name
|
||||
- Condition de prise en charge : :care_condition
|
||||
|
||||
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",
|
||||
|
||||
];
|
||||
|
|
|
@ -22,5 +22,7 @@ return [
|
|||
"DEVICE" => "Appareillage",
|
||||
'CURRENT_AFFECTION' => "AFFECTION COURANTE",
|
||||
'LONG_TERM_AFFECTION' => "AFFECTION LONGUE DURÉE",
|
||||
'EXONERATION' => "EXONERATION"
|
||||
'EXONERATION' => "EXONERATION",
|
||||
'HAVING_RIGHT' => "AYANT DROIT",
|
||||
'INSURED' => 'ASSURÉ'
|
||||
];
|
||||
|
|
|
@ -42,6 +42,7 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
|
|||
$router->get('provider-classes', 'HealthCareSheetController@getNetworkProviderClasses');
|
||||
$router->get('acts', 'HealthCareSheetController@getNetworkActs');
|
||||
|
||||
$router->get('health-care-sheets', 'HealthCareSheetController@getHealthCareSheets');
|
||||
$router->post('health-care-sheets/consultation', 'HealthCareSheetController@storeHealthCareSheetConsultation');
|
||||
$router->post('health-care-sheets/execution', 'HealthCareSheetController@storeHealthCareSheetExecution');
|
||||
|
||||
|
|
Loading…
Reference in New Issue