Improve execution of health care sheet

This commit is contained in:
Djery-Tom 2021-12-20 12:20:58 +01:00
parent a69b3253dc
commit c689b89cb0
6 changed files with 100 additions and 16 deletions

View File

@ -839,6 +839,10 @@ class HealthCareSheetController extends Controller
if (!in_array($i->id, $prescriptionsIds)) {
continue;
}
if ($i->billed) {
return $this->errorResponse(__('errors.prescription_already_invoiced', ['id' => array_search($i->id, $prescriptionsIds) + 1]));
}
$itemId = $i->id;
$item->unit_price = array_filter($prescriptions, function ($r) use ($itemId) {
return $r['id'] == $itemId;
@ -850,6 +854,9 @@ class HealthCareSheetController extends Controller
if (!in_array($i->id, $examsIds)) {
continue;
}
if ($i->billed) {
return $this->errorResponse(__('errors.exam_already_invoiced', ['id' => array_search($i->id, $examsIds) + 1]));
}
$itemId = $i->id;
$item->unit_price = array_filter($exams, function ($r) use ($itemId) {
return $r['id'] == $itemId;
@ -862,8 +869,12 @@ class HealthCareSheetController extends Controller
$item->insured_paid_amount = $parts->insured_part * $item->unit_price * ($item->quantity ?? 1);
$item->insurer_paid_amount = $parts->insurer_part * $item->unit_price * ($item->quantity ?? 1);
$item->created_at = $item->updated_at = $datetime;
$item->billed = true;
$item->push();
$i->billed = true;
$i->save();
if ($relation == 'prescriptions') {
NhHealthCareSheetsPrescription::create([
@ -884,12 +895,12 @@ class HealthCareSheetController extends Controller
}
#Clone pivots
$performances = NhHealthCareSheetsPerformance::where('sheet_id', $sheet->id)->get();
foreach ($performances as $pf) {
$p = $pf->replicate();
$p->sheet_id = $healthCareSheet->id;
$p->push();
}
// $performances = NhHealthCareSheetsPerformance::where('sheet_id', $sheet->id)->get();
// foreach ($performances as $pf) {
// $p = $pf->replicate();
// $p->sheet_id = $healthCareSheet->id;
// $p->push();
// }
NhHealthCareSheetsHistory::create([
'action' => 'ADD',
@ -948,7 +959,7 @@ class HealthCareSheetController extends Controller
* description="Status des feuilles de soins",
* @OA\Schema(
* type="string",
* enum = {"UNTREATED","TREATED","ACCEPTED"},
* enum = {"UNTREATED","TREATED","ACCEPTED","TO_BILL"},
* default = "UNTREATED"
* ),
* in="query",
@ -979,13 +990,22 @@ class HealthCareSheetController extends Controller
$this->validate($request, [
'user_id' => 'required|integer|exists:users,id',
'type' => 'nullable|in:CONSULTATION,EXECUTION',
'state' => 'nullable|in:UNTREATED,TREATED,ACCEPTED'
'state' => 'nullable|in:UNTREATED,TREATED,ACCEPTED,TO_BILL'
]);
$type = $request->input('type');
$state = $request->input('state');
$query = 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'));
if (!empty($state) && $state == 'TO_BILL') {
// Liste des feuilles de soins a afficher pour l'execution
$query = NhInfosHealthCareSheets::with(['performances.act:id,code,name', 'exams' => function ($q) {
return $q->with(['act:id,code,name'])->where('billed', 0);
}, 'prescriptions' => function ($q) {
return $q->with(['drug_or_device:id,name'])->where('billed', 0);
}])->where('user_id', $request->input('user_id'));
}
if (!empty($type)) {
$query = $query->where('type', $type);
}
@ -1004,7 +1024,20 @@ class HealthCareSheetController extends Controller
}
}
$sheets = $query->get();
$sheets = $query->orderBy('created_at', 'DESC')->get();
if (!empty($state) && $state == 'TO_BILL') {
// Liste des feuilles de soins a afficher pour l'execution ,
// Retirer les feuilles de soins qui n'ont ni exams ou prescriptions non soldes
$notEmptySheets = [];
foreach ($sheets as $s) {
if (sizeof($s->exams) == 0 && sizeof($s->prescriptions) == 0) {
continue;
}
$notEmptySheets[] = $s;
}
$sheets = $notEmptySheets;
}
foreach ($sheets as $sheet) {
$this->formalizeHealthCareSheet($sheet);
}

View File

@ -19,6 +19,7 @@ use Illuminate\Database\Eloquent\Model;
* @property float $unit_price
* @property float $insured_paid_amount
* @property float $insurer_paid_amount
* @property int $billed
* @property Carbon $created_at
* @property Carbon $updated_at
*
@ -31,9 +32,10 @@ class NhExam extends Model
protected $casts = [
'act_id' => 'int',
'quantity' => 'int',
'unit_price' => 'float',
'insured_paid_amount' => 'float',
'insurer_paid_amount' => 'float'
// 'unit_price' => 'float',
// 'insured_paid_amount' => 'float',
// 'insurer_paid_amount' => 'float',
'billed' => 'boolean'
];
protected $fillable = [
@ -42,7 +44,8 @@ class NhExam extends Model
'quantity',
'unit_price',
'insured_paid_amount',
'insurer_paid_amount'
'insurer_paid_amount',
'billed'
];
public function act()

View File

@ -33,7 +33,8 @@ class NhMedicalPrescription extends Model
'quantity' => 'int',
// 'unit_price' => 'float',
// 'insured_paid_amount' => 'float',
// 'insurer_paid_amount' => 'float'
// 'insurer_paid_amount' => 'float',
'billed' => 'boolean'
];
protected $fillable = [
@ -43,6 +44,7 @@ class NhMedicalPrescription extends Model
'unit_price',
'insured_paid_amount',
'insurer_paid_amount',
'billed',
'created_at',
'updated_at'
];

View File

@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddBilledToNhMedicalPrescriptionsAndNhExams extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('nh_medical_prescriptions', function (Blueprint $table) {
$table->boolean('billed')->default(0)->after('insurer_paid_amount')
->comment("Pour savoir si cela a deja ete facturé dans une execution");
});
Schema::table('nh_exams', function (Blueprint $table) {
$table->boolean('billed')->default(0)->after('insurer_paid_amount')
->comment("Pour savoir si cela a deja ete facturé dans une execution");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('nh_medical_prescriptions', function (Blueprint $table) {
$table->dropColumn('billed');
});
Schema::table('nh_exams', function (Blueprint $table) {
$table->dropColumn('billed');
});
}
}

View File

@ -35,5 +35,7 @@ return [
'drug_device_already_exists' => "This drug / device code already exists",
"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"
"unauthorized" => "You are not authorized to perform this operation",
"prescription_already_invoiced" => "The prescription :id has already been invoiced",
"exam_already_invoiced" => "The exam:id has already been invoiced"
];

View File

@ -35,5 +35,7 @@ return [
'drug_device_already_exists' => "Ce code médicament / appareillage existe deja",
"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"
"unauthorized" => "Vous n'etes pas autorisé à effectuer cette operation",
"prescription_already_invoiced" => "La prescription :id a deja été facturée",
"exam_already_invoiced" => "L'examen :id a deja été facturé"
];