mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
680 lines
27 KiB
PHP
680 lines
27 KiB
PHP
<?php
|
|
|
|
namespace Modules\Insurance\Http\Controllers;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Streamline\Models\CommunityHealthInsurancePlan;
|
|
use Streamline\Models\Drug;
|
|
use Streamline\Models\InpatientBedCategory;
|
|
use Streamline\Models\InsuranceBenefit;
|
|
use Streamline\Models\InsuranceBenefitItem;
|
|
use Streamline\Models\InsuranceInpatientAccommodationRates;
|
|
use Streamline\Models\Investigation;
|
|
use Streamline\Models\Procedure;
|
|
use Streamline\Models\Services;
|
|
use Streamline\Models\Sundry;
|
|
use Streamline\Models\Ward;
|
|
|
|
class InsuranceBenefitController extends Controller {
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
*/
|
|
public function index() {
|
|
$insurance_benefits = InsuranceBenefit::get();
|
|
$insurance_plans = CommunityHealthInsurancePlan::pluck('name', 'id')->toArray();
|
|
|
|
return view('insurance::insurance_benefits.index', compact('insurance_benefits', 'insurance_plans'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
*/
|
|
public function create() {
|
|
$insurance_plans = CommunityHealthInsurancePlan::pluck('name', 'id')->toArray();
|
|
$insurance_plans = ['' => '--select--'] + $insurance_plans;
|
|
|
|
$wards = Ward::where('available', 1)->pluck('name', 'id')->prepend('All Wards', '0');
|
|
|
|
return view('insurance::insurance_benefits.create', compact('insurance_plans', 'wards'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
*/
|
|
public function store(Request $request) {
|
|
request()->validate([
|
|
'name' => 'required',
|
|
'waiting_period' => 'required',
|
|
'annual_member_limit' => 'required',
|
|
'annual_family_limit' => 'required',
|
|
'fee' => 'required',
|
|
'plan_id' => 'required',
|
|
]);
|
|
|
|
//validation passed
|
|
$benefit = new InsuranceBenefit();
|
|
$benefit->name = $request->name;
|
|
$benefit->waiting_period = $request->waiting_period;
|
|
$benefit->plan_id = $request->plan_id;
|
|
$benefit->fee = $request->fee;
|
|
$benefit->annual_member_limit = $request->annual_member_limit;
|
|
$benefit->annual_family_limit = $request->annual_family_limit;
|
|
$benefit->opd_percentage = $request->opd_percentage ?? NULL;
|
|
$benefit->ipd_percentage = $request->ipd_percentage ?? NULL;
|
|
$benefit->wards = $request->ward_id ? implode(",", $request->ward_id) : "0";
|
|
$benefit->created_by = Auth::id();
|
|
|
|
try {
|
|
$benefit->save();
|
|
flash("Insurance Benefit has been created")->success();
|
|
return redirect("/insurance_benefits/");
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred. Please try again later")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
*/
|
|
public function show($id) {
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
*/
|
|
public function edit($id) {
|
|
$benefit = InsuranceBenefit::find($id);
|
|
|
|
$insurance_plans = CommunityHealthInsurancePlan::pluck('name', 'id')->toArray();
|
|
$insurance_plans = ['' => '--select--'] + $insurance_plans;
|
|
|
|
$wards = Ward::where('available', 1)->pluck('name', 'id')->prepend('All Wards', '0');
|
|
|
|
return view('insurance::insurance_benefits.edit', compact('benefit', 'insurance_plans', 'wards'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
*/
|
|
public function update(Request $request, $id) {
|
|
request()->validate([
|
|
'name' => 'required',
|
|
'waiting_period' => 'required',
|
|
'annual_member_limit' => 'required',
|
|
'annual_family_limit' => 'required',
|
|
'fee' => 'required',
|
|
'plan_id' => 'required',
|
|
]);
|
|
|
|
//validation passed
|
|
$benefit = InsuranceBenefit::find($id);
|
|
$benefit->name = $request->name;
|
|
$benefit->waiting_period = $request->waiting_period;
|
|
$benefit->plan_id = $request->plan_id;
|
|
$benefit->fee = $request->fee;
|
|
$benefit->annual_member_limit = $request->annual_member_limit;
|
|
$benefit->annual_family_limit = $request->annual_family_limit;
|
|
$benefit->opd_percentage = $request->opd_percentage ?? NULL;
|
|
$benefit->ipd_percentage = $request->ipd_percentage ?? NULL;
|
|
$benefit->wards = $request->ward_id ? implode(",", $request->ward_id) : "0";
|
|
$benefit->updated_by = Auth::id();
|
|
|
|
try {
|
|
$benefit->save();
|
|
flash("Insurance Benefit has been updated")->success();
|
|
return redirect("/insurance_benefits/");
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred. Please try again later")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
*/
|
|
public function destroy($id) {
|
|
$benefit = InsuranceBenefit::find($id);
|
|
|
|
try {
|
|
$benefit->delete();
|
|
|
|
// remove the benefit items as well
|
|
InsuranceBenefitItem::where('benefit_id', $id)->delete();
|
|
|
|
flash("Insurance Benefit has been deactivated")->success();
|
|
return redirect("/insurance_benefits/");
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred. Please try again later")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
*/
|
|
public function inactive() {
|
|
$insurance_benefits = InsuranceBenefit::onlyTrashed()->get();
|
|
|
|
$insurance_plans = CommunityHealthInsurancePlan::pluck('name', 'id')->toArray();
|
|
$insurance_plans = ['' => '--select--'] + $insurance_plans;
|
|
|
|
return view('insurance::insurance_benefits.inactive', compact('insurance_benefits', 'insurance_plans'));
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
*/
|
|
public function activate($id) {
|
|
$benefit = InsuranceBenefit::withTrashed()->find($id);
|
|
|
|
try {
|
|
$benefit->restore();
|
|
|
|
// restore the benefit items as well
|
|
InsuranceBenefitItem::where('benefit_id', $id)->restore();
|
|
|
|
flash("Insurance Benefit has been restored")->success();
|
|
return redirect("/insurance_benefits/");
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred. Please try again later")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
public function details($id) {
|
|
$benefit = InsuranceBenefit::find($id);
|
|
$drugs = DB::table('drugs')->pluck('name', 'id');
|
|
$procedures = DB::table('procedures')->pluck('name', 'id');
|
|
$services = DB::table('services')->pluck('name', 'id');
|
|
$investigations = DB::table('investigations')->pluck('name', 'id');
|
|
$sundries = DB::table('sundries')->pluck('name', 'id');
|
|
$bed_categories = DB::table('inpatient_bed_categories')->pluck('name', 'id');
|
|
$benefit_drugs = DB::table('insurance_benefit_items')->where('item_type', 4)
|
|
->where('benefit_id', $id)->get();
|
|
$benefit_sundries = DB::table('insurance_benefit_items')->where('item_type', 5)
|
|
->where('benefit_id', $id)->get();
|
|
$benefit_invs = DB::table('insurance_benefit_items')->where('item_type', 3)
|
|
->where('benefit_id', $id)->get();
|
|
$benefit_procedures = DB::table('insurance_benefit_items')->where('item_type', 2)
|
|
->where('benefit_id', $id)->get();
|
|
$benefit_services = DB::table('insurance_benefit_items')->where('item_type', 1)
|
|
->where('benefit_id', $id)->get();
|
|
$benefit_bed_categories = InsuranceInpatientAccommodationRates::where('benefit_id', $id)->limit(5)->get();
|
|
|
|
return view('insurance::insurance_benefits.details', compact('benefit', 'drugs', 'procedures', 'services', 'investigations',
|
|
'sundries', 'benefit_drugs', 'benefit_sundries', 'benefit_invs', 'benefit_procedures', 'benefit_services', 'benefit_bed_categories', 'bed_categories'));
|
|
}
|
|
|
|
public function add_items($id, $item_type, Request $request) {
|
|
$benefit = InsuranceBenefit::find($id);
|
|
$insurance_benefit_item = DB::table('insurance_benefit_items')->where('benefit_id', $id)
|
|
->where('item_type', $item_type)->first();
|
|
$exclude_ids = $insurance_benefit_item ? explode(",", $insurance_benefit_item->item_id) : [];
|
|
$selected_ids = $request->items_ids ?? [];
|
|
$table_name = "";
|
|
|
|
if ($item_type == 1) {
|
|
$table_name = 'services';
|
|
} elseif ($item_type == 2) {
|
|
$table_name = 'procedures';
|
|
} elseif ($item_type == 3) {
|
|
$table_name = 'investigations';
|
|
} elseif ($item_type == 4) {
|
|
$table_name = 'drugs';
|
|
} elseif ($item_type == 5) {
|
|
$table_name = 'sundries';
|
|
}
|
|
|
|
if ($table_name != "") {
|
|
$items = DB::table($table_name)->where('available', 1)->whereNotIn('id', $exclude_ids)->whereNull('deleted_at')->pluck('name', 'id');
|
|
|
|
if ($request->submit == "select_all_items") {
|
|
$selected_items = DB::table($table_name)->where('available', 1)->whereNotIn('id', $exclude_ids)->whereNull('deleted_at')->get(['name', 'id', 'non_insured_price']);
|
|
} else {
|
|
$selected_items = DB::table($table_name)->where('available', 1)->whereIn('id', $selected_ids)->whereNull('deleted_at')->get(['name', 'id', 'non_insured_price']);
|
|
}
|
|
} else {
|
|
$selected_items = [];
|
|
$items = [];
|
|
}
|
|
|
|
return view('insurance::insurance_benefits.add_items', compact('items', 'benefit', 'item_type', 'selected_items'));
|
|
}
|
|
|
|
public function save_items(Request $request) {
|
|
if (!is_array($request->item_id) || count($request->item_id) < 1) {
|
|
flash("Please select items before continuing")->error();
|
|
return back()->withInput();
|
|
}
|
|
|
|
$benefit_id = $request->benefit_id;
|
|
$item_type = $request->item_type;
|
|
$items = $request->item_id;
|
|
$co_payment = $request->co_payment;
|
|
$ipd_co_payment = $request->ipd_co_payment;
|
|
$capitation_fee = $request->capitation_fee;
|
|
$annual_member_limit = $request->annual_member_limit;
|
|
$annual_family_limit = $request->annual_family_limit;
|
|
$authorisation = $request->authorisation;
|
|
$apply_opd_percentage = $request->apply_opd_percentage ?? [];
|
|
$apply_ipd_percentage = $request->apply_ipd_percentage ?? [];
|
|
|
|
DB::beginTransaction();
|
|
|
|
// check if procedures for this benefit already exist
|
|
$insurance_benefit_item = DB::table('insurance_benefit_items')->where('benefit_id', $benefit_id)
|
|
->where('item_type', $item_type)->first();
|
|
|
|
if ($insurance_benefit_item) {
|
|
$insurance_benefit_item_arr = explode(",", $insurance_benefit_item->item_id);
|
|
$insurance_benefit_item_arr = array_merge($insurance_benefit_item_arr, $items);
|
|
|
|
$insurance_benefit_item = InsuranceBenefitItem::find($insurance_benefit_item->id);
|
|
$insurance_benefit_item->item_id = implode(",", $insurance_benefit_item_arr);
|
|
$insurance_benefit_item->updated_by = Auth::id();
|
|
} else {
|
|
$insurance_benefit_item = new InsuranceBenefitItem();
|
|
$insurance_benefit_item->plan_id = get_name($benefit_id, 'id', 'plan_id', 'insurance_benefits');
|
|
$insurance_benefit_item->benefit_id = $benefit_id;
|
|
$insurance_benefit_item->item_type = $item_type;
|
|
$insurance_benefit_item->item_id = implode(",", $items);
|
|
$insurance_benefit_item->created_by = Auth::id();
|
|
}
|
|
|
|
try {
|
|
$insurance_benefit_item->save();
|
|
} catch (\Exception $e) {
|
|
DB::rollback();
|
|
flash("An error occurred. Please try again or contact Stre@mline Support")->error();
|
|
return back()->withInput();
|
|
}
|
|
|
|
for ($i = 0; $i < count($items); $i++) {
|
|
switch ($item_type) {
|
|
case 1:
|
|
$item = Services::find($items[$i]);
|
|
break;
|
|
case 2:
|
|
$item = Procedure::find($items[$i]);
|
|
break;
|
|
case 3:
|
|
$item = Investigation::find($items[$i]);
|
|
break;
|
|
case 4:
|
|
$item = Drug::find($items[$i]);
|
|
break;
|
|
case 5:
|
|
$item = Sundry::find($items[$i]);
|
|
break;
|
|
default:
|
|
$item = false;
|
|
}
|
|
|
|
if ($item) {
|
|
$json_array = [$benefit_id => [
|
|
"co_payment" => $co_payment[$i],
|
|
"ipd_co_payment" => $ipd_co_payment[$i],
|
|
"capitation_fee" => $capitation_fee[$i],
|
|
"annual_member_limit" => $annual_member_limit[$i],
|
|
"annual_family_limit" => $annual_family_limit[$i],
|
|
"authorisation" => $authorisation[$i],
|
|
"apply_opd_percentage" => (in_array($items[$i], $apply_opd_percentage) ? 1 : 0),
|
|
"apply_ipd_percentage" => (in_array($items[$i], $apply_ipd_percentage) ? 1 : 0),
|
|
]];
|
|
|
|
$insurance_benefit_details = json_decode($item->insurance_benefit_details, true) ?? [];
|
|
$insurance_benefit_details = $insurance_benefit_details + $json_array;
|
|
|
|
$item->insurance_benefit_details = json_encode($insurance_benefit_details);
|
|
|
|
try {
|
|
$item->save();
|
|
} catch (\Exception $e) {
|
|
DB::rollback();
|
|
flash("An error occurred. Please try again or contact Stre@mline Support")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
}
|
|
|
|
DB::commit();
|
|
flash("Items have been added to the benefit")->success();
|
|
|
|
return redirect('/insurance_benefits/details/' . $benefit_id);
|
|
}
|
|
|
|
public function view_items($id, $item_type) {
|
|
$benefit = InsuranceBenefit::find($id);
|
|
|
|
switch ($item_type) {
|
|
case 1:
|
|
$items = DB::table('services')->pluck('name', 'id');
|
|
break;
|
|
case 2:
|
|
$items = DB::table('procedures')->pluck('name', 'id');
|
|
break;
|
|
case 3:
|
|
$items = DB::table('investigations')->pluck('name', 'id');
|
|
break;
|
|
case 4:
|
|
$items = DB::table('drugs')->pluck('name', 'id');
|
|
break;
|
|
case 5:
|
|
$items = DB::table('sundries')->pluck('name', 'id');
|
|
break;
|
|
default:
|
|
$items = [];
|
|
break;
|
|
}
|
|
|
|
$benefit_items = DB::table('insurance_benefit_items')->where('item_type', $item_type)
|
|
->where('benefit_id', $id)->get();
|
|
|
|
return view('insurance::insurance_benefits.view_items', compact('items', 'benefit_items', 'benefit', 'item_type'));
|
|
}
|
|
|
|
public function remove_item($item_id, $item_type, $benefit_id) {
|
|
switch ($item_type) {
|
|
case 1:
|
|
$item = Services::find($item_id);
|
|
break;
|
|
case 2:
|
|
$item = Procedure::find($item_id);
|
|
break;
|
|
case 3:
|
|
$item = Investigation::find($item_id);
|
|
break;
|
|
case 4:
|
|
$item = Drug::find($item_id);
|
|
break;
|
|
case 5:
|
|
$item = Sundry::find($item_id);
|
|
break;
|
|
default:
|
|
$item = false;
|
|
}
|
|
|
|
if ($item) {
|
|
$insurance_benefit_details = json_decode($item->insurance_benefit_details, true);
|
|
|
|
if (isset($insurance_benefit_details[$benefit_id])) {
|
|
unset($insurance_benefit_details[$benefit_id]);
|
|
|
|
$item->insurance_benefit_details = json_encode($insurance_benefit_details);
|
|
|
|
$benefit_items = DB::table('insurance_benefit_items')->where('item_type', $item_type)
|
|
->where('benefit_id', $benefit_id)->first();
|
|
$benefit_items_array = explode(",", $benefit_items->item_id);
|
|
$benefit_items_array = array_diff($benefit_items_array, [$item_id]);
|
|
|
|
$insurance_benefit_item = InsuranceBenefitItem::find($benefit_items->id);
|
|
$insurance_benefit_item->item_id = implode(",", $benefit_items_array);
|
|
$insurance_benefit_item->updated_by = Auth::id();
|
|
|
|
try {
|
|
$item->save();
|
|
$insurance_benefit_item->save();
|
|
|
|
// find any tariffs and remove them as well
|
|
DB::table('insurance_tariffs')->where('item_id', $item_id)
|
|
->where('item_type', $item_type)->where('benefit_id', $benefit_id)->update(['deleted_at' => Carbon::now()]);
|
|
|
|
flash("Item has been removed from the benefit")->success();
|
|
} catch (\Exception $e) {
|
|
flash("An error occurred. Please try again later")->error();
|
|
}
|
|
} else {
|
|
flash("An error occurred. Please try again later")->error();
|
|
}
|
|
} else {
|
|
flash("An error occurred. Please try again later")->error();
|
|
}
|
|
|
|
return redirect('/insurance_benefits/view_items/' . $benefit_id . '/' . $item_type);
|
|
}
|
|
|
|
public function edit_items($id, $item_type) {
|
|
$benefit = InsuranceBenefit::find($id);
|
|
|
|
switch ($item_type) {
|
|
case 1:
|
|
$items = DB::table('services')->pluck('name', 'id');
|
|
break;
|
|
case 2:
|
|
$items = DB::table('procedures')->pluck('name', 'id');
|
|
break;
|
|
case 3:
|
|
$items = DB::table('investigations')->pluck('name', 'id');
|
|
break;
|
|
case 4:
|
|
$items = DB::table('drugs')->pluck('name', 'id');
|
|
break;
|
|
case 5:
|
|
$items = DB::table('sundries')->where('available', 1)->pluck('name', 'id');
|
|
break;
|
|
default:
|
|
$items = [];
|
|
break;
|
|
}
|
|
|
|
$benefit_items = DB::table('insurance_benefit_items')->where('item_type', $item_type)
|
|
->where('benefit_id', $id)->get();
|
|
|
|
return view('insurance::insurance_benefits.edit_items', compact('items', 'benefit_items', 'benefit', 'item_type'));
|
|
}
|
|
|
|
public function update_items(Request $request) {
|
|
$benefit_id = $request->benefit_id;
|
|
$item_type = $request->item_type;
|
|
$items = $request->item_id;
|
|
$co_payment = $request->co_payment;
|
|
$ipd_co_payment = $request->ipd_co_payment;
|
|
$capitation_fee = $request->capitation_fee;
|
|
$annual_member_limit = $request->annual_member_limit;
|
|
$annual_family_limit = $request->annual_family_limit;
|
|
$authorisation = $request->authorisation;
|
|
$apply_opd_percentage = $request->apply_opd_percentage ?? [];
|
|
$apply_ipd_percentage = $request->apply_ipd_percentage ?? [];
|
|
|
|
DB::beginTransaction();
|
|
|
|
for ($i = 0; $i < count($items); $i++) {
|
|
switch ($item_type) {
|
|
case 1:
|
|
$item = Services::find($items[$i]);
|
|
break;
|
|
case 2:
|
|
$item = Procedure::find($items[$i]);
|
|
break;
|
|
case 3:
|
|
$item = Investigation::find($items[$i]);
|
|
break;
|
|
case 4:
|
|
$item = Drug::find($items[$i]);
|
|
break;
|
|
case 5:
|
|
$item = Sundry::find($items[$i]);
|
|
break;
|
|
default:
|
|
$item = false;
|
|
}
|
|
|
|
if ($item) {
|
|
$json_array = [
|
|
"ipd_co_payment" => $ipd_co_payment[$i],
|
|
"co_payment" => $co_payment[$i],
|
|
"capitation_fee" => $capitation_fee[$i],
|
|
"annual_member_limit" => $annual_member_limit[$i],
|
|
"annual_family_limit" => $annual_family_limit[$i],
|
|
"authorisation" => $authorisation[$i],
|
|
"apply_opd_percentage" => (in_array($items[$i], $apply_opd_percentage) ? 1 : 0),
|
|
"apply_ipd_percentage" => (in_array($items[$i], $apply_ipd_percentage) ? 1 : 0),
|
|
];
|
|
|
|
$insurance_benefit_details = json_decode($item->insurance_benefit_details, true);
|
|
$insurance_benefit_details[$benefit_id] = $json_array;
|
|
$item->insurance_benefit_details = json_encode($insurance_benefit_details);
|
|
|
|
try {
|
|
$item->save();
|
|
} catch (\Exception $e) {
|
|
DB::rollback();
|
|
flash("An error occurred. Please try again or contact Stre@mline Support")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
}
|
|
|
|
DB::commit();
|
|
flash("Benefit items have been updated")->success();
|
|
|
|
return redirect('/insurance_benefits/details/' . $benefit_id);
|
|
}
|
|
|
|
public function add_inpatient_accommodation($id, Request $request) {
|
|
$bed_categories = InpatientBedCategory::pluck('name', 'id')->toArray();
|
|
$bed_categories = $bed_categories + ['' => '--select--'];
|
|
|
|
$benefit = InsuranceBenefit::find($id);
|
|
|
|
if ($request->bed_category) {
|
|
$selected_bed_category = InpatientBedCategory::find($request->bed_category);
|
|
} else {
|
|
$selected_bed_category = false;
|
|
}
|
|
|
|
return view('insurance::insurance_benefits.add_inpatient_accommodation', compact('bed_categories', 'benefit', 'id',
|
|
'selected_bed_category'));
|
|
}
|
|
|
|
public function save_inpatient_accommodation(Request $request) {
|
|
$accommodation = new InsuranceInpatientAccommodationRates();
|
|
|
|
$accommodation->bed_category_id = $request->bed_category_id;
|
|
$accommodation->benefit_id = $request->benefit_id;
|
|
$accommodation->plan_id = $request->plan_id;
|
|
$accommodation->cost_type = $request->cost_type;
|
|
|
|
$accommodation->cost_per_night = $request->cost_per_night;
|
|
$accommodation->chi_cost_per_night = $request->chi_cost_per_night;
|
|
$accommodation->cost_first_night = $request->cost_first_night;
|
|
$accommodation->chi_cost_first_night = $request->chi_cost_first_night;
|
|
$accommodation->cost_range = $request->cost_range;
|
|
$accommodation->chi_cost_range = $request->chi_cost_range;
|
|
$accommodation->cost_after = $request->cost_after;
|
|
$accommodation->chi_cost_after = $request->chi_cost_after;
|
|
|
|
$accommodation->annual_member_limit = $request->annual_member_limit;
|
|
$accommodation->annual_family_limit = $request->annual_family_limit;
|
|
$accommodation->gender = $request->gender;
|
|
$accommodation->age_limit = $request->age_limit_start . ',' . $request->age_limit_end;
|
|
$accommodation->age_type = $request->age_type;
|
|
$accommodation->authorisation_required = $request->authorisation;
|
|
$accommodation->created_by = Auth::id();
|
|
|
|
try {
|
|
$accommodation->save();
|
|
flash("Accommodation has been added to benefit")->success();
|
|
return redirect('/insurance_benefits/details/' . $request->benefit_id);
|
|
} catch (\Exception $e) {
|
|
flash("An error occurred. Please try again later")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
public function view_inpatient_accommodation($id) {
|
|
$bed_categories = DB::table('inpatient_bed_categories')->where('available', 1)->pluck('name', 'id');
|
|
$rates = InsuranceInpatientAccommodationRates::where('benefit_id', $id)->get();
|
|
$benefit = InsuranceBenefit::find($id);
|
|
|
|
return view('insurance::insurance_benefits.view_inpatient_accommodation', compact('bed_categories', 'rates', 'benefit'));
|
|
}
|
|
|
|
public function view_accommodation_details($id) {
|
|
$rate = InsuranceInpatientAccommodationRates::find($id);
|
|
|
|
if ($rate) {
|
|
$bed_category = InpatientBedCategory::find($rate->bed_category_id);
|
|
|
|
if ($bed_category) {
|
|
$benefit = InsuranceBenefit::find($rate->benefit_id);
|
|
|
|
return view('insurance::insurance_benefits.view_accommodation_details', compact('rate', 'bed_category', 'benefit'));
|
|
}
|
|
}
|
|
|
|
flash('An error occurred!')->error();
|
|
return redirect('/home');
|
|
}
|
|
|
|
public function edit_inpatient_accommodation($id) {
|
|
$rate = InsuranceInpatientAccommodationRates::find($id);
|
|
$bed_category = InpatientBedCategory::find($rate->bed_category_id);
|
|
$benefit = InsuranceBenefit::find($rate->benefit_id);
|
|
|
|
return view('insurance::insurance_benefits.edit_inpatient_accommodation', compact('rate', 'bed_category', 'benefit'));
|
|
}
|
|
|
|
public function update_inpatient_accommodation(Request $request) {
|
|
$accommodation = InsuranceInpatientAccommodationRates::find($request->rate_id);
|
|
|
|
$accommodation->cost_per_night = $request->cost_per_night;
|
|
$accommodation->chi_cost_per_night = $request->chi_cost_per_night;
|
|
$accommodation->cost_first_night = $request->cost_first_night;
|
|
$accommodation->chi_cost_first_night = $request->chi_cost_first_night;
|
|
$accommodation->cost_range = $request->cost_range;
|
|
$accommodation->chi_cost_range = $request->chi_cost_range;
|
|
$accommodation->cost_after = $request->cost_after;
|
|
$accommodation->chi_cost_after = $request->chi_cost_after;
|
|
|
|
$accommodation->annual_member_limit = $request->annual_member_limit;
|
|
$accommodation->annual_family_limit = $request->annual_family_limit;
|
|
$accommodation->gender = $request->gender;
|
|
$accommodation->age_limit = $request->age_limit_start . ',' . $request->age_limit_end;
|
|
$accommodation->age_type = $request->age_type;
|
|
$accommodation->authorisation_required = $request->authorisation;
|
|
$accommodation->updated_by = Auth::id();
|
|
|
|
try {
|
|
$accommodation->save();
|
|
flash("Accommodation has been updated")->success();
|
|
return redirect('/insurance_benefits/view_inpatient_accommodation/' . $request->benefit_id);
|
|
} catch (\Exception $e) {
|
|
flash("An error occurred. Please try again later")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
public function delete_inpatient_accommodation($id) {
|
|
$rate = InsuranceInpatientAccommodationRates::find($id);
|
|
|
|
try {
|
|
$benefit_id = $rate->benefit_id;
|
|
|
|
$rate->delete();
|
|
|
|
flash("Inpatient Accommodation has been deactivated")->success();
|
|
return redirect('/insurance_benefits/view_inpatient_accommodation/' . $benefit_id);
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred. Please try again later")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
}
|