mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-12 11:11:31 +00:00
283 lines
12 KiB
PHP
Executable File
283 lines
12 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Insurance\Http\Controllers;
|
|
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Redirector;
|
|
use Streamline\Models\InsuranceGroup;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Streamline\Models\HeadOfFamily;
|
|
|
|
class InsuranceGroupController extends Controller {
|
|
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
$this->middleware('permission:insurance-group-list');
|
|
$this->middleware('permission:insurance-group-create', ['only' => ['create', 'store']]);
|
|
$this->middleware('permission:insurance-group-edit', ['only' => ['edit', 'update']]);
|
|
$this->middleware('permission:insurance-group-delete', ['only' => ['destroy']]);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index() {
|
|
$insurance_groups = InsuranceGroup::orderBy('name', 'asc')->paginate(100);
|
|
$used_groups = DB::table('insurance_members')->whereNull('deleted_at')->distinct('group_id')->pluck('group_id')->toArray();
|
|
$insurance_groups_select = InsuranceGroup::orderBy('name', 'asc')->pluck('name', 'id')->prepend('- Select Group -', '');
|
|
|
|
return view('insurance::insurance_groups.index', compact('insurance_groups', 'used_groups', 'insurance_groups_select'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create() {
|
|
$countries = DB::table('countries')->whereNull('deleted_at')->pluck('name','id')->prepend('- Select country of origin - ', '');
|
|
$chi_risks = DB::table('community_health_insurance_risks')->whereNull('deleted_at')->pluck('name','id')->prepend('None', '0');
|
|
|
|
return view('insurance::insurance_groups.create', compact('countries', 'chi_risks'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request) {
|
|
request()->validate([
|
|
'name' => 'required',
|
|
'contact_name' => 'required',
|
|
'contact_number' => 'required'
|
|
]);
|
|
|
|
$logged_in_user_id = Auth::user()->id;
|
|
$insurance_group = new InsuranceGroup;
|
|
|
|
$insurance_group->name = $request->name;
|
|
$insurance_group->contact_name = $request->contact_name;
|
|
$insurance_group->contact_number = $request->contact_number;
|
|
$insurance_group->group_email = $request->group_email;
|
|
$insurance_group->country_id = $request->country_id;
|
|
$insurance_group->last_fees_billing_date = is_null($request->last_fees_billing_date) ? null : Carbon::createFromFormat('d-m-Y', $request->last_fees_billing_date)->toDateString();
|
|
$insurance_group->last_fees_payment_date = is_null($request->last_fees_payment_date) ? null : Carbon::createFromFormat('d-m-Y', $request->last_fees_payment_date)->toDateString();
|
|
$insurance_group->risk_ids = is_null($request->risk_id) ? null : implode(",", $request->risk_id);
|
|
$insurance_group->created_by = $logged_in_user_id;
|
|
$insurance_group->updated_by = $logged_in_user_id;
|
|
|
|
|
|
if ($insurance_group->save()):
|
|
flash($request->name . " Insurance Group has been saved")->success();
|
|
return redirect("/insurance_groups/");
|
|
else:
|
|
flash("There was an error")->error();
|
|
endif;
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id) {
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id) {
|
|
$insurance_group = InsuranceGroup::where(['id' => $id])->first();
|
|
|
|
if (!$insurance_group) {
|
|
flash()->error("There is no such insurance group");
|
|
return redirect('/insurance_groups/');
|
|
} else {
|
|
$countries = DB::table('countries')->pluck('name','id')->prepend('- Select country of origin - ', '');
|
|
$chi_risks = DB::table('community_health_insurance_risks')->whereNull('deleted_at')->pluck('name','id')->prepend('None', '0');
|
|
return view('insurance::insurance_groups.edit', compact('insurance_group', 'countries', 'chi_risks'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param Request $request
|
|
* @param int $id
|
|
* @return Application|\Illuminate\Foundation\Application|RedirectResponse|Redirector|void
|
|
*/
|
|
public function update(Request $request, $id) {
|
|
request()->validate([
|
|
'name' => 'required',
|
|
'contact_name' => 'required',
|
|
'contact_number' => 'required'
|
|
]);
|
|
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
$insurance_group = InsuranceGroup::find($id);
|
|
$insurance_group->name = $request->name;
|
|
$insurance_group->contact_name = $request->contact_name;
|
|
$insurance_group->contact_number = $request->contact_number;
|
|
$insurance_group->group_email = $request->group_email;
|
|
$insurance_group->country_id = $request->country_id;
|
|
$insurance_group->last_fees_billing_date = Carbon::createFromFormat('d-m-Y', $request->last_fees_billing_date)->toDateString();
|
|
$insurance_group->last_fees_payment_date = Carbon::createFromFormat('d-m-Y', $request->last_fees_payment_date)->toDateString();
|
|
$insurance_group->risk_ids = is_null($request->risk_id) ? null : implode(",", $request->risk_id);
|
|
$insurance_group->updated_by = $logged_in_user_id;
|
|
|
|
if ($insurance_group->save()):
|
|
flash($request->name . " Insurance Group has been updated")->success();
|
|
return redirect("/insurance_groups/");
|
|
else:
|
|
flash("There was an error")->error();
|
|
endif;
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
*/
|
|
public function destroy($id) {
|
|
$insurance_group = InsuranceGroup::find($id);
|
|
|
|
if ($insurance_group->delete()):
|
|
flash("Insurance Group has been deleted.")->success();
|
|
return redirect('/insurance_groups/');
|
|
endif;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
*/
|
|
public function inactive() {
|
|
$insurance_groups = InsuranceGroup::onlyTrashed()
|
|
->orderBy('name', 'asc')
|
|
->paginate(50);
|
|
|
|
if (count($insurance_groups) < 1) {
|
|
flash()->error("There is no inactive insurance group");
|
|
return redirect('/insurance_groups/');
|
|
} else {
|
|
return view('insurance::insurance_groups.inactive', compact('insurance_groups'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return Application|\Illuminate\Foundation\Application|Redirector|RedirectResponse|void
|
|
*/
|
|
public function activate($id) {
|
|
$insurance_group = InsuranceGroup::withTrashed()->find($id);
|
|
|
|
if ($insurance_group->restore()):
|
|
flash("Insurance group has been activated.")->success();
|
|
return redirect('/insurance_groups/');
|
|
endif;
|
|
}
|
|
|
|
public function insurance_group_details($id) {
|
|
|
|
$insurance_members = DB::table('insurance_members')
|
|
->where('insurance_members.group_id', $id)
|
|
->join('insurance_heads_of_family', 'insurance_members.family_id', '=', 'insurance_heads_of_family.id')
|
|
->join('patients', 'insurance_members.patient_id', '=', 'patients.id')
|
|
->select('patients.first_name', 'patients.last_name', 'patients.id', 'patients.number', 'insurance_heads_of_family.name')
|
|
->orderByDesc('insurance_members.family_id')
|
|
->get();
|
|
|
|
$members_count = DB::table('insurance_members')->where('group_id', $id)->count();
|
|
|
|
$result = DB::table('insurance_groups')->select('name')->where('id', $id)->first();
|
|
$group_name = $result->name;
|
|
|
|
// get group subscription status
|
|
$insurance_subscriptions_details = explode("/", check_insurance_group_status($id));
|
|
|
|
$start_date = $insurance_subscriptions_details[1];
|
|
$end_date = $insurance_subscriptions_details[2];
|
|
|
|
if ($insurance_subscriptions_details[0] == 1) {
|
|
$insurance_status = 'Active';
|
|
} else {
|
|
$insurance_status = 'Inactive';
|
|
}
|
|
|
|
return view('insurance::insurance_groups.insurance_group_details', compact('insurance_members', 'members_count', 'group_name', 'start_date', 'end_date', 'insurance_status', 'id'));
|
|
}
|
|
|
|
public function get_families_of_group($group_id)
|
|
{
|
|
$group_details = InsuranceGroup::find($group_id);
|
|
$attached_families = HeadOfFamily::where('group_id', $group_id)->get();
|
|
$code = '';
|
|
$code .= '<table class="table success-table table-sm">';
|
|
$counter = 0;
|
|
|
|
$family_members_to_exclude_array = [];
|
|
$all_member_ids_to_exclude = session()->has("member_ids_to_exclude") ? session()->get("member_ids_to_exclude") : [];
|
|
$all_family_ids_to_exclude = session()->has("family_ids_to_exclude") ? session()->get("family_ids_to_exclude") : [];
|
|
|
|
if (count($attached_families) > 0) {
|
|
$code .= '<tbody>';
|
|
$code .= '<tr><th><strong>Family head</strong></th><th><strong>Members with their premiums</strong></th></tr>';
|
|
foreach ($attached_families as $family) {
|
|
if (!in_array( $family->id, $all_family_ids_to_exclude)) {
|
|
$counter++;
|
|
$family_head_name = $family->name;
|
|
$family_members_array = explode(",", $family->family_members_ids);
|
|
$family_premiums_array = explode(",", $family->family_member_premiums);
|
|
|
|
$code .= '<tr>';
|
|
$code .= '<td><span style="color:blue; font-weight: 300">'. $counter.'. '.$family_head_name.'</span><a href="/remove_family_from_group_premium/'.$family->id.'" onclick="return confirm(\'Are you sure?\')" style="color: red"><br>Exclude this family</a></td>';
|
|
$code .= '<td>';
|
|
for ($i=0; $i < count($family_members_array); $i++) {
|
|
if (!in_array($family_members_array[$i], $all_member_ids_to_exclude)) {
|
|
$member = insurance_flag(get_name($family_members_array[$i], "id", "patient_id", "insurance_members"));
|
|
$code .= '- '.$member.' ('.ugandan_shillings($family_premiums_array[$i]).') <a href="/remove_member_from_group_premium/'.$family->id.'/'.$family_members_array[$i].'" onclick="return confirm(\'Are you sure?\')" style="color: #bf5656">Exclude member</a><br><br>';
|
|
} else{
|
|
$family_members_to_exclude_array[] = $family_members_array[$i];
|
|
}
|
|
}
|
|
$code .= '</td>';
|
|
$code .= '</tr>';
|
|
}
|
|
}
|
|
$code .= '</tbody>';
|
|
}
|
|
|
|
$code .= '</table>';
|
|
|
|
return $code;
|
|
}
|
|
|
|
public function searchByGroup(Request $request): RedirectResponse
|
|
{
|
|
if (is_numeric($request->group_id)) {
|
|
return redirect('/insurance_groups/insurance_group_details/' . $request->group_id);
|
|
} else {
|
|
flash()->error("Invalid group id");
|
|
return redirect('insurance_groups');
|
|
}
|
|
}
|
|
|
|
}
|