mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
168 lines
4.4 KiB
PHP
Executable File
168 lines
4.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\ClinicalData\Http\Controllers;
|
|
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Http\Request;
|
|
use Streamline\Models\PackageUnit;
|
|
|
|
class PackageUnitController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$package_units = PackageUnit::orderBy('name', 'asc')->get();
|
|
|
|
return view('clinical_data::package_units.index', compact('package_units'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('clinical_data::package_units.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
request()->validate([
|
|
'name' => 'required'
|
|
]);
|
|
|
|
$logged_in_user_id = auth()->user()->id;
|
|
$package_unit = new PackageUnit;
|
|
|
|
$package_unit->name = $request->name;
|
|
$package_unit->created_by = $logged_in_user_id;
|
|
$package_unit->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$package_unit->save();
|
|
flash($request->name . " has been saved")->success();
|
|
return redirect("/package_unit/");
|
|
} 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(PackageUnit $package_unit)
|
|
{
|
|
if (!$package_unit) {
|
|
flash()->error("There is no such Unit of Measure");
|
|
return redirect('/package_unit/');
|
|
} else {
|
|
return view('clinical_data::package_units.edit', compact('package_unit'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
request()->validate([
|
|
'name' => 'required'
|
|
]);
|
|
|
|
$logged_in_user_id = auth()->user()->id;
|
|
$package_unit = PackageUnit::find($id);
|
|
|
|
$package_unit->name = $request->name;
|
|
$package_unit->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$package_unit->save();
|
|
flash($request->name . " has been updated")->success();
|
|
return redirect("/package_unit/");
|
|
} 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(PackageUnit $package_unit)
|
|
{
|
|
if ($package_unit->delete()):
|
|
flash($package_unit->name." has been deleted.")->success();
|
|
return redirect('/package_unit/');
|
|
endif;
|
|
|
|
flash('Unable to delete package unit')->error();
|
|
return redirect('package_unit');
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function inactive() {
|
|
$package_units = PackageUnit::onlyTrashed()
|
|
->orderBy('name', 'asc')
|
|
->get();
|
|
|
|
if (count($package_units) < 1) {
|
|
flash()->error("There is no inactive package unit");
|
|
return redirect('/package_unit/');
|
|
} else {
|
|
return view('clinical_data::package_units.inactive', compact('package_units'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function activate($id) {
|
|
$package_unit = PackageUnit::withTrashed()->find($id);
|
|
|
|
if ($package_unit->restore()):
|
|
flash("Unit has been activated.")->success();
|
|
return redirect('/package_unit_inactive');
|
|
endif;
|
|
}
|
|
}
|