Improve execution of health care sheet
This commit is contained in:
parent
a69b3253dc
commit
c689b89cb0
|
@ -839,6 +839,10 @@ class HealthCareSheetController extends Controller
|
||||||
if (!in_array($i->id, $prescriptionsIds)) {
|
if (!in_array($i->id, $prescriptionsIds)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($i->billed) {
|
||||||
|
return $this->errorResponse(__('errors.prescription_already_invoiced', ['id' => array_search($i->id, $prescriptionsIds) + 1]));
|
||||||
|
}
|
||||||
|
|
||||||
$itemId = $i->id;
|
$itemId = $i->id;
|
||||||
$item->unit_price = array_filter($prescriptions, function ($r) use ($itemId) {
|
$item->unit_price = array_filter($prescriptions, function ($r) use ($itemId) {
|
||||||
return $r['id'] == $itemId;
|
return $r['id'] == $itemId;
|
||||||
|
@ -850,6 +854,9 @@ class HealthCareSheetController extends Controller
|
||||||
if (!in_array($i->id, $examsIds)) {
|
if (!in_array($i->id, $examsIds)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($i->billed) {
|
||||||
|
return $this->errorResponse(__('errors.exam_already_invoiced', ['id' => array_search($i->id, $examsIds) + 1]));
|
||||||
|
}
|
||||||
$itemId = $i->id;
|
$itemId = $i->id;
|
||||||
$item->unit_price = array_filter($exams, function ($r) use ($itemId) {
|
$item->unit_price = array_filter($exams, function ($r) use ($itemId) {
|
||||||
return $r['id'] == $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->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->insurer_paid_amount = $parts->insurer_part * $item->unit_price * ($item->quantity ?? 1);
|
||||||
$item->created_at = $item->updated_at = $datetime;
|
$item->created_at = $item->updated_at = $datetime;
|
||||||
|
$item->billed = true;
|
||||||
$item->push();
|
$item->push();
|
||||||
|
|
||||||
|
$i->billed = true;
|
||||||
|
$i->save();
|
||||||
|
|
||||||
|
|
||||||
if ($relation == 'prescriptions') {
|
if ($relation == 'prescriptions') {
|
||||||
NhHealthCareSheetsPrescription::create([
|
NhHealthCareSheetsPrescription::create([
|
||||||
|
@ -884,12 +895,12 @@ class HealthCareSheetController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
#Clone pivots
|
#Clone pivots
|
||||||
$performances = NhHealthCareSheetsPerformance::where('sheet_id', $sheet->id)->get();
|
// $performances = NhHealthCareSheetsPerformance::where('sheet_id', $sheet->id)->get();
|
||||||
foreach ($performances as $pf) {
|
// foreach ($performances as $pf) {
|
||||||
$p = $pf->replicate();
|
// $p = $pf->replicate();
|
||||||
$p->sheet_id = $healthCareSheet->id;
|
// $p->sheet_id = $healthCareSheet->id;
|
||||||
$p->push();
|
// $p->push();
|
||||||
}
|
// }
|
||||||
|
|
||||||
NhHealthCareSheetsHistory::create([
|
NhHealthCareSheetsHistory::create([
|
||||||
'action' => 'ADD',
|
'action' => 'ADD',
|
||||||
|
@ -948,7 +959,7 @@ class HealthCareSheetController extends Controller
|
||||||
* description="Status des feuilles de soins",
|
* description="Status des feuilles de soins",
|
||||||
* @OA\Schema(
|
* @OA\Schema(
|
||||||
* type="string",
|
* type="string",
|
||||||
* enum = {"UNTREATED","TREATED","ACCEPTED"},
|
* enum = {"UNTREATED","TREATED","ACCEPTED","TO_BILL"},
|
||||||
* default = "UNTREATED"
|
* default = "UNTREATED"
|
||||||
* ),
|
* ),
|
||||||
* in="query",
|
* in="query",
|
||||||
|
@ -979,13 +990,22 @@ class HealthCareSheetController extends Controller
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'user_id' => 'required|integer|exists:users,id',
|
'user_id' => 'required|integer|exists:users,id',
|
||||||
'type' => 'nullable|in:CONSULTATION,EXECUTION',
|
'type' => 'nullable|in:CONSULTATION,EXECUTION',
|
||||||
'state' => 'nullable|in:UNTREATED,TREATED,ACCEPTED'
|
'state' => 'nullable|in:UNTREATED,TREATED,ACCEPTED,TO_BILL'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$type = $request->input('type');
|
$type = $request->input('type');
|
||||||
$state = $request->input('state');
|
$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'));
|
$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)) {
|
if (!empty($type)) {
|
||||||
$query = $query->where('type', $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) {
|
foreach ($sheets as $sheet) {
|
||||||
$this->formalizeHealthCareSheet($sheet);
|
$this->formalizeHealthCareSheet($sheet);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* @property float $unit_price
|
* @property float $unit_price
|
||||||
* @property float $insured_paid_amount
|
* @property float $insured_paid_amount
|
||||||
* @property float $insurer_paid_amount
|
* @property float $insurer_paid_amount
|
||||||
|
* @property int $billed
|
||||||
* @property Carbon $created_at
|
* @property Carbon $created_at
|
||||||
* @property Carbon $updated_at
|
* @property Carbon $updated_at
|
||||||
*
|
*
|
||||||
|
@ -31,9 +32,10 @@ class NhExam extends Model
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'act_id' => 'int',
|
'act_id' => 'int',
|
||||||
'quantity' => 'int',
|
'quantity' => 'int',
|
||||||
'unit_price' => 'float',
|
// 'unit_price' => 'float',
|
||||||
'insured_paid_amount' => 'float',
|
// 'insured_paid_amount' => 'float',
|
||||||
'insurer_paid_amount' => 'float'
|
// 'insurer_paid_amount' => 'float',
|
||||||
|
'billed' => 'boolean'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
@ -42,7 +44,8 @@ class NhExam extends Model
|
||||||
'quantity',
|
'quantity',
|
||||||
'unit_price',
|
'unit_price',
|
||||||
'insured_paid_amount',
|
'insured_paid_amount',
|
||||||
'insurer_paid_amount'
|
'insurer_paid_amount',
|
||||||
|
'billed'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function act()
|
public function act()
|
||||||
|
|
|
@ -33,7 +33,8 @@ class NhMedicalPrescription extends Model
|
||||||
'quantity' => 'int',
|
'quantity' => 'int',
|
||||||
// 'unit_price' => 'float',
|
// 'unit_price' => 'float',
|
||||||
// 'insured_paid_amount' => 'float',
|
// 'insured_paid_amount' => 'float',
|
||||||
// 'insurer_paid_amount' => 'float'
|
// 'insurer_paid_amount' => 'float',
|
||||||
|
'billed' => 'boolean'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
@ -43,6 +44,7 @@ class NhMedicalPrescription extends Model
|
||||||
'unit_price',
|
'unit_price',
|
||||||
'insured_paid_amount',
|
'insured_paid_amount',
|
||||||
'insurer_paid_amount',
|
'insurer_paid_amount',
|
||||||
|
'billed',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at'
|
||||||
];
|
];
|
||||||
|
|
|
@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,5 +35,7 @@ return [
|
||||||
'drug_device_already_exists' => "This drug / device code already exists",
|
'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",
|
"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"
|
||||||
];
|
];
|
||||||
|
|
|
@ -35,5 +35,7 @@ return [
|
||||||
'drug_device_already_exists' => "Ce code médicament / appareillage existe deja",
|
'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",
|
"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é"
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue