mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
185 lines
5.4 KiB
PHP
Executable File
185 lines
5.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\ClinicalData\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Streamline\Models\ReferralHospital;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Database\QueryException;
|
|
|
|
class ReferralHospitalController extends Controller {
|
|
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
$this->middleware('permission:referral-hospital-list', ['only' => ['index']]);
|
|
$this->middleware('permission:referral-hospital-create', ['only' => ['create', 'store']]);
|
|
$this->middleware('permission:referral-hospital-edit', ['only' => ['edit', 'update']]);
|
|
$this->middleware('permission:referral-hospital-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index() {
|
|
$referral_hospitals = ReferralHospital::orderBy('name', 'asc')->paginate(50);
|
|
|
|
return view('clinical_data::referral_hospitals.index', compact('referral_hospitals'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create() {
|
|
return view('clinical_data::referral_hospitals.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;
|
|
$referral_hospital = new ReferralHospital;
|
|
|
|
$referral_hospital->name = $request->name;
|
|
$referral_hospital->created_by = $logged_in_user_id;
|
|
$referral_hospital->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$referral_hospital->save();
|
|
flash($request->name . " Referral Hospital has been saved")->success();
|
|
return redirect("/referral_hospitals/");
|
|
} 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) {
|
|
$referral_hospital = ReferralHospital::where(['id' => $id])->first();
|
|
|
|
if (!$referral_hospital) {
|
|
flash()->error("There is no such referral hospital");
|
|
return redirect('/referral_hospitals/');
|
|
} else {
|
|
return view('clinical_data::referral_hospitals.edit', compact('referral_hospital'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
|
|
$referral_hospital = ReferralHospital::find($id);
|
|
$referral_hospital->name = $request->name;
|
|
$referral_hospital->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$referral_hospital->save();
|
|
flash($request->name . " Referral Hospital has been updated")->success();
|
|
return redirect("/referral_hospitals/");
|
|
} 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) {
|
|
$referral_hospital = ReferralHospital::find($id);
|
|
|
|
if ($referral_hospital->delete()):
|
|
flash("Hospital has been deleted.")->success();
|
|
return redirect('/referral_hospitals/');
|
|
endif;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function inactive() {
|
|
$referral_hospitals = ReferralHospital::onlyTrashed()
|
|
->orderBy('name', 'asc')
|
|
->paginate(50);
|
|
|
|
if (count($referral_hospitals) < 1) {
|
|
flash()->error("There is no inactive referral hospital");
|
|
return redirect('/referral_hospitals/');
|
|
} else {
|
|
return view('clinical_data::referral_hospitals.inactive', compact('referral_hospitals'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function activate($id) {
|
|
$referral_hospital = ReferralHospital::withTrashed()->find($id);
|
|
|
|
if ($referral_hospital->restore()):
|
|
flash("Hospital has been activated.")->success();
|
|
return redirect('/referral_hospitals/inactive');
|
|
endif;
|
|
}
|
|
|
|
public function get_referrals(){
|
|
//code to be returned to view
|
|
$code = "<option> -- select -- </option>";
|
|
|
|
$referrals = ReferralHospital::orderBy('name', 'asc')->get();
|
|
|
|
foreach ($referrals as $referral) {
|
|
$code .= "<option value='" . $referral->id . "'>" . $referral->name . "</option>";
|
|
}
|
|
|
|
return $code;
|
|
}
|
|
|
|
}
|