mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
162 lines
4.9 KiB
PHP
Executable File
162 lines
4.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Investigations\Http\Controllers;
|
|
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Streamline\Models\LabInstrument;
|
|
|
|
class LabInstrumentsController extends Controller {
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
|
|
*/
|
|
public function index() {
|
|
$instruments = LabInstrument::get();
|
|
|
|
return view('investigations::lab_instruments.index', compact('instruments'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
|
|
*/
|
|
public function create() {
|
|
return view('investigations::lab_instruments.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
*/
|
|
public function store(Request $request) {
|
|
request()->validate([
|
|
'name' => 'required'
|
|
]);
|
|
|
|
$instrument = new LabInstrument();
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
$instrument->name = $request->name;
|
|
$instrument->created_by = $logged_in_user_id;
|
|
$instrument->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$instrument->save();
|
|
flash("Lab Instrument has been saved")->success();
|
|
return redirect("/lab_instruments/");
|
|
} catch (QueryException $e) {
|
|
flash("Something went wrong. Please try again")->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\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
*/
|
|
public function edit($id) {
|
|
$instrument = LabInstrument::where(['id' => $id])->first();
|
|
|
|
if (!$instrument) {
|
|
flash()->error("Lab Instrument not found");
|
|
return redirect('/lab_instruments/');
|
|
} else {
|
|
return view('investigations::lab_instruments.edit', compact('instrument'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
*/
|
|
public function update(Request $request, $id) {
|
|
request()->validate([
|
|
'name' => 'required',
|
|
]);
|
|
|
|
//validation passed
|
|
$instrument = LabInstrument::find($id);
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
$instrument->name = $request->name;
|
|
$instrument->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$instrument->save();
|
|
flash("Lab Instrument has been updated")->success();
|
|
return redirect("/lab_instruments/");
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
*/
|
|
public function destroy($id) {
|
|
$instrument = LabInstrument::find($id);
|
|
|
|
if ($instrument->delete()) {
|
|
flash("Lab Instrument has been deleted.")->success();
|
|
return redirect('/lab_instruments/');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
|
|
*/
|
|
public function inactive() {
|
|
$instruments = LabInstrument::onlyTrashed()->get();
|
|
|
|
if (count($instruments) < 1) {
|
|
flash()->error("There is no inactive Lab Instrument");
|
|
return redirect('/lab_instruments/');
|
|
} else {
|
|
return view('investigations::lab_instruments.inactive', compact('instruments'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
*/
|
|
public function activate($id) {
|
|
$instrument = LabInstrument::withTrashed()->find($id);
|
|
|
|
if($instrument->restore()){
|
|
flash("Lab Instrument has been activated.")->success();
|
|
return redirect('/lab_instruments/inactive');
|
|
}
|
|
}
|
|
}
|