mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
196 lines
5.5 KiB
PHP
Executable File
196 lines
5.5 KiB
PHP
Executable File
<?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\Models\Parish;
|
|
use Streamline\Models\Subcounty;
|
|
|
|
class ParishController extends Controller {
|
|
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
$this->middleware('permission:parish-list', ['only' => ['index']]);
|
|
$this->middleware('permission:parish-create', ['only' => ['create', 'store']]);
|
|
$this->middleware('permission:parish-edit', ['only' => ['edit', 'update']]);
|
|
$this->middleware('permission:parish-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index() {
|
|
$parishes = Parish::orderBy('name', 'asc')->get();
|
|
|
|
$sub_counties = Subcounty::withTrashed()->pluck('name', 'id');
|
|
|
|
return view('clinical_data::parishes.index', compact('parishes', 'sub_counties'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create() {
|
|
$subcounties = Subcounty::all(['id', 'name', 'county_id'])->pluck("name_with_county", "id")->prepend('- select -', '')->toArray();
|
|
|
|
return view('clinical_data::parishes.create', compact('subcounties'));
|
|
}
|
|
|
|
/**
|
|
* 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',
|
|
'sub_county_id' => 'required'
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
$string = "";
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
flash($string)->error();
|
|
return back()->withErrors($validator)->withInput();
|
|
|
|
}
|
|
|
|
$user_id = Auth::user()->id;
|
|
$parish = new Parish;
|
|
|
|
$parish->name = $request->name;
|
|
$parish->subcounty_id = $request->sub_county_id;
|
|
$parish->created_by = $user_id;
|
|
$parish->updated_by = $user_id;
|
|
|
|
try {
|
|
$parish->save();
|
|
flash($request->name . " Parish has been saved")->success();
|
|
return redirect("/parishes/");
|
|
} 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) {
|
|
$parish = Parish::where(['id' => $id])->first();
|
|
|
|
$sub_counties = Subcounty::all(['id', 'name', 'county_id'])->pluck("name_with_county", "id")->prepend('- select -', '')->toArray();
|
|
|
|
if (!$parish) {
|
|
flash()->error("That parish is not registered");
|
|
return redirect('/parishes/');
|
|
} else {
|
|
return view('clinical_data::parishes.edit', compact('parish', 'sub_counties'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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',
|
|
'sub_county_id' => 'required'
|
|
]);
|
|
|
|
$parish = Parish::find($id);
|
|
|
|
$parish->name = $request->name;
|
|
$parish->subcounty_id = $request->sub_county_id;
|
|
$parish->updated_by = Auth::user()->id;
|
|
|
|
try {
|
|
$parish->save();
|
|
flash($request->name . " Parish has been updated")->success();
|
|
return redirect("/parishes/");
|
|
} 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) {
|
|
$parish = Parish::find($id);
|
|
|
|
if ($parish->delete()) {
|
|
flash("Parish has been deleted.")->success();
|
|
return redirect('/parishes/');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function inactive() {
|
|
$parishes = Parish::onlyTrashed()
|
|
->orderBy('name', 'asc')
|
|
->get();
|
|
|
|
$sub_counties = Subcounty::pluck('name', 'id');
|
|
|
|
if (count($parishes) < 1) {
|
|
flash()->error("There is no inactive parishes");
|
|
return redirect('/parishes/');
|
|
}
|
|
|
|
return view('clinical_data::parishes.inactive', compact('parishes', 'sub_counties'));
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function activate($id) {
|
|
$parish = Parish::withTrashed()->find($id);
|
|
|
|
if($parish->restore()){
|
|
flash("Parish has been activated.")->success();
|
|
return redirect('/parishes/inactive');
|
|
}
|
|
}
|
|
|
|
}
|