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:
+171
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Streamline\Models\Donors;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DonorsController extends Controller{
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:donors-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:donors-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:donors-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:donors-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:donors-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:donors-status', ['only' => ['activate, inactive']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(){
|
||||
$donors = Donors::orderBy('name', 'asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::donors.index', compact('donors'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(){
|
||||
return view('clinical_data::donors.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'
|
||||
]);
|
||||
|
||||
//validation passed
|
||||
$donor = new Donors;
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$donor->name = $request->name;
|
||||
$donor->created_by = $logged_in_user_id;
|
||||
$donor->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$donor->save();
|
||||
flash($request->name . " donor has been saved")->success();
|
||||
return redirect("/donors/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id){
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id){
|
||||
$donor = Donors::where(['id' => $id])->first();
|
||||
|
||||
if (!$donor) {
|
||||
flash()->error("Donor not found");
|
||||
return redirect('/donors/');
|
||||
} else {
|
||||
return view('clinical_data::donors.edit', compact('donor'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id){
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
//validation passed
|
||||
$donor = Donors::find($id);
|
||||
$donor->name = $request->name;
|
||||
|
||||
try {
|
||||
$donor->save();
|
||||
flash($request->name . " donor has been updated")->success();
|
||||
return redirect("/donors/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id){
|
||||
$donor = Donors::find($id);
|
||||
|
||||
if ($donor->delete()){
|
||||
flash("Donor has been deleted.")->success();
|
||||
return redirect('/donors/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$donors = Donors::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($donors) < 1) {
|
||||
flash()->error("There is no inactive donor");
|
||||
return redirect('/donors/');
|
||||
} else {
|
||||
return view('clinical_data::donors.inactive', compact('donors'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$donor = Donors::withTrashed()->find($id);
|
||||
|
||||
if ($donor->restore()):
|
||||
flash("Donor has been activated.")->success();
|
||||
return redirect('/donors/inactive');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user