Improve health care sheet consultation and prescription to take in consideration act amount
This commit is contained in:
parent
acf323e799
commit
a642ee3dcc
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
abstract class ActBillingType
|
||||||
|
{
|
||||||
|
const UNIT_PRICE = 'UNIT_PRICE';
|
||||||
|
const PACKAGE = 'PACKAGE';
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
use App\ActBillingType;
|
||||||
use App\Events\InsuredConsultation;
|
use App\Events\InsuredConsultation;
|
||||||
use App\Exceptions\AppException;
|
use App\Exceptions\AppException;
|
||||||
use App\HealthCareSheetType;
|
use App\HealthCareSheetType;
|
||||||
|
@ -610,7 +611,7 @@ class HealthCareSheetController extends Controller
|
||||||
'pregnancy_end_at' => 'nullable|date_format:Y-m-d|after:pregnancy_start_at',
|
'pregnancy_end_at' => 'nullable|date_format:Y-m-d|after:pregnancy_start_at',
|
||||||
'performances' => 'required|array',
|
'performances' => 'required|array',
|
||||||
'performances.*.act_id' => 'required|integer|exists:nh_acts,id',
|
'performances.*.act_id' => 'required|integer|exists:nh_acts,id',
|
||||||
'performances.*.amount' => 'required|numeric',
|
'performances.*.amount' => 'nullable|numeric',
|
||||||
'performances.*.home_visit_fees' => 'nullable|numeric',
|
'performances.*.home_visit_fees' => 'nullable|numeric',
|
||||||
'prescriptions' => 'nullable|array',
|
'prescriptions' => 'nullable|array',
|
||||||
'prescriptions.*.drug_or_device_id' => 'required|integer|exists:nh_drugs_and_devices,id',
|
'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',
|
'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();
|
$insurance = NhInsurance::where('insured_id', $request->input('insured_id'))->whereIn('state', [InsuranceState::PAID, InsuranceState::PARTIALLY_PAID])->first();
|
||||||
if (!isset($insurance)) {
|
if (!isset($insurance)) {
|
||||||
return $this->errorResponse(trans('errors.not_insured'));
|
return $this->errorResponse(trans('errors.not_insured'));
|
||||||
|
@ -644,6 +646,22 @@ class HealthCareSheetController extends Controller
|
||||||
return $this->errorResponse(trans('errors.nano_health_not_activated'));
|
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'));
|
$parts = $this->getConfigInsuranceParts($nhConfig, $request->input('care_condition'));
|
||||||
$currency_code = $this->getNetworkCurrency($insurance->network_id);
|
$currency_code = $this->getNetworkCurrency($insurance->network_id);
|
||||||
|
|
||||||
|
@ -676,7 +694,7 @@ class HealthCareSheetController extends Controller
|
||||||
$healthCareSheet->created_at = $healthCareSheet->updated_at = $datetime;
|
$healthCareSheet->created_at = $healthCareSheet->updated_at = $datetime;
|
||||||
$healthCareSheet->save();
|
$healthCareSheet->save();
|
||||||
|
|
||||||
foreach ($request->input('performances', []) as $p) {
|
foreach ($performances as $p) {
|
||||||
$fees = !empty($p['home_visit_fees']) ? $p['home_visit_fees'] : 0;
|
$fees = !empty($p['home_visit_fees']) ? $p['home_visit_fees'] : 0;
|
||||||
$performance = NhPerformance::create([
|
$performance = NhPerformance::create([
|
||||||
'act_id' => $p['act_id'],
|
'act_id' => $p['act_id'],
|
||||||
|
@ -762,21 +780,33 @@ class HealthCareSheetController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function useAuthorizationRequest($act_id, $insurance_id, $beneficiary_id, $sheet_id, $datetime): void
|
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);
|
$act = NhAct::find($act_id);
|
||||||
if (empty($beneficiary_id)) {
|
if (!isset($act)) {
|
||||||
$authorization_request = $authorization_request->whereNull('beneficiary_id');
|
throw new AppException(trans('errors.act_not_found'));
|
||||||
} else {
|
|
||||||
$authorization_request = $authorization_request->where('beneficiary_id', $beneficiary_id);
|
|
||||||
}
|
}
|
||||||
|
$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([
|
$authorization_request->update([
|
||||||
'state' => 'USED',
|
'state' => 'USED',
|
||||||
'health_care_sheet_id' => $sheet_id,
|
'health_care_sheet_id' => $sheet_id,
|
||||||
'updated_at' => $datetime
|
'updated_at' => $datetime
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -890,7 +920,7 @@ class HealthCareSheetController extends Controller
|
||||||
'prescriptions.*.unit_price' => 'required|numeric',
|
'prescriptions.*.unit_price' => 'required|numeric',
|
||||||
'exams' => 'required_without:prescriptions|array',
|
'exams' => 'required_without:prescriptions|array',
|
||||||
'exams.*.id' => 'required|integer|exists:nh_exams,id',
|
'exams.*.id' => 'required|integer|exists:nh_exams,id',
|
||||||
'exams.*.unit_price' => 'required|numeric',
|
'exams.*.unit_price' => 'nullable|numeric',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$prescriptions = $request->input('prescriptions', []);
|
$prescriptions = $request->input('prescriptions', []);
|
||||||
|
@ -964,6 +994,7 @@ class HealthCareSheetController extends Controller
|
||||||
}
|
}
|
||||||
$itemIndex = array_search($i->id, $prescriptionsIds);
|
$itemIndex = array_search($i->id, $prescriptionsIds);
|
||||||
if ($i->billed) {
|
if ($i->billed) {
|
||||||
|
DB::rollback();
|
||||||
return $this->errorResponse(__('errors.prescription_already_invoiced', ['id' => $itemIndex + 1]));
|
return $this->errorResponse(__('errors.prescription_already_invoiced', ['id' => $itemIndex + 1]));
|
||||||
}
|
}
|
||||||
$item->unit_price = $prescriptions[$itemIndex]['unit_price'];
|
$item->unit_price = $prescriptions[$itemIndex]['unit_price'];
|
||||||
|
@ -975,9 +1006,19 @@ class HealthCareSheetController extends Controller
|
||||||
}
|
}
|
||||||
$itemIndex = array_search($i->id, $examsIds);
|
$itemIndex = array_search($i->id, $examsIds);
|
||||||
if ($i->billed) {
|
if ($i->billed) {
|
||||||
|
DB::rollBack();
|
||||||
return $this->errorResponse(__('errors.exam_already_invoiced', ['id' => $itemIndex + 1]));
|
return $this->errorResponse(__('errors.exam_already_invoiced', ['id' => $itemIndex + 1]));
|
||||||
}
|
}
|
||||||
|
// 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'];
|
$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';
|
// $sheet->patient_situation = 'HAVING_RIGHT';
|
||||||
// }
|
// }
|
||||||
|
|
||||||
foreach ($request->input('performances', []) as $p) {
|
foreach ($performances as $p) {
|
||||||
if (!empty($p['to_delete'])) {
|
if (!empty($p['to_delete'])) {
|
||||||
NhPerformance::find($p['id'])->delete();
|
NhPerformance::find($p['id'])->delete();
|
||||||
NhHealthCareSheetsPerformance::where('sheet_id', $sheet->id)->where('performance_id', $p['id'])->delete();
|
NhHealthCareSheetsPerformance::where('sheet_id', $sheet->id)->where('performance_id', $p['id'])->delete();
|
||||||
|
|
|
@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
*
|
*
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property int $drug_or_device_id
|
* @property int $drug_or_device_id
|
||||||
|
* @property string $drug_or_device_name
|
||||||
* @property string $dosage
|
* @property string $dosage
|
||||||
* @property int $quantity
|
* @property int $quantity
|
||||||
* @property float $unit_price
|
* @property float $unit_price
|
||||||
|
@ -39,6 +40,7 @@ class NhMedicalPrescription extends Model
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'drug_or_device_id',
|
'drug_or_device_id',
|
||||||
|
'drug_or_device_name',
|
||||||
'dosage',
|
'dosage',
|
||||||
'quantity',
|
'quantity',
|
||||||
'unit_price',
|
'unit_price',
|
||||||
|
|
|
@ -18,7 +18,8 @@ class AddAmountToNhActsAndUpdateNhInsurancesState extends Migration
|
||||||
DB::statement("alter table nh_insurances modify state enum ('PAID', 'UNDER_STOPPING',
|
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;");
|
'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()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::table('nh_acts', function (Blueprint $table) {
|
Schema::table('nh_acts', function (Blueprint $table) {
|
||||||
$table->dropColumn(['billing_type']);
|
$table->dropColumn(['amount', 'unit_value']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,4 +63,8 @@ return [
|
||||||
'network_not_found' => "The network does not exist",
|
'network_not_found' => "The network does not exist",
|
||||||
'invoice_already_paid' => 'This invoice has already been paid',
|
'invoice_already_paid' => 'This invoice has already been paid',
|
||||||
'payment_deadline_reached' => 'The payment deadline has already passed',
|
'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",
|
||||||
];
|
];
|
||||||
|
|
|
@ -63,4 +63,8 @@ return [
|
||||||
'network_not_found' => "Le réseau n'existe pas",
|
'network_not_found' => "Le réseau n'existe pas",
|
||||||
'invoice_already_paid' => 'Cette facture a déjà été payée',
|
'invoice_already_paid' => 'Cette facture a déjà été payée',
|
||||||
'payment_deadline_reached' => 'Le délai de paiement est déjà passé',
|
'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",
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue