mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
201 lines
5.8 KiB
PHP
Executable File
201 lines
5.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\ClinicalData\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Streamline\Models\StaffPositions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Database\QueryException;
|
|
|
|
class StaffPositionsController extends Controller{
|
|
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
$this->middleware('permission:staff_positions-list', ['only' => ['index']]);
|
|
$this->middleware('permission:staff_positions-detail', ['only' => ['show']]);
|
|
$this->middleware('permission:staff_positions-create', ['only' => ['create', 'store']]);
|
|
$this->middleware('permission:staff_positions-edit', ['only' => ['edit', 'update']]);
|
|
$this->middleware('permission:staff_positions-delete', ['only' => ['destroy']]);
|
|
$this->middleware('permission:staff_positions-status', ['only' => ['activate, inactive']]);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index() {
|
|
$positions = StaffPositions::orderBy('name', 'asc')
|
|
->paginate(50);
|
|
return view('clinical_data::staff_positions.index', compact('positions'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create() {
|
|
return view('clinical_data::staff_positions.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request) {
|
|
$validator = Validator::make($request->all(), [
|
|
'name' => 'required'
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
//validation failed
|
|
$string = "";
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
return back()->withErrors($validator)->withInput();
|
|
} else {
|
|
|
|
//validation passed
|
|
$position = new StaffPositions;
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
$position->name = $request->name;
|
|
$position->created_by = $logged_in_user_id;
|
|
$position->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$position->save();
|
|
flash($request->name . " Staff Position has been saved")->success();
|
|
return redirect("/staff_positions/");
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
$position = StaffPositions::where(['id' => $id])->first();
|
|
|
|
if (!$position) {
|
|
flash()->error("There is no such staff position");
|
|
return redirect('/staff_positions/');
|
|
} else {
|
|
return view('clinical_data::staff_positions.edit', compact('position'));
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id) {
|
|
$validator = Validator::make($request->all(), [
|
|
'name' => 'required'
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
//validation failed
|
|
|
|
$string = "";
|
|
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
|
|
// flash($string)->error();
|
|
|
|
return back()->withErrors($validator)->withInput();
|
|
} else {
|
|
//validation passed
|
|
$position = StaffPositions::find($id);
|
|
$position->name = $request->name;
|
|
|
|
try {
|
|
|
|
$position->save();
|
|
flash($request->name . " Staff Position has been updated")->success();
|
|
return redirect("/staff_positions/");
|
|
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id) {
|
|
$position = StaffPositions::find($id);
|
|
|
|
if ($position->delete()):
|
|
flash("Staff Position has been deleted.")->success();
|
|
return redirect('/staff_positions/');
|
|
endif;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function inactive() {
|
|
$positions = StaffPositions::onlyTrashed()
|
|
->orderBy('name', 'asc')
|
|
->paginate(50);
|
|
|
|
if (count($positions) < 1) {
|
|
flash()->error("There is no inactive staff position");
|
|
return redirect('/staff_positions/');
|
|
} else {
|
|
return view('clinical_data::staff_positions.inactive', compact('positions'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function activate($id) {
|
|
$position = StaffPositions::withTrashed()->find($id);
|
|
|
|
if ($position->restore()):
|
|
flash("Staff Position has been activated.")->success();
|
|
return redirect('/staff_positions/inactive');
|
|
endif;
|
|
}
|
|
}
|