mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
175 lines
5.4 KiB
PHP
Executable File
175 lines
5.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Investigations\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Streamline\Models\LaboratorySpecimen;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class LaboratorySpecimenController extends Controller
|
|
{
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
$this->middleware('permission:lab_specimen-list', ['only' => ['index']]);
|
|
$this->middleware('permission:lab_specimen-detail', ['only' => ['show']]);
|
|
$this->middleware('permission:lab_specimen-create', ['only' => ['create', 'store']]);
|
|
$this->middleware('permission:lab_specimen-edit', ['only' => ['edit', 'update']]);
|
|
$this->middleware('permission:lab_specimen-delete', ['only' => ['destroy']]);
|
|
$this->middleware('permission:lab_specimen-status', ['only' => ['activate, inactive']]);
|
|
}
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$lab_specimens = LaboratorySpecimen::orderBy('name', 'asc')->paginate(50);
|
|
|
|
return view('investigations::laboratory_specimen.index',compact('lab_specimens'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('investigations::laboratory_specimen.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|unique:laboratory_specimens'
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
$string = "";
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
return back()->withErrors($validator)->withInput();
|
|
} else {
|
|
$specimen = new LaboratorySpecimen;
|
|
$specimen->name = $request->name;
|
|
$specimen->save();
|
|
|
|
if (isset($request->other_specimen_names)) {
|
|
$other_specimens_array = $request->other_specimen_names;
|
|
|
|
for ($i=0; $i < count($other_specimens_array) ; $i++) {
|
|
if (!is_null($other_specimens_array[$i]) && $other_specimens_array[$i] != "") {
|
|
$lab_specimen = new LaboratorySpecimen;
|
|
$lab_specimen->name = $other_specimens_array[$i];
|
|
$lab_specimen->created_by = auth()->user()->id;
|
|
$lab_specimen->updated_by = auth()->user()->id;
|
|
$lab_specimen->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
flash('New specimen added successfully')->success();
|
|
return redirect('laboratory_specimen');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
$lab_specimen = LaboratorySpecimen::find($id);
|
|
|
|
if (!$lab_specimen) {
|
|
flash()->error("There is no such specimen");
|
|
return redirect('laboratory_specimen');
|
|
} else {
|
|
return view('investigations::laboratory_specimen.edit', compact('lab_specimen'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$lab_specimen = LaboratorySpecimen::find($id);
|
|
$lab_specimen->name = $request->name;
|
|
$lab_specimen->update();
|
|
|
|
flash('successfully updated details for '.$lab_specimen->name)->success();
|
|
return redirect('laboratory_specimen');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$lab_specimen = LaboratorySpecimen::find($id);
|
|
if ($lab_specimen->delete()) {
|
|
flash($lab_specimen->name. ' has been successfully deleted')->success();
|
|
return redirect('laboratory_specimen');
|
|
}
|
|
flash('error occurred. Contact system admin')->error();
|
|
return redirect()->back()->withInput();
|
|
}
|
|
|
|
/*
|
|
*Display inactive bed categories
|
|
*/
|
|
public function inactive()
|
|
{
|
|
$lab_specimens = LaboratorySpecimen::onlyTrashed()->orderBy('name','asc')->paginate(50);
|
|
|
|
if (count($lab_specimens) < 1) {
|
|
flash()->error("There is no inactive specimens");
|
|
return redirect('laboratory_specimen');
|
|
} else {
|
|
return view('investigations::laboratory_specimen.inactive', compact('lab_specimens'));
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Activate an inactive inpatient bed category
|
|
*/
|
|
public function activate($id)
|
|
{
|
|
$lab_specimens = LaboratorySpecimen::withTrashed()->find($id);
|
|
|
|
if ($lab_specimens->restore()):
|
|
flash("Specimen has been activated.")->success();
|
|
return redirect('/inactive/laboratory_specimen/');
|
|
endif;
|
|
}
|
|
}
|