mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
166 lines
4.6 KiB
PHP
166 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\ClinicalData\Http\Controllers;
|
|
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Streamline\Http\Controllers\Controller;
|
|
use Streamline\Models\DrugRoute;
|
|
|
|
class DrugRouteController extends Controller {
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
$this->middleware('permission:drug-route-list', ['only' => ['index']]);
|
|
$this->middleware('permission:drug-route-create', ['only' => ['create', 'store']]);
|
|
$this->middleware('permission:drug-route-edit', ['only' => ['edit', 'update']]);
|
|
$this->middleware('permission:drug-route-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
|
}
|
|
|
|
/**create
|
|
* Display a listing of the resource.
|
|
*
|
|
*/
|
|
public function index() {
|
|
$drug_routes = DrugRoute::orderBy('name', 'asc')
|
|
->paginate(50);
|
|
|
|
return view('clinical_data::drug_routes.index', compact('drug_routes'));
|
|
}
|
|
|
|
/**
|
|
* Show the route for creating a new resource.
|
|
*
|
|
*/
|
|
public function create() {
|
|
return view('clinical_data::drug_routes.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
*/
|
|
public function store(Request $request) {
|
|
request()->validate([
|
|
'name' => 'required'
|
|
]);
|
|
|
|
$logged_in_user_id = Auth::user()->id;
|
|
$drug_route = new DrugRoute;
|
|
|
|
$drug_route->name = $request->name;
|
|
$drug_route->created_by = $logged_in_user_id;
|
|
$drug_route->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$drug_route->save();
|
|
flash($request->name . " drug route has been saved")->success();
|
|
return redirect("/drug_routes/");
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
*/
|
|
public function show($id) {
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the route for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
*/
|
|
public function edit($id) {
|
|
$drug_route = DrugRoute::where(['id' => $id])->first();
|
|
|
|
if (!$drug_route) {
|
|
flash()->error("Drug route not found");
|
|
return redirect('/drug_routes/');
|
|
} else {
|
|
return view('clinical_data::drug_routes.edit', compact('drug_route'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
*/
|
|
public function update(Request $request, $id) {
|
|
request()->validate([
|
|
'name' => 'required'
|
|
]);
|
|
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
$drug_route = DrugRoute::find($id);
|
|
$drug_route->name = $request->name;
|
|
$drug_route->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$drug_route->save();
|
|
flash($request->name . " Drug route has been updated")->success();
|
|
return redirect("/drug_routes/");
|
|
} 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) {
|
|
$drug_route = DrugRoute::find($id);
|
|
|
|
if ($drug_route->delete()){
|
|
flash("route has been deleted.")->success();
|
|
return redirect('/drug_routes/');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function inactive() {
|
|
$drug_routes = DrugRoute::onlyTrashed()
|
|
->orderBy('name', 'asc')
|
|
->paginate(50);
|
|
|
|
if (count($drug_routes) < 1) {
|
|
flash()->error("There is no inactive routes");
|
|
return redirect('/drug_routes/');
|
|
} else {
|
|
return view('clinical_data::drug_routes.inactive', compact('drug_routes'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function activate($id) {
|
|
$drug_route = DrugRoute::withTrashed()->find($id);
|
|
|
|
if ($drug_route->restore()){
|
|
flash("route has been activated.")->success();
|
|
return redirect('/drug_routes/');
|
|
}
|
|
}
|
|
}
|