mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-12 03:01:32 +00:00
updated streamline-setup v2
This commit is contained in:
+283
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\Resource;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Streamline\Models\ResourceCategory;
|
||||
|
||||
class ResourceController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:resources-list', ['only' => ['index', 'select']]);
|
||||
$this->middleware('permission:resources-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:resources-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:resources-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:resources-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:resources-status', ['only' => ['activate, inactive']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$resources = DB::table('resources')
|
||||
->whereNull('deleted_at')
|
||||
->orderBy('title','asc')
|
||||
->get();
|
||||
|
||||
$categories = DB::table('resource_categories')->whereNull('deleted_at')->pluck("name", "id");
|
||||
$category_select = ResourceCategory::orderBy('name')->get();
|
||||
|
||||
return view('clinical_data::resources.index', compact('resources','categories','category_select'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
||||
public function create()
|
||||
{
|
||||
$resource_categories = DB::table('resource_categories')
|
||||
->whereNull('deleted_at')
|
||||
->orderBy('name', 'asc')
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
$resource_categories = ['' => '- select -'] + $resource_categories;
|
||||
|
||||
flash('BE SURE TO FILL IN ALL THE NEEDED FIELDS.')->error();
|
||||
|
||||
return view('clinical_data::resources.create', compact('resource_categories'));
|
||||
}
|
||||
/**
|
||||
* 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(), [
|
||||
'title' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
flash($string)->error();
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$resource = new Resource;
|
||||
|
||||
|
||||
$resource->title = $request->title;
|
||||
$resource->body = $request->body;
|
||||
|
||||
$attach_path = $request->file('attach_path');
|
||||
$file_destination_path = $file_name = '';
|
||||
|
||||
if ($attach_path) {
|
||||
$file_name = $attach_path->getClientOriginalName();
|
||||
// $file_source_path = $attach_path->getRealPath();
|
||||
// $file_size = $attach_path-->getSize();
|
||||
// $file_mime_type = $attach_path-->getMimeType();
|
||||
$file_destination_path = 'uploads/resources/';
|
||||
$attach_path->move($file_destination_path, $file_name);
|
||||
}
|
||||
|
||||
$resource->attach_path = $file_destination_path . $file_name;
|
||||
$resource->category_id = $request->category_id;
|
||||
$resource->created_by = $logged_in_user_id;
|
||||
$resource->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$resource->save();
|
||||
flash($request->title . " Resource has been saved")->success();
|
||||
return redirect("/resources/");
|
||||
} 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)
|
||||
{
|
||||
$resources_categories = DB::table('resource_categories')
|
||||
->whereNull('deleted_at')
|
||||
->orderBy('name', 'asc')
|
||||
->pluck('name','id');
|
||||
|
||||
//$resource = Resource::where(['id' => $id])->first();
|
||||
$resource = Resource::find($id);
|
||||
|
||||
if (!$resource) {
|
||||
flash()->error("There is no such resource");
|
||||
return redirect('/resources/');
|
||||
} else {
|
||||
return view('clinical_data::resources.edit', compact('resource'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
||||
public function update(Request $request, $id) {
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'title' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
flash($string)->error();
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$resource = Resource::find($id);
|
||||
$resource->title = $request->title;
|
||||
$resource->body = $request->body;
|
||||
|
||||
$attach_path = $request->file('attach_path');
|
||||
$file_destination_path = $file_name = '';
|
||||
|
||||
if ($attach_path) {
|
||||
$file_name = $attach_path->getClientOriginalName();
|
||||
// $file_source_path = $attach_path->getRealPath();
|
||||
// $file_size = $attach_path->getSize();
|
||||
// $file_mime_type = $attach_path->getMimeType();
|
||||
$file_destination_path = 'uploads/resources/';
|
||||
$attach_path->move($file_destination_path, $file_name);
|
||||
}
|
||||
|
||||
$current_file = $request->current_file;
|
||||
$new_file = $file_destination_path . $file_name;
|
||||
|
||||
$resource->attach_path = $new_file ? $new_file : $current_file;
|
||||
$resource->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$resource->save();
|
||||
flash($request->title . " Resource has been updated")->success();
|
||||
return redirect("/resources/");
|
||||
} 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) {
|
||||
$resources = Resource::find($id);
|
||||
$resources->delete();
|
||||
|
||||
if ($resources->save()):
|
||||
flash("Resources has been deleted.")->success();
|
||||
return redirect('/resources/');
|
||||
endif;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$resources = Resource::onlyTrashed()
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
$categories = DB::table('resource_categories')->whereNull('deleted_at')->pluck("name", "id");
|
||||
|
||||
$category_select = DB::table('resource_categories')->whereNull('deleted_at')->orderBy('name')->distinct()->pluck('name');
|
||||
|
||||
if (is_null($resources)) {
|
||||
flash()->error("There is no inactive resource");
|
||||
return redirect('/resources/');
|
||||
}
|
||||
|
||||
return view('clinical_data::resources.inactive', compact('resources', 'categories', 'category_select'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$resource = Resource::withTrashed()->find($id);
|
||||
|
||||
$resource->deleted_at = null;
|
||||
|
||||
if ($resource->restore()):
|
||||
flash("The Resource has been activated.")->success();
|
||||
return redirect('/resources/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* select the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function select(Request $request) {
|
||||
$resource_category_id = $request->category_select;
|
||||
|
||||
$resources = Resource::orderBy('title', 'asc')
|
||||
->Where('category_id', $resource_category_id)
|
||||
->paginate(50);
|
||||
|
||||
$category_select = ResourceCategory::orderBy('name')->get();
|
||||
|
||||
$categories = ResourceCategory::pluck("name", "id");
|
||||
|
||||
return view('clinical_data::resources.index', compact('resources', 'categories','category_select'));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user