mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
191 lines
5.5 KiB
PHP
Executable File
191 lines
5.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\ClinicalData\Http\Controllers;
|
|
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Streamline\Models\Speciality;
|
|
|
|
class SpecialityController extends Controller
|
|
{
|
|
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
$this->middleware('permission:specialty-list', ['only' => ['index']]);
|
|
$this->middleware('permission:specialty-create', ['only' => ['create', 'store']]);
|
|
$this->middleware('permission:specialty-edit', ['only' => ['edit', 'update']]);
|
|
$this->middleware('permission:specialty-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index() {
|
|
$specialities = Speciality::orderBy('name', 'asc')
|
|
->paginate(50);
|
|
|
|
return view('clinical_data::specialities.index', compact('specialities'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create() {
|
|
return view('clinical_data::specialities.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()) {
|
|
$string = "";
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
return back()->withErrors($validator)->withInput();
|
|
} else {
|
|
$logged_in_user_id = Auth::user()->id;
|
|
$speciality = new Speciality;
|
|
|
|
$speciality->name = $request->name;
|
|
$speciality->created_by = $logged_in_user_id;
|
|
$speciality->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$speciality->save();
|
|
flash($request->name . " Speciality has been saved")->success();
|
|
return redirect("/specialities/");
|
|
} 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) {
|
|
$speciality = Speciality::where(['id' => $id])->first();
|
|
|
|
if (!$speciality) {
|
|
flash()->error("There is no such speciality");
|
|
return redirect('/specialities/');
|
|
} else {
|
|
return view('clinical_data::specialities.edit', compact('speciality'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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()) {
|
|
$string = "";
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
return back()->withErrors($validator)->withInput();
|
|
} else {
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
$speciality = Speciality::find($id);
|
|
$speciality->name = $request->name;
|
|
$speciality->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$speciality->save();
|
|
flash($request->name . " Speciality has been updated")->success();
|
|
return redirect("/specialities/");
|
|
} 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) {
|
|
$speciality = Speciality::find($id);
|
|
|
|
if ($speciality->delete()):
|
|
flash("Speciality has been deleted.")->success();
|
|
return redirect('/specialities/');
|
|
endif;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function inactive() {
|
|
|
|
$specialities = Speciality::onlyTrashed()
|
|
->orderBy('name', 'asc')
|
|
->paginate(50);
|
|
|
|
if (empty($specialities)) {
|
|
flash()->error("There is no inactive Speciality");
|
|
return redirect('/specialities/');
|
|
} else {
|
|
return view('clinical_data::specialities.inactive', compact('specialities'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function activate($id) {
|
|
$speciality = Speciality::withTrashed()->find($id);
|
|
|
|
if ($speciality->restore()):
|
|
flash("Supplier has been activated.")->success();
|
|
return redirect('/specialities/inactive');
|
|
endif;
|
|
}
|
|
}
|