mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
199 lines
6.0 KiB
PHP
199 lines
6.0 KiB
PHP
<?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\Http\Controllers\Controller;
|
|
use Streamline\Models\SlitLampTestArea;
|
|
use Streamline\Models\SlitLampTestAreaValue;
|
|
|
|
class SlitLampTestAreaValueController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index() {
|
|
$test_area_values = SlitLampTestAreaValue::orderBy('name', 'asc')->get();
|
|
$test_areas = SlitLampTestArea::pluck('name', 'id')->toArray();
|
|
return view('clinical_data::test_area_values.index', compact('test_area_values', 'test_areas'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create() {
|
|
$test_areas = SlitLampTestArea::pluck('name', 'id')->prepend('-select-', '')->toArray();
|
|
return view('clinical_data::test_area_values.create', compact('test_areas'));
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
$test_area_value = new SlitLampTestAreaValue;
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
$test_area_value->name = $request->name;
|
|
$test_area_value->slit_lamp_test_area_id = $request->area;
|
|
$test_area_value->created_by = $logged_in_user_id;
|
|
$test_area_value->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$test_area_value->save();
|
|
flash($request->name . " Staff Position has been saved")->success();
|
|
return redirect("/test_area_values/");
|
|
} 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) {
|
|
$test_area_value = SlitLampTestAreaValue::where(['id' => $id])->first();
|
|
$test_areas = SlitLampTestArea::pluck('name', 'id')->toArray();
|
|
|
|
if (!$test_area_value) {
|
|
flash()->error("There is no such staff test_area_value");
|
|
return redirect('/test_area_values/');
|
|
} else {
|
|
return view('clinical_data::test_area_values.edit', compact('test_area_value', 'test_areas'));
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 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 {
|
|
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
//validation passed
|
|
$test_area_value = SlitLampTestAreaValue::find($id);
|
|
$test_area_value->name = $request->name;
|
|
$test_area_value->slit_lamp_test_area_id = $request->area;
|
|
$test_area_value->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
|
|
$test_area_value->save();
|
|
flash($request->name . " Staff Position has been updated")->success();
|
|
return redirect("/test_area_values/");
|
|
} 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) {
|
|
$test_area_value = SlitLampTestAreaValue::findOrFail($id);
|
|
|
|
if ($test_area_value->delete()):
|
|
flash("Staff Position has been deleted.")->success();
|
|
return redirect('/test_area_values/');
|
|
endif;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function inactive() {
|
|
$test_area_values = SlitLampTestAreaValue::onlyTrashed()
|
|
->orderBy('name', 'asc')
|
|
->paginate(50);
|
|
|
|
if (count($test_area_values) < 1) {
|
|
flash()->error("There is no inactive staff test_area_value");
|
|
return redirect('/test_area_values/');
|
|
} else {
|
|
return view('clinical_data::test_area_values.inactive', compact('test_area_values'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function activate($id) {
|
|
$test_area_value = SlitLampTestAreaValue::withTrashed()->findOrFail($id);
|
|
|
|
if ($test_area_value->restore()):
|
|
flash("Staff Position has been activated.")->success();
|
|
return redirect('/test_area_values/inactive');
|
|
endif;
|
|
}
|
|
}
|