mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
resolved conflicts
This commit is contained in:
+142
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\District;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class DistrictController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:district-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:district-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:district-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:district-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$districts = District::orderBy('name', 'asc')->get();
|
||||
|
||||
return view('clinical_data::districts.index', compact('districts'));
|
||||
}
|
||||
|
||||
public function create() {
|
||||
return view('clinical_data::districts.create');
|
||||
}
|
||||
|
||||
public function store(Request $request) {
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
flash($string)->error();
|
||||
return back()->withErrors($validator)->withInput();
|
||||
|
||||
} else{
|
||||
|
||||
$user_id = Auth::user()->id;
|
||||
$district = new District;
|
||||
|
||||
$district->name = $request->name;
|
||||
$district->created_by = $user_id;
|
||||
$district->updated_by = $user_id;
|
||||
|
||||
try {
|
||||
$district->save();
|
||||
flash($request->name . " District has been saved")->success();
|
||||
return redirect("/districts/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
public function edit($id) {
|
||||
$district = District::where(['id' => $id])->first();
|
||||
|
||||
if (!$district) {
|
||||
flash()->error("That district is not registered");
|
||||
return redirect('/districts/');
|
||||
} else {
|
||||
return view('clinical_data::districts.edit', compact('district'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, $id) {
|
||||
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$district = District::find($id);
|
||||
|
||||
$district->name = $request->name;
|
||||
$district->updated_by = Auth::user()->id;
|
||||
|
||||
try {
|
||||
$district->save();
|
||||
flash($request->name . " District has been updated")->success();
|
||||
return redirect("/districts/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id) {
|
||||
$district = District::find($id);
|
||||
|
||||
if ($district->delete()) {
|
||||
flash("District has been deleted.")->success();
|
||||
return redirect('/districts/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$districts = District::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
if (count($districts) < 1) {
|
||||
flash()->error("There is no inactive district");
|
||||
}
|
||||
|
||||
return view('clinical_data::districts.inactive', compact('districts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$district = District::withTrashed()->find($id);
|
||||
|
||||
if($district->restore()){
|
||||
flash("District has been activated.")->success();
|
||||
return redirect('/districts/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user