mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
resolved conflicts
This commit is contained in:
+173
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\AgeGroup;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class AgeGroupController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:age-group-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:age-group-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:age-group-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:age-group-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$age_groups = AgeGroup::orderBy('name','asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::age_groups.index', compact('age_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('clinical_data::age_groups.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$age_group = new AgeGroup;
|
||||
|
||||
$age_group->name = $request->name;
|
||||
$age_group->age_type = $request->age_type;
|
||||
$age_group->from_age = $request->from_age;
|
||||
$age_group->to_age = $request->to_age;
|
||||
$age_group->created_by = $logged_in_user_id;
|
||||
$age_group->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$age_group->save();
|
||||
flash($request->name . " Age Group has been saved")->success();
|
||||
return redirect("/age_groups/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$age_group = AgeGroup::where(['id' => $id])->first();
|
||||
|
||||
if (!$age_group) {
|
||||
flash()->error("There is no such Age Group");
|
||||
return redirect('/age_groups/');
|
||||
} else {
|
||||
return view('clinical_data::age_groups.edit', compact('age_group'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$age_group = AgeGroup::find($id);
|
||||
|
||||
$age_group->name = $request->name;
|
||||
$age_group->age_type = $request->age_type;
|
||||
$age_group->from_age = $request->from_age;
|
||||
$age_group->to_age = $request->to_age;
|
||||
$age_group->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$age_group->save();
|
||||
flash($request->name . " Age Group has been updated")->success();
|
||||
return redirect("/age_groups/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$age_group = AgeGroup::find($id);
|
||||
|
||||
if ($age_group->delete()):
|
||||
flash("Age Group has been deleted.")->success();
|
||||
return redirect('/age_groups/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
*/
|
||||
public function inactive() {
|
||||
$age_groups = AgeGroup::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($age_groups) < 1) {
|
||||
flash()->error("There is no inactive age group");
|
||||
return redirect('/age_groups/');
|
||||
} else {
|
||||
return view('clinical_data::age_groups.inactive', compact('age_groups'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function activate($id) {
|
||||
$age_group= AgeGroup::withTrashed()->find($id);
|
||||
|
||||
if ($age_group->restore()):
|
||||
flash("Age Group has been activated.")->success();
|
||||
return redirect('/age_groups/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user