Add beneficiary_id to health care sheets table

This commit is contained in:
Djery-Tom 2022-01-12 18:25:40 +01:00
parent d2074d4e21
commit 192e5cac9a
5 changed files with 113 additions and 2 deletions

View File

@ -948,6 +948,17 @@ class HealthCareSheetController extends Controller
* required=false
* ),
* @OA\Parameter(
* parameter="beneficiary_id",
* name="beneficiary_id",
* description="ID du beneficiaire",
* @OA\Schema(
* type="integer",
* default = 3
* ),
* in="query",
* required=false
* ),
* @OA\Parameter(
* parameter="network_agent_id",
* name="network_agent_id",
* description="ID de l'agent dans le reseau",
@ -1006,6 +1017,7 @@ class HealthCareSheetController extends Controller
{
$this->validate($request, [
'user_id' => 'required_without:network_agent_id|integer|exists:users,id',
'beneficiary_id' => 'nullable|integer|exists:nh_having_rights,id',
'network_agent_id' => 'required_without:user_id|integer|exists:networks_agents,id',
'type' => 'nullable|in:CONSULTATION,EXECUTION',
'state' => 'nullable|in:UNTREATED,TREATED,ACCEPTED,TO_BILL'
@ -1014,10 +1026,14 @@ class HealthCareSheetController extends Controller
$type = $request->input('type');
$state = $request->input('state');
$user_id = $request->input('user_id');
$beneficiary_id = $request->input('beneficiary_id');
$network_agent_id = $request->input('network_agent_id');
if (!empty($user_id)) {
if (!empty($user_id) || !empty($beneficiary_id)) {
$query = NhInfosHealthCareSheets::where('user_id', $user_id);
if (!empty($beneficiary_id)) {
$query = $query->where('beneficiary_id', $beneficiary_id);
}
if (!empty($network_agent_id)) {
$query = $query->where('network_agent_id', $network_agent_id);
}
@ -1037,6 +1053,10 @@ class HealthCareSheetController extends Controller
return $q->with(['drug_or_device:id,name'])->where('billed', 0);
}])->where('state', InsuranceSubscriptionState::ACCEPTED)
->where('user_id', $request->input('user_id'));
if (!empty($beneficiary_id)) {
$query = $query->where('beneficiary_id', $beneficiary_id);
}
}
if (!empty($type)) {

View File

@ -15,6 +15,7 @@ use Illuminate\Database\Eloquent\Model;
* @property int $id
* @property string $health_care_sheet_id
* @property int $insurance_id
* @property int $beneficiary_id
* @property int $network_agent_id
* @property string $patient_lastname
* @property string|null $patient_firstname
@ -40,6 +41,7 @@ class NhHealthCareSheet extends Model
protected $casts = [
'insurance_id' => 'int',
'beneficiary_id' => 'int',
'network_agent_id' => 'int',
'prescription_sheet_id' => 'int'
];
@ -53,6 +55,7 @@ class NhHealthCareSheet extends Model
protected $fillable = [
'health_care_sheet_id',
'insurance_id',
'beneficiary_id',
'network_agent_id',
'patient_lastname',
'patient_firstname',
@ -79,6 +82,11 @@ class NhHealthCareSheet extends Model
return $this->belongsTo(NhInsurance::class, 'insurance_id');
}
public function beneficiary()
{
return $this->belongsTo(NhHavingRight::class, 'beneficiary_id');
}
public function performances()
{
return $this->hasManyThrough(NhPerformance::class, NhHealthCareSheetsPerformance::class,

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddBeneficiaryIdToNhHealthCareSheetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('nh_health_care_sheets', function (Blueprint $table) {
$table->integer('beneficiary_id')->nullable()->after('insurance_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('nh_health_care_sheets', function (Blueprint $table) {
$table->dropColumn('beneficiary_id');
});
}
}

View File

@ -0,0 +1,51 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class UpdateNhInfosHealthCareSheetsView2 extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement("CREATE OR REPLACE VIEW `nh_infos_health_care_sheets` AS
SELECT nhi.insured_id,
nhi.network_id,
nhi.user_id,
nhcs.*,
nhpc.name as practitioner_provider_class,
ag.lastname as institution_name,
ag.code_membre as institution_code,
cc.currency_code,
p_nhcs.health_care_sheet_id as consultation_health_care_sheet_id,
p_nhcs.practitioner_lastname as consultation_practitioner_lastname,
p_nhcs.practitioner_firstname as consultation_practitioner_firstname,
p_ag.lastname as consultation_institution_name,
p_nhpc.name as consultation_practitioner_provider_class
FROM nh_health_care_sheets nhcs
INNER JOIN nh_insurances nhi ON nhi.id = nhcs.insurance_id
INNER JOIN agent_plus ag ON ag.network_agent_id = nhcs.network_agent_id
INNER JOIN countries_currencies cc ON cc.id = ag.country_id
INNER JOIN nh_provider_classes nhpc ON nhpc.id = nhcs.practitioner_provider_class_id
LEFT JOIN nh_health_care_sheets p_nhcs ON p_nhcs.id = nhcs.prescription_sheet_id
LEFT JOIN agent_plus p_ag ON p_nhcs.network_agent_id = p_ag.network_agent_id
LEFT JOIN nh_provider_classes p_nhpc ON p_nhpc.id = p_nhcs.practitioner_provider_class_id
ORDER BY nhcs.created_at DESC");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@ -129,5 +129,5 @@ Une nouvelle execution de prescription vient d'etre effectuée sur votre assuran
Connectez-vous à l'application pour avoir plus de details et valider cette opération.
",
'consultation_or_prescription_updated' => "Consultation ou prescription mis à jour",
'consultation_or_prescription_updated' => "Consultation ou prescription mise à jour",
];