Improve health care sheet consultation and prescription to take in consideration act amount

This commit is contained in:
Djery-Tom 2022-04-04 18:29:52 +01:00
parent acf323e799
commit a642ee3dcc
6 changed files with 81 additions and 19 deletions

10
app/ActBillingType.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace App;
abstract class ActBillingType
{
const UNIT_PRICE = 'UNIT_PRICE';
const PACKAGE = 'PACKAGE';
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\ActBillingType;
use App\Events\InsuredConsultation;
use App\Exceptions\AppException;
use App\HealthCareSheetType;
@ -610,7 +611,7 @@ class HealthCareSheetController extends Controller
'pregnancy_end_at' => 'nullable|date_format:Y-m-d|after:pregnancy_start_at',
'performances' => 'required|array',
'performances.*.act_id' => 'required|integer|exists:nh_acts,id',
'performances.*.amount' => 'required|numeric',
'performances.*.amount' => 'nullable|numeric',
'performances.*.home_visit_fees' => 'nullable|numeric',
'prescriptions' => 'nullable|array',
'prescriptions.*.drug_or_device_id' => 'required|integer|exists:nh_drugs_and_devices,id',
@ -622,6 +623,7 @@ class HealthCareSheetController extends Controller
'exams.*.quantity' => 'required|integer',
]);
$performances = $request->input('performances', []);
$insurance = NhInsurance::where('insured_id', $request->input('insured_id'))->whereIn('state', [InsuranceState::PAID, InsuranceState::PARTIALLY_PAID])->first();
if (!isset($insurance)) {
return $this->errorResponse(trans('errors.not_insured'));
@ -644,6 +646,22 @@ class HealthCareSheetController extends Controller
return $this->errorResponse(trans('errors.nano_health_not_activated'));
}
// Fetch performances amounts
foreach ($performances as $i => $p) {
$act = NhAct::find($p['act_id']);
if ($act->billing_type == ActBillingType::UNIT_PRICE && empty($p['quantity'])) {
return $this->errorResponse(trans('errors.act_quantity_required', ['act_name' => $act->name]));
}
if (empty($act->amount)) {
if (empty($p['amount'])) {
return $this->errorResponse(trans('errors.act_amount_required', ['act_name' => $act->name]));
}
} else {
$performances[$i]['amount'] = $act->amount;
}
}
$parts = $this->getConfigInsuranceParts($nhConfig, $request->input('care_condition'));
$currency_code = $this->getNetworkCurrency($insurance->network_id);
@ -676,7 +694,7 @@ class HealthCareSheetController extends Controller
$healthCareSheet->created_at = $healthCareSheet->updated_at = $datetime;
$healthCareSheet->save();
foreach ($request->input('performances', []) as $p) {
foreach ($performances as $p) {
$fees = !empty($p['home_visit_fees']) ? $p['home_visit_fees'] : 0;
$performance = NhPerformance::create([
'act_id' => $p['act_id'],
@ -762,20 +780,32 @@ class HealthCareSheetController extends Controller
}
private function useAuthorizationRequest($act_id, $insurance_id, $beneficiary_id, $sheet_id, $datetime): void
{
$authorization_request = NhAuthorizationOfCareRequest::where('act_id', $act_id)->where('insurance_id', $insurance_id);
if (empty($beneficiary_id)) {
$authorization_request = $authorization_request->whereNull('beneficiary_id');
} else {
$authorization_request = $authorization_request->where('beneficiary_id', $beneficiary_id);
$act = NhAct::find($act_id);
if (!isset($act)) {
throw new AppException(trans('errors.act_not_found'));
}
$authorization_query = NhAuthorizationOfCareRequest::where('act_id', $act_id)->where('insurance_id', $insurance_id)
->where('state', '!=', 'USED');
if (empty($beneficiary_id)) {
$authorization_query = $authorization_query->whereNull('beneficiary_id');
} else {
$authorization_query = $authorization_query->where('beneficiary_id', $beneficiary_id);
}
$authorization_request = $authorization_query->first();
if ($act->authorization_type == 'PRIOR') {
if (!isset($authorization_request)) {
throw new AppException(trans('errors.act_authorization_request_required', ['act_name' => $act->name]));
}
$authorization_request->update([
'state' => 'USED',
'health_care_sheet_id' => $sheet_id,
'updated_at' => $datetime
]);
}
$authorization_request->update([
'state' => 'USED',
'health_care_sheet_id' => $sheet_id,
'updated_at' => $datetime
]);
}
@ -890,7 +920,7 @@ class HealthCareSheetController extends Controller
'prescriptions.*.unit_price' => 'required|numeric',
'exams' => 'required_without:prescriptions|array',
'exams.*.id' => 'required|integer|exists:nh_exams,id',
'exams.*.unit_price' => 'required|numeric',
'exams.*.unit_price' => 'nullable|numeric',
]);
$prescriptions = $request->input('prescriptions', []);
@ -964,6 +994,7 @@ class HealthCareSheetController extends Controller
}
$itemIndex = array_search($i->id, $prescriptionsIds);
if ($i->billed) {
DB::rollback();
return $this->errorResponse(__('errors.prescription_already_invoiced', ['id' => $itemIndex + 1]));
}
$item->unit_price = $prescriptions[$itemIndex]['unit_price'];
@ -975,9 +1006,19 @@ class HealthCareSheetController extends Controller
}
$itemIndex = array_search($i->id, $examsIds);
if ($i->billed) {
DB::rollBack();
return $this->errorResponse(__('errors.exam_already_invoiced', ['id' => $itemIndex + 1]));
}
$item->unit_price = $exams[$itemIndex]['unit_price'];
// Fetch exam unit price
if (empty($i->act->amount)) {
if (empty($exams[$itemIndex]['unit_price'])) {
DB::rollBack();
return $this->errorResponse(trans('errors.act_unit_price_required', ['act_name' => $i->act->name]));
}
$item->unit_price = $exams[$itemIndex]['unit_price'];
} else {
$item->unit_price = $i->act->amount;
}
}
@ -1752,7 +1793,7 @@ class HealthCareSheetController extends Controller
// $sheet->patient_situation = 'HAVING_RIGHT';
// }
foreach ($request->input('performances', []) as $p) {
foreach ($performances as $p) {
if (!empty($p['to_delete'])) {
NhPerformance::find($p['id'])->delete();
NhHealthCareSheetsPerformance::where('sheet_id', $sheet->id)->where('performance_id', $p['id'])->delete();

View File

@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Model;
*
* @property int $id
* @property int $drug_or_device_id
* @property string $drug_or_device_name
* @property string $dosage
* @property int $quantity
* @property float $unit_price
@ -39,6 +40,7 @@ class NhMedicalPrescription extends Model
protected $fillable = [
'drug_or_device_id',
'drug_or_device_name',
'dosage',
'quantity',
'unit_price',

View File

@ -18,7 +18,8 @@ class AddAmountToNhActsAndUpdateNhInsurancesState extends Migration
DB::statement("alter table nh_insurances modify state enum ('PAID', 'UNDER_STOPPING',
'STOPPED', 'EXPIRED', 'UNDER_ACTIVATION', 'UNDER_RENEW','UNDER_ADDING_BENEFICIARY', 'PARTIALLY_PAID', 'SUSPENDED') default 'PAID' not null;");
$table->decimal('amount', 10)->nullable()->after('billing_type');
$table->string('unit_value')->nullable()->after('billing_type');
$table->decimal('amount', 10)->nullable()->after('unit_value');
});
}
@ -30,7 +31,7 @@ class AddAmountToNhActsAndUpdateNhInsurancesState extends Migration
public function down()
{
Schema::table('nh_acts', function (Blueprint $table) {
$table->dropColumn(['billing_type']);
$table->dropColumn(['amount', 'unit_value']);
});
}
}

View File

@ -37,7 +37,7 @@ return [
"care_sheet_already_been_processed" => "This care sheet has already been processed",
"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",
"exam_already_invoiced" => "The exam :id has already been invoiced",
"performance_not_belong_to_sheet" => "The service: id does not belong to the care sheet",
"exam_not_belong_to_sheet" => "The exam: id does not belong to the care sheet",
"prescription_not_belong_to_sheet" => "The prescription: id does not belong to the care sheet",
@ -63,4 +63,8 @@ return [
'network_not_found' => "The network does not exist",
'invoice_already_paid' => 'This invoice has already been paid',
'payment_deadline_reached' => 'The payment deadline has already passed',
'act_unit_price_required' => "The unit price is required for the act :act_name",
'act_amount_required' => "The amount is required for the act :act_name",
'act_quantity_required' => "The quantity is required for the act :act_name",
'act_authorization_request_required' => "An authorization is required to apply the act :act_name",
];

View File

@ -63,4 +63,8 @@ return [
'network_not_found' => "Le réseau n'existe pas",
'invoice_already_paid' => 'Cette facture a déjà été payée',
'payment_deadline_reached' => 'Le délai de paiement est déjà passé',
'act_unit_price_required' => "Le prix unitaire est requis pour l'acte :act_name",
'act_amount_required' => "Le montant est requis pour l'acte :act_name",
'act_quantity_required' => "La quantité est requise pour l'acte :act_name",
'act_authorization_request_required' => "Une autorisation est requise pour appliquer l'acte :act_name",
];