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:
+203
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\AccountType;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class AccountTypeController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:account-types-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:create-account-types', ['only' => ['create','store','edit','update']]);
|
||||
$this->middleware('permission:view-account-type-details', ['only' => ['show']]);
|
||||
$this->middleware('permission:activate-account-types', ['only' => ['activate']]);
|
||||
$this->middleware('permission:de-activate-account-types', ['only' => ['inactive']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$account_types = AccountType::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
return view('clinical_data::account_types.index', compact('account_types'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::account_types.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
// flash($string)->error();
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
|
||||
//validation passed
|
||||
$account_type = new AccountType;
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$account_type->name = $request->name;
|
||||
$account_type->description = $request->description;
|
||||
$account_type->created_by = $logged_in_user_id;
|
||||
$account_type->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$account_type->save();
|
||||
flash($request->name . " Account Type has been saved")->success();
|
||||
return redirect("/account_types/");
|
||||
} 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) {
|
||||
$account_type = AccountType::where(['id' => $id])->first();
|
||||
|
||||
if (!$account_type) {
|
||||
flash()->error("Account Type not found");
|
||||
return redirect('/account_types/');
|
||||
} else {
|
||||
return view('clinical_data::account_types.edit', compact('account_type'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
|
||||
$string = "";
|
||||
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
|
||||
// flash($string)->error();
|
||||
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
//validation passed
|
||||
$account_type = AccountType::find($id);
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$account_type->name = $request->name;
|
||||
$account_type->description = $request->description;
|
||||
$account_type->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$account_type->save();
|
||||
flash($request->name . " Account Type has been updated")->success();
|
||||
return redirect("/account_types/");
|
||||
} 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) {
|
||||
$account_type = AccountType::find($id);
|
||||
|
||||
if ($account_type->delete()):
|
||||
flash("Account Type has been deleted.")->success();
|
||||
return redirect('/account_types/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$account_types = AccountType::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($account_types) < 1) {
|
||||
flash()->error("There is no inactive account type");
|
||||
return redirect('/account_types/');
|
||||
} else {
|
||||
return view('clinical_data::account_types.inactive', compact('account_types'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$account_type = AccountType::withTrashed()->find($id);
|
||||
|
||||
if ($account_type->restore()):
|
||||
flash("Account Type has been activated.")->success();
|
||||
return redirect('/account_types/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\AgeGroup;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class AgeGroupController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:age-group-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:age-group-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:age-group-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:age-group-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$age_groups = AgeGroup::orderBy('name','asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::age_groups.index', compact('age_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('clinical_data::age_groups.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$age_group = new AgeGroup;
|
||||
|
||||
$age_group->name = $request->name;
|
||||
$age_group->age_type = $request->age_type;
|
||||
$age_group->from_age = $request->from_age;
|
||||
$age_group->to_age = $request->to_age;
|
||||
$age_group->created_by = $logged_in_user_id;
|
||||
$age_group->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$age_group->save();
|
||||
flash($request->name . " Age Group has been saved")->success();
|
||||
return redirect("/age_groups/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$age_group = AgeGroup::where(['id' => $id])->first();
|
||||
|
||||
if (!$age_group) {
|
||||
flash()->error("There is no such Age Group");
|
||||
return redirect('/age_groups/');
|
||||
} else {
|
||||
return view('clinical_data::age_groups.edit', compact('age_group'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$age_group = AgeGroup::find($id);
|
||||
|
||||
$age_group->name = $request->name;
|
||||
$age_group->age_type = $request->age_type;
|
||||
$age_group->from_age = $request->from_age;
|
||||
$age_group->to_age = $request->to_age;
|
||||
$age_group->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$age_group->save();
|
||||
flash($request->name . " Age Group has been updated")->success();
|
||||
return redirect("/age_groups/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$age_group = AgeGroup::find($id);
|
||||
|
||||
if ($age_group->delete()):
|
||||
flash("Age Group has been deleted.")->success();
|
||||
return redirect('/age_groups/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
*/
|
||||
public function inactive() {
|
||||
$age_groups = AgeGroup::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($age_groups) < 1) {
|
||||
flash()->error("There is no inactive age group");
|
||||
return redirect('/age_groups/');
|
||||
} else {
|
||||
return view('clinical_data::age_groups.inactive', compact('age_groups'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function activate($id) {
|
||||
$age_group= AgeGroup::withTrashed()->find($id);
|
||||
|
||||
if ($age_group->restore()):
|
||||
flash("Age Group has been activated.")->success();
|
||||
return redirect('/age_groups/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\InpatientBedCategory;
|
||||
use Streamline\Models\WardBedStay;
|
||||
|
||||
class BedCategoriesController extends Controller {
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:bed_categories-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:bed_categories-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:bed_categories-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:bed_categories-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:bed_categories-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:bed_categories-status', ['only' => ['activate, inactive']]);
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index() {
|
||||
$bed_categories = InpatientBedCategory::orderBy('name', 'asc')->paginate(50);
|
||||
$bed_data = [];
|
||||
$bed_stays = WardBedStay::distinct('bed_category')->whereNotNull('bed_category')->get(['bed_category']);
|
||||
foreach ($bed_stays as $value) $bed_data[] = $value->bed_category;
|
||||
|
||||
return view('clinical_data::bed_categories.index',compact('bed_categories', 'bed_data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create() {
|
||||
$chart_of_accounts = ChartOfAccount::pluck('name', 'id')->prepend('-select-', '')->toArray();
|
||||
|
||||
$income_accounts = ChartOfAccount::where(['type' => 1])
|
||||
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$income_accounts = ['' => '- select -'] + $income_accounts;
|
||||
|
||||
return view('clinical_data::bed_categories.create', compact('chart_of_accounts', 'income_accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$bed_category = new InpatientBedCategory;
|
||||
$bed_category->name = $request->name;
|
||||
$bed_category->cost_type = $request->cost_type;
|
||||
$bed_category->cost_per_night = $request->cost_per_night;
|
||||
$bed_category->cost_first_night = $request->cost_first_night;
|
||||
$bed_category->to_night = $request->to_night;
|
||||
$bed_category->income_account = $request->income_account;
|
||||
$bed_category->cost_range = $request->cost_range;
|
||||
$bed_category->cost_after = $request->cost_after;
|
||||
$bed_category->available = $request->available;
|
||||
$bed_category->staff_in_charge = Auth::id();
|
||||
$bed_category->created_by = Auth::id();
|
||||
|
||||
try {
|
||||
$bed_category->save();
|
||||
flash('successfully saved bed category')->success();
|
||||
return redirect('bed_categories');
|
||||
} catch (\Exception $e) {
|
||||
flash('Error in saving bed category. Contact system admin')->error();
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
*/
|
||||
public function edit($id) {
|
||||
$inpatient_bed_category = InpatientBedCategory::where(['id' => $id])->first();
|
||||
$chart_of_accounts = ChartOfAccount::pluck('name', 'id')->prepend('-select-', '')->toArray();
|
||||
|
||||
if (!$inpatient_bed_category) {
|
||||
flash()->error("There is no such bed category");
|
||||
return redirect('/bed_categories/');
|
||||
} else {
|
||||
return view('clinical_data::bed_categories.edit', compact('inpatient_bed_category', 'chart_of_accounts'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$bed_category = InpatientBedCategory::find($id);
|
||||
$bed_category->name = $request->name;
|
||||
$bed_category->cost_type = $request->cost_type;
|
||||
$bed_category->cost_per_night = $request->cost_per_night;
|
||||
$bed_category->cost_first_night = $request->cost_first_night;
|
||||
$bed_category->to_night = $request->to_night;
|
||||
$bed_category->cost_range = $request->cost_range;
|
||||
$bed_category->income_account = $request->income_account;
|
||||
$bed_category->cost_after = $request->cost_after;
|
||||
$bed_category->available = $request->available;
|
||||
$bed_category->updated_by = Auth::id();
|
||||
|
||||
try {
|
||||
$bed_category->save();
|
||||
flash('successfully edited bed category')->success();
|
||||
return redirect('bed_categories');
|
||||
} catch (\Exception $e) {
|
||||
flash('Error in editing bed category. Contact system admin')->error();
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
*/
|
||||
public function destroy($id) {
|
||||
$inpatient_bed_category = InpatientBedCategory::find($id);
|
||||
|
||||
if ($inpatient_bed_category->delete()) {
|
||||
flash($inpatient_bed_category->name. ' inpatient bed category has been successfully deleted')->success();
|
||||
return redirect('bed_categories');
|
||||
}
|
||||
|
||||
flash('error occurred. Contact system admin')->error();
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
/*
|
||||
*Display inactive bed categories
|
||||
*/
|
||||
public function inactive() {
|
||||
$bed_categories = InpatientBedCategory::onlyTrashed()->orderBy('name','asc')->paginate(50);
|
||||
|
||||
if (empty($bed_categories)) {
|
||||
flash()->error("There is no inactive occupation");
|
||||
return redirect('/bed_categories/');
|
||||
} else {
|
||||
return view('clinical_data::bed_categories.inactive', compact('bed_categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Activate an inactive inpatient bed category
|
||||
*/
|
||||
public function activate($id) {
|
||||
$bed_categories = InpatientBedCategory::withTrashed()->find($id);
|
||||
|
||||
try {
|
||||
$bed_categories->restore();
|
||||
flash("Bed Category has been activated.")->success();
|
||||
} catch (\Exception $e) {
|
||||
flash("Bed Category activation failed.")->success();
|
||||
}
|
||||
|
||||
return redirect('/inactive/bed_categories/');
|
||||
}
|
||||
}
|
||||
+298
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\AccountType;
|
||||
use Streamline\Models\Banking;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\ChartOfAccountSlug;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Streamline\Models\TrackReceipt;
|
||||
|
||||
class ChartOfAccountController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:chart-of-accounts-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:create-chart-of-accounts', ['only' => ['create','store','edit','update']]);
|
||||
$this->middleware('permission:view-chart-of-account-details', ['only' => ['show']]);
|
||||
$this->middleware('permission:activate-chart-of-accounts', ['only' => ['activate']]);
|
||||
$this->middleware('permission:de-activate-chart-of-accounts', ['only' => ['inactive']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')->get();
|
||||
|
||||
$chart_of_accounts_list = ChartOfAccount::orderBy('name', 'asc')
|
||||
->pluck('name', 'id');
|
||||
|
||||
$account_types = DB::table('account_types')
|
||||
->orderBy('name', 'asc')
|
||||
->pluck('name', 'id');
|
||||
|
||||
return view('clinical_data::chart_of_accounts.index', compact('chart_of_accounts', 'chart_of_accounts_list', 'account_types'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
$chart_of_accounts_list = ChartOfAccount::orderBy('name', 'asc')
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
$chart_of_accounts_list = ['' => '- select -'] + $chart_of_accounts_list;
|
||||
|
||||
$account_types = AccountType::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
$coa_slugs = ChartOfAccountSlug::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$slugs = [];
|
||||
$slugs = [" " => "- Select -"];
|
||||
foreach ($coa_slugs as $key => $value) {
|
||||
$slug_item = str_replace("_", " ", $value);
|
||||
$slugs[$value] = $slug_item;
|
||||
}
|
||||
|
||||
return view('clinical_data::chart_of_accounts.create', compact('chart_of_accounts_list', 'account_types', 'slugs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
flash($string)->error();
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
|
||||
//validation passed
|
||||
$chart_of_account = new ChartOfAccount;
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$chart_of_account->name = $request->name;
|
||||
$chart_of_account->type = $request->type;
|
||||
$chart_of_account->description = $request->description;
|
||||
$chart_of_account->sub_account_of = $request->sub_account_of;
|
||||
$chart_of_account->balance = $request->balance ? $request->balance : 0;
|
||||
$chart_of_account->slug = str_replace(" ", "_", strtolower($chart_of_account->name));
|
||||
$chart_of_account->core = $request->core;
|
||||
$chart_of_account->created_by = $logged_in_user_id;
|
||||
$chart_of_account->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
|
||||
$chart_of_account->save();
|
||||
|
||||
$trans_id = generateReceiptNumberFromDB('Initial Bank Deposit');
|
||||
|
||||
if($request->type == '4'){
|
||||
capture_bank_record('DEPOSIT', Carbon::parse($request->opening_balance_date)->toDateTimeString(), $chart_of_account->id, 'Initial Deposit', ($request->opening_balance ? $request->opening_balance : 0),
|
||||
($request->opening_balance ? $request->opening_balance : 0), 0, 'Initial Deposit', $trans_id);
|
||||
/* capture_bank_record('DEPOSIT', Carbon::parse($current_balance_date=0)->toDateTimeString(), $chart_of_account->id, 'Current Balance', ($request->opening_balance ? $request->opening_balance : 0),
|
||||
($request->opening_balance ? $request->opening_balance : 0), 0, 'Current Balance', $trans_id_2); */
|
||||
}
|
||||
|
||||
flash($request->name . " Chart of Account has been saved")->success();
|
||||
return redirect("/chart_of_accounts/");
|
||||
} 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) {
|
||||
$chart_of_account = ChartOfAccount::where('id', $id)->first();
|
||||
|
||||
$chart_of_accounts_list = ChartOfAccount::orderBy('name', 'asc')
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
$chart_of_accounts_list = ['' => '- select -'] + $chart_of_accounts_list;
|
||||
|
||||
$account_types = AccountType::orderBy('name', 'asc')
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
$account_types = ['' => '- select -'] + $account_types;
|
||||
|
||||
$coa_slugs = ChartOfAccountSlug::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$slugs = [" " => "- Select -"];
|
||||
foreach ($coa_slugs as $key => $value) {
|
||||
$slug_item = str_replace("_", " ", $value);
|
||||
$slugs[$value] = $slug_item;
|
||||
}
|
||||
|
||||
if (!$chart_of_account) {
|
||||
flash()->error("Chart of Account not found");
|
||||
return redirect('/chart_of_accounts/');
|
||||
} else {
|
||||
return view('clinical_data::chart_of_accounts.edit', compact('chart_of_account', 'chart_of_accounts_list', 'account_types', 'slugs'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
|
||||
$string = "";
|
||||
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
//validation passed
|
||||
$chart_of_account = ChartOfAccount::find($id);
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$chart_of_account->name = $request->name;
|
||||
$chart_of_account->type = $request->type ?? $chart_of_account->type;
|
||||
$chart_of_account->description = $request->description;
|
||||
$chart_of_account->sub_account_of = $request->sub_account_of ?? NULL;
|
||||
$chart_of_account->balance = $request->balance;
|
||||
$chart_of_account->core = $request->core ?? $chart_of_account->core;
|
||||
$chart_of_account->updated_by = $logged_in_user_id;
|
||||
if (!is_null($request->slug)) {
|
||||
$chart_of_account->slug = $request->slug;
|
||||
}
|
||||
|
||||
try {
|
||||
$initial_transaction = Banking::where(['bank' => $id, 'memo' => 'Initial Deposit'])
|
||||
->update([
|
||||
'account_balance' => $request->balance
|
||||
]);
|
||||
}catch (QueryException $_e){
|
||||
flash('Failed To Update Opening Bank Balance.')->error();
|
||||
}
|
||||
|
||||
try {
|
||||
$chart_of_account->save();
|
||||
flash($request->name . " Chart of Account has been updated")->success();
|
||||
return redirect("/chart_of_accounts/");
|
||||
} 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) {
|
||||
$undeletable_core_chart_of_accounts = [];
|
||||
//check if the account is a core before allowing deletion
|
||||
$undeletable_core_chart_of_accounts = ChartOfAccount::where('core',1)->orderBy('id', 'asc')->pluck('id')->toArray();
|
||||
if (in_array($id, $undeletable_core_chart_of_accounts)) {
|
||||
flash('You can not delete this chart of accounts. It is a core chart of account used by the system')->error();
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
//check if the account has any attached transaction without and not delete it
|
||||
//Table to check 1. banking, 2. Quotations, 3.payments, 4.patient_category_invoices
|
||||
//maybe checking many tables isn't the best idea.
|
||||
|
||||
$chart_of_account = ChartOfAccount::find($id);
|
||||
|
||||
if ($chart_of_account->delete()):
|
||||
flash("Chart of Account has been deleted.")->success();
|
||||
return redirect('/chart_of_accounts/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$chart_of_accounts = ChartOfAccount::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
$chart_of_accounts_list = ChartOfAccount::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->pluck('name', 'id');
|
||||
|
||||
$account_types = AccountType::orderBy('name', 'asc')
|
||||
->pluck('name', 'id');
|
||||
|
||||
if (count($chart_of_accounts) < 1) {
|
||||
flash()->error("There is no inactive chart_of_account");
|
||||
return redirect('/chart_of_accounts/');
|
||||
} else {
|
||||
// Log::info($chart_of_accounts);
|
||||
return view('clinical_data::chart_of_accounts.inactive', compact('chart_of_accounts', 'chart_of_accounts_list', 'account_types'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$chart_of_account = ChartOfAccount::withTrashed()->find($id);
|
||||
|
||||
if ($chart_of_account->restore()):
|
||||
flash("Chart of Account has been activated.")->success();
|
||||
return redirect('/chart_of_accounts/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\ClinicalData\Services\Clinics\ClinicsServiceInterface;
|
||||
use Streamline\Models\Clinic;
|
||||
use Streamline\Models\Triage;
|
||||
use Streamline\Models\PatientEpisode;
|
||||
use Streamline\Services\StreamlineSetupServiceInterface;
|
||||
|
||||
class ClinicController extends Controller {
|
||||
|
||||
protected ClinicsServiceInterface $clinicService;
|
||||
protected StreamlineSetupServiceInterface $setupService;
|
||||
|
||||
public function __construct(ClinicsServiceInterface $clinicService, StreamlineSetupServiceInterface $setupService) {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:clinic-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:clinic-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:clinic-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:clinic-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
|
||||
$this->clinicService = $clinicService;
|
||||
$this->setupService = $setupService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$clinics = Clinic::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
$clinic_types = $this->clinicService->getClinicTypes();
|
||||
|
||||
$clinic_ids = PatientEpisode::distinct('clinic_id')->whereNotNull('clinic_id')->pluck('clinic_id', 'clinic_id')->toArray();
|
||||
$triage_clinics = Triage::distinct('clinic_allocation')->whereNotNull('clinic_allocation')->pluck('clinic_allocation', 'clinic_allocation')->toArray();
|
||||
foreach ($triage_clinics as $value) if(!empty($value) && !in_array($value,$clinic_ids)) $clinic_ids[$value] = $value;
|
||||
|
||||
return view('clinical_data::clinics.index', compact('clinics', 'clinic_types', 'clinic_ids'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
$clinics = $this->clinicService->getClinicsSeeder();
|
||||
$clinic_types = $this->clinicService->getClinicTypes();
|
||||
|
||||
return view('clinical_data::clinics.create',compact('clinics', 'clinic_types'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
//validation passed
|
||||
|
||||
if (isset($request->skip)&& session()->has('streamline_setup')) {
|
||||
//update the streamline setup table with the new finished step
|
||||
$this->setupService->saveStep("clinics registration", 1);
|
||||
|
||||
return redirect("wards/create");
|
||||
} else {
|
||||
$createdClinic = $this->clinicService->createClinic($request->name, $request->clinic_type, $request->available);
|
||||
|
||||
if ($createdClinic) {
|
||||
flash($request->name . " Clinic has been saved")->success();
|
||||
} else {
|
||||
flash("An error occurred will saving the clinic")->error();
|
||||
}
|
||||
|
||||
//in case more clinics have been added during the initial setup
|
||||
if (session()->has('streamline_setup')) {
|
||||
if (isset($request->other_clinics)) {
|
||||
$other_clinics_array = $request->other_clinics;
|
||||
for ($i=0; $i < count($other_clinics_array) ; $i++) {
|
||||
$createdClinic = $this->clinicService->createClinic($other_clinics_array[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($request->selected_clinics)) {
|
||||
$selected_clinics_array = $request->selected_clinics;
|
||||
$seeder_clinics = $this->clinicService->getClinicsSeeder();
|
||||
|
||||
for ($i=0; $i < count($selected_clinics_array) ; $i++) {
|
||||
$clinic_name = $seeder_clinics[$selected_clinics_array[$i]]["name"];
|
||||
$clinic_slug = $seeder_clinics[$selected_clinics_array[$i]]["slug"];
|
||||
$createdClinic = $this->clinicService->createClinic($clinic_name, $clinic_slug);
|
||||
}
|
||||
}
|
||||
|
||||
// update the streamline setup table with the new finished step
|
||||
$this->setupService->saveStep("clinics registration", 1);
|
||||
|
||||
flash("Clinics have been added")->success();
|
||||
|
||||
return redirect("wards/create");
|
||||
}
|
||||
|
||||
return redirect("/clinics/");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
*/
|
||||
public function edit($id): View | RedirectResponse
|
||||
{
|
||||
$clinic = $this->clinicService->getClinicById($id);
|
||||
$clinic_types = $this->clinicService->getClinicTypes();
|
||||
|
||||
if (!$clinic) {
|
||||
flash()->error("Clinic not found");
|
||||
return redirect('/clinics/');
|
||||
} else {
|
||||
return view('clinical_data::clinics.edit', compact('clinic', 'clinic_types'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, int $id): RedirectResponse
|
||||
{
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
//validation passed
|
||||
$updated_clinic = $this->clinicService->editClinic($id, $request->name, $request->available, $request->clinic_type);
|
||||
|
||||
if ($updated_clinic) {
|
||||
flash($request->name . " clinic has been updated")->success();
|
||||
return redirect("/clinics/");
|
||||
} else {
|
||||
flash("An error occurred! Please try again later")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function destroy(int $id): RedirectResponse {
|
||||
$isClinicDeleted = $this->clinicService->deactivateClinic($id);
|
||||
|
||||
if ($isClinicDeleted) {
|
||||
flash("Clinic has been deleted.")->success();
|
||||
return redirect('/clinics/');
|
||||
} else {
|
||||
flash("An error occurred")->error();
|
||||
return redirect('/clinics/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return RedirectResponse|View
|
||||
*/
|
||||
public function inactive(): RedirectResponse|View {
|
||||
$clinics = Clinic::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (empty($clinics)) {
|
||||
flash()->error("There is no inactive clinic");
|
||||
return redirect('/clinics/');
|
||||
} else {
|
||||
return view('clinical_data::clinics.inactive', compact('clinics'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function activate(int $id): RedirectResponse
|
||||
{
|
||||
$isClinicActive = $this->clinicService->activateClinic($id);
|
||||
|
||||
if($isClinicActive[0]){
|
||||
flash($isClinicActive[1])->success();
|
||||
} else {
|
||||
flash($isClinicActive[1])->error();
|
||||
}
|
||||
|
||||
return redirect('/clinics/inactive');
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ClinicalDataController extends Controller {
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
return view('clinical_data::clinical_data.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Streamline\Models\Company;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CompanyController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index() {
|
||||
$companies = Company::orderBy('name', 'asc')->paginate(50);
|
||||
return view('clinical_data::companies.index', compact('companies'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::companies.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
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>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$company = new Company;
|
||||
|
||||
$company->name = $request->name;
|
||||
$company->contact = $request->contact;
|
||||
$company->slug = $request->identifier;
|
||||
$company->created_by = $logged_in_user_id;
|
||||
$company->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$company->save();
|
||||
flash($request->name . " Company has been saved")->success();
|
||||
return redirect("/companies/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function quick_store(Request $request) {
|
||||
|
||||
$company = new Company;
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$company->name = $request->name;
|
||||
$company->contact = $request->contact;
|
||||
$company->slug = $request->slug;
|
||||
$company->created_by = $logged_in_user_id;
|
||||
$company->updated_by = $logged_in_user_id;
|
||||
|
||||
if($company->save()){
|
||||
return 'success';
|
||||
}else{
|
||||
return 'fail';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
public function edit($id) {
|
||||
$company = Company::where(['id' => $id])->first();
|
||||
|
||||
if (!$company) {
|
||||
flash()->error("There is no such Company");
|
||||
return redirect('/companies/');
|
||||
} else {
|
||||
return view('clinical_data::companies.edit', compact('company'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$company = Company::find($id);
|
||||
$company->name = $request->name;
|
||||
$company->contact = $request->contact;
|
||||
$company->slug = $request->slug;
|
||||
$company->created_by = $logged_in_user_id;
|
||||
$company->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$company->save();
|
||||
flash($request->name . " Company has been updated")->success();
|
||||
return redirect("/companies/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function destroy($id) {
|
||||
$company = Company::find($id);
|
||||
|
||||
if ($company->delete()):
|
||||
flash("Company has been deleted.")->success();
|
||||
return redirect('/companies/');
|
||||
endif;
|
||||
}
|
||||
|
||||
|
||||
public function inactive() {
|
||||
|
||||
$companies = Company::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($companies) < 1) {
|
||||
flash()->error("There is no inactive Company");
|
||||
return redirect('/companies/');
|
||||
} else {
|
||||
return view('clinical_data::companies.inactive', compact('companies'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function activate($id) {
|
||||
$company = Company::withTrashed()->find($id);
|
||||
|
||||
if ($company->restore()):
|
||||
flash("Company has been activated.")->success();
|
||||
return redirect('/companies/inactive');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Streamline\Models\Country;
|
||||
|
||||
class CountriesController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:countries-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:countries-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:countries-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:countries-edit', ['only' => ['edit', 'edit_all', 'update', 'update_all', 'updatePatientEpisode']]);
|
||||
$this->middleware('permission:countries-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:countries-status', ['only' => ['activate, inactive']]);
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$countries = Country::orderBy('name', 'asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::countries.index', compact('countries'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('clinical_data::countries.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
if ($validator->fails())
|
||||
{
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
flash($string)->error();
|
||||
return back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
else {
|
||||
$country = new Country;
|
||||
|
||||
$country->name = $request->name;
|
||||
$country->created_by = Auth::user()->id;
|
||||
$country->updated_by = Auth::user()->id;
|
||||
|
||||
try {
|
||||
$country->save();
|
||||
flash($request->name . " Country has been saved")->success();
|
||||
return redirect("/countries/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$country = Country::where(['id' => $id])->first();
|
||||
|
||||
if (!$country) {
|
||||
flash()->error("There is no such country");
|
||||
return redirect('/countries/');
|
||||
} else {
|
||||
return view('clinical_data::countries.edit', compact('country'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function update(Request $request, Country $countries)
|
||||
{
|
||||
$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 {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$country = Country::find($id);
|
||||
$country->name = $request->name;
|
||||
$country->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$country->save();
|
||||
flash($request->name . " Country has been updated")->success();
|
||||
return redirect("/countries/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$country = Country::find($id);
|
||||
|
||||
if ($country->delete()):
|
||||
flash("Country has been deleted.")->success();
|
||||
return redirect('/countries/');
|
||||
endif;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive()
|
||||
{
|
||||
$countries = Country::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($countries) < 1) {
|
||||
flash()->error("There is no inactive country");
|
||||
return redirect('/countries/');
|
||||
} else {
|
||||
return view('clinical_data::countries.inactive', compact('countries'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id)
|
||||
{
|
||||
$country = Country::withTrashed()->find($id);
|
||||
|
||||
if ($country->restore()):
|
||||
flash("Country has been activated.")->success();
|
||||
return redirect('/countries/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
<?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\County;
|
||||
use Streamline\Models\District;
|
||||
|
||||
class CountyController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:county-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:county-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:county-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:county-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$counties = County::orderBy('name', 'asc')->get();
|
||||
|
||||
$districts = District::pluck('name', 'id');
|
||||
|
||||
return view('clinical_data::counties.index', compact('counties', 'districts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
$districts = District::pluck('name', 'id')->toArray();
|
||||
|
||||
$districts = ['' => '- select -'] + $districts;
|
||||
|
||||
return view('clinical_data::counties.create', compact('districts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'district_id' => '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;
|
||||
$county = new County;
|
||||
|
||||
$county->name = $request->name;
|
||||
$county->district_id = $request->district_id;
|
||||
$county->created_by = $user_id;
|
||||
$county->updated_by = $user_id;
|
||||
|
||||
try {
|
||||
$county->save();
|
||||
flash($request->name . " County has been saved")->success();
|
||||
return redirect("/counties/");
|
||||
} 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) {
|
||||
$county = County::where(['id' => $id])->first();
|
||||
|
||||
$districts = District::pluck('name', 'id')->toArray();
|
||||
|
||||
$districts = ['' => '- select -'] + $districts;
|
||||
|
||||
if (!$county) {
|
||||
flash()->error("That county is not registered");
|
||||
return redirect('/counties/');
|
||||
} else {
|
||||
return view('clinical_data::counties.edit', compact('county', 'districts'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'district_id' => 'required'
|
||||
]);
|
||||
|
||||
$county = County::find($id);
|
||||
|
||||
$county->name = $request->name;
|
||||
$county->district_id = $request->district_id;
|
||||
$county->updated_by = Auth::user()->id;
|
||||
|
||||
try {
|
||||
$county->save();
|
||||
flash($request->name . " County has been updated")->success();
|
||||
return redirect("/counties/");
|
||||
} 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) {
|
||||
$county = County::find($id);
|
||||
|
||||
if ($county->delete()) {
|
||||
flash("County has been deleted.")->success();
|
||||
return redirect('/counties/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$counties = County::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
$districts = District::pluck('name', 'id');
|
||||
|
||||
if (count($counties) < 1) {
|
||||
flash()->error("There is no inactive counties");
|
||||
return redirect('/counties/');
|
||||
} else {
|
||||
return view('clinical_data::counties.inactive', compact('counties', 'districts'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$county = County::withTrashed()->find($id);
|
||||
|
||||
if($county->restore()){
|
||||
flash("County has been activated.")->success();
|
||||
return redirect('/counties/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\Department;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class DepartmentController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:departments-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:departments-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:departments-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:departments-edit', ['only' => ['edit', 'edit_all', 'update', 'update_all', 'updatePatientEpisode']]);
|
||||
$this->middleware('permission:departments-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:departments-status', ['only' => ['activate, inactive']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$departments = Department::orderBy('name', 'asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::departments.index', compact('departments'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('clinical_data::departments.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
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;
|
||||
$department = new Department;
|
||||
|
||||
$department->name = $request->name;
|
||||
$department->created_by = $logged_in_user_id;
|
||||
$department->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$department->save();
|
||||
flash($request->name . " Department has been saved")->success();
|
||||
return redirect("/departments/");
|
||||
} 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)
|
||||
{
|
||||
$department = Department::where(['id' => $id])->first();
|
||||
|
||||
if (!$department) {
|
||||
flash()->error("There is no such department");
|
||||
return redirect('/departments/');
|
||||
} else {
|
||||
return view('clinical_data::departments.edit', compact('department'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'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 {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$department = Department::find($id);
|
||||
$department->name = $request->name;
|
||||
$department->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$department->save();
|
||||
flash($request->name . " Department has been updated")->success();
|
||||
return redirect("/departments/");
|
||||
} 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)
|
||||
{
|
||||
$department = Department::find($id);
|
||||
|
||||
if ($department->delete()):
|
||||
flash("Department has been deleted.")->success();
|
||||
return redirect('/departments/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive()
|
||||
{
|
||||
$departments = Department::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($departments) < 1) {
|
||||
flash()->error("There is no inactive department");
|
||||
return redirect('/departments/');
|
||||
} else {
|
||||
return view('clinical_data::departments.inactive', compact('departments'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id)
|
||||
{
|
||||
$department = Department::withTrashed()->find($id);
|
||||
|
||||
if ($department->restore()):
|
||||
flash("Department has been activated.")->success();
|
||||
return redirect('/departments/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the active resources for bulk editing.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit_all()
|
||||
{
|
||||
$departments = Department::orderBy('name', 'asc')->paginate(25);
|
||||
|
||||
if (count($departments) < 1) {
|
||||
flash()->error("There is no active department");
|
||||
return redirect('/departments/');
|
||||
} else {
|
||||
return view('clinical_data::departments.edit.all', compact('departments'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all the resources in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update_all(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 {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$id_array = $request->id;
|
||||
$name_array = $request->name;
|
||||
|
||||
for ($x = 0; $x < count($id_array); $x++):
|
||||
$department = Department::find($id_array[$x]);
|
||||
|
||||
$department->name = $name_array[$x];
|
||||
$department->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$department->save();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
endfor;
|
||||
|
||||
flash("Departments have been updated")->success();
|
||||
return redirect("/departments/");
|
||||
}
|
||||
}
|
||||
}
|
||||
+495
@@ -0,0 +1,495 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\Diagnosis;
|
||||
use Streamline\Models\Consultation;
|
||||
use Streamline\Models\InpatientInfo;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Streamline\Models\DiagnosisCategory;
|
||||
use Streamline\Models\InsuranceTariff;
|
||||
use Streamline\Models\HmisCategory;
|
||||
use Streamline\Models\HmisCategoryOptions;
|
||||
|
||||
class DiagnosisController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:diagnosis-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:diagnosis-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:diagnosis-edit', ['only' => ['edit', 'update', 'edit_all', 'update_all']]);
|
||||
$this->middleware('permission:diagnosis-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index() {
|
||||
$diagnoses = Diagnosis::orderBy('name', 'asc')->leftJoin('hmis_category_options as h', 'h.id', 'diagnoses.hmis_no_inpatient')
|
||||
->select('diagnoses.*', 'h.number as inpatient_number')
|
||||
->paginate(10000);
|
||||
|
||||
$hmis_categories = DB::table('hmis_categories')
|
||||
->orderBy('title', 'asc')
|
||||
->pluck('title', 'id');
|
||||
|
||||
$issued_diagnoses = [];
|
||||
$hmis_category_options = HmisCategoryOptions::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
$consultations_primary = Consultation::distinct('primary_diagnosis')->select('primary_diagnosis');
|
||||
$inpatient_primary = InpatientInfo::distinct('primary_diagnosis')->select('primary_diagnosis')->union($consultations_primary)->get()->toArray();
|
||||
foreach($inpatient_primary as $diagnosis) if(!in_array($diagnosis['primary_diagnosis'], $issued_diagnoses) && !empty($diagnosis['primary_diagnosis'])) $issued_diagnoses[]=$diagnosis['primary_diagnosis'];
|
||||
$consultations_other = Consultation::distinct('other_diagnoses')->select('other_diagnoses');
|
||||
$inpatient_other = InpatientInfo::distinct('other_diagnoses')->select('other_diagnoses')->union($consultations_other)->get();
|
||||
foreach($inpatient_other as $diagnosis_other) {
|
||||
$other_diagnoses = unserialize($diagnosis_other->other_diagnoses);
|
||||
if(!empty($other_diagnoses)) foreach($other_diagnoses as $other_diagnosis) if(!in_array(intval($other_diagnosis), $issued_diagnoses)) $issued_diagnoses[]= intval($other_diagnosis);
|
||||
}
|
||||
|
||||
return view('clinical_data::diagnoses.index', compact('diagnoses', 'hmis_categories','issued_diagnoses', 'hmis_category_options'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create() {
|
||||
$hmis_categories = DB::table('hmis_categories')->whereIn('section_number',[6,7,1])->orderBy('title', 'asc')->get();
|
||||
$inpatient_hmis_categories = $hmis_categories->filter(function($hmis_category){
|
||||
return $hmis_category->type == 1;
|
||||
})->pluck('title', 'id')->prepend('- Select HMIS Inpatient Category -', '');
|
||||
$outpatient_hmis_categories = $hmis_categories->filter(function($hmis_category){
|
||||
return $hmis_category->type == 0;
|
||||
})->pluck('title', 'id')->prepend('- Select HMIS Outpatient Category -', '');
|
||||
|
||||
$parent_categories = array_unique(HmisCategoryOptions::where('parent_option', '<>','')->pluck('parent_option')->toArray());
|
||||
$diagnosis_categories = DiagnosisCategory::orderBy('name', 'asc')->pluck('name', 'id')->prepend('None', 0);
|
||||
|
||||
$insurance_tariffs = DB::table('insurance_tariffs')->whereNull('deleted_at')->pluck('name', 'id')->toArray();
|
||||
|
||||
return view('clinical_data::diagnoses.create', compact('hmis_categories', 'insurance_tariffs','parent_categories', 'inpatient_hmis_categories', 'outpatient_hmis_categories', 'diagnosis_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
request()->validate([
|
||||
'name' => 'required|unique:diagnoses'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
$diagnosis = new Diagnosis;
|
||||
|
||||
//Reference Names
|
||||
$reference_names_array = $request->reference_names;
|
||||
$reference_names = "";
|
||||
|
||||
//Processing reference areas
|
||||
$reference_areas_array = $request->reference_areas;
|
||||
$reference_areas = "";
|
||||
|
||||
if ($request->insurance_tariffs) {
|
||||
$diagnosis->insurance_tariffs = implode(",", $request->insurance_tariffs);
|
||||
}
|
||||
|
||||
for ($x = 0; $x < count($reference_areas_array); $x++):
|
||||
$reference_area = $reference_areas_array[$x];
|
||||
$reference_area_data = parse_url($reference_area);
|
||||
if (empty($reference_area_data['scheme'])):
|
||||
$reference_area = 'http://' . ltrim($reference_area, '/');
|
||||
endif;
|
||||
|
||||
$reference_areas .= $reference_area . ",";
|
||||
$reference_names .= rtrim($reference_names_array[$x], ", ") . ",";
|
||||
endfor;
|
||||
if (!empty($request->district_code) && $request->outpatient_hmis_category_option == '655') {
|
||||
$district_code = HmisCategoryOptions::updateOrCreate(['name' => $request->district_code,'number' => 'Code', 'hmis_category_id' => 0],[
|
||||
'name' => $request->district_code,
|
||||
'number' => 'Code',
|
||||
'hmis_category_id' => 0,
|
||||
'parent_option' => $request->outpatient_hmis_category_option,
|
||||
'created_by' => Auth()->user()->id
|
||||
]);
|
||||
}
|
||||
|
||||
$diagnosis->name = $request->name;
|
||||
$diagnosis->icd10_code = $request->icd10_code;
|
||||
$diagnosis->available = $request->available;
|
||||
// $diagnosis->hmis_no_outpatient = $request->hmis_no_outpatient;
|
||||
$diagnosis->hmis_no_inpatient = $request->hmis_no_inpatient;
|
||||
$diagnosis->prompts = $request->prompts;
|
||||
$diagnosis->diagnosis_category = $request->diagnosis_category?? null;
|
||||
$diagnosis->chronic_status = $request->chronic_status;
|
||||
$diagnosis->reference_areas = rtrim($reference_areas, ", ");
|
||||
$diagnosis->reference_names = rtrim($reference_names, ", ");
|
||||
$diagnosis->hmis_category = $request->hmis_category;
|
||||
$diagnosis->dependent_option = $request->parent_dependent_option ?? null;
|
||||
$diagnosis->outpatient_hmis_category = $request->outpatient_hmis_category ?? null;
|
||||
$diagnosis->outpatient_hmis_category_option = $request->outpatient_hmis_category_option ?? null;
|
||||
if(!empty($district_code->id)) $diagnosis->outpatient_dependent_option = $district_code->id;
|
||||
else $diagnosis->outpatient_dependent_option = $request->outpatient_dependent_option ?? null;
|
||||
$diagnosis->created_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$diagnosis->save();
|
||||
|
||||
if ($request->insurance_tariffs) {
|
||||
// add diagnoses to the tariffs
|
||||
foreach ($request->insurance_tariffs as $tariff_id) {
|
||||
try {
|
||||
$tariff = InsuranceTariff::find($tariff_id);
|
||||
|
||||
if ($tariff->linked_diagnoses) {
|
||||
$current_diagnoses = explode(",", $tariff->linked_diagnoses);
|
||||
$current_diagnoses = array_merge($current_diagnoses, $diagnosis->id);
|
||||
} else {
|
||||
$current_diagnoses = [$diagnosis->id];
|
||||
}
|
||||
|
||||
$tariff->linked_diagnoses = implode(",", $current_diagnoses);
|
||||
$tariff->save();
|
||||
|
||||
} catch (\Exception $exception) {}
|
||||
}
|
||||
}
|
||||
|
||||
flash($request->name . " Diagnosis has been saved")->success();
|
||||
return redirect("/diagnoses/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred!")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function edit($id) {
|
||||
$diagnosis = Diagnosis::findOrFail($id);
|
||||
$hmis_categories = HmisCategory::whereIn('section_number',[6,7,1])->orderBy('title', 'asc')->get();
|
||||
$diagnosis_categories = DiagnosisCategory::orderBy('name', 'asc')->pluck('name', 'id')->prepend('None', 0);
|
||||
$parent_categories = array_unique(HmisCategoryOptions::where('parent_option', '<>','')->pluck('parent_option')->toArray());
|
||||
$insurance_tariffs = DB::table('insurance_tariffs')->whereNull('deleted_at')->pluck('name', 'id')->toArray();
|
||||
|
||||
$inpatient_category_options_header = (!empty($diagnosis->hmis_no_inpatient) || $diagnosis->hmis_no_inpatient == '-')? '- Select HMIS Inpatient Category Option -': '- Firstly, Select HMIS Inpatient Category -';
|
||||
$outpatient_category_options_header = !empty($diagnosis->outpatient_hmis_category)? '- Select HMIS Outpatient Category Option -': '- Firstly, Select HMIS Outpatient Category -';
|
||||
$dependent_options_header = '- Select Dependent Option -';$inpatient_category_options = $outpatient_dependent_options = $dependent_options = $outpatient_category_options =[];
|
||||
if(!empty($diagnosis->hmis_no_inpatient) || $diagnosis->hmis_no_inpatient == '-') $inpatient_category_options = HmisCategoryOptions::where('hmis_category_id', $diagnosis->hmis_category)->pluck('name','id')->prepend($inpatient_category_options_header, '');
|
||||
if(!empty($diagnosis->outpatient_hmis_category)) $outpatient_category_options = HmisCategoryOptions::where('hmis_category_id', $diagnosis->outpatient_hmis_category)->pluck('name','id')->prepend($outpatient_category_options_header, '');
|
||||
if(!empty($diagnosis->hmis_no_inpatient) || $diagnosis->hmis_no_inpatient == '-' || in_array($diagnosis->hmis_no_inpatient, $parent_categories)) $dependent_options = HmisCategoryOptions::where('parent_option', $diagnosis->hmis_no_inpatient)->pluck('name','id')->prepend($dependent_options_header, '');
|
||||
if(!empty($diagnosis->outpatient_hmis_category_option) || in_array($diagnosis->outpatient_hmis_category_option, $parent_categories)) $outpatient_dependent_options = HmisCategoryOptions::where('parent_option', $diagnosis->outpatient_hmis_category_option)->pluck('name','id')->prepend($dependent_options_header, '');
|
||||
$inpatient_hmis_categories = $hmis_categories->filter(function($hmis_category){
|
||||
return $hmis_category->type == 1;
|
||||
})->pluck('title', 'id')->prepend('- Select HMIS Inpatient Category -', '');
|
||||
$outpatient_hmis_categories = $hmis_categories->filter(function($hmis_category){
|
||||
return $hmis_category->type == 0;
|
||||
})->pluck('title', 'id')->prepend('- Select HMIS Outpatient Category -', '');
|
||||
|
||||
return view('clinical_data::diagnoses.edit', compact('diagnosis', 'inpatient_hmis_categories', 'insurance_tariffs', 'outpatient_hmis_categories', 'outpatient_category_options', 'diagnosis_categories', 'inpatient_category_options', 'dependent_options', 'parent_categories', 'outpatient_dependent_options'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
request()->validate([
|
||||
'name' => 'required|unique:diagnoses,name,'.$id
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
//Reference Names
|
||||
$reference_names_array = $request->reference_names;
|
||||
$reference_names = "";
|
||||
|
||||
//Processing reference areas
|
||||
$reference_areas_array = $request->reference_areas;
|
||||
$reference_areas = "";
|
||||
|
||||
if (!empty($reference_areas_array)) {
|
||||
for ($x = 0; $x < count($reference_areas_array); $x++):
|
||||
$reference_area = $reference_areas_array[$x];
|
||||
$reference_area_data = parse_url($reference_area);
|
||||
if (empty($reference_area_data['scheme'])):
|
||||
$reference_area = 'http://' . ltrim($reference_area, '/');
|
||||
endif;
|
||||
|
||||
$reference_areas .= $reference_area . ",";
|
||||
$reference_names .= rtrim($reference_names_array[$x], ", ") . ",";
|
||||
endfor;
|
||||
}
|
||||
|
||||
if (!empty($request->district_code) && $request->outpatient_hmis_category_option == '655') {
|
||||
$district_code = HmisCategoryOptions::updateOrCreate(['id' => $request->district_code_id,'number' => 'Code', 'hmis_category_id' => 0],[
|
||||
// 'id'=>$hmis_category_option['id'],
|
||||
'name' => $request->district_code,
|
||||
'number' => 'Code',
|
||||
'hmis_category_id' => 0,
|
||||
'parent_option' => $request->outpatient_hmis_category_option,
|
||||
'created_by' => Auth()->user()->id
|
||||
]);
|
||||
}
|
||||
|
||||
$diagnosis = Diagnosis::find($id);
|
||||
$diagnosis->name = $request->name;
|
||||
$diagnosis->icd10_code = $request->icd10_code;
|
||||
$diagnosis->available = $request->available;
|
||||
// $diagnosis->hmis_no_outpatient = $request->hmis_no_outpatient;
|
||||
$diagnosis->hmis_no_inpatient = $request->hmis_no_inpatient;
|
||||
$diagnosis->prompts = $request->prompts;
|
||||
$diagnosis->chronic_status = $request->chronic_status;
|
||||
$diagnosis->reference_areas = rtrim($reference_areas, ", ");
|
||||
$diagnosis->reference_names = rtrim($reference_names, ", ");
|
||||
$diagnosis->hmis_category = $request->hmis_category;
|
||||
$diagnosis->diagnosis_category = $request->diagnosis_category?? null;
|
||||
$diagnosis->dependent_option = $request->parent_dependent_option ?? null;
|
||||
$diagnosis->outpatient_hmis_category = $request->outpatient_hmis_category ?? null;
|
||||
$diagnosis->outpatient_hmis_category_option = $request->outpatient_hmis_category_option ?? null;
|
||||
if(!empty($district_code->id) && $request->outpatient_hmis_category_option == '655') $diagnosis->outpatient_dependent_option = $district_code->id;
|
||||
else $diagnosis->outpatient_dependent_option = $request->outpatient_dependent_option ?? null;
|
||||
$diagnosis->updated_by = $logged_in_user_id;
|
||||
|
||||
if ($request->insurance_tariffs) {
|
||||
$original_tariffs = explode(",", $diagnosis->insurance_tariffs);
|
||||
$diagnosis->insurance_tariffs = implode(",", $request->insurance_tariffs);
|
||||
|
||||
$removed_tariffs = array_diff($original_tariffs, $request->insurance_tariffs);
|
||||
$added_tariffs = array_diff($request->insurance_tariffs, $original_tariffs);
|
||||
|
||||
// add diagnoses to the tariffs
|
||||
foreach ($added_tariffs as $tariff_id) {
|
||||
try {
|
||||
$tariff = InsuranceTariff::find($tariff_id);
|
||||
|
||||
if ($tariff->linked_diagnoses) {
|
||||
$current_diagnoses = explode(",", $tariff->linked_diagnoses);
|
||||
$current_diagnoses = array_merge($current_diagnoses, $diagnosis->id);
|
||||
} else {
|
||||
$current_diagnoses = [$diagnosis->id];
|
||||
}
|
||||
|
||||
$tariff->linked_diagnoses = implode(",", $current_diagnoses);
|
||||
$tariff->save();
|
||||
|
||||
} catch (\Exception $exception) {}
|
||||
}
|
||||
|
||||
// remove diagnosis from tariffs
|
||||
foreach ($removed_tariffs as $tariff_id) {
|
||||
try {
|
||||
$tariff = InsuranceTariff::find($tariff_id);
|
||||
$current_diagnoses = explode(",", $tariff->linked_diagnoses);
|
||||
|
||||
if (in_array($diagnosis->id, $current_diagnoses)) {
|
||||
unset($current_diagnoses[array_search($diagnosis->id, $current_diagnoses)]);
|
||||
|
||||
$tariff->linked_diagnoses = implode(",", $current_diagnoses);
|
||||
$tariff->save();
|
||||
}
|
||||
} catch (\Exception $exception) {}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$diagnosis->save();
|
||||
flash($request->name . " Diagnosis has been updated")->success();
|
||||
return redirect("/diagnoses/");
|
||||
} 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) {
|
||||
$diagnosis = Diagnosis::find($id);
|
||||
|
||||
if ($diagnosis->delete()){
|
||||
flash("Diagnosis has been deleted.")->success();
|
||||
return redirect('/diagnoses/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$diagnoses = Diagnosis::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
$hmis_categories = DB::table('hmis_categories')
|
||||
->orderBy('title', 'asc')
|
||||
->pluck('title', 'id');
|
||||
|
||||
if (empty($diagnoses)) {
|
||||
flash()->error("There is no inactive diagnosis");
|
||||
return redirect('/diagnoses/');
|
||||
} else {
|
||||
return view('clinical_data::diagnoses.inactive', compact('diagnoses', 'hmis_categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$diagnosis = Diagnosis::withTrashed()->find($id);
|
||||
|
||||
if ($diagnosis->restore()){
|
||||
flash("Diagnosis has been activated.")->success();
|
||||
return redirect('/diagnoses/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the active resources for bulk editing.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit_all() {
|
||||
$diagnoses = Diagnosis::orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
$hmis_categories = DB::table('hmis_categories')
|
||||
->pluck('title', 'id')
|
||||
->toArray();
|
||||
|
||||
$hmis_categories = ['' => '- select -'] + $hmis_categories;
|
||||
|
||||
if (count($diagnoses) < 1) {
|
||||
flash()->error("There is no active diagnosis");
|
||||
return redirect('/diagnoses/');
|
||||
} else {
|
||||
return view('clinical_data::diagnoses.edit.all', compact('diagnoses', 'hmis_categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all the resources in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update_all(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 {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$id_array = $request->id;
|
||||
$name_array = $request->name;
|
||||
$icd10_code_array = $request->icd10_code;
|
||||
$hmis_no_outpatient_array = $request->hmis_no_outpatient;
|
||||
$hmis_no_inpatient_array = $request->hmis_no_inpatient;
|
||||
$prompts_array = $request->prompts;
|
||||
$chronic_status_array = $request->chronic_status;
|
||||
$reference_areas_array = $request->reference_areas;
|
||||
$reference_names_array = $request->reference_names;
|
||||
$hmis_category_array = $request->hmis_category;
|
||||
|
||||
for ($x = 0; $x < count($id_array); $x++):
|
||||
$diagnosis = Diagnosis::find($id_array[$x]);
|
||||
|
||||
$diagnosis->name = $name_array[$x];
|
||||
$diagnosis->icd10_code = $icd10_code_array[$x];
|
||||
$diagnosis->hmis_no_outpatient = $hmis_no_outpatient_array[$x];
|
||||
$diagnosis->hmis_no_inpatient = $hmis_no_inpatient_array[$x];
|
||||
$diagnosis->prompts = $prompts_array[$x];
|
||||
$diagnosis->chronic_status = $chronic_status_array[$x];
|
||||
$diagnosis->reference_areas = rtrim($reference_areas_array[$x], ", ");
|
||||
$diagnosis->reference_names = rtrim($reference_names_array[$x], ", ");
|
||||
$diagnosis->hmis_category = $hmis_category_array[$x];
|
||||
$diagnosis->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$diagnosis->save();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
endfor;
|
||||
|
||||
flash("Diagnoses have been updated")->success();
|
||||
return redirect("/diagnoses/");
|
||||
}
|
||||
}
|
||||
|
||||
public function get_diagnosis(Request $request) {
|
||||
$diagnosis_id = $request->diagnosis_id;
|
||||
$diagnosis = Diagnosis::where('id', $diagnosis_id)->first();
|
||||
|
||||
$reference_areas_array = explode(",", $diagnosis->reference_areas);
|
||||
$reference_names_array = explode(",", $diagnosis->reference_names);
|
||||
|
||||
$prompt = empty($diagnosis->prompts) ? " " : $diagnosis->prompts;
|
||||
|
||||
$links = "";
|
||||
|
||||
for ($x = 0; $x < count($reference_areas_array); $x++) {
|
||||
if (isset($reference_areas_array[$x]) && isset($reference_names_array[$x])){
|
||||
$links .= "<a href='" . $reference_areas_array[$x] . "' target='_blank' >" . $reference_names_array[$x] . "</a> <span style='color: red'> | </span>";
|
||||
}
|
||||
}
|
||||
|
||||
return $prompt . "&&" . $links;
|
||||
}
|
||||
|
||||
public function get_diagnosis_by_category($category){
|
||||
$code = "<option> - select - </option>";
|
||||
$diagnoses = Diagnosis::where('diagnosis_category', $category)->orderBy('name', 'asc')->get();
|
||||
foreach ($diagnoses as $diagnosis) {
|
||||
$code .= "<option value='" . $diagnosis->id . "'>" . $diagnosis->name . "</option>";
|
||||
}
|
||||
$code .= "</select>";
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function get_diagnosis_categories(){
|
||||
$diagnoses = DiagnosisCategory::all();
|
||||
$code = "<option> - select - </option>";
|
||||
foreach ($diagnoses as $diagnosis) {
|
||||
$code .= "<option value='" . $diagnosis->id . "'>" . $diagnosis->name . "</option>";
|
||||
}
|
||||
$code .= "</select>";
|
||||
return $code;
|
||||
}
|
||||
|
||||
}
|
||||
+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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
}
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\DosageFrequency;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class DosageFrequencyController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:dosage-frequency-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:dosage-frequency-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:dosage-frequency-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:dosage-frequency-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$frequencies = DosageFrequency::orderBy('name', 'asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::dosage_frequencies.index', compact('frequencies'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::dosage_frequencies.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'factor' => 'required'
|
||||
]);
|
||||
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$frequency = new DosageFrequency;
|
||||
|
||||
$frequency->name = $request->name;
|
||||
$frequency->factor = $request->factor;
|
||||
$frequency->created_by = $logged_in_user_id;
|
||||
$frequency->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$frequency->save();
|
||||
flash($request->name . " Dosage Frequency has been saved")->success();
|
||||
return redirect("/dosage_frequencies/");
|
||||
} 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) {
|
||||
$frequency = DosageFrequency::where(['id' => $id])->first();
|
||||
|
||||
if (!$frequency) {
|
||||
flash()->error("There is no such dosage frequency");
|
||||
return redirect('/dosage_frequencies/');
|
||||
} else {
|
||||
return view('clinical_data::dosage_frequencies.edit', compact('frequency'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'factor' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$frequency = DosageFrequency::find($id);
|
||||
$frequency->name = $request->name;
|
||||
$frequency->factor = $request->factor;
|
||||
$frequency->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$frequency->save();
|
||||
flash($request->name . " Dosage Frequency has been updated")->success();
|
||||
return redirect("/dosage_frequencies/");
|
||||
} 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) {
|
||||
$frequency = DosageFrequency::find($id);
|
||||
|
||||
if ($frequency->delete()):
|
||||
flash("Frequency has been deleted.")->success();
|
||||
return redirect('/dosage_frequencies/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$frequencies = DosageFrequency::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($frequencies) < 1) {
|
||||
flash()->error("There is no inactive frequency");
|
||||
return redirect('/dosage_frequencies/');
|
||||
} else {
|
||||
return view('clinical_data::dosage_frequencies.inactive', compact('frequencies'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$dosage_frequency = DosageFrequency::withTrashed()->find($id);
|
||||
|
||||
if ($dosage_frequency->restore()){
|
||||
flash("Frequency has been activated.")->success();
|
||||
return redirect('/dosage_frequencies/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\DrugCategory;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class DrugCategoryController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:drug-category-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:drug-category-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:drug-category-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:drug-category-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$drug_categories = DrugCategory::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
return view('clinical_data::drug_categories.index', compact('drug_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::drug_categories.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',
|
||||
'anti_malarial'=>'required|integer'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = auth()->user()->id;
|
||||
$drug_category = new DrugCategory;
|
||||
|
||||
$drug_category->name = $request->name;
|
||||
$drug_category->created_by = $logged_in_user_id;
|
||||
$drug_category->anti_malarial = $request->anti_malarial;
|
||||
|
||||
try {
|
||||
$drug_category->save();
|
||||
flash($request->name . " Drug Category has been saved")->success();
|
||||
return redirect("/drug_categories/");
|
||||
} 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) {
|
||||
$drug_category = DrugCategory::where(['id' => $id])->first();
|
||||
|
||||
if (!$drug_category) {
|
||||
flash()->error("There is no such Category");
|
||||
return redirect('/drug_categories/');
|
||||
} else {
|
||||
return view('clinical_data::drug_categories.edit', compact('drug_category'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'anti_malarial' => 'required|integer'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = auth()->user()->id;
|
||||
|
||||
$drug_category = DrugCategory::find($id);
|
||||
$drug_category->name = $request->name;
|
||||
$drug_category->anti_malarial = $request->anti_malarial;
|
||||
$drug_category->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug_category->save();
|
||||
flash($request->name . " Drug Category has been updated")->success();
|
||||
return redirect("/drug_categories/");
|
||||
} 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) {
|
||||
$drug_category = DrugCategory::find($id);
|
||||
|
||||
if ($drug_category->delete()){
|
||||
flash("Category has been deleted.")->success();
|
||||
return redirect('/drug_categories/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$drug_categories = DrugCategory::onlyTrashed()->orderBy('name', 'asc')->paginate(50);
|
||||
|
||||
if (empty($drug_categories)) {
|
||||
flash()->error("There is no inactive Category");
|
||||
return redirect('/drug_categories/');
|
||||
} else {
|
||||
return view('clinical_data::drug_categories.inactive', compact('drug_categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$drug_category = DrugCategory::withTrashed()->find($id);
|
||||
|
||||
if ($drug_category->restore()){
|
||||
flash("Category has been activated.")->success();
|
||||
return redirect('/drug_categories/');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+994
@@ -0,0 +1,994 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\Drug;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Streamline\Models\DrugCategory;
|
||||
use Streamline\Models\DrugForm;
|
||||
use Streamline\Models\DrugUnit;
|
||||
use Streamline\Models\PriceListCategories;
|
||||
use Streamline\Models\Supplier;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Streamline\Http\Controllers\StreamlineSetupManager;
|
||||
use Streamline\Models\Treatment;
|
||||
use Streamline\Models\WardTreatment;
|
||||
use Streamline\Models\ItemBatchWatcher;
|
||||
use Streamline\Services\ItemsStockService;
|
||||
use Streamline\Services\StreamlineSetupServiceInterface;
|
||||
class DrugController extends Controller {
|
||||
protected StreamlineSetupServiceInterface $setupService;
|
||||
protected ItemsStockService $itemsStockService;
|
||||
|
||||
function __construct(
|
||||
StreamlineSetupServiceInterface $setupService,
|
||||
ItemsStockService $itemsStockService
|
||||
) {
|
||||
/*$this->middleware('auth');
|
||||
$this->middleware('permission:drug-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:drug-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:drug-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:drug-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:drug-delete', ['only' => ['destroy']]);*/
|
||||
$this->setupService = $setupService;
|
||||
$this->itemsStockService = $itemsStockService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index() {
|
||||
$drugs = Drug::orderBy('name', 'asc')->paginate(1500);
|
||||
$ordered_drugs = [];
|
||||
$treatment_ids = Treatment::distinct('drugs')->select('drugs');
|
||||
$ward_treatment_ids = WardTreatment::distinct('drugs')->select('drugs')->union($treatment_ids)->get();
|
||||
foreach ($ward_treatment_ids as $ward_treatment_id) {
|
||||
$drug_ids = explode(',', $ward_treatment_id->drugs);
|
||||
foreach ($drug_ids as $drug_id) if(!empty($drug_id) && !in_array($drug_id, $ordered_drugs)) $ordered_drugs[$drug_id] = $drug_id;
|
||||
}
|
||||
|
||||
return view('clinical_data::drugs.index', compact('drugs', 'ordered_drugs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create() {
|
||||
$drug_categories = DrugCategory::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$drug_categories = ['' => '- select -'] + $drug_categories;
|
||||
|
||||
$drug_units = DrugUnit::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$drug_units = ['' => '- select -'] + $drug_units;
|
||||
|
||||
$drug_forms = DrugForm::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$drug_forms = ['' => '- select -'] + $drug_forms;
|
||||
|
||||
$suppliers = Supplier::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$suppliers = ['' => '- select -'] + $suppliers;
|
||||
|
||||
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$inventory_asset_accounts = ChartOfAccount::where(['type' => 10])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$income_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
|
||||
$inventory_asset_accounts = ['' => '- select -'] + $inventory_asset_accounts;
|
||||
$income_accounts = ['' => '- select -'] + $income_accounts;
|
||||
|
||||
$default_drugs = StreamlineSetupManager::get_drugs_array();
|
||||
|
||||
$package_units = DB::table('package_units')->whereNull('deleted_at')->orderBy('name')->pluck('name','id')->toArray();
|
||||
$package_units = ['' => '- select -'] + $package_units;
|
||||
|
||||
return view('clinical_data::drugs.create', compact('drug_categories', 'drug_units', 'drug_forms', 'suppliers',
|
||||
'income_accounts','default_drugs', 'inventory_asset_accounts', 'cost_of_goods_accounts', 'package_units'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
|
||||
if (session()->has('streamline_setup') && isset($request->skip)){
|
||||
//Artisan::call('db:seed', ['--class' => 'DrugsTableSeeder']);
|
||||
//update the streamline setup table with the new finished step
|
||||
$this->setupService->saveStep("drugs registration", 1);
|
||||
|
||||
// flash("Default drugs list has been added")->success();
|
||||
return redirect("procedures/create");
|
||||
} else {
|
||||
// get all current price lists
|
||||
$price_list = PriceListCategories::withTrashed()->select('id')->get();
|
||||
$price_list_category = [];
|
||||
$price_list_price = [];
|
||||
|
||||
foreach ($price_list as $record){
|
||||
array_push($price_list_category, $record->id);
|
||||
array_push($price_list_price, $request->non_insured_price);
|
||||
}
|
||||
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
$drug = new Drug;
|
||||
|
||||
$drug->name = $request->name;
|
||||
$drug->category_id = $request->category_id;
|
||||
$drug->available = $request->available;
|
||||
$drug->form_id = $request->form_id;
|
||||
$drug->unit_id = $request->unit_id;
|
||||
$drug->reference_areas = !empty($request->reference_areas)? implode(',',$request->reference_areas):null;
|
||||
$drug->reference_name = !empty($request->reference_name)? implode(',',$request->reference_name):null;
|
||||
$drug->pack = $request->pack;
|
||||
$drug->strength = $request->strength;
|
||||
$drug->prompt = $request->prompt;
|
||||
$drug->info_english = $request->info_english;
|
||||
$drug->info_vernacular = $request->info_vernacular;
|
||||
$drug->store_stock = 0; //$request->store_stock;
|
||||
$drug->pharmacy_stock = 0; //$request->pharmacy_stock;
|
||||
$drug->reorder_level = $request->reorder_level;
|
||||
$drug->long_term = $request->long_term;
|
||||
/*if ($request->is_initial_stock_count == 1) {
|
||||
$drug->opening_stock = $drug->store_stock + $drug->pharmacy_stock;
|
||||
$drug->opening_cost_price = $request->cost_price;
|
||||
}*/
|
||||
$drug->expiry_date = $request->expiry_date;
|
||||
$drug->supplier_id = $request->supplier_id;
|
||||
|
||||
if (isset($request->price_list_category_id)) {
|
||||
$drug->price_list_category = !is_null($request->price_list_category_id) ? implode(",", $request->price_list_category_id) : null;
|
||||
$drug->price_list_price = !is_null($request->price_list_price) ? implode(",", $request->price_list_price) : null;
|
||||
} else {
|
||||
$drug->price_list_category = NULL;
|
||||
$drug->price_list_price = NULL;
|
||||
}
|
||||
|
||||
$drug->insurance_coverage = 0;
|
||||
$drug->cost_price = $request->cost_price;
|
||||
$drug->non_insured_price = $request->non_insured_price;
|
||||
$drug->insured_price = 0;
|
||||
$drug->account_id = $request->account_id;
|
||||
$drug->inventory_account = $request->inventory_account;
|
||||
$drug->cost_of_goods_account = $request->cog_account;
|
||||
$drug->description = $request->description;
|
||||
$drug->package_unit_id = $request->package_unit_id;
|
||||
$drug->does_package_unit_have_sub_packages = $request->does_package_unit_have_sub_packages;
|
||||
$drug->quantity_in_each_package_unit = $request->quantity_in_each_package_unit;
|
||||
$drug->quantity_in_each_sub_package = $request->quantity_in_each_sub_package;
|
||||
$drug->number_of_sub_packages_in_main_package_unit = $request->number_of_sub_packages_in_main_package;
|
||||
$drug->created_by = $logged_in_user_id;
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
$drug->created_at = Carbon::now();
|
||||
$drug->updated_at = Carbon::now();
|
||||
|
||||
try {
|
||||
if ($drug->name != "" && !is_null($drug->name)) {
|
||||
$drug->save();
|
||||
}
|
||||
|
||||
if (session()->has('streamline_setup')) {
|
||||
if (isset($request->selected_drugs)) {
|
||||
$selected_drugs_array = $request->selected_drugs;
|
||||
if (!empty($selected_drugs_array)) {
|
||||
|
||||
for ($i=0; $i < count($selected_drugs_array) ; $i++) {
|
||||
/* try this magic to get details for the selected service */
|
||||
$drugs_array = StreamlineSetupManager::get_drugs_array();
|
||||
$key=array_search($selected_drugs_array[$i], array_column($drugs_array, 'name'));
|
||||
$drug_details = $drugs_array[$key];
|
||||
/* end of magic trial */
|
||||
|
||||
$default_drug = new Drug;
|
||||
$default_drug->name = $drug_details['name'];
|
||||
$default_drug->cost_price = $drug_details['cost_price'];
|
||||
$default_drug->insured_price = 0;
|
||||
$default_drug->non_insured_price = $drug_details['non_insured_price'];
|
||||
$default_drug->category_id = $drug_details['category_id'];
|
||||
$drug->account_id = $request->account_id;
|
||||
$drug->inventory_account = $request->inventory_account;
|
||||
$drug->cost_of_goods_account = $request->cog_account;
|
||||
$default_drug->form_id = $drug_details['form_id'];
|
||||
$default_drug->unit_id = $drug_details['unit_id'];
|
||||
$default_drug->expiry_date = Carbon::now()->addWeek();
|
||||
$default_drug->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
//update the streamline setup table with the new finished step
|
||||
$this->setupService->saveStep("drugs registration", 1);
|
||||
// $streamline_setup = new \Streamline\Models\StreamlineSetupStep;
|
||||
// $streamline_setup->step = "drug registration";
|
||||
// $streamline_setup->completion_status = 1;
|
||||
// $streamline_setup->save();
|
||||
flash("Drugs have been added. PLease ensure that you edit the expiry date before the end of the week")->success();
|
||||
|
||||
return redirect("procedures/create");
|
||||
}
|
||||
|
||||
flash($request->name . " Drug has been saved")->success();
|
||||
return redirect("/drugs/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function edit($id) {
|
||||
$drug_categories = DrugCategory::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$drug_units = DrugUnit::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
$drug_forms = DrugForm::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
|
||||
$drug = Drug::where(['id' => $id])->first();
|
||||
|
||||
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$inventory_asset_accounts = ChartOfAccount::where(['type' => 10])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$income_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
|
||||
$inventory_asset_accounts = ['' => '- select -'] + $inventory_asset_accounts;
|
||||
$income_accounts = ['' => '- select -'] + $income_accounts;
|
||||
|
||||
if (!$drug) {
|
||||
flash()->error("There is no such drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.edit', compact('drug_units', 'drug_forms', 'drug', 'drug_categories', 'cost_of_goods_accounts', 'inventory_asset_accounts',
|
||||
'income_accounts'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
|
||||
/**
|
||||
* So a little explanation for this point, there are four methods for updating the column values
|
||||
* for a drug in the drugs table and am using one update method to route them through here,
|
||||
* differentiate them by the $request->id passed along since i guess no one will dare use the id
|
||||
* field or value and then according to whatever value is passed in the id using if elseif statements
|
||||
* tried a switch but the code was really messy and an if is the best, feel free to edit to your heart's content ;)
|
||||
*/
|
||||
if (isset($request->id)) {
|
||||
if ($request->id == 0) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$drug = Drug::find($id);
|
||||
$drug->name = $request->name;
|
||||
$drug->prompt = $request->prompt;
|
||||
$drug->info_vernacular = $request->info_vernacular;
|
||||
$drug->info_english = $request->info_english;
|
||||
$drug->pharmacy_comment = $request->pharmacy_comment;
|
||||
$drug->description = $request->description;
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug->save();
|
||||
flash($request->name . " Drug has been updated")->success();
|
||||
return redirect("/drugs/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
} elseif ($request->id == 1) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
'cost_price' => 'required',
|
||||
'non_insured_price' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$drug = Drug::find($id);
|
||||
$drug->name = $request->name;
|
||||
$drug->cost_price = $request->cost_price;
|
||||
$drug->non_insured_price = $request->non_insured_price;
|
||||
$drug->insured_price = 0;
|
||||
$drug->price_list_category = !is_null($request->price_list_category_id) ? implode(",", $request->price_list_category_id) : null;
|
||||
$drug->price_list_price = !is_null($request->price_list_price) ? implode(",", $request->price_list_price) : null;
|
||||
$drug->pricing_factor_infant = $request->pricing_factor_infant;
|
||||
$drug->pricing_factor_children = $request->pricing_factor_children;
|
||||
$drug->pricing_factor_adult = $request->pricing_factor_adult;
|
||||
$drug->ip_daily_cost_adult = $request->ip_daily_cost_adult;
|
||||
$drug->ip_daily_cost_children = $request->ip_daily_cost_children;
|
||||
$drug->ip_daily_cost_infant = $request->ip_daily_cost_infant;
|
||||
$drug->ip_daily_cost_adult_insured = 0;
|
||||
$drug->ip_daily_cost_children_insured = 0;
|
||||
$drug->ip_daily_cost_infant_insured = 0;
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug->save();
|
||||
flash($request->name . " Drug has been updated")->success();
|
||||
return redirect("/drugs/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
} elseif ($request->id == 2) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
'form_id' => 'required',
|
||||
'pack' => 'required',
|
||||
'strength' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$drug = Drug::find($id);
|
||||
$drug->name = $request->name;
|
||||
$drug->form_id = $request->form_id;
|
||||
$drug->pack = $request->pack;
|
||||
$drug->strength = $request->strength;
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
|
||||
if ($drug->save()):
|
||||
flash($request->name . " has been saved")->success();
|
||||
return redirect("/drugs/");
|
||||
else:
|
||||
flash("There was an error")->error();
|
||||
endif;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
'form_id' => 'required',
|
||||
'unit_id' => 'required',
|
||||
'pharmacy_stock' => 'required',
|
||||
'store_stock' => 'required',
|
||||
'reorder_level' => 'required',
|
||||
'long_term' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$drug = Drug::find($id);
|
||||
$drug->name = $request->name;
|
||||
$drug->category_id = $request->category_id;
|
||||
$drug->form_id = $request->form_id;
|
||||
$drug->available = $request->available;
|
||||
$drug->reference_areas = !empty($request->reference_areas)? implode(',',$request->reference_areas):null;
|
||||
$drug->reference_name = !empty($request->reference_name)? implode(',',$request->reference_name):null;
|
||||
$drug->unit_id = $request->unit_id;
|
||||
$drug->store_stock = $request->store_stock;
|
||||
$drug->pharmacy_stock = $request->pharmacy_stock;
|
||||
$drug->reorder_level = $request->reorder_level;
|
||||
$drug->long_term = $request->long_term;
|
||||
$drug->hssip = $request->hssip;
|
||||
$drug->insurance_coverage = 0;
|
||||
$drug->account_id = $request->account_id;
|
||||
$drug->inventory_account = $request->inventory_account;
|
||||
$drug->cost_of_goods_account = $request->cog_account;
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
|
||||
if ($drug->save()):
|
||||
flash($request->name . " has been saved")->success();
|
||||
return redirect("/drugs/");
|
||||
else:
|
||||
flash("There was an error")->error();
|
||||
endif;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id) {
|
||||
$drug = Drug::find($id);
|
||||
if (empty($drug->pharmacy_stock) && empty($drug->store_stock) && empty($drug->opening_stock)) {
|
||||
if ($drug->delete()):
|
||||
flash("Drug has been deleted.")->success();
|
||||
return redirect('/drugs/');
|
||||
endif;
|
||||
} else {
|
||||
flash()->error($drug->name ." is still in stock.");
|
||||
return redirect('/drugs/');
|
||||
}
|
||||
}
|
||||
|
||||
public function inactive() {
|
||||
|
||||
$drugs = Drug::onlyTrashed()->orderBy('name', 'asc')->paginate(50);
|
||||
|
||||
if (empty($drugs)) {
|
||||
flash()->error("There is no inactive drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.inactive', compact('drugs'));
|
||||
}
|
||||
}
|
||||
|
||||
public function activate($id) {
|
||||
$drug = Drug::withTrashed()->find($id);
|
||||
|
||||
if ($drug->restore()):
|
||||
flash("Drug has been activated.")->success();
|
||||
return redirect('/drugs/');
|
||||
endif;
|
||||
}
|
||||
|
||||
public function edit_drugs_calculations($id) {
|
||||
|
||||
$drug_forms = DrugForm::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
|
||||
$drug = Drug::where(['id' => $id])->first();
|
||||
|
||||
if (!$drug) {
|
||||
flash()->error("There is no such drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.edit.drugs_calculations', compact('drug_forms', 'drug'));
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_drugs_pricing($id) {
|
||||
$drug = Drug::where(['id' => $id])->first();
|
||||
|
||||
if (!$drug) {
|
||||
flash()->error("There is no such drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.edit.drugs_pricing', compact('drug'));
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_drugs_prompts($id) {
|
||||
$drug = Drug::where(['id' => $id])->first();
|
||||
|
||||
if (!$drug) {
|
||||
flash()->error("There is no such drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.edit.drugs_prompts', compact('drug'));
|
||||
}
|
||||
}
|
||||
|
||||
public function index_drugs_expiring(Request $request) {
|
||||
|
||||
$today = Carbon::now(); $range = !empty($request->time_period)? $request->time_period : 0;
|
||||
$started =$request->start_date; $ended = $request->end_date;
|
||||
if ($request->time_period) {
|
||||
if ($request->time_period == 0) {
|
||||
|
||||
$drugs = ItemBatchWatcher::where(function ($query) {
|
||||
$query->where('store_stock', '>', 0)
|
||||
->orWhere('pharmacy_stock', '>', 0);
|
||||
})->where('item_type', 1)->where('expiry_date', '<', DATE($today))
|
||||
->orderBy('expiry_date', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There are no expired drugs");
|
||||
}
|
||||
} elseif ($request->time_period == 1) {
|
||||
|
||||
$drugs = ItemBatchWatcher::where(function ($query) {
|
||||
$query->where('store_stock', '>', 0)
|
||||
->orWhere('pharmacy_stock', '>', 0);
|
||||
})->where('item_type', 1)->whereBetween('expiry_date', [DATE($today), DATE($today->addWeek())])
|
||||
->orderBy('expiry_date', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There are no drugs expiring in a week");
|
||||
}
|
||||
} elseif ($request->time_period == 2) {
|
||||
|
||||
$drugs = ItemBatchWatcher::where(function ($query) {
|
||||
$query->where('store_stock', '>', 0)
|
||||
->orWhere('pharmacy_stock', '>', 0);
|
||||
})->where('item_type', 1)->whereBetween('expiry_date', [DATE($today), DATE($today->addWeeks(2))])
|
||||
->orderBy('expiry_date', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There are no drugs expiring in two weeks");
|
||||
}
|
||||
} elseif ($request->time_period == 3) {
|
||||
$request->validate([
|
||||
'start_date' => 'required|date|required_with:end_date',
|
||||
'end_date' => 'bail|required|required_with:start_date|date|after:start_date',
|
||||
]);
|
||||
$end = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
|
||||
$start = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
|
||||
$drugs = ItemBatchWatcher::where(function ($query) {
|
||||
$query->where('store_stock', '>', 0)
|
||||
->orWhere('pharmacy_stock', '>', 0);
|
||||
})->where('item_type', 1)->whereBetween('expiry_date', [$start, $end])
|
||||
->orderBy('expiry_date', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($drugs) < 1) flash()->error("There are no drugs expiring between ".$start. " and " .$end);
|
||||
} elseif ($request->time_period == 4) {
|
||||
|
||||
$drugs = ItemBatchWatcher::where(function ($query) {
|
||||
$query->where('store_stock', '>', 0)
|
||||
->orWhere('pharmacy_stock', '>', 0);
|
||||
})->where('item_type', 1)->whereBetween('expiry_date', [DATE($today), DATE($today->addWeeks(4))])
|
||||
->orderBy('expiry_date', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There are no drugs expiring in a month");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$drugs = ItemBatchWatcher::where(function ($query) {
|
||||
$query->where('store_stock', '>', 0)
|
||||
->orWhere('pharmacy_stock', '>', 0);
|
||||
})->where('item_type', 1)->where('expiry_date', '<', DATE($today))
|
||||
->orderBy('expiry_date', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There are no expired drugs");
|
||||
}
|
||||
}
|
||||
|
||||
return view('clinical_data::drugs.index_drugs_expiring', compact('drugs', 'range', 'started', 'ended'));
|
||||
}
|
||||
|
||||
public function index_drugs_low_stock() {
|
||||
|
||||
$drugs = Drug::whereColumn('store_stock', '<', 'reorder_level')
|
||||
->orWhere('store_stock', '<', '20')
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(500);
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There is no out of stock drugs");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.index_drugs_low_stock', compact('drugs'));
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_all() {
|
||||
$drugs = Drug::orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
$drug_units = DrugUnit::orderBy('name', 'asc')
|
||||
->pluck('name', 'id');
|
||||
|
||||
$drug_forms = DrugForm::orderBy('name', 'asc')
|
||||
->pluck('name', 'id');
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There is no active drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.edit.all', compact('drugs', 'drug_units', 'drug_forms'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update_all(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
//'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$id_array = $request->id;
|
||||
|
||||
$name_array = $request->name;
|
||||
$form_id_array = $request->form_id;
|
||||
$unit_id_array = $request->unit_id;
|
||||
$store_stock_array = $request->store_stock;
|
||||
$pharmacy_stock_array = $request->pharmacy_stock;
|
||||
$reorder_level_array = $request->reorder_level;
|
||||
$long_term_array = $request->long_term;
|
||||
$hssip_array = $request->hssip;
|
||||
|
||||
for ($x = 0; $x < count($id_array); $x++) {
|
||||
$drug = Drug::find($id_array[$x]);
|
||||
|
||||
$drug->name = isset($name_array[$x]) ? $name_array[$x] : $drug->name;
|
||||
$drug->form_id = isset($form_id_array[$x]) ? $form_id_array[$x] : $drug->form_id;
|
||||
$drug->unit_id = isset($unit_id_array[$x]) ? $unit_id_array[$x] : $drug->unit_id;
|
||||
$drug->store_stock = isset($store_stock_array[$x]) ? $store_stock_array[$x] : $drug->store_stock;
|
||||
$drug->pharmacy_stock = isset($pharmacy_stock_array[$x]) ? $pharmacy_stock_array[$x] : $drug->pharmacy_stock;
|
||||
$drug->reorder_level = isset($reorder_level_array[$x]) ? $reorder_level_array[$x] : $drug->reorder_level;
|
||||
$drug->long_term = isset($long_term_array[$x]) ? $long_term_array[$x] : $drug->long_term;
|
||||
$drug->hssip = isset($hssip_array[$x]) ? $hssip_array[$x] : $drug->hssip;
|
||||
$drug->insurance_coverage = 0;
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug->save();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
flash("Drugs have been updated")->success();
|
||||
return redirect("/drugs/");
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_all_prompts() {
|
||||
$drugs = Drug::orderBy('name', 'asc')->get();
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There is no active drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.edit.all_prompts', compact('drugs'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update_all_prompts(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
//'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$id_array = $request->id;
|
||||
|
||||
$name_array = $request->name;
|
||||
$prompt_array = $request->prompt;
|
||||
$info_vernacular_array = $request->info_vernacular;
|
||||
$info_english_array = $request->info_english;
|
||||
$pharmacy_comment_array = $request->pharmacy_comment;
|
||||
|
||||
for ($x = 0; $x < count($id_array); $x++) {
|
||||
$drug = Drug::find($id_array[$x]);
|
||||
|
||||
$drug->name = isset($name_array[$x]) ? $name_array[$x] : $drug->name;
|
||||
$drug->prompt = isset($prompt_array[$x]) ? $prompt_array[$x] : $drug->prompt;
|
||||
$drug->info_vernacular = isset($info_vernacular_array[$x]) ? $info_vernacular_array[$x] : $drug->info_vernacular;
|
||||
$drug->info_english = isset($info_english_array[$x]) ? $info_english_array[$x] : $drug->info_english;
|
||||
$drug->pharmacy_comment = isset($pharmacy_comment_array[$x]) ? $pharmacy_comment_array[$x] : $drug->pharmacy_comment;
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug->save();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
flash("Drug Prompts have been updated")->success();
|
||||
return redirect("/drugs/");
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_all_pricing() {
|
||||
$drugs = Drug::orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There is no active drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.edit.all_pricing', compact('drugs'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update_all_pricing(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
//'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$id_array = $request->id;
|
||||
|
||||
$name_array = $request->name;
|
||||
$cost_price_array = $request->cost_price;
|
||||
$non_insured_price_array = $request->non_insured_price;
|
||||
$pricing_factor_infant_array = $request->pricing_factor_infant;
|
||||
$pricing_factor_children_array = $request->pricing_factor_children;
|
||||
$pricing_factor_adult_array = $request->pricing_factor_adult;
|
||||
$ip_daily_cost_adult_array = $request->ip_daily_cost_adult;
|
||||
$ip_daily_cost_children_array = $request->ip_daily_cost_children;
|
||||
$ip_daily_cost_infant_array = $request->ip_daily_cost_infant;
|
||||
|
||||
for ($x = 0; $x < count($id_array); $x++) {
|
||||
$drug = Drug::find($id_array[$x]);
|
||||
|
||||
$drug->name = isset($name_array[$x]) ? $name_array[$x] : $drug->name;
|
||||
$drug->cost_price = isset($cost_price_array[$x]) ? $cost_price_array[$x] : $drug->cost_price;
|
||||
$drug->non_insured_price = isset($non_insured_price_array[$x]) ? $non_insured_price_array[$x] : $drug->non_insured_price;
|
||||
$drug->insured_price = 0;
|
||||
$drug->pricing_factor_infant = isset($pricing_factor_infant_array[$x]) ? $pricing_factor_infant_array[$x] : $drug->pricing_factor_infant;
|
||||
$drug->pricing_factor_children = isset($pricing_factor_children_array[$x]) ? $pricing_factor_children_array[$x] : $drug->pricing_factor_children;
|
||||
$drug->pricing_factor_adult = isset($pricing_factor_adult_array[$x]) ? $pricing_factor_adult_array[$x] : $drug->pricing_factor_adult;
|
||||
$drug->ip_daily_cost_adult = isset($ip_daily_cost_adult_array[$x]) ? $ip_daily_cost_adult_array[$x] : $drug->ip_daily_cost_adult;
|
||||
$drug->ip_daily_cost_children = isset($ip_daily_cost_children_array[$x]) ? $ip_daily_cost_children_array[$x] : $drug->ip_daily_cost_children;
|
||||
$drug->ip_daily_cost_infant = isset($ip_daily_cost_infant_array[$x]) ? $ip_daily_cost_infant_array[$x] : $drug->ip_daily_cost_infant;
|
||||
$drug->ip_daily_cost_adult_insured = 0;
|
||||
$drug->ip_daily_cost_children_insured = 0;
|
||||
$drug->ip_daily_cost_infant_insured = 0;
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug->save();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
flash("Drugs Pricing have been updated")->success();
|
||||
return redirect("/drugs/");
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_all_calculations() {
|
||||
$drugs = Drug::orderBy('name', 'asc')->get();
|
||||
|
||||
$drug_forms = DrugForm::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
|
||||
if (count($drugs) < 1) {
|
||||
flash()->error("There is no active drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.edit.all_calculations', compact('drugs', 'drug_forms'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update_all_calculations(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
//'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$id_array = $request->id;
|
||||
|
||||
$name_array = $request->name;
|
||||
$form_array = $request->form_id;
|
||||
$pack_array = $request->pack;
|
||||
$strength_array = $request->strength;
|
||||
|
||||
for ($x = 0; $x < count($id_array); $x++) {
|
||||
$drug = Drug::find($id_array[$x]);
|
||||
|
||||
$drug->name = $name_array[$x];
|
||||
$drug->form_id = $form_array[$x];
|
||||
$drug->pack = $pack_array[$x];
|
||||
$drug->strength = $strength_array[$x];
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug->save();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
flash("Drug Calculations have been updated")->success();
|
||||
|
||||
// This data is needed for redirection
|
||||
$drugs = Drug::orderBy('name', 'asc')->get();
|
||||
$drug_forms = DrugForm::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
|
||||
return view('clinical_data::drugs.edit.all_calculations', compact('drugs', 'drug_forms'));
|
||||
}
|
||||
}
|
||||
|
||||
public function bulk_create() {
|
||||
$drug_categories = DrugCategory::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$drug_categories = ['' => '- select -'] + $drug_categories;
|
||||
|
||||
$drug_units = DrugUnit::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$drug_units = ['' => '- select -'] + $drug_units;
|
||||
|
||||
$drug_forms = DrugForm::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$drug_forms = ['' => '- select -'] + $drug_forms;
|
||||
|
||||
$suppliers = Supplier::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$suppliers = ['' => '- select -'] + $suppliers;
|
||||
|
||||
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$inventory_asset_accounts = ChartOfAccount::where(['type' => 10])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$income_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
|
||||
$inventory_asset_accounts = ['' => '- select -'] + $inventory_asset_accounts;
|
||||
$income_accounts = ['' => '- select -'] + $income_accounts;
|
||||
|
||||
|
||||
return view('clinical_data::drugs.bulk_create', compact('drug_categories', 'drug_units', 'drug_forms', 'suppliers',
|
||||
'income_accounts', 'inventory_asset_accounts', 'cost_of_goods_accounts'));
|
||||
}
|
||||
|
||||
public function bulk_store(Request $request) {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$counter = 0;
|
||||
|
||||
$name_array = $request->name;
|
||||
$category_id_array = $request->category_id;
|
||||
$form_id_array = $request->form_id;
|
||||
$unit_id_array = $request->unit_id;
|
||||
$prompt_array = $request->prompt;
|
||||
$info_english_array = $request->info_english;
|
||||
$info_vernacular_array = $request->info_vernacular;
|
||||
$store_stock_array = $request->store_stock;
|
||||
$reorder_level_array = $request->reorder_level;
|
||||
$expiry_date_array = $request->expiry_date;
|
||||
$supplier_id_array = $request->supplier_id;
|
||||
$cost_price_array = $request->cost_price;
|
||||
$non_insured_price_array = $request->non_insured_price;
|
||||
$account_id_array = $request->account_id;
|
||||
$inventory_account_array = $request->inventory_account;
|
||||
$cost_of_goods_account_array = $request->cog_account;
|
||||
$description_array = $request->description;
|
||||
|
||||
for ($x = 0; $x < count($name_array); $x++) {
|
||||
if ($name_array[$x]) {
|
||||
$counter += 1;
|
||||
$drug = new Drug;
|
||||
|
||||
$drug->name = $name_array[$x];
|
||||
$drug->category_id = $category_id_array[$x];
|
||||
$drug->form_id = $form_id_array[$x];
|
||||
$drug->unit_id = $unit_id_array[$x];
|
||||
$drug->prompt = $prompt_array[$x];
|
||||
$drug->info_english = $info_english_array[$x];
|
||||
$drug->info_vernacular = $info_vernacular_array[$x];
|
||||
$drug->store_stock = $store_stock_array[$x];
|
||||
$drug->reorder_level = $reorder_level_array[$x];
|
||||
$drug->expiry_date = $expiry_date_array[$x];
|
||||
$drug->supplier_id = $supplier_id_array[$x];
|
||||
$drug->insurance_coverage = 0;
|
||||
$drug->cost_price = $cost_price_array[$x];
|
||||
$drug->non_insured_price = $non_insured_price_array[$x];
|
||||
$drug->insured_price = 0;
|
||||
$drug->account_id = $account_id_array[$x];
|
||||
$drug->cost_of_goods_account = $cost_of_goods_account_array[$x];
|
||||
$drug->inventory_account = $inventory_account_array[$x];
|
||||
$drug->description = $description_array[$x];
|
||||
$drug->created_by = $logged_in_user_id;
|
||||
$drug->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug->save();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flash($counter . " drugs have been saved")->success();
|
||||
return redirect("/drugs/");
|
||||
}
|
||||
|
||||
public function edit_purchase_packaging(Request $request, $id)
|
||||
{
|
||||
$drug = Drug::find($id);
|
||||
|
||||
if (!$drug) {
|
||||
flash()->error("There is no such drug");
|
||||
return redirect('/drugs/');
|
||||
} else {
|
||||
return view('clinical_data::drugs.edit.items_purchase_packaging', compact('drug'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update_purchase_packaging(Request $request)
|
||||
{
|
||||
$drug = Drug::find($request->id);
|
||||
$drug->does_package_unit_have_sub_packages = $request->does_package_unit_have_sub_packages;
|
||||
$drug->quantity_in_each_package_unit = $request->quantity_in_each_package_unit;
|
||||
$drug->quantity_in_each_sub_package = $request->quantity_in_each_sub_package;
|
||||
$drug->number_of_sub_packages_in_main_package_unit = $request->number_of_sub_packages_in_main_package;
|
||||
$drug->update();
|
||||
|
||||
return redirect('drugs');
|
||||
}
|
||||
|
||||
public function get_drug_store_stock($id){
|
||||
$drug = Drug::find($id);
|
||||
|
||||
if ($drug) {
|
||||
$stock_level = $this->itemsStockService->getItemAllQuantityByTotal($id, 1);
|
||||
|
||||
if ($stock_level > 0) {
|
||||
$message =' <br><span style="color: darkgreen"><b>'.$stock_level.' Units in Stock</b></span>';
|
||||
} else {
|
||||
$message = ' <br><span style="color: darkorange"><b>Drug is out of stock</b></span>';
|
||||
}
|
||||
} else {
|
||||
$message = "";
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
}
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\DrugForm;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class DrugFormController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:drug-form-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:drug-form-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:drug-form-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:drug-form-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**create
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$drug_forms = DrugForm::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
return view('clinical_data::drug_forms.index', compact('drug_forms'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::drug_forms.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;
|
||||
$drug_form = new DrugForm;
|
||||
|
||||
$drug_form->name = $request->name;
|
||||
$drug_form->created_by = $logged_in_user_id;
|
||||
$drug_form->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug_form->save();
|
||||
flash($request->name . " drug form has been saved")->success();
|
||||
return redirect("/drug_forms/");
|
||||
} 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) {
|
||||
$drug_form = DrugForm::where(['id' => $id])->first();
|
||||
|
||||
if (!$drug_form) {
|
||||
flash()->error("Drug Form not found");
|
||||
return redirect('/drug_forms/');
|
||||
} else {
|
||||
return view('clinical_data::drug_forms.edit', compact('drug_form'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$drug_form = DrugForm::find($id);
|
||||
$drug_form->name = $request->name;
|
||||
$drug_form->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug_form->save();
|
||||
flash($request->name . " Drug Form has been updated")->success();
|
||||
return redirect("/drug_forms/");
|
||||
} 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) {
|
||||
$drug_form = DrugForm::find($id);
|
||||
|
||||
if ($drug_form->delete()){
|
||||
flash("Form has been deleted.")->success();
|
||||
return redirect('/drug_forms/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$drug_forms = DrugForm::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($drug_forms) < 1) {
|
||||
flash()->error("There is no inactive Forms");
|
||||
return redirect('/drug_forms/');
|
||||
} else {
|
||||
return view('clinical_data::drug_forms.inactive', compact('drug_forms'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$drug_form = DrugForm::withTrashed()->find($id);
|
||||
|
||||
if ($drug_form->restore()){
|
||||
flash("Form has been activated.")->success();
|
||||
return redirect('/drug_forms/');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Streamline\Http\Controllers\Controller;
|
||||
use Streamline\Models\DrugRoute;
|
||||
|
||||
class DrugRouteController extends Controller {
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:drug-route-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:drug-route-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:drug-route-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:drug-route-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**create
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index() {
|
||||
$drug_routes = DrugRoute::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
return view('clinical_data::drug_routes.index', compact('drug_routes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the route for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::drug_routes.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$drug_route = new DrugRoute;
|
||||
|
||||
$drug_route->name = $request->name;
|
||||
$drug_route->created_by = $logged_in_user_id;
|
||||
$drug_route->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug_route->save();
|
||||
flash($request->name . " drug route has been saved")->success();
|
||||
return redirect("/drug_routes/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the route for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function edit($id) {
|
||||
$drug_route = DrugRoute::where(['id' => $id])->first();
|
||||
|
||||
if (!$drug_route) {
|
||||
flash()->error("Drug route not found");
|
||||
return redirect('/drug_routes/');
|
||||
} else {
|
||||
return view('clinical_data::drug_routes.edit', compact('drug_route'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$drug_route = DrugRoute::find($id);
|
||||
$drug_route->name = $request->name;
|
||||
$drug_route->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug_route->save();
|
||||
flash($request->name . " Drug route has been updated")->success();
|
||||
return redirect("/drug_routes/");
|
||||
} 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) {
|
||||
$drug_route = DrugRoute::find($id);
|
||||
|
||||
if ($drug_route->delete()){
|
||||
flash("route has been deleted.")->success();
|
||||
return redirect('/drug_routes/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$drug_routes = DrugRoute::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($drug_routes) < 1) {
|
||||
flash()->error("There is no inactive routes");
|
||||
return redirect('/drug_routes/');
|
||||
} else {
|
||||
return view('clinical_data::drug_routes.inactive', compact('drug_routes'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$drug_route = DrugRoute::withTrashed()->find($id);
|
||||
|
||||
if ($drug_route->restore()){
|
||||
flash("route has been activated.")->success();
|
||||
return redirect('/drug_routes/');
|
||||
}
|
||||
}
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\DrugUnit;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class DrugUnitController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:drug-unit-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:drug-unit-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:drug-unit-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:drug-unit-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$drug_units = DrugUnit::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
return view('clinical_data::drug_units.index', compact('drug_units'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::drug_units.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;
|
||||
$drug_unit = new DrugUnit;
|
||||
|
||||
$drug_unit->name = $request->name;
|
||||
$drug_unit->created_by = $logged_in_user_id;
|
||||
$drug_unit->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug_unit->save();
|
||||
flash($request->name . " Drug Unit has been saved")->success();
|
||||
return redirect("/drug_units/");
|
||||
} 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) {
|
||||
$drug_unit = DrugUnit::where(['id' => $id])->first();
|
||||
|
||||
if (!$drug_unit) {
|
||||
flash()->error("There is no such Unit");
|
||||
return redirect('/drug_units/');
|
||||
} else {
|
||||
return view('clinical_data::drug_units.edit', compact('drug_unit'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$drug_unit = DrugUnit::find($id);
|
||||
$drug_unit->name = $request->name;
|
||||
$drug_unit->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$drug_unit->save();
|
||||
flash($request->name . " Drug Unit has been updated")->success();
|
||||
return redirect("/drug_units/");
|
||||
} 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) {
|
||||
$drug_unit = DrugUnit::find($id);
|
||||
|
||||
if ($drug_unit->delete()):
|
||||
flash("Drug Unit has been deleted.")->success();
|
||||
return redirect('/drug_units/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$drug_units = DrugUnit::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($drug_units) < 1) {
|
||||
flash()->error("There is no inactive drug unit");
|
||||
return redirect('/drug_units/');
|
||||
} else {
|
||||
return view('clinical_data::drug_units.inactive', compact('drug_units'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$drug_unit = DrugUnit::withTrashed()->find($id);
|
||||
|
||||
if ($drug_unit->restore()){
|
||||
flash("Drug Unit has been activated.")->success();
|
||||
return redirect('/drug_units/');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\EyeClinicMainExam;
|
||||
use Streamline\Models\EyeGlasses;
|
||||
use Streamline\Http\Controllers\Controller;
|
||||
use Streamline\Models\OrderedEyeGlasses;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Services\ItemsStockService;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class EyeGlassesController extends Controller {
|
||||
public function __construct(private ItemsStockService $itemsStockService) {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:eye_glasses-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:eye_glasses-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:eye_glasses-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:eye_glasses-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index() {
|
||||
$eye_glasses = EyeGlasses::orderBy('name', 'asc')->get();
|
||||
|
||||
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
|
||||
return view('clinical_data::eye_glasses.index', compact('eye_glasses', 'chart_of_accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create() {
|
||||
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$inventory_asset_accounts = ChartOfAccount::where(['type' => 10])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$chart_of_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
|
||||
$inventory_asset_accounts = ['' => '- select -'] + $inventory_asset_accounts;
|
||||
$chart_of_accounts = ['' => '- select -'] + $chart_of_accounts;
|
||||
|
||||
return view('clinical_data::eye_glasses.create', compact('chart_of_accounts', 'cost_of_goods_accounts', 'inventory_asset_accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
request()->validate([
|
||||
'name' => 'required',
|
||||
'price' => 'required',
|
||||
'account_id' => 'required'
|
||||
]);
|
||||
|
||||
//validation passed
|
||||
$eye_glass = new EyeGlasses;
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$eye_glass->name = $request->name;
|
||||
$eye_glass->buying_price = $request->price;
|
||||
$eye_glass->non_insured_price = $request->non_insured_price;
|
||||
$eye_glass->account_id = $request->account_id;
|
||||
$eye_glass->cost_of_goods_account = $request->cost_of_goods_account;
|
||||
$eye_glass->inventory_account = $request->inventory_account;
|
||||
$eye_glass->created_by = $logged_in_user_id;
|
||||
$eye_glass->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$eye_glass->save();
|
||||
flash($request->name . " Eye glasses has been saved")->success();
|
||||
return redirect("/opticals/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred!")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id) {
|
||||
$eye_glass = EyeGlasses::where(['id' => $id])->first();
|
||||
|
||||
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$inventory_asset_accounts = ChartOfAccount::where(['type' => 10])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$chart_of_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
|
||||
$inventory_asset_accounts = ['' => '- select -'] + $inventory_asset_accounts;
|
||||
$chart_of_accounts = ['' => '- select -'] + $chart_of_accounts;
|
||||
|
||||
if (!$eye_glass) {
|
||||
flash()->error("Eye Glasses not found");
|
||||
return redirect('/opticals/');
|
||||
} else {
|
||||
return view('clinical_data::eye_glasses.edit', compact('eye_glass', 'chart_of_accounts', 'cost_of_goods_accounts', 'inventory_asset_accounts'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
request()->validate([
|
||||
'name' => 'required',
|
||||
'account_id' => 'required'
|
||||
]);
|
||||
|
||||
//validation passed
|
||||
$eye_glass = EyeGlasses::find($id);
|
||||
$eye_glass->name = $request->name;
|
||||
$eye_glass->buying_price = $request->buying_price;
|
||||
$eye_glass->non_insured_price = $request->non_insured_price;
|
||||
$eye_glass->cost_of_goods_account = $request->cost_of_goods_account;
|
||||
$eye_glass->inventory_account = $request->inventory_account;
|
||||
$eye_glass->account_id = $request->account_id;
|
||||
|
||||
try {
|
||||
$eye_glass->save();
|
||||
flash($request->name . " Eye glasses has been updated")->success();
|
||||
return redirect("/opticals/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred!")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id) {
|
||||
$eye_glass = EyeGlasses::find($id);
|
||||
|
||||
if ($eye_glass->delete()):
|
||||
flash("Eye glasses has been deleted.")->success();
|
||||
return redirect('/opticals/');
|
||||
endif;
|
||||
}
|
||||
|
||||
public function inactive() {
|
||||
$eye_glasses = EyeGlasses::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
|
||||
return view('clinical_data::eye_glasses.inactive', compact('eye_glasses', 'chart_of_accounts'));
|
||||
}
|
||||
|
||||
public function activate($id) {
|
||||
$eye_glass = EyeGlasses::withTrashed()->find($id);
|
||||
|
||||
if ($eye_glass->restore()):
|
||||
flash("Eye glasses have been activated.")->success();
|
||||
return redirect('/opticals/inactive');
|
||||
endif;
|
||||
}
|
||||
public function get_optical_pricing(Request $request){
|
||||
$item_id = $request->item;
|
||||
$patient_id = $request->patient_id;
|
||||
$patient_insurance_status = $request->patient_insurance_status ?? 0;
|
||||
$optical = EyeGlasses::find($item_id);
|
||||
if(is_numeric($patient_insurance_status) && $patient_insurance_status == 1 && $patient_id != 0 && is_numeric($patient_id)) {
|
||||
$selling_price = get_item_insurance_co_payment($patient_id, $optical->id, 7, false, 0);
|
||||
} else {
|
||||
// check if the patient category is attached to a price list
|
||||
$price_list_id = is_patient_category_attached_to_price_list($patient_id);
|
||||
if ($price_list_id) {
|
||||
$selling_price = get_price_list_category_price($price_list_id, 7, $optical->id);
|
||||
} else {
|
||||
$selling_price = get_name($optical->id, "id", "non_insured_price", "eye_glasses");
|
||||
}
|
||||
}
|
||||
if (stock_levels_to_consider() == 0) {
|
||||
$total_stock = $this->itemsStockService->getItemAllQuantityByTotal($optical->id, 7);
|
||||
} else {
|
||||
$total_stock = $this->itemsStockService->getItemPharmacyQuantity($optical->id, 7);
|
||||
}
|
||||
$out_of_stock = $total_stock < 1;
|
||||
$out_of_stock = ($out_of_stock)?1:0;
|
||||
$drug_expiry_date = $this->itemsStockService->getItemLatestExpiryDate($optical->id, 7) ?? $optical->expiry_date;
|
||||
if (Carbon::createFromFormat('Y-m-d', $drug_expiry_date)->isBefore(Carbon::tomorrow())) {
|
||||
$optical_is_expired = 1;
|
||||
} else {
|
||||
$optical_is_expired = 0;
|
||||
}
|
||||
return response()->json(['selling_price' => $selling_price,'total_stock'=>$out_of_stock,'expiry'=>$optical_is_expired]);
|
||||
}
|
||||
public function order(){
|
||||
$patient_id = session()->get('patient_id');
|
||||
$episode_id = session()->get('episode_id');
|
||||
$patient = Patient::where('id', $patient_id)->first();
|
||||
|
||||
$eye_glasses = EyeGlasses::orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$ordered_eye_glasses = OrderedEyeGlasses::where([
|
||||
'patient_id' => $patient_id,
|
||||
'episode_id' => $episode_id,
|
||||
'payment_status' => 0
|
||||
])->first();
|
||||
|
||||
return view('clinical_data::eye_glasses.order', compact('patient', 'patient_id', 'episode_id', 'eye_glasses', 'ordered_eye_glasses'));
|
||||
}
|
||||
|
||||
public function submit_order(Request $request){
|
||||
if(is_null($request->optical_id) || is_null($request->optical_id[0])) {
|
||||
flash("No optical item has been selected")->error();
|
||||
return back()->withInput();
|
||||
} else {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$episode_id = session()->get('episode_id');
|
||||
|
||||
$optical_ids_array = $request->optical_id;
|
||||
$quantity_array = $request->item_quantity;
|
||||
|
||||
if (isset($request->order_id) && get_name($request->order_id, 'id', 'payment_status', 'ordered_eye_glasses') == 0) {
|
||||
$optical_order = OrderedEyeGlasses::find($request->order_id);
|
||||
$optical_order->updated_by = Auth::id();
|
||||
} else {
|
||||
$optical_order = new OrderedEyeGlasses;
|
||||
$optical_order->patient_id = $patient_id;
|
||||
$optical_order->episode_id = $episode_id;
|
||||
$optical_order->payment_status = 0;
|
||||
$optical_order->created_by = Auth::id();
|
||||
}
|
||||
|
||||
$optical_order->eye_glasses_id = implode(",", $optical_ids_array);
|
||||
$optical_order->quantity = implode(",", $quantity_array);
|
||||
$optical_order->save();
|
||||
|
||||
flash("Optical Items have been saved")->success();
|
||||
|
||||
// redirect to consultation or patient_episode page depending on where the user is from
|
||||
if (session()->has('redirect_to_consultation')) {
|
||||
$url = session()->get('redirect_to_consultation');
|
||||
session()->forget('redirect_to_consultation');
|
||||
return redirect($url);
|
||||
} else {
|
||||
return redirect("/patient_episodes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function cancel_ordered_glasses($order_id) {
|
||||
$orders = OrderedEyeGlasses::where(['id' => $order_id, 'payment_status' => 0])->delete();
|
||||
|
||||
if ($orders) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\GeneralItem;
|
||||
use Streamline\Models\UnitOfMeasure;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Streamline\Models\GeneralItemStoreStockReconciliation;
|
||||
|
||||
class GeneralItemsController extends Controller
|
||||
{
|
||||
// public function __construct() {
|
||||
// $this->middleware('auth');
|
||||
// $this->middleware('permission:general_items-list', ['only' => ['index']]);
|
||||
// $this->middleware('permission:general_items-create', ['only' => ['create', 'store']]);
|
||||
// $this->middleware('permission:general_items-edit', ['only' => ['edit', 'update']]);
|
||||
// $this->middleware('permission:general_items-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
// }
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$general_items = GeneralItem::get();
|
||||
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
$expense_accounts = ChartOfAccount::where(['type' => 2])
|
||||
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$payables_accounts = ChartOfAccount::where(['type' => 6])
|
||||
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
return view('clinical_data::general_items.index', compact('general_items', 'chart_of_accounts', 'payables_accounts', 'expense_accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])
|
||||
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$expense_accounts = ChartOfAccount::where(['type' => 2])
|
||||
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$payables_accounts = ChartOfAccount::where(['type' => 6])
|
||||
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
|
||||
$expense_accounts = ['' => '- select -'] + $expense_accounts;
|
||||
$payables_accounts = ['' => '- select -'] + $payables_accounts;
|
||||
|
||||
return view('clinical_data::general_items.create', compact('cost_of_goods_accounts', 'payables_accounts', 'expense_accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'cost_price' => 'required'
|
||||
]);
|
||||
|
||||
$general_item = new GeneralItem();
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$general_item->name = $request->name;
|
||||
$general_item->cost_price = $request->cost_price;
|
||||
$general_item->expenses_account_id = $request->expenses_account_id;
|
||||
$general_item->payables_account_id = $request->payables_account_id;
|
||||
//$general_item->supplier_id = $request->supplier_id;
|
||||
//$general_item->store_stock = $request->store_stock;
|
||||
//$general_item->cost_of_goods_account = $request->cost_of_goods_account;
|
||||
//$general_item->item_type = $request->item_type;
|
||||
$general_item->created_by = $logged_in_user_id;
|
||||
$general_item->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$general_item->save();
|
||||
flash("General item has been saved")->success();
|
||||
return redirect("/general_items/");
|
||||
} catch (QueryException $e) {
|
||||
flash("Something went wrong. Please try again")->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)
|
||||
{
|
||||
$general_item = GeneralItem::where(['id' => $id])->first();
|
||||
$units = UnitOfMeasure::get();
|
||||
|
||||
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])
|
||||
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$expenses_accounts = ChartOfAccount::where(['type' => 2])
|
||||
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$payables_accounts = ChartOfAccount::where(['type' => 6])
|
||||
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
|
||||
$expenses_accounts = ['' => '- select -'] + $expenses_accounts;
|
||||
$payables_accounts = ['' => '- select -'] + $payables_accounts;
|
||||
|
||||
|
||||
if (!$general_item) {
|
||||
flash()->error("General item not found");
|
||||
return redirect('/general_items/');
|
||||
} else {
|
||||
return view('clinical_data::general_items.edit', compact('general_item', 'payables_accounts', 'expenses_accounts', 'cost_of_goods_accounts'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'cost_price' => 'required',
|
||||
]);
|
||||
|
||||
//validation passed
|
||||
$general_item = GeneralItem::find($id);
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$general_item->name = $request->name;
|
||||
$general_item->cost_price = $request->cost_price;
|
||||
$general_item->expenses_account_id = $request->expenses_account_id;
|
||||
$general_item->payables_account_id = $request->payables_account_id;
|
||||
$general_item->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$general_item->save();
|
||||
flash("General item has been updated")->success();
|
||||
return redirect("/general_items/");
|
||||
} 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)
|
||||
{
|
||||
$general_item = GeneralItem::find($id);
|
||||
|
||||
if ($general_item->delete()) {
|
||||
flash("The item has been deleted.")->success();
|
||||
return redirect('/general_items/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
|
||||
*/
|
||||
public function inactive() {
|
||||
$general_items = GeneralItem::onlyTrashed()->get();
|
||||
$expense_accounts = ChartOfAccount::where(['type' => 2])
|
||||
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$payables_accounts = ChartOfAccount::where(['type' => 6])
|
||||
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
|
||||
|
||||
if (count($general_items) < 1) {
|
||||
flash()->error("There is no inactive General Item");
|
||||
return redirect('/general_items/');
|
||||
} else {
|
||||
return view('clinical_data::general_items.inactive', compact('general_items', 'expense_accounts', 'payables_accounts'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function activate($id) {
|
||||
$general_item = GeneralItem::withTrashed()->find($id);
|
||||
|
||||
if($general_item->restore()){
|
||||
flash("A general item has been activated.")->success();
|
||||
return redirect('/general_items/inactive');
|
||||
}
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\HmisCategory;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class HmisCategoryController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:hmis-category-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:hmis-category-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:hmis-category-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:hmis-category-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index() {
|
||||
$hmis_categories = HmisCategory::orderBy('title', 'asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::hmis_categories.index', compact('hmis_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::hmis_categories.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
request()->validate([
|
||||
'title' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
$hmis_category = new HmisCategory;
|
||||
|
||||
$hmis_category->title = $request->title;
|
||||
$hmis_category->number = $request->number;
|
||||
$hmis_category->type = $request->type;
|
||||
$hmis_category->created_by = $logged_in_user_id;
|
||||
$hmis_category->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$hmis_category->save();
|
||||
flash($request->title . " HMIS Category has been saved")->success();
|
||||
return redirect("/hmis_categories/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
*/
|
||||
public function edit($id) {
|
||||
$hmis_category = HmisCategory::where(['id' => $id])->first();
|
||||
|
||||
if (!$hmis_category) {
|
||||
flash()->error("There is no such HMIS Category");
|
||||
return redirect('/hmis_categories/');
|
||||
} else {
|
||||
return view('clinical_data::hmis_categories.edit', compact('hmis_category'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
request()->validate([
|
||||
'title' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
$hmis_category = HmisCategory::find($id);
|
||||
|
||||
$hmis_category->title = $request->title;
|
||||
$hmis_category->number = $request->number;
|
||||
$hmis_category->type = $request->type;
|
||||
$hmis_category->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$hmis_category->save();
|
||||
flash($request->title . " HMIS Category has been updated")->success();
|
||||
return redirect("/hmis_categories/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
*/
|
||||
public function destroy($id) {
|
||||
$hmis_category = HmisCategory::find($id);
|
||||
|
||||
if ($hmis_category->delete()):
|
||||
flash("HMIS Category has been deleted.")->success();
|
||||
return redirect('/hmis_categories/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
*/
|
||||
public function inactive() {
|
||||
$hmis_categories = HmisCategory::onlyTrashed()
|
||||
->orderBy('title', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (empty($hmis_categories)) {
|
||||
flash()->error("There is no inactive HMIS Category");
|
||||
return redirect('/hmis_categories/');
|
||||
} else {
|
||||
return view('clinical_data::hmis_categories.inactive', compact('hmis_categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function activate($id) {
|
||||
$hmis_category = HmisCategory::withTrashed()->find($id);
|
||||
|
||||
if ($hmis_category->restore()):
|
||||
flash("HMIS Category has been activated.")->success();
|
||||
return redirect('/hmis_categories/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\HmisCategory;
|
||||
use Streamline\Models\HmisCategoryOptions;
|
||||
use Illuminate\Database\QueryException;
|
||||
class HmisCategoryOptionsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$hmis_categories = HmisCategory::orderBy('title', 'asc')->select("id","number","title","type","section_number")->get()->toArray();
|
||||
$category_options = HmisCategoryOptions::orderBy('name', 'asc')->select("id","name","number","hmis_category_id")->get();
|
||||
|
||||
return view('clinical_data::hmis_categories_options.index', compact('hmis_categories','category_options'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$hmis_categories = HmisCategory::orderBy('title', 'asc')->get();
|
||||
return view('clinical_data::hmis_categories_options.create', compact('hmis_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'number' => 'required',
|
||||
'hmis_category' => 'required'
|
||||
]);
|
||||
|
||||
$option = new HmisCategoryOptions;
|
||||
|
||||
$option->name = $request->name;
|
||||
$option->number = $request->number;
|
||||
$option->hmis_category_id = $request->hmis_category;
|
||||
$option->created_by = Auth()->user()->id;
|
||||
|
||||
try {
|
||||
$option->save();
|
||||
flash($request->name . " HMIS Category Option has been saved")->success();
|
||||
return redirect("/hmis_categories_options/");
|
||||
} 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)
|
||||
{
|
||||
$option = HmisCategoryOptions::findOrFail($id);
|
||||
$type = HmisCategory::find($option->hmis_category_id);
|
||||
$hmis_categories = HmisCategory::orderBy('title', 'asc')->get()->toArray();
|
||||
return view('clinical_data::hmis_categories_options.edit', compact('option', 'hmis_categories', 'type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'number' => 'required',
|
||||
'hmis_category' => 'required'
|
||||
]);
|
||||
$option = HmisCategoryOptions::findOrFail($id);
|
||||
|
||||
$option->name = $request->name;
|
||||
$option->number = $request->number;
|
||||
$option->hmis_category_id = $request->hmis_category;
|
||||
$option->updated_by = Auth()->user()->id;
|
||||
try {
|
||||
$option->save();
|
||||
flash($request->name . " HMIS Category Option has been updated.")->success();
|
||||
return redirect("/hmis_categories_options/");
|
||||
} 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)
|
||||
{
|
||||
$option = HmisCategoryOptions::findOrFail($id);
|
||||
|
||||
if ($option->delete()) {
|
||||
flash("HMIS Category Option has been deleted.")->success();
|
||||
return redirect('/hmis_categories_options/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
*/
|
||||
public function inactive() {
|
||||
$options = HmisCategoryOptions::onlyTrashed()->orderBy('name', 'asc')->paginate(50);
|
||||
return view('clinical_data::hmis_categories_options.inactive', compact('options'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function activate($id) {
|
||||
$option = HmisCategoryOptions::withTrashed()->find($id);
|
||||
|
||||
if ($option->restore()):
|
||||
flash("HMIS Category Option has been activated.")->success();
|
||||
return redirect('/hmis_categories_options/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
public function get_hmis_type_options (Request $request) {
|
||||
$options = HmisCategory::where('type', $request->type)->get();
|
||||
$data ='<option value="" selected disabled>- Select HMIS Category -</option>';
|
||||
foreach($options as $option){
|
||||
$data .= '<option value="'.$option->id.'">'.$option->title.'</option>';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\AgeGroup;
|
||||
use Streamline\Models\Observation;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class ObservationController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:observation-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:observation-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:observation-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:observation-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$observations = Observation::orderBy('name', 'asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::observations.index', compact('observations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create() {
|
||||
$age_groups = AgeGroup::orderBy('name', 'asc')
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
|
||||
return view('clinical_data::observations.create', compact('age_groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$observation = new Observation;
|
||||
$observation->name = $request->name;
|
||||
$observation->measurement = $request->measurement;
|
||||
|
||||
if ($request->options_or_range == "2") {
|
||||
$options = implode(',', $request->options);
|
||||
|
||||
if ($options == "") {
|
||||
flash("Please select options for this observation")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
|
||||
$observation->options = $options;
|
||||
}
|
||||
|
||||
$observation->option_for_normal = $request->option_for_normal;
|
||||
$observation->lower_limit = $request->lower_limit;
|
||||
$observation->upper_limit = $request->upper_limit;
|
||||
|
||||
if(is_array($request->age_group)){
|
||||
$age_group = implode(',', $request->age_group);
|
||||
} else {
|
||||
$age_group = "";
|
||||
}
|
||||
|
||||
$observation->age_group = $age_group;
|
||||
$observation->slug = str_replace(' ', '_', strtolower($request->name));
|
||||
$observation->compulsory = $request->compulsory;
|
||||
$observation->created_by = $logged_in_user_id;
|
||||
$observation->updated_by = $logged_in_user_id;
|
||||
try {
|
||||
$observation->save();
|
||||
flash($request->name . " Observation has been saved")->success();
|
||||
return redirect("/observations/");
|
||||
} 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) {
|
||||
$observation = Observation::where(['id' => $id])->first();
|
||||
|
||||
$age_groups = AgeGroup::orderBy('name', 'asc')
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
|
||||
if (!$observation) {
|
||||
flash()->error("There is no such observation");
|
||||
return redirect('/observations/');
|
||||
} else {
|
||||
return view('clinical_data::observations.edit', compact('observation', 'age_groups'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$observation = Observation::find($id);
|
||||
$observation->name = $request->name;
|
||||
$observation->measurement = $request->measurement;
|
||||
|
||||
if ($request->options_or_range == "2") {
|
||||
if (!is_array($request->options)) {
|
||||
flash("Please select options for this observation")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
|
||||
$options = implode(',', $request->options);
|
||||
|
||||
$observation->options = $options;
|
||||
} else {
|
||||
$observation->options = NULL;
|
||||
}
|
||||
|
||||
$observation->option_for_normal = $request->option_for_normal;
|
||||
$observation->lower_limit = $request->lower_limit;
|
||||
$observation->upper_limit = $request->upper_limit;
|
||||
|
||||
if(is_array($request->age_group)){
|
||||
$age_group = implode(',', $request->age_group);
|
||||
} else {
|
||||
$age_group = "";
|
||||
}
|
||||
|
||||
$observation->age_group = $age_group;
|
||||
$observation->compulsory = $request->compulsory;
|
||||
$observation->created_by = $logged_in_user_id;
|
||||
$observation->updated_by = $logged_in_user_id;
|
||||
try {
|
||||
$observation->save();
|
||||
flash($request->name . " Observation has been updated")->success();
|
||||
return redirect("/observations/");
|
||||
} 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) {
|
||||
$observation = Observation::find($id);
|
||||
|
||||
if ($observation->delete()):
|
||||
flash("Observation has been deleted.")->success();
|
||||
return redirect('/observations/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$observations = Observation::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($observations) < 1) {
|
||||
flash()->error("There is no inactive observation");
|
||||
return redirect('/observations/');
|
||||
} else {
|
||||
return view('clinical_data::observations.inactive', compact('observations'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$observation = Observation::withTrashed()->find($id);
|
||||
|
||||
if ($observation->restore()){
|
||||
flash("Observation has been activated.")->success();
|
||||
return redirect('/observations/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
public function get_observation_info($id) {
|
||||
$observation = Observation::find($id);
|
||||
|
||||
$return_data = [];
|
||||
|
||||
if ($observation) {
|
||||
$return_data["error"] = 0;
|
||||
$return_data["slug"] = $observation->slug;
|
||||
$return_data["normal_range"] = $observation->lower_limit . ' - ' . $observation->upper_limit;
|
||||
} else {
|
||||
$return_data["error"] = 1;
|
||||
}
|
||||
|
||||
return json_encode($return_data);
|
||||
}
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\Occupation;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class OccupationController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:occupation-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:occupation-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:occupation-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:occupation-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:occupation-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:occupation-status', ['only'=>['inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$occupations = Occupation::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
return view('clinical_data::occupations.index', compact('occupations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::occupations.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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|min:4"
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
flash($string)->error();
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$occupation = new Occupation;
|
||||
|
||||
$occupation->name = $request->name;
|
||||
$occupation->created_by = Auth::user()->id;
|
||||
$occupation->updated_by = Auth::user()->id;
|
||||
|
||||
try {
|
||||
$occupation->save();
|
||||
flash($request->name . " Occupation has been saved")->success();
|
||||
return redirect("/occupations/");
|
||||
} 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) {
|
||||
$occupation = Occupation::where(['id' => $id])->first();
|
||||
|
||||
if (!$occupation) {
|
||||
flash()->error("Occupation not found");
|
||||
return redirect('/occupations/');
|
||||
} else {
|
||||
return view('clinical_data::occupations.edit', compact('occupation'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'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 {
|
||||
//validation passed
|
||||
$occupation = Occupation::find($id);
|
||||
$occupation->name = $request->name;
|
||||
|
||||
try {
|
||||
$occupation->save();
|
||||
flash($request->name . " Occupation has been updated")->success();
|
||||
return redirect("/occupations/");
|
||||
} 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) {
|
||||
$occupation = Occupation::find($id);
|
||||
|
||||
if ($occupation->delete()):
|
||||
flash("Occupation has been deleted.")->success();
|
||||
return redirect('/occupations/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$occupations = Occupation::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($occupations) < 1) {
|
||||
flash()->error("There is no inactive occupation");
|
||||
return redirect('/occupations/');
|
||||
} else {
|
||||
// Log::info($occupations);
|
||||
return view('clinical_data::occupations.inactive', compact('occupations'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$occupation = Occupation::withTrashed()->find($id);
|
||||
|
||||
if ($occupation->restore()):
|
||||
flash("Occupation has been activated.")->success();
|
||||
return redirect('/occupations/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+296
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\Outcome;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class OutcomeController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:outcome-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:outcome-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:outcome-edit', ['only' => ['edit', 'update', 'edit_all', 'update_all']]);
|
||||
$this->middleware('permission:outcome-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$outcomes = Outcome::orderBy('name', 'asc')->paginate(2000);
|
||||
|
||||
return view('clinical_data::outcomes.index', compact('outcomes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('clinical_data::outcomes.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;
|
||||
$outcome = new Outcome;
|
||||
|
||||
$outcome->name = $request->name;
|
||||
$outcome->created_by = $logged_in_user_id;
|
||||
$outcome->updated_by = $logged_in_user_id;
|
||||
try {
|
||||
$outcome->save();
|
||||
flash($request->name . " Outcome has been saved")->success();
|
||||
return redirect("/outcomes/");
|
||||
} 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)
|
||||
{
|
||||
$outcome = Outcome::where(['id' => $id])->first();
|
||||
|
||||
if (!$outcome) {
|
||||
flash()->error("There is no such outcome");
|
||||
return redirect('/outcomes/');
|
||||
} else {
|
||||
return view('clinical_data::outcomes.edit', compact('outcome'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$outcome = Outcome::find($id);
|
||||
$outcome->name = $request->name;
|
||||
$outcome->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$outcome->save();
|
||||
flash($request->name . " Outcome has been updated")->success();
|
||||
return redirect("/outcomes/");
|
||||
} 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)
|
||||
{
|
||||
$outcome = Outcome::find($id);
|
||||
|
||||
if ($outcome->delete()) {
|
||||
flash("Outcome has been deleted.")->success();
|
||||
return redirect('/outcomes/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive()
|
||||
{
|
||||
$outcomes = Outcome::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($outcomes) < 1) {
|
||||
flash()->error("There is no inactive outcome");
|
||||
return redirect('/outcomes/');
|
||||
} else {
|
||||
return view('clinical_data::outcomes.inactive', compact('outcomes'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id)
|
||||
{
|
||||
$outcome = Outcome::withTrashed()->find($id);
|
||||
|
||||
if ($outcome->restore()) {
|
||||
flash("Outcome has been activated.")->success();
|
||||
return redirect('/outcomes/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search a resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
$query_name = $request->query_name;
|
||||
$query_active = $request->query_active;
|
||||
|
||||
if ($query_name != "") {
|
||||
$outcomes = Outcome::where([
|
||||
['active', '=', $query_active],
|
||||
['name', 'LIKE', '%' . $query_name . '%']
|
||||
])
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(10)
|
||||
->setPath('');
|
||||
|
||||
$outcomes->appends(array(
|
||||
'query_name' => $query_name,
|
||||
'query_active' => $query_active
|
||||
));
|
||||
|
||||
if (count($outcomes)) {
|
||||
if ($query_active) {
|
||||
return view('clinical_data::outcomes.index', compact('outcomes')) //;
|
||||
->withDetails($outcomes)
|
||||
->withQuery($query_name, $query_active);
|
||||
} else {
|
||||
return view('clinical_data::outcomes.inactive', compact('outcomes')) //;
|
||||
->withDetails($outcomes)
|
||||
->withQuery($query_name, $query_active);
|
||||
}
|
||||
}
|
||||
}
|
||||
flash()->error("No Details found. Try searching again!");
|
||||
return redirect('/outcomes/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the active resources for bulk editing.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit_all()
|
||||
{
|
||||
$outcomes = Outcome::orderBy('name', 'asc')->paginate(2000);
|
||||
|
||||
if (count($outcomes) < 1) {
|
||||
flash()->error("There is no active outcome");
|
||||
return redirect('/outcomes/');
|
||||
} else {
|
||||
return view('clinical_data::outcomes.edit.all', compact('outcomes'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all the resources in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update_all(Request $request)
|
||||
{
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$id_array = $request->id;
|
||||
$name_array = $request->name;
|
||||
|
||||
for ($x = 0; $x < count($id_array); $x++) {
|
||||
$outcome = Outcome::find($id_array[$x]);
|
||||
|
||||
$outcome->name = $name_array[$x];
|
||||
$outcome->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$outcome->save();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
flash("Outcomes have been updated")->success();
|
||||
return redirect("/outcomes/");
|
||||
}
|
||||
|
||||
public function get_outcomes()
|
||||
{
|
||||
//code to be returned to view
|
||||
$code = "<option> -- select -- </option>";
|
||||
|
||||
$outcomes = Outcome::orderBy('name', 'asc')->get();
|
||||
|
||||
foreach ($outcomes as $outcome) {
|
||||
$code .= "<option value='" . $outcome->id . "'>" . $outcome->name . "</option>";
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/* test server side scolling with datatables */
|
||||
public function datatable_test()
|
||||
{
|
||||
$outcomes = Outcome::orderBy('name', 'asc')->get();
|
||||
|
||||
return response()->json($outcomes);
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\PackageUnit;
|
||||
|
||||
class PackageUnitController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$package_units = PackageUnit::orderBy('name', 'asc')->get();
|
||||
|
||||
return view('clinical_data::package_units.index', compact('package_units'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('clinical_data::package_units.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;
|
||||
$package_unit = new PackageUnit;
|
||||
|
||||
$package_unit->name = $request->name;
|
||||
$package_unit->created_by = $logged_in_user_id;
|
||||
$package_unit->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$package_unit->save();
|
||||
flash($request->name . " has been saved")->success();
|
||||
return redirect("/package_unit/");
|
||||
} 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(PackageUnit $package_unit)
|
||||
{
|
||||
if (!$package_unit) {
|
||||
flash()->error("There is no such Unit of Measure");
|
||||
return redirect('/package_unit/');
|
||||
} else {
|
||||
return view('clinical_data::package_units.edit', compact('package_unit'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
$package_unit = PackageUnit::find($id);
|
||||
|
||||
$package_unit->name = $request->name;
|
||||
$package_unit->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$package_unit->save();
|
||||
flash($request->name . " has been updated")->success();
|
||||
return redirect("/package_unit/");
|
||||
} 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(PackageUnit $package_unit)
|
||||
{
|
||||
if ($package_unit->delete()):
|
||||
flash($package_unit->name." has been deleted.")->success();
|
||||
return redirect('/package_unit/');
|
||||
endif;
|
||||
|
||||
flash('Unable to delete package unit')->error();
|
||||
return redirect('package_unit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$package_units = PackageUnit::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
if (count($package_units) < 1) {
|
||||
flash()->error("There is no inactive package unit");
|
||||
return redirect('/package_unit/');
|
||||
} else {
|
||||
return view('clinical_data::package_units.inactive', compact('package_units'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$package_unit = PackageUnit::withTrashed()->find($id);
|
||||
|
||||
if ($package_unit->restore()):
|
||||
flash("Unit has been activated.")->success();
|
||||
return redirect('/package_unit_inactive');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\PatientCategory;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Streamline\Models\Patient;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class PatientCategoryController extends Controller
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:patient_category-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:patient_category-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:patient_category-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:patient_category-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:patient_category-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:patient_category-status', ['only' => ['activate, inactive']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$patient_categories = PatientCategory::orderBy('name', 'asc')->get();
|
||||
|
||||
$used_categories = Patient::distinct('category_id')->get(['category_id']);
|
||||
$used_categories_data = [];
|
||||
foreach ($used_categories as $value) if(!empty($value->category_id)) $used_categories_data[] = $value->category_id;
|
||||
|
||||
return view('clinical_data::patient_categories.index', compact('patient_categories', 'used_categories_data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('clinical_data::patient_categories.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
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;
|
||||
$patient_category = new PatientCategory;
|
||||
|
||||
$patient_category->name = $request->name;
|
||||
$patient_category->available = $request->available;
|
||||
if ($request->set_credit_limit == 1 && $request->credit_limit != 0) {
|
||||
$patient_category->credit_limit = $request->credit_limit;
|
||||
}
|
||||
$patient_category->created_by = $logged_in_user_id;
|
||||
$patient_category->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$patient_category->save();
|
||||
flash($request->name . " Patient Category has been saved")->success();
|
||||
return redirect("/patient_categories/");
|
||||
} 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)
|
||||
{
|
||||
$patient_categories = PatientCategory::where(['id' => $id])->first();
|
||||
|
||||
if (!$patient_categories) {
|
||||
flash()->error("There is no such category");
|
||||
} else {
|
||||
return view('clinical_data::patient_categories.edit', compact('patient_categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'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 {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$patient_category = PatientCategory::find($id);
|
||||
$patient_category->name = $request->name;
|
||||
$patient_category->available = $request->available;
|
||||
$patient_category->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$patient_category->save();
|
||||
flash($request->name . " Patient Category has been updated")->success();
|
||||
return redirect("/patient_categories/");
|
||||
} 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)
|
||||
{
|
||||
$patient_categories = PatientCategory::find($id);
|
||||
if ($patient_categories->delete()):
|
||||
flash("Category has been deleted.")->success();
|
||||
return redirect('/patient_categories/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$patient_categories = PatientCategory::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(10);
|
||||
|
||||
if (empty($patient_categories)) {
|
||||
flash()->error("There is no inactive patient category");
|
||||
return redirect('/patient_categories/');
|
||||
} else {
|
||||
return view('clinical_data::patient_categories.inactive', compact('patient_categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$patient_category = PatientCategory::withTrashed()->find($id);
|
||||
|
||||
if ($patient_category->restore()):
|
||||
flash("Patient Category has been activated.")->success();
|
||||
return redirect('/patient_categories/');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Http\Controllers\Auth;
|
||||
use Streamline\Http\Controllers\Controller;
|
||||
use Streamline\Models\PatientRegistrationField;
|
||||
|
||||
class PatientRegistrationFieldController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:list-patient-registration-fields', ['only' => ['index', 'select']]);
|
||||
$this->middleware('permission:create-patient-registration-field', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:edit-patient-registration-field', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:delete-patient-registration-field', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$patient_registration_fields = PatientRegistrationField::orderBy('name', 'asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::patient_registration_fields.index', compact('patient_registration_fields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('clinical_data::patient_registration_fields.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|string|max:255|unique:patient_registration_fields',
|
||||
'compulsory'=> 'required|in:1,0'
|
||||
]);
|
||||
|
||||
$patient_registration_field = new PatientRegistrationField();
|
||||
$patient_registration_field->name = $request->name;
|
||||
$patient_registration_field->compulsory = $request->compulsory;
|
||||
$patient_registration_field->options = ($request->options_or_range == '2')? implode(',', $request->options):null;
|
||||
$patient_registration_field->created_by = Auth::id();
|
||||
|
||||
try {
|
||||
$patient_registration_field->save();
|
||||
flash($request->name . " Patient registration field has been saved")->success();
|
||||
return redirect("/patient_registration_fields/");
|
||||
} 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)
|
||||
{
|
||||
$patient_registration_field = PatientRegistrationField::findOrFail($id);
|
||||
return view('clinical_data::patient_registration_fields.edit', compact('patient_registration_field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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|string|max:255|unique:patient_registration_fields,name,'.$id,
|
||||
'compulsory'=> 'required|in:1,0'
|
||||
]);
|
||||
|
||||
$patient_registration_field = PatientRegistrationField::find($id);
|
||||
$patient_registration_field->name = $request->name;
|
||||
$patient_registration_field->compulsory = $request->compulsory;
|
||||
$patient_registration_field->options = ($request->options_or_range == '2')? implode(',', $request->options):null;
|
||||
$patient_registration_field->updated_by = Auth::id();
|
||||
try {
|
||||
$patient_registration_field->save();
|
||||
flash($request->name . " Patient registration field has been updated")->success();
|
||||
return redirect("/patient_registration_fields/");
|
||||
} 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)
|
||||
{
|
||||
$patient_registration_field = PatientRegistrationField::findOrFail($id);
|
||||
|
||||
if ($patient_registration_field->delete()) {
|
||||
flash("Patient Registration Field has been deleted.")->success();
|
||||
return redirect('/patient_registration_fields/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resources.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive()
|
||||
{
|
||||
$patient_registration_fields = PatientRegistrationField::onlyTrashed()->orderBy('created_at', 'desc')->paginate(50);
|
||||
|
||||
return view('clinical_data::patient_registration_fields.inactive', compact('patient_registration_fields'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id)
|
||||
{
|
||||
$patient_registration_field = PatientRegistrationField::onlyTrashed()->findOrFail($id);
|
||||
|
||||
if ($patient_registration_field->restore()) {
|
||||
flash("Patient Registration Field has been activated.")->success();
|
||||
return redirect('/patient_registration_fields/');
|
||||
} else {
|
||||
flash()->error("Patient Registration Field hasn't been activated.");
|
||||
return redirect()->route('patient_registration_fields.inactive');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+173
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\ProcedureCategory;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class ProcedureCategoriesController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:procedure-category-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:procedure-category-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:procedure-category-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:procedure-category-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$categories = ProcedureCategory::orderBy('name', 'asc') ->paginate(50);
|
||||
|
||||
return view('clinical_data::procedure_categories.index', compact('categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::procedure_categories.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
|
||||
$procedure_category = new ProcedureCategory;
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$procedure_category->name = $request->name;
|
||||
$procedure_category->created_by = $logged_in_user_id;
|
||||
$procedure_category->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$procedure_category->save();
|
||||
flash($request->name . " Procedure Category has been saved")->success();
|
||||
return redirect("/procedure_categories/");
|
||||
} 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) {
|
||||
$categories = ProcedureCategory::where(['id' => $id])->first();
|
||||
|
||||
if (!$categories) {
|
||||
flash()->error("Procedure Category not found");
|
||||
return redirect("/procedure_categories/");
|
||||
} else {
|
||||
return view('clinical_data::procedure_categories.edit', compact('categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
//validation passed
|
||||
$procedure_category = ProcedureCategory::find($id);
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$procedure_category->name = $request->name;
|
||||
$procedure_category->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$procedure_category->save();
|
||||
flash($request->name . " Procedure Category has been updated")->success();
|
||||
return redirect("/procedure_categories/");
|
||||
} 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) {
|
||||
$procedure_categories = ProcedureCategory::find($id);
|
||||
|
||||
if ($procedure_categories->delete()):
|
||||
flash("Category has been deleted.")->success();
|
||||
return redirect('/procedure_categories/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$categories = ProcedureCategory::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($categories) < 1) {
|
||||
flash()->error("There is no inactive Category");
|
||||
return redirect('/procedure_categories/');
|
||||
} else {
|
||||
return view('clinical_data::procedure_categories.inactive', compact('categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$procedure_categories = ProcedureCategory::withTrashed()->find($id);
|
||||
|
||||
if ($procedure_categories->restore()):
|
||||
flash("Category has been activated.")->success();
|
||||
return redirect('/procedure_categories/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+562
@@ -0,0 +1,562 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Http\Controllers\StreamlineSetupManager;
|
||||
use Streamline\Models\Alert;
|
||||
use Streamline\Models\Allergy;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\InsuranceClaim;
|
||||
use Streamline\Models\PatientDocument;
|
||||
use Streamline\Models\PriceListCategories;
|
||||
use Streamline\Models\Procedure;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Models\PatientEpisode;
|
||||
use Streamline\Models\OrderedProcedure;
|
||||
use Streamline\Models\ProcedureCategory;
|
||||
use Streamline\Models\Consultation;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Streamline\Models\HmisCategory;
|
||||
use Streamline\Services\StreamlineSetupServiceInterface;
|
||||
class ProcedureController extends Controller {
|
||||
protected StreamlineSetupServiceInterface $setupService;
|
||||
public function __construct(StreamlineSetupServiceInterface $setupService) {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:procedure-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:procedure-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:procedure-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:procedure-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
$this->setupService = $setupService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$procedures = Procedure::where('available', 1)->orderBy('name', 'asc')->get();
|
||||
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
|
||||
$ordered_procedures_array = [];
|
||||
$ordered_procedures = OrderedProcedure::distinct('procedure_id')->get(['procedure_id']);
|
||||
foreach ($ordered_procedures as $ordered_procedure) {
|
||||
$actual = explode(',', $ordered_procedure->procedure_id);
|
||||
foreach ($actual as $value) $ordered_procedures_array[] = $value;
|
||||
}
|
||||
$ordered_procedures_ids = array_unique($ordered_procedures_array);
|
||||
|
||||
$categories = ProcedureCategory::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
$hmis_categories = DB::table('hmis_categories')->orderBy('title', 'asc')->pluck('title', 'id')->toArray();
|
||||
|
||||
return view('clinical_data::procedures.index', compact('procedures', 'chart_of_accounts', 'categories', 'hmis_categories', 'ordered_procedures_ids'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
$procedure_categories = ProcedureCategory::pluck('name', 'id')
|
||||
->toArray();
|
||||
|
||||
$procedure_categories = ['' => '- select -'] + $procedure_categories;
|
||||
|
||||
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
|
||||
$chart_of_accounts = ['' => '- select -'] + $chart_of_accounts;
|
||||
|
||||
$procedures = StreamlineSetupManager::get_procedures_array();
|
||||
|
||||
$hmis_categories = HmisCategory::all('title', 'id','number','type', 'section_number')->toArray();
|
||||
|
||||
return view('clinical_data::procedures.create', compact('procedure_categories', 'chart_of_accounts','procedures', 'hmis_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
if (session()->has('streamline_setup')){
|
||||
//skip validation
|
||||
} else {
|
||||
request()->validate([
|
||||
'name' => 'required',
|
||||
'non_insured_price' => 'required',
|
||||
'account_id' => 'required',
|
||||
'category' => 'required',
|
||||
'procedure_type' => 'required',
|
||||
'hmis_category_inpatient'=>'nullable|required_if:procedure_type,1|required_with:hmis_category_inpatient_options',
|
||||
'hmis_category_inpatient_options'=>'nullable|required_with:hmis_category_inpatient',
|
||||
'hysterectomy_type'=>'nullable|required_if:hmis_category_inpatient_options,5'
|
||||
]);
|
||||
}
|
||||
if (session()->has('streamline_setup')&& isset($request->skip)){
|
||||
//update the streamline setup table with the new finished step
|
||||
$this->setupService->saveStep("procedures registration", 1);
|
||||
return redirect("sundries/create");
|
||||
}
|
||||
|
||||
// get all current price lists
|
||||
$price_list = PriceListCategories::withTrashed()->select('id')->get();
|
||||
$price_list_category = [];
|
||||
$price_list_price = [];
|
||||
|
||||
foreach ($price_list as $record){
|
||||
array_push($price_list_category, $record->id);
|
||||
array_push($price_list_price, $request->non_insured_price);
|
||||
}
|
||||
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
$procedure = new Procedure;
|
||||
|
||||
$procedure->name = $request->name;
|
||||
$procedure->code = $request->code;
|
||||
$procedure->reference_link = !empty($request->reference_link)? implode(',',$request->reference_link):null;
|
||||
$procedure->reference_text = !empty($request->reference_text)? implode(',',$request->reference_text):null;
|
||||
$procedure->non_insured_price = $request->non_insured_price;
|
||||
$procedure->insured_price = 0;
|
||||
$procedure->available = $request->available;
|
||||
|
||||
if (isset($request->price_list_category_id) && isset($request->price_list_price)) {
|
||||
$procedure->price_list_category = !is_null($request->price_list_category_id) ? implode(",", $request->price_list_category_id) : null;
|
||||
$procedure->price_list_price = !is_null($request->price_list_price) ? implode(",", $request->price_list_price) : null;
|
||||
} else {
|
||||
$procedure->price_list_category = implode(",", $price_list_category);
|
||||
$procedure->price_list_price = implode(",", $price_list_price);
|
||||
}
|
||||
|
||||
$procedure->account_id = $request->account_id;
|
||||
$procedure->category_id = $request->category;
|
||||
$procedure->hmis_number = $request->hmis_number;
|
||||
/*== hmis stuff =====*/
|
||||
$procedure->hmis_no_outpatient = (!empty($request->hmis_no_outpatient[0]))? implode(",", $request->hmis_no_outpatient) : null;
|
||||
$procedure->hmis_category = is_array($request->hmis_category) ? implode(",", $request->hmis_category) : "";
|
||||
$procedure->hmis_no_inpatient = ($request->hmis_category_inpatient_options != '5')? $request->hmis_category_inpatient_options:$request->hysterectomy_type;
|
||||
$procedure->hmis_category_inpatient = $request->hmis_category_inpatient;
|
||||
$procedure->hmis_inpatient_type = $request->procedure_type;
|
||||
/*===================*/
|
||||
$procedure->created_by = $logged_in_user_id;
|
||||
$procedure->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
if ($procedure->name != "" && !is_null($procedure->name)) {
|
||||
$procedure->save();
|
||||
}
|
||||
|
||||
flash($request->name . " Procedure has been saved")->success();
|
||||
|
||||
if (session()->has('streamline_setup')) {
|
||||
if (isset($request->selected_procedures)) {
|
||||
$selected_procedures_array = $request->selected_procedures;
|
||||
if (!empty($selected_procedures_array)) {
|
||||
|
||||
for ($i=0; $i < count($selected_procedures_array) ; $i++) {
|
||||
/* try this magic to get details for the selected service */
|
||||
$procedures_array = StreamlineSetupManager::get_procedures_array();
|
||||
$key = array_search($selected_procedures_array[$i], array_column($procedures_array, 'Procedure_Name'));
|
||||
$procedure_details = $procedures_array[$key];
|
||||
/* end of magic trial */
|
||||
|
||||
$default_procedure = new Procedure;
|
||||
$default_procedure->name = $procedure_details['Procedure_Name'];
|
||||
$default_procedure->insured_price = 0;
|
||||
$default_procedure->non_insured_price = 0;
|
||||
$default_procedure->category_id = $procedure_details['Category'];
|
||||
$default_procedure->account_id = $procedure_details['Account_Id'];
|
||||
$default_procedure->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
//update the streamline setup table with the new finished step
|
||||
$this->setupService->saveStep("procedures registration", 1);
|
||||
// $streamline_setup = new \Streamline\Models\StreamlineSetupStep;
|
||||
// $streamline_setup->step = "procedures registration";
|
||||
// $streamline_setup->completion_status = 1;
|
||||
// $streamline_setup->save();
|
||||
return redirect("sundries/create");
|
||||
}
|
||||
return redirect("/procedures/");
|
||||
} 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) {
|
||||
$procedure = Procedure::where(['id' => $id])->first();
|
||||
|
||||
$procedure_categories = ProcedureCategory::pluck('name', 'id')
|
||||
->toArray();
|
||||
$procedure_categories = ['' => '- select -'] + $procedure_categories;
|
||||
|
||||
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
|
||||
$chart_of_accounts = ['' => '- select -'] + $chart_of_accounts;
|
||||
|
||||
// $hmis_categories = DB::table('hmis_categories')->orderBy('title', 'asc')->pluck('title', 'id')->toArray();
|
||||
|
||||
// $hmis_categories = ['' => '- select -'] + $hmis_categories;
|
||||
$hmis_categories_options = [];
|
||||
$hmis_categories = HmisCategory::all('title', 'id','number','type', 'section_number')->toArray();
|
||||
$categories_options = DB::table('hmis_category_options')->where('hmis_category_id', $procedure->hmis_category_inpatient)->get();
|
||||
foreach ($categories_options as $options) $hmis_categories_options[] =['id'=>$options->id, 'name'=>$options->name, 'number'=>$options->number];
|
||||
if (!$procedure) {
|
||||
flash()->error("There is no such procedure");
|
||||
return redirect('/procedures/');
|
||||
} else {
|
||||
return view('clinical_data::procedures.edit', compact('procedure', 'procedure_categories', 'chart_of_accounts', 'hmis_categories','hmis_categories_options'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'non_insured_price' => 'required',
|
||||
'account_id' => 'required',
|
||||
'category' => 'required',
|
||||
'procedure_type' => 'required',
|
||||
'hmis_category_inpatient'=>'nullable|required_if:procedure_type,1|required_with:hmis_category_inpatient_options',
|
||||
'hmis_category_inpatient_options'=>'nullable|required_with:hmis_category_inpatient',
|
||||
'hysterectomy_type'=>'nullable|required_if:hmis_category_inpatient_options,5'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$procedure = Procedure::find($id);
|
||||
|
||||
$procedure->name = $request->name;
|
||||
$procedure->code = $request->code;
|
||||
$procedure->non_insured_price = $request->non_insured_price;
|
||||
$procedure->available = $request->available;
|
||||
$procedure->reference_link = !empty($request->reference_link)? implode(',',$request->reference_link):null;
|
||||
$procedure->reference_text = !empty($request->reference_text)? implode(',',$request->reference_text):null;
|
||||
$procedure->insured_price = 0;
|
||||
$procedure->insurance = 0;
|
||||
$procedure->price_list_category = !is_null($request->price_list_category_id) ? implode(",", $request->price_list_category_id) : null;
|
||||
$procedure->price_list_price = !is_null($request->price_list_price) ? implode(",", $request->price_list_price) : null;
|
||||
$procedure->account_id = $request->account_id;
|
||||
$procedure->category_id = $request->category;
|
||||
$procedure->hmis_number = $request->hmis_number;
|
||||
/*== hmis stuff =====*/
|
||||
$procedure->hmis_no_outpatient = (!empty($request->hmis_no_outpatient[0]))? implode(",", $request->hmis_no_outpatient):null;
|
||||
// $procedure->hmis_category = implode(",", $request->hmis_category);
|
||||
/*== Hmis 108 stuff =====*/
|
||||
$procedure->hmis_no_inpatient = ($request->hmis_category_inpatient_options != '5')? $request->hmis_category_inpatient_options:$request->hysterectomy_type;
|
||||
$procedure->hmis_category_inpatient = $request->hmis_category_inpatient;
|
||||
$procedure->hmis_inpatient_type = $request->procedure_type;
|
||||
/*===================*/
|
||||
$procedure->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$procedure->save();
|
||||
flash($request->name . " Procedure has been updated")->success();
|
||||
return redirect("/procedures/");
|
||||
} 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) {
|
||||
$procedure = Procedure::find($id);
|
||||
|
||||
if ($procedure->delete()):
|
||||
flash("Procedure has been deleted.")->success();
|
||||
return redirect('/procedures/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$procedures = Procedure::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
$chart_of_accounts = DB::table('chart_of_accounts')
|
||||
->orderBy('name', 'asc')
|
||||
->pluck('name', 'id');
|
||||
|
||||
$categories = DB::table('procedure_categories')
|
||||
->orderBy('name', 'asc')
|
||||
->pluck('name', 'id');
|
||||
|
||||
if (count($procedures) < 1) {
|
||||
flash()->error("There is no inactive procedure");
|
||||
return redirect('/procedures/');
|
||||
} else {
|
||||
return view('clinical_data::procedures.inactive', compact('procedures', 'chart_of_accounts', 'categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$procedure = Procedure::withTrashed()->find($id);
|
||||
|
||||
if ($procedure->restore()):
|
||||
flash("Procedure has been activated.")->success();
|
||||
return redirect('/procedures/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Order procedures for the patient
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function order_procedures(){
|
||||
$patient_id = session()->get('patient_id');
|
||||
$episode_id = session()->get('episode_id');
|
||||
$patient = Patient::where('id', $patient_id)->first();
|
||||
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id");
|
||||
$procedures = Procedure::where('available', 1)->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$ordered_procedures = DB::table('ordered_procedures')->whereNull('deleted_at')
|
||||
->where(['patient_id'=>$patient_id, 'episode_id'=>$episode_id, 'payment_status'=>0])
|
||||
->first();
|
||||
|
||||
$users_collection = DB::table('users')->orderBy("first_name","asc")->select("id")->get()->toArray();
|
||||
$users_array = [];
|
||||
foreach ($users_collection as $value){
|
||||
$user = \Streamline\Models\User::find($value->id);
|
||||
if (!is_null($user)) {
|
||||
$users_array[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
||||
}
|
||||
}
|
||||
$users_array = ['' => '- select -'] + $users_array;
|
||||
|
||||
$employees = DB::table('users')->whereNull('deleted_at')->orderBy('first_name', 'asc')->get();
|
||||
|
||||
return view('clinical_data::procedures.order_procedures',compact('patient_id','episode_id','patient','categories','employees','procedures','ordered_procedures', 'users_array'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store ordered procedures for a patient episode
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function store_ordered_procedures(Request $request){
|
||||
if(is_null($request->procedure_id)){
|
||||
flash("No procedure has been selected")->error();
|
||||
return back()->withInput();
|
||||
} else {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$episode_id = session()->get('episode_id');
|
||||
|
||||
$procedure_ids_array = $request->procedure_id;
|
||||
$procedure_cost_array = $request->item_cost;
|
||||
$procedure_performed = [];
|
||||
$procedure_performed_id = [];
|
||||
|
||||
//loop through performed procedures and update the performed column
|
||||
$performed_procedures_array = $request->performed_procedures;
|
||||
$performed_by_array = $request->procedure_performed_by;
|
||||
$procedure_performed_by_amount = $request->procedure_performed_by_amount;
|
||||
$procedure_performed_date = $request->procedure_performed_date;
|
||||
|
||||
// filter to check if all entries have been filled for performed by and discard otherwise
|
||||
for ($i = 0; $i < count($procedure_ids_array); $i++) {
|
||||
if ($performed_procedures_array[$i] == 1 && ($performed_by_array[$i] != "" || $performed_by_array[$i] != null) &&
|
||||
($procedure_performed_by_amount[$i] != "" || $procedure_performed_by_amount[$i] != null) &&
|
||||
($procedure_performed_date[$i] != "" || $procedure_performed_date[$i] != null)) {
|
||||
$procedure_performed_id[] = record_staff_that_has_performed_the_service_with_price($patient_id, $episode_id, 1, $procedure_ids_array[$i], 0,
|
||||
$performed_by_array[$i], $procedure_performed_by_amount[$i], $procedure_performed_date[$i]);
|
||||
$procedure_performed[] = 1;
|
||||
} else {
|
||||
$procedure_performed[] = 0;
|
||||
$procedure_performed_id[] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($request->order_id) && get_name($request->order_id, 'id', 'payment_status', 'ordered_procedures') == 0) {
|
||||
$procedure_order = OrderedProcedure::find($request->order_id);
|
||||
|
||||
// delete the previous preformed_by_ids
|
||||
try {
|
||||
DB::table('staff_performed_services')->whereIn('id', explode(",", $procedure_order->performed_id))->delete();
|
||||
} catch (\Exception $e) {}
|
||||
} else {
|
||||
$procedure_order = new OrderedProcedure;
|
||||
$procedure_order->patient_id = $patient_id;
|
||||
$procedure_order->episode_id = $episode_id;
|
||||
$procedure_order->payment_status = 0; //0 by default to mean not paid
|
||||
$procedure_order->created_by = auth()->user()->id;
|
||||
}
|
||||
|
||||
$procedure_order->procedure_id = implode(",", $procedure_ids_array);
|
||||
$procedure_order->procedure_amount = implode(",", $procedure_cost_array);
|
||||
$procedure_order->performed = implode(",", $procedure_performed);
|
||||
$procedure_order->performed_id = implode(",", $procedure_performed_id);
|
||||
$procedure_order->eye = implode(",", $request->eye);
|
||||
$procedure_order->updated_by = auth()->user()->id;
|
||||
$procedure_order->save();
|
||||
|
||||
// create an insurance claim for the ordered items
|
||||
if ($request->patient_insurance_status == 1) {
|
||||
generate_insurance_claim($procedure_order->id, 2);
|
||||
}
|
||||
|
||||
flash("Procedures have been saved")->success();
|
||||
|
||||
// redirect to consultation or patient_episode page depending on where the user is from
|
||||
if (session()->has('redirect_to_consultation')) {
|
||||
$url = session()->get('redirect_to_consultation');
|
||||
session()->forget('redirect_to_consultation');
|
||||
return redirect($url);
|
||||
} elseif (session()->has('anc_visit_redirect')) {
|
||||
$url = session()->get('anc_visit_redirect');
|
||||
session()->forget('anc_visit_redirect');
|
||||
return redirect($url);
|
||||
} else {
|
||||
if(session()->has('previous_action') && session()->get('previous_action') == 'anc_consultation_page') {
|
||||
return redirect("ante_natal_clinic/route");
|
||||
session()->forget('previous_action');
|
||||
}
|
||||
else return redirect("/patient_episodes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fetch_procedure_performance_fee(Request $request) {
|
||||
$patient_id = $request->patient_id;
|
||||
$patient_category_id = get_name($patient_id, 'id', 'category_id', 'patients');
|
||||
$performed_by = $request->performed_by;
|
||||
$item_id = $request->item_id;
|
||||
|
||||
$price_list_category_details = \Streamline\Models\PriceListCategories::where(['patient_category_id' => $patient_category_id])->first();
|
||||
|
||||
if ($price_list_category_details) {
|
||||
$price_list_category_id = $price_list_category_details->id;
|
||||
|
||||
$fees_array = get_item_price_and_performance_fee_based_on_price_list_category($performed_by, $item_id, 1, $price_list_category_id);
|
||||
|
||||
return ($fees_array[1] == 0) ? $fees_array[0] : $fees_array[1];
|
||||
} else {
|
||||
//do this for cases where the there are no price lists for the patient's patient_category
|
||||
$fees_array = get_item_price_and_performance_fee_array_without_price_list($item_id, $performed_by, 1);
|
||||
|
||||
return ($fees_array[1] == 0) ? $fees_array[0] : $fees_array[1];
|
||||
}
|
||||
}
|
||||
|
||||
public function cancel_ordered_procedures($order_id) {
|
||||
$ordered_procedure = OrderedProcedure::find($order_id);
|
||||
|
||||
try {
|
||||
$ordered_procedure->delete();
|
||||
|
||||
// check if there are any insurance claims available
|
||||
$claim = InsuranceClaim::where('order_id', $order_id)->where('item_type', 2)->first();
|
||||
|
||||
if ($claim) {
|
||||
$claim->delete();
|
||||
}
|
||||
|
||||
return 1;
|
||||
} catch (\Exception $exception) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_procedure_details(Request $request) {
|
||||
$patient_id = $request->patient_id;
|
||||
$patient_insurance_status = $request->patient_insurance_status ?? 0;
|
||||
$is_inpatient = $request->is_inpatient == 1;
|
||||
$ward_id = $request->ward_id ?? 0;
|
||||
|
||||
$procedure = DB::table('procedures')->find($request->procedure_id);
|
||||
|
||||
if(is_numeric($patient_insurance_status) && $patient_insurance_status == 1 && $patient_id != 0 && is_numeric($patient_id)) {
|
||||
$selling_price = get_item_insurance_co_payment($patient_id, $procedure->id, 2, $is_inpatient, $ward_id);
|
||||
} else {
|
||||
// check if the patient category is attached to a price list
|
||||
$price_list_id = is_patient_category_attached_to_price_list($patient_id);
|
||||
if ($price_list_id) {
|
||||
$selling_price = get_price_list_category_price($price_list_id, 4, $procedure->id);
|
||||
} else {
|
||||
$selling_price = $procedure->non_insured_price;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_chi_enabled() && is_patient_item_covered($patient_id, $procedure->id, 2)) {
|
||||
$covered_by_chi = ' <br><span style="color: darkgreen"><b>Covered by CHI</b></span>';
|
||||
} else {
|
||||
$covered_by_chi = "";
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
"selling_price" => $selling_price,
|
||||
"covered_by_chi" => $covered_by_chi,
|
||||
]);
|
||||
}
|
||||
public function get_hmis_categories_options(Request $request) {
|
||||
$options = DB::table('hmis_category_options')->where('hmis_category_id', $request->hmis_category)->orderBy('name', 'asc')->get();
|
||||
$data ='<option value="" selected disabled>- Select HMIS category Option -</option>';
|
||||
foreach($options as $option){
|
||||
$data .= '<option value="'.$option->id.'">'.$option->name.'</option>';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function get_dependent_hmis_category_options(Request $request) {
|
||||
$options = DB::table('hmis_category_options')->where('parent_option', $request->parent_category)->orderBy('name', 'asc')->get();
|
||||
$data ='<option value="" selected disabled>- Select Dependent Option -</option>';
|
||||
foreach($options as $option){
|
||||
$data .= '<option value="'.$option->id.'">'.$option->name.'</option>';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,481 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Streamline\Models\County;
|
||||
use Streamline\Models\District;
|
||||
use Streamline\Models\Occupation;
|
||||
use Streamline\Models\Parish;
|
||||
use Streamline\Models\Subcounty;
|
||||
use Streamline\Models\Village;
|
||||
|
||||
class ResidenceController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function get_counties($id)
|
||||
{
|
||||
$code = "<option> -- select -- </option>";
|
||||
$counties = DB::table('counties')
|
||||
->whereNull('deleted_at')
|
||||
->where(['district_id' => $id])
|
||||
->get();
|
||||
|
||||
foreach ($counties as $county) {
|
||||
$code .= "<option value='" . $county->id . "'>" . $county->name . "</option>";
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function get_subcounties($id)
|
||||
{
|
||||
$code = "<option> -- select -- </option>";
|
||||
|
||||
$subcounties = DB::table('subcounties')
|
||||
->whereNull('deleted_at')
|
||||
->where(['county_id' => $id])
|
||||
->get();
|
||||
|
||||
foreach ($subcounties as $subcounty) {
|
||||
$code .= "<option value='" . $subcounty->id . "'>" . $subcounty->name . "</option>";
|
||||
}
|
||||
|
||||
$code .= "</select>";
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function get_parishes($id)
|
||||
{
|
||||
$code = "<option> -- select -- </option>";
|
||||
|
||||
$parishes = DB::table('parishes')
|
||||
->whereNull('deleted_at')
|
||||
->where(['subcounty_id' => $id])
|
||||
->get();
|
||||
|
||||
foreach ($parishes as $parish) {
|
||||
$code .= "<option value='" . $parish->id . "'>" . $parish->name . "</option>";
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function get_villages($id)
|
||||
{
|
||||
$code = "<option> -- select -- </option>";
|
||||
|
||||
$villages = DB::table('villages')
|
||||
->whereNull('deleted_at')
|
||||
->where(['parish_id' => $id])
|
||||
->get();
|
||||
|
||||
foreach ($villages as $village) {
|
||||
$code .= "<option value='" . $village->id . "'>" . $village->name . "</option>";
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/*
|
||||
* get patient residences and send corresponding drop down options
|
||||
*/
|
||||
public function search_districts(Request $request) {
|
||||
$data = [];
|
||||
|
||||
if ($request->has('q')) {
|
||||
$search = $request->q;
|
||||
$data = DB::table('districts')->select("name", "id")
|
||||
->where('name', 'LIKE', "%$search%")
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function search_counties(Request $request) {
|
||||
$data = [];
|
||||
|
||||
if ($request->has('q')) {
|
||||
$search = $request->q;
|
||||
$data = DB::table('counties')->leftJoin('districts', 'districts.id', '=', 'counties.district_id')
|
||||
->select("counties.name", "counties.id", "districts.name as district_name")
|
||||
->where('counties.name', 'LIKE', "%$search%")
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function search_subcounties(Request $request) {
|
||||
$data = [];
|
||||
|
||||
if ($request->has('q')) {
|
||||
$search = $request->q;
|
||||
$data = DB::table('subcounties')->leftJoin('counties', 'counties.id', '=', 'subcounties.county_id')
|
||||
->select("subcounties.name", "subcounties.id", "counties.name as county_name")
|
||||
->where('subcounties.name', 'LIKE', "%$search%")
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function search_parishes(Request $request) {
|
||||
$data = [];
|
||||
|
||||
if ($request->has('q')) {
|
||||
$search = $request->q;
|
||||
$data = DB::table('parishes')->leftJoin('subcounties', 'subcounties.id', '=', 'parishes.subcounty_id')
|
||||
->select("parishes.name", "parishes.id", "subcounties.name as sub_county_name")
|
||||
->where('parishes.name', 'LIKE', "%$search%")
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function search_villages(Request $request) {
|
||||
$data = [];
|
||||
|
||||
if ($request->has('q')) {
|
||||
$search = $request->q;
|
||||
$data = DB::table('villages')->leftJoin('parishes', 'parishes.id', '=', 'villages.parish_id')
|
||||
->select("villages.name", "villages.id", "parishes.name as parish_name")
|
||||
->where('villages.name', 'LIKE', "%$search%")
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function get_residence($district_id)
|
||||
{
|
||||
//loop is going to take long execution time
|
||||
$villages_array = [];
|
||||
$parishes_array = [];
|
||||
$subcounties_array = [];
|
||||
|
||||
$counties = DB::table('counties')->where(['district_id' => $district_id])->whereNull('deleted_at')->pluck("name", "id");
|
||||
foreach ($counties as $county_id => $county_name) {
|
||||
$subcounties = DB::table('subcounties')->where(['county_id' => $county_id])->whereNull('deleted_at')->get();
|
||||
foreach ($subcounties as $subcounty) {
|
||||
$subcounties_array[$subcounty->id] = $subcounty->name;
|
||||
$parishes = DB::table('parishes')->where(['subcounty_id' => $subcounty->id])->whereNull('deleted_at')->get();
|
||||
foreach ($parishes as $parish) {
|
||||
$parishes_array[$parish->id] = $parish->name;
|
||||
$villages = DB::table('villages')->where(['parish_id' => $parish->id])->whereNull('deleted_at')->get();
|
||||
foreach ($villages as $village) {
|
||||
$villages_array[$village->id] = $village->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['subcounties' => $subcounties_array, 'parishes' => $parishes_array, 'villages' => $villages_array];
|
||||
}
|
||||
|
||||
public function get_residence_district($district_id)
|
||||
{
|
||||
//loop is going to take long execution time
|
||||
$villages_array = [];
|
||||
$parishes_array = [];
|
||||
$sub_counties_array = [];
|
||||
$counties_array = [];
|
||||
$residences_array = [];
|
||||
|
||||
$counties = DB::table('counties')->where(['district_id' => $district_id])->whereNull('deleted_at')->orderBy("name", "asc")->pluck("name", "id");
|
||||
foreach ($counties as $county_id => $county_name) {
|
||||
$counties_array[$county_id] = $county_name;
|
||||
$subcounties = DB::table('subcounties')->where(['county_id' => $county_id])->whereNull('deleted_at')->get();
|
||||
foreach ($subcounties as $subcounty) {
|
||||
$sub_counties_array[$subcounty->id] = $subcounty->name;
|
||||
$parishes = DB::table('parishes')->where(['subcounty_id' => $subcounty->id])->whereNull('deleted_at')->get();
|
||||
foreach ($parishes as $parish) {
|
||||
$parishes_array[$parish->id] = $parish->name;
|
||||
$villages = DB::table('villages')->where(['parish_id' => $parish->id])->whereNull('deleted_at')->get();
|
||||
foreach ($villages as $village) {
|
||||
$villages_array[$village->id] = $village->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$residences_array['counties'] = $counties_array;
|
||||
$residences_array['subcounties'] = $sub_counties_array;
|
||||
$residences_array['parishes'] = $parishes_array;
|
||||
$residences_array['villages'] = $villages_array;
|
||||
|
||||
return json_encode($residences_array);
|
||||
}
|
||||
|
||||
public function get_residence_county($county_id)
|
||||
{
|
||||
//loop is going to take long execution time
|
||||
$villages_array = [];
|
||||
$parishes_array = [];
|
||||
$sub_counties_array = [];
|
||||
$residences_array = [];
|
||||
|
||||
$subcounties = DB::table('subcounties')->where(['county_id' => $county_id])->whereNull('deleted_at')->orderBy("name", "asc")->get();
|
||||
foreach ($subcounties as $subcounty) {
|
||||
$sub_counties_array[$subcounty->id] = $subcounty->name;
|
||||
$parishes = DB::table('parishes')->where(['subcounty_id' => $subcounty->id])->whereNull('deleted_at')->get();
|
||||
foreach ($parishes as $parish) {
|
||||
$parishes_array[$parish->id] = $parish->name;
|
||||
$villages = DB::table('villages')->where(['parish_id' => $parish->id])->whereNull('deleted_at')->get();
|
||||
foreach ($villages as $village) {
|
||||
$villages_array[$village->id] = $village->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$residences_array['subcounties'] = $sub_counties_array;
|
||||
$residences_array['parishes'] = $parishes_array;
|
||||
$residences_array['villages'] = $villages_array;
|
||||
|
||||
return json_encode($residences_array);
|
||||
}
|
||||
|
||||
public function get_residence_sub_county($sub_county_id)
|
||||
{
|
||||
//loop is going to take long execution time
|
||||
$villages_array = [];
|
||||
$parishes_array = [];
|
||||
$residences_array = [];
|
||||
|
||||
$parishes = DB::table('parishes')->where(['subcounty_id' => $sub_county_id])->whereNull('deleted_at')->orderBy("name", "asc")->get();
|
||||
foreach ($parishes as $parish) {
|
||||
$parishes_array[$parish->id] = $parish->name;
|
||||
$villages = DB::table('villages')->where(['parish_id' => $parish->id])->whereNull('deleted_at')->get();
|
||||
foreach ($villages as $village) {
|
||||
$villages_array[$village->id] = $village->name;
|
||||
}
|
||||
}
|
||||
|
||||
$residences_array['parishes'] = $parishes_array;
|
||||
$residences_array['villages'] = $villages_array;
|
||||
|
||||
return json_encode($residences_array);
|
||||
}
|
||||
|
||||
public function get_residence_parish($parish_id)
|
||||
{
|
||||
//loop is going to take long execution time
|
||||
$villages_array = [];
|
||||
$residences_array = [];
|
||||
|
||||
$villages = DB::table('villages')->where(['parish_id' => $parish_id])->whereNull('deleted_at')->orderBy("name", "asc")->get();
|
||||
foreach ($villages as $village) {
|
||||
$villages_array[$village->id] = $village->name;
|
||||
}
|
||||
|
||||
$residences_array['villages'] = $villages_array;
|
||||
|
||||
return json_encode($residences_array);
|
||||
}
|
||||
|
||||
/* cater for adding a new occupation from a modal dynamically */
|
||||
public function add_new_occupation_dynamically(Request $request)
|
||||
{
|
||||
$occupation = new Occupation;
|
||||
$occupation->name = $request->name;
|
||||
$occupation->created_by = Auth::user()->id;
|
||||
$occupation->updated_by = Auth::user()->id;
|
||||
|
||||
try {
|
||||
$occupation->save();
|
||||
return $occupation->id;
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function add_new_district_dynamically(Request $request)
|
||||
{
|
||||
$district = new District;
|
||||
$district->name = $request->name;
|
||||
$district->created_by = Auth::user()->id;
|
||||
$district->updated_by = Auth::user()->id;
|
||||
|
||||
$check = District::where('name', $request->name)->pluck('name')->first();
|
||||
if (is_null($check)) {
|
||||
try {
|
||||
$district->save();
|
||||
return $district->id;
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
} else {
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
|
||||
public function add_new_county_dynamically(Request $request)
|
||||
{
|
||||
$county = new County;
|
||||
$county->name = $request->name;
|
||||
$county->district_id = $request->district_id;
|
||||
$county->created_by = Auth::user()->id;
|
||||
$county->updated_by = Auth::user()->id;
|
||||
|
||||
$check = County::where('name', $request->name)->pluck('name')->first();
|
||||
if (is_null($check)) {
|
||||
try {
|
||||
$county->save();
|
||||
return $county->id;
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
} else {
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
|
||||
public function add_new_subcounty_dynamically(Request $request)
|
||||
{
|
||||
$sub_county = new Subcounty;
|
||||
$sub_county->name = $request->name;
|
||||
$sub_county->county_id = $request->county_id;
|
||||
$sub_county->created_by = Auth::user()->id;
|
||||
$sub_county->updated_by = Auth::user()->id;
|
||||
|
||||
$check = Subcounty::where('name', $request->name)->pluck('name')->first();
|
||||
if (is_null($check)) {
|
||||
try {
|
||||
$sub_county->save();
|
||||
return $sub_county->id;
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
} else {
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
|
||||
public function add_new_parish_dynamically(Request $request)
|
||||
{
|
||||
$parish = new Parish;
|
||||
$parish->name = $request->name;
|
||||
$parish->subcounty_id = $request->subcounty_id;
|
||||
$parish->created_by = Auth::user()->id;
|
||||
$parish->updated_by = Auth::user()->id;
|
||||
|
||||
$check = Parish::where('name', $request->name)->pluck('name')->first();
|
||||
if (is_null($check)) {
|
||||
try {
|
||||
$parish->save();
|
||||
return $parish->id;
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
} else {
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
|
||||
public function add_new_village_dynamically(Request $request)
|
||||
{
|
||||
$village = new Village;
|
||||
$village->name = $request->name;
|
||||
$village->parish_id = $request->parish_id;
|
||||
$village->created_by = Auth::user()->id;
|
||||
$village->updated_by = Auth::user()->id;
|
||||
|
||||
$check = Village::where('name', $request->name)->pluck('name')->first();
|
||||
if (is_null($check)) {
|
||||
try {
|
||||
$village->save();
|
||||
return $village->id;
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
} else {
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
|
||||
public function quick_add_residence(Request $request)
|
||||
{
|
||||
$district_id = $request->district_id;
|
||||
$new_district_name = $request->new_district_name;
|
||||
$county_id = $request->county_id;
|
||||
$new_county_name = $request->new_county_name;
|
||||
$subcounty_id = $request->subcounty_id;
|
||||
$new_subcounty_name = $request->new_subcounty_name;
|
||||
$parish_id = $request->parish_id;
|
||||
$new_parish_name = $request->new_parish_name;
|
||||
$village_id = 0;
|
||||
$new_village_name = $request->new_village_name;
|
||||
|
||||
if (!isset($district_id) && isset($new_district_name)) {
|
||||
$district = new District;
|
||||
$district->name = $new_district_name;
|
||||
$district->created_by = Auth::user()->id;
|
||||
$district->updated_by = Auth::user()->id;
|
||||
$district->save();
|
||||
|
||||
$district_id = $district->id;
|
||||
}
|
||||
|
||||
if (!isset($county_id) && isset($new_county_name) && is_numeric($district_id)) {
|
||||
$county = new County;
|
||||
$county->name = $new_county_name;
|
||||
$county->district_id = $district_id;
|
||||
$county->created_by = Auth::user()->id;
|
||||
$county->updated_by = Auth::user()->id;
|
||||
$county->save();
|
||||
|
||||
$county_id = $county->id;
|
||||
}
|
||||
|
||||
if (!isset($subcounty_id) && isset($new_subcounty_name) && is_numeric($county_id)) {
|
||||
$sub_county = new Subcounty;
|
||||
$sub_county->name = $new_subcounty_name;
|
||||
$sub_county->county_id = $county_id;
|
||||
$sub_county->created_by = Auth::user()->id;
|
||||
$sub_county->updated_by = Auth::user()->id;
|
||||
$sub_county->save();
|
||||
|
||||
$subcounty_id = $sub_county->id;
|
||||
}
|
||||
|
||||
if (!isset($parish_id) && isset($new_parish_name) && is_numeric($subcounty_id)) {
|
||||
$parish = new Parish;
|
||||
$parish->name = $new_parish_name;
|
||||
$parish->subcounty_id = $subcounty_id;
|
||||
$parish->created_by = Auth::user()->id;
|
||||
$parish->updated_by = Auth::user()->id;
|
||||
$parish->save();
|
||||
|
||||
$parish_id = $parish->id;
|
||||
}
|
||||
|
||||
if (isset($new_village_name)) {
|
||||
$village = new Village;
|
||||
$village->name = $new_village_name;
|
||||
$village->parish_id = is_numeric($parish_id) ? $parish_id : 0;
|
||||
$village->created_by = Auth::user()->id;
|
||||
$village->updated_by = Auth::user()->id;
|
||||
$village->save();
|
||||
|
||||
$village_id = $village->id;
|
||||
}
|
||||
|
||||
return (is_numeric($village_id) ? $village_id : 0) . "," . (is_numeric($parish_id) ? $parish_id : 0) . "," . (is_numeric($subcounty_id) ? $subcounty_id : 0) . "," .
|
||||
(is_numeric($county_id) ? $county_id : 0) . "," . (is_numeric($district_id) ? $district_id : 0);
|
||||
}
|
||||
}
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\ResourceCategory;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ResourceCategoryController extends Controller
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:resource_category-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:resource_category-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:resource_category-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:resource_category-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:resource_category-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:resource_category-status', ['only'=>['inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
$resource_categories = ResourceCategory::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
return view('clinical_data::resource_categories.index', compact('resource_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
return view('clinical_data::resource_categories.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
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_category = new ResourceCategory;
|
||||
|
||||
$resource_category->name = $request->name;
|
||||
$resource_category->created_by = $logged_in_user_id;
|
||||
$resource_category->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$resource_category->save();
|
||||
flash($request->name . " Resource Category has been saved")->success();
|
||||
return redirect("/resource_categories/");
|
||||
} 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)
|
||||
{
|
||||
$resource_category = ResourceCategory::where(['id' => $id])->first();
|
||||
|
||||
if (!$resource_category) {
|
||||
flash()->error("There is no such Category");
|
||||
return redirect('/resource_categories/');
|
||||
} else {
|
||||
return view('clinical_data::resource_categories.edit', compact('resource_category'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'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 {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$resource_category = ResourceCategory::find($id);
|
||||
$resource_category->name = $request->name;
|
||||
$resource_category->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$resource_category->save();
|
||||
flash($request->name . " Resource Category has been updated")->success();
|
||||
return redirect("/resource_categories/");
|
||||
} 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)
|
||||
{
|
||||
$resource_category = ResourceCategory::find($id);
|
||||
|
||||
if ($resource_category->delete()):
|
||||
|
||||
flash("Category has been deleted.")->success();
|
||||
return redirect('/resource_categories/');
|
||||
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$resource_categories = ResourceCategory::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($resource_categories) < 1) {
|
||||
|
||||
flash()->error("There is no inactive Category");
|
||||
return redirect('/resource_categories/');
|
||||
|
||||
} else {
|
||||
return view('clinical_data::resource_categories.inactive', compact('resource_categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$resource_category = ResourceCategory::withTrashed()->find($id);
|
||||
|
||||
if ($resource_category->restore()):
|
||||
flash("Category has been activated.")->success();
|
||||
return redirect('/resource_categories/inactive');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
+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'));
|
||||
|
||||
}
|
||||
}
|
||||
+463
@@ -0,0 +1,463 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Http\Controllers\StreamlineSetupManager;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\InsuranceClaim;
|
||||
use Streamline\Models\PriceListCategories;
|
||||
use Streamline\Models\Services;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Streamline\Models\Supplier;
|
||||
use Streamline\Models\User;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Models\OrderedService;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Streamline\Services\StreamlineSetupServiceInterface;
|
||||
class ServicesController extends Controller {
|
||||
public function __construct(protected StreamlineSetupServiceInterface $setupService
|
||||
) {
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$service_items = Services::where('available', 1)->orderby('name', 'asc')->get();
|
||||
$chart_of_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$ordered_services_array = [];
|
||||
$ordered_services = OrderedService::distinct('service_id')->get(['service_id']);
|
||||
|
||||
foreach ($ordered_services as $ordered_service) {
|
||||
$ordered_services_array = array_merge($ordered_services_array, explode(',', $ordered_service->service_id));
|
||||
}
|
||||
|
||||
$ordered_service_ids = array_unique($ordered_services_array);
|
||||
|
||||
return view('clinical_data::service_items.index',compact('service_items', 'chart_of_accounts','ordered_service_ids'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(){
|
||||
$suppliers = Supplier::orderBy('name','asc')->pluck('name','id')->toArray();
|
||||
$suppliers = ['' => '- select -'] + $suppliers;
|
||||
|
||||
$chart_of_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$chart_of_accounts = ['' => '- select -'] + $chart_of_accounts;
|
||||
|
||||
$services = StreamlineSetupManager::get_services_array();
|
||||
|
||||
$users = DB::table('users')->orderBy("first_name","asc")->select("id")->get()->toArray();
|
||||
$users_array = [];
|
||||
|
||||
foreach ($users as $value){
|
||||
$user = User::find($value->id);
|
||||
if (!is_null($user)) {
|
||||
$users_array[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
||||
}
|
||||
}
|
||||
$users_array = ['' => '- Select Staff -'] + $users_array;
|
||||
|
||||
return view('clinical_data::service_items.create',compact('suppliers','chart_of_accounts','services','users_array'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
//if it for streamline setup then you can skip the request validation
|
||||
if (session()->has('streamline_setup')){
|
||||
//skip validation
|
||||
} else {
|
||||
request()->validate([
|
||||
'name' => 'required',
|
||||
]);
|
||||
}
|
||||
|
||||
if (isset($request->skip)) {
|
||||
//Artisan::call('db:seed', ['--class' => 'ServicesTableSeeder']);
|
||||
//update the streamline setup table with the new finished step
|
||||
$this->setupService->saveStep("services registration", 1);
|
||||
// $streamline_setup = new \Streamline\Models\StreamlineSetupStep;
|
||||
// $streamline_setup->step = "services registration";
|
||||
// $streamline_setup->completion_status = 1;
|
||||
// $streamline_setup->save();
|
||||
|
||||
return redirect("investigations/create");
|
||||
} else {
|
||||
// get all current price lists
|
||||
$price_list = PriceListCategories::withTrashed()->select('id')->get();
|
||||
$price_list_category = [];
|
||||
$price_list_price = [];
|
||||
|
||||
foreach ($price_list as $record){
|
||||
array_push($price_list_category, $record->id);
|
||||
array_push($price_list_price, $request->non_insured_price);
|
||||
}
|
||||
|
||||
$service_item = new Services;
|
||||
$service_item->name = $request->name;
|
||||
|
||||
if ($request->attach_to_staff_name == 1) {
|
||||
$attached_user_id = $request->user_id;
|
||||
$attached_user_name = get_full_name($attached_user_id, "id", "first_name", "last_name", "users");
|
||||
$service_item->name = $service_item->name." - ".$attached_user_name;
|
||||
}
|
||||
|
||||
$service_item->insured_price = 0;
|
||||
$service_item->available = $request->available;
|
||||
$service_item->non_insured_price = $request->non_insured_price;
|
||||
$service_item->cost_price = $request->non_insured_price;
|
||||
$service_item->account_id = $request->account_id;
|
||||
|
||||
if (isset($request->price_list_category_id) && isset($request->price_list_price)) {
|
||||
$service_item->price_list_category = !is_null($request->price_list_category_id) ? implode(",", $request->price_list_category_id) : null;
|
||||
$service_item->price_list_price = !is_null($request->price_list_price) ? implode(",", $request->price_list_price) : null;
|
||||
} else {
|
||||
$service_item->price_list_category = implode(",", $price_list_category);
|
||||
$service_item->price_list_price = implode(",", $price_list_price);
|
||||
}
|
||||
|
||||
$service_item->insurance_coverage = 0;
|
||||
$service_item->item_type = $request->type_of_service;
|
||||
$service_item->supplier_id = 0; // not necessary
|
||||
$service_item->description = $request->description;
|
||||
|
||||
try{
|
||||
if ($service_item->name != "" && !is_null($service_item->name)) {
|
||||
$service_item->save();
|
||||
}
|
||||
|
||||
flash("New service item has been added")->success();
|
||||
|
||||
if (session()->has('streamline_setup')) {
|
||||
|
||||
if (isset($request->selected_services)) {
|
||||
$selected_services_array = $request->selected_services;
|
||||
if (!empty($selected_services_array)) {
|
||||
|
||||
for ($i=0; $i < count($selected_services_array) ; $i++) {
|
||||
/* try this magic to get details for the selected service */
|
||||
$services_array = StreamlineSetupManager::get_services_array();
|
||||
$key=array_search($selected_services_array[$i], array_column($services_array, 'Item_Name'));
|
||||
$service_details = $services_array[$key];
|
||||
/* end of magic trial */
|
||||
$service_item = new Services;
|
||||
$service_item->name = $service_details['Item_Name'];
|
||||
$service_item->cost_price = $service_details['Cost_Price'];
|
||||
$service_item->insured_price = 0;
|
||||
$service_item->non_insured_price = $service_details['Non_Insured_Amount'];
|
||||
$service_item->account_id = $service_details['Account_Id'];
|
||||
$service_item->item_type = $service_details['Item_Type'];
|
||||
$service_item->description = $service_details['Description'];
|
||||
$service_item->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->setupService->saveStep("services registration", 1);
|
||||
// $streamline_setup = new \Streamline\Models\StreamlineSetupStep;
|
||||
// $streamline_setup->step = "services registration";
|
||||
// $streamline_setup->completion_status = 1;
|
||||
// $streamline_setup->save();
|
||||
return redirect("investigations/create");
|
||||
}
|
||||
return redirect('/service_items');
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
flash("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) {
|
||||
$service = Services::where(['id' => $id])->first();
|
||||
|
||||
$chart_of_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$chart_of_accounts = ['' => '- select -'] + $chart_of_accounts;
|
||||
|
||||
if (!$service) {
|
||||
flash()->error("Service not found");
|
||||
return redirect('/service_items/');
|
||||
} else {
|
||||
return view('clinical_data::service_items.edit', compact('service', 'chart_of_accounts'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id){
|
||||
$service_item = Services::find($id);
|
||||
$service_item->name = $request->name;
|
||||
$service_item->available = $request->available;
|
||||
$service_item->insured_price = 0;
|
||||
$service_item->non_insured_price = $request->non_insured_price;
|
||||
$service_item->price_list_category = !is_null($request->price_list_category_id) ? implode(",", $request->price_list_category_id) : null;
|
||||
$service_item->price_list_price = !is_null($request->price_list_price) ? implode(",", $request->price_list_price) : null;
|
||||
$service_item->account_id = $request->account_id;
|
||||
$service_item->insurance_coverage = 0;
|
||||
$service_item->item_type = $request->type_of_service;
|
||||
$service_item->description = $request->description;
|
||||
|
||||
if ($service_item->save()) {
|
||||
flash("Service item has been edited")->success();
|
||||
return redirect('/service_items');
|
||||
}
|
||||
|
||||
flash("Error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id) {
|
||||
$service = Services::find($id);
|
||||
|
||||
if ($service->delete()) {
|
||||
flash("Service item has been deleted")->success();
|
||||
return redirect('/service_items');
|
||||
}
|
||||
|
||||
flash("Service has not been deleted")->success();
|
||||
return redirect('service_items');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$services = Services::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
return view('clinical_data::service_items.inactive', compact('services'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$service = Services::withTrashed()->find($id);
|
||||
|
||||
if($service->restore()){
|
||||
flash("Service has been activated.")->success();
|
||||
return redirect('/service_items/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* order sundries for the patient
|
||||
*/
|
||||
public function order_services() {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$episode_id = session()->get('episode_id');
|
||||
$patient = Patient::where('id', $patient_id)->first();
|
||||
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id");
|
||||
$services = Services::where('available', 1)->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$ordered_services = DB::table('ordered_services')->whereNull('deleted_at')->where(['patient_id'=>$patient_id, 'episode_id'=>$episode_id, 'payment_status' => 0])->first();
|
||||
|
||||
$users_collection = DB::table('users')->orderBy("first_name","asc")->select("id")->get()->toArray();
|
||||
$users_array = [];
|
||||
foreach ($users_collection as $value){
|
||||
$user = \Streamline\Models\User::find($value->id);
|
||||
if (!is_null($user)) {
|
||||
$users_array[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
||||
}
|
||||
}
|
||||
$users_array = ['' => '- select -'] + $users_array;
|
||||
|
||||
$employees = DB::table('users')->whereNull('deleted_at')->orderBy('first_name', 'asc')->get();
|
||||
|
||||
return view('clinical_data::service_items.ordered_services',compact('patient_id','episode_id','patient','categories','employees','services','ordered_services', 'users_array'));
|
||||
}
|
||||
|
||||
/*
|
||||
* store ordered sundries for a patient episode
|
||||
*/
|
||||
public function store_ordered_services(Request $request) {
|
||||
if(is_null($request->service_id) || is_null($request->service_id[0])) {
|
||||
flash("No service has been selected")->error();
|
||||
return back()->withInput();
|
||||
} else {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$episode_id = session()->get('episode_id');
|
||||
|
||||
$service_ids_array = $request->service_id;
|
||||
$quantity_array = $request->item_quantity;
|
||||
$service_performed = [];
|
||||
$service_performed_id = [];
|
||||
$performed_service_array = $request->performed_services;
|
||||
$performed_by_array = $request->service_performed_by;
|
||||
$service_performed_by_amount = $request->service_performed_by_amount;
|
||||
$service_performed_date = $request->service_performed_date;
|
||||
|
||||
// filter to check if all entries have been filled for performed by and discard otherwise
|
||||
for ($i = 0; $i < count($service_ids_array); $i++) {
|
||||
// check if it is in the excluded item count
|
||||
if (isset($performed_service_array[$i]) && $performed_service_array[$i] == 1 && isset($performed_by_array[$i]) && $performed_by_array[$i] != "" &&
|
||||
isset($service_performed_by_amount[$i]) && $service_performed_by_amount[$i] != "" &&
|
||||
isset($service_performed_date[$i]) && $service_performed_date[$i] != "") {
|
||||
$service_performed_id[] = record_staff_that_has_performed_the_service_with_price($patient_id, $episode_id, 3, $service_ids_array[$i], 0,
|
||||
$performed_by_array[$i], $service_performed_by_amount[$i], $service_performed_date[$i]);
|
||||
$service_performed[] = 1;
|
||||
} else {
|
||||
$service_performed[] = 0;
|
||||
$service_performed_id[] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($request->order_id) && get_name($request->order_id, 'id', 'payment_status', 'ordered_services') == 0) {
|
||||
$service_order = Orderedservice::find($request->order_id);
|
||||
|
||||
// delete the previous preformed_by_ids
|
||||
try {
|
||||
DB::table('staff_performed_services')->whereIn('id', explode(",", $service_order->performed_id))->delete();
|
||||
} catch (\Exception $e) {}
|
||||
} else {
|
||||
$service_order = new Orderedservice;
|
||||
$service_order->patient_id = $patient_id;
|
||||
$service_order->episode_id = $episode_id;
|
||||
$service_order->payment_status = 0; //0 by default to mean not paid
|
||||
$service_order->created_by = auth()->user()->id;
|
||||
}
|
||||
|
||||
$service_order->service_id = implode(",", $service_ids_array);
|
||||
$service_order->quantity = implode(",", $quantity_array);
|
||||
$service_order->performed = implode(",", $service_performed);
|
||||
$service_order->performed_id = implode(",", $service_performed_id);
|
||||
$service_order->updated_by = auth()->user()->id;
|
||||
$service_order->save();
|
||||
|
||||
// create an insurance claim for the ordered items
|
||||
if ($request->patient_insurance_status == 1) {
|
||||
generate_insurance_claim($service_order->id, 1);
|
||||
}
|
||||
|
||||
flash("Services have been saved")->success();
|
||||
|
||||
// redirect to consultation or patient_episode page depending on where the user is from
|
||||
if (session()->has('redirect_to_consultation')) {
|
||||
$url = session()->get('redirect_to_consultation');
|
||||
session()->forget('redirect_to_consultation');
|
||||
return redirect($url);
|
||||
} else {
|
||||
return redirect("/patient_episodes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fetch_service_performance_fee(Request $request) {
|
||||
$patient_id = $request->patient_id;
|
||||
$patient_category_id = get_name($patient_id, 'id', 'category_id', 'patients');
|
||||
$performed_by = $request->performed_by;
|
||||
$item_id = $request->item_id;
|
||||
|
||||
$price_list_category_details = \Streamline\Models\PriceListCategories::where(['patient_category_id' => $patient_category_id])->first();
|
||||
|
||||
if ($price_list_category_details) {
|
||||
$price_list_category_id = $price_list_category_details->id;
|
||||
|
||||
$fees_array = get_item_price_and_performance_fee_based_on_price_list_category($performed_by, $item_id, 3, $price_list_category_id);
|
||||
|
||||
return ($fees_array[1] == 0) ? $fees_array[0] : $fees_array[1];
|
||||
} else {
|
||||
//do this for cases where the there are no price lists for the patient's patient_category
|
||||
$fees_array = get_item_price_and_performance_fee_array_without_price_list($item_id, $performed_by, 3);
|
||||
|
||||
return ($fees_array[1] == 0) ? $fees_array[0] : $fees_array[1];
|
||||
}
|
||||
}
|
||||
|
||||
public function cancel_ordered_services($order_id) {
|
||||
$ordered_service = OrderedService::find($order_id);
|
||||
|
||||
try {
|
||||
$ordered_service->delete();
|
||||
|
||||
// check if there are any insurance claims available
|
||||
$claim = InsuranceClaim::where('order_id', $order_id)->where('item_type', 1)->first();
|
||||
|
||||
if ($claim) {
|
||||
$claim->delete();
|
||||
}
|
||||
|
||||
return 1;
|
||||
} catch (\Exception $exception) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_service_details(Request $request) {
|
||||
$patient_id = $request->patient_id;
|
||||
$patient_insurance_status = $request->patient_insurance_status ?? 0;
|
||||
|
||||
$service = DB::table('services')->find($request->service_id);
|
||||
|
||||
if(is_numeric($patient_insurance_status) && $patient_insurance_status == 1 && $patient_id != 0 && is_numeric($patient_id)) {
|
||||
$selling_price = get_item_insurance_co_payment($patient_id, $service->id, 1, false, 0);
|
||||
} else {
|
||||
// check if the patient category is attached to a price list
|
||||
$price_list_id = is_patient_category_attached_to_price_list($patient_id);
|
||||
if ($price_list_id) {
|
||||
$selling_price = get_price_list_category_price($price_list_id, 6, $service->id);
|
||||
} else {
|
||||
$selling_price = $service->non_insured_price;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_chi_enabled() && is_patient_item_covered($patient_id, $service->id, 1)) {
|
||||
$covered_by_chi = ' <br><span style="color: darkgreen"><b>Covered by CHI</b></span>';
|
||||
} else {
|
||||
$covered_by_chi = "";
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
"selling_price" => $selling_price,
|
||||
"covered_by_chi" => $covered_by_chi,
|
||||
]);
|
||||
}
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
<?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\Http\Controllers\Controller;
|
||||
use Streamline\Models\SlitLampTestArea;
|
||||
|
||||
class SlitLampTestAreaController extends Controller {
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index() {
|
||||
$test_areas = SlitLampTestArea::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
return view('clinical_data::test_areas.index', compact('test_areas'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::test_areas.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
|
||||
//validation passed
|
||||
$test_area = new SlitLampTestArea;
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$test_area->name = $request->name;
|
||||
$test_area->slug = "slit_".substr($request->name, 0, 2);
|
||||
$test_area->created_by = $logged_in_user_id;
|
||||
$test_area->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$test_area->save();
|
||||
flash($request->name . " Staff Position has been saved")->success();
|
||||
return redirect("/test_areas/");
|
||||
} 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) {
|
||||
$test_area = SlitLampTestArea::where(['id' => $id])->first();
|
||||
|
||||
if (!$test_area) {
|
||||
flash()->error("There is no such staff position");
|
||||
return redirect('/test_areas/');
|
||||
} else {
|
||||
return view('clinical_data::test_areas.edit', compact('test_area'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
|
||||
$string = "";
|
||||
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
|
||||
// flash($string)->error();
|
||||
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
//validation passed
|
||||
$test_area = SlitLampTestArea::find($id);
|
||||
$test_area->name = $request->name;
|
||||
|
||||
try {
|
||||
|
||||
$test_area->save();
|
||||
flash($request->name . " Staff Position has been updated")->success();
|
||||
return redirect("/test_areas/");
|
||||
|
||||
} 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) {
|
||||
$test_area = SlitLampTestArea::findOrFail($id);
|
||||
|
||||
if ($test_area->delete()):
|
||||
flash("Staff Position has been deleted.")->success();
|
||||
return redirect('/test_areas/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$test_areas = SlitLampTestArea::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($test_areas) < 1) {
|
||||
flash()->error("There is no inactive staff position");
|
||||
return redirect('/test_areas/');
|
||||
} else {
|
||||
return view('clinical_data::test_areas.inactive', compact('test_areas'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$test_area = SlitLampTestArea::withTrashed()->findOrFail($id);
|
||||
|
||||
if ($test_area->restore()):
|
||||
flash("Staff Position has been activated.")->success();
|
||||
return redirect('/test_areas/inactive');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
<?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\Http\Controllers\Controller;
|
||||
use Streamline\Models\SlitLampTestArea;
|
||||
use Streamline\Models\SlitLampTestAreaValue;
|
||||
|
||||
class SlitLampTestAreaValueController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$test_area_values = SlitLampTestAreaValue::orderBy('name', 'asc')->get();
|
||||
$test_areas = SlitLampTestArea::pluck('name', 'id')->toArray();
|
||||
return view('clinical_data::test_area_values.index', compact('test_area_values', 'test_areas'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
$test_areas = SlitLampTestArea::pluck('name', 'id')->prepend('-select-', '')->toArray();
|
||||
return view('clinical_data::test_area_values.create', compact('test_areas'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
|
||||
//validation passed
|
||||
$test_area_value = new SlitLampTestAreaValue;
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$test_area_value->name = $request->name;
|
||||
$test_area_value->slit_lamp_test_area_id = $request->area;
|
||||
$test_area_value->created_by = $logged_in_user_id;
|
||||
$test_area_value->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$test_area_value->save();
|
||||
flash($request->name . " Staff Position has been saved")->success();
|
||||
return redirect("/test_area_values/");
|
||||
} 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) {
|
||||
$test_area_value = SlitLampTestAreaValue::where(['id' => $id])->first();
|
||||
$test_areas = SlitLampTestArea::pluck('name', 'id')->toArray();
|
||||
|
||||
if (!$test_area_value) {
|
||||
flash()->error("There is no such staff test_area_value");
|
||||
return redirect('/test_area_values/');
|
||||
} else {
|
||||
return view('clinical_data::test_area_values.edit', compact('test_area_value', 'test_areas'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
|
||||
$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;
|
||||
|
||||
//validation passed
|
||||
$test_area_value = SlitLampTestAreaValue::find($id);
|
||||
$test_area_value->name = $request->name;
|
||||
$test_area_value->slit_lamp_test_area_id = $request->area;
|
||||
$test_area_value->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
|
||||
$test_area_value->save();
|
||||
flash($request->name . " Staff Position has been updated")->success();
|
||||
return redirect("/test_area_values/");
|
||||
} 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) {
|
||||
$test_area_value = SlitLampTestAreaValue::findOrFail($id);
|
||||
|
||||
if ($test_area_value->delete()):
|
||||
flash("Staff Position has been deleted.")->success();
|
||||
return redirect('/test_area_values/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$test_area_values = SlitLampTestAreaValue::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($test_area_values) < 1) {
|
||||
flash()->error("There is no inactive staff test_area_value");
|
||||
return redirect('/test_area_values/');
|
||||
} else {
|
||||
return view('clinical_data::test_area_values.inactive', compact('test_area_values'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$test_area_value = SlitLampTestAreaValue::withTrashed()->findOrFail($id);
|
||||
|
||||
if ($test_area_value->restore()):
|
||||
flash("Staff Position has been activated.")->success();
|
||||
return redirect('/test_area_values/inactive');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
<?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\Speciality;
|
||||
|
||||
class SpecialityController extends Controller
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:specialty-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:specialty-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:specialty-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:specialty-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$specialities = Speciality::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
return view('clinical_data::specialities.index', compact('specialities'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::specialities.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$speciality = new Speciality;
|
||||
|
||||
$speciality->name = $request->name;
|
||||
$speciality->created_by = $logged_in_user_id;
|
||||
$speciality->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$speciality->save();
|
||||
flash($request->name . " Speciality has been saved")->success();
|
||||
return redirect("/specialities/");
|
||||
} 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) {
|
||||
$speciality = Speciality::where(['id' => $id])->first();
|
||||
|
||||
if (!$speciality) {
|
||||
flash()->error("There is no such speciality");
|
||||
return redirect('/specialities/');
|
||||
} else {
|
||||
return view('clinical_data::specialities.edit', compact('speciality'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'name' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$speciality = Speciality::find($id);
|
||||
$speciality->name = $request->name;
|
||||
$speciality->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$speciality->save();
|
||||
flash($request->name . " Speciality has been updated")->success();
|
||||
return redirect("/specialities/");
|
||||
} 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) {
|
||||
$speciality = Speciality::find($id);
|
||||
|
||||
if ($speciality->delete()):
|
||||
flash("Speciality has been deleted.")->success();
|
||||
return redirect('/specialities/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
|
||||
$specialities = Speciality::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (empty($specialities)) {
|
||||
flash()->error("There is no inactive Speciality");
|
||||
return redirect('/specialities/');
|
||||
} else {
|
||||
return view('clinical_data::specialities.inactive', compact('specialities'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$speciality = Speciality::withTrashed()->find($id);
|
||||
|
||||
if ($speciality->restore()):
|
||||
flash("Supplier has been activated.")->success();
|
||||
return redirect('/specialities/inactive');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\StaffPositions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class StaffPositionsController extends Controller{
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:staff_positions-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:staff_positions-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:staff_positions-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:staff_positions-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:staff_positions-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:staff_positions-status', ['only' => ['activate, inactive']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$positions = StaffPositions::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
return view('clinical_data::staff_positions.index', compact('positions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::staff_positions.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
|
||||
//validation passed
|
||||
$position = new StaffPositions;
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$position->name = $request->name;
|
||||
$position->created_by = $logged_in_user_id;
|
||||
$position->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$position->save();
|
||||
flash($request->name . " Staff Position has been saved")->success();
|
||||
return redirect("/staff_positions/");
|
||||
} 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) {
|
||||
$position = StaffPositions::where(['id' => $id])->first();
|
||||
|
||||
if (!$position) {
|
||||
flash()->error("There is no such staff position");
|
||||
return redirect('/staff_positions/');
|
||||
} else {
|
||||
return view('clinical_data::staff_positions.edit', compact('position'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//validation failed
|
||||
|
||||
$string = "";
|
||||
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
|
||||
// flash($string)->error();
|
||||
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
//validation passed
|
||||
$position = StaffPositions::find($id);
|
||||
$position->name = $request->name;
|
||||
|
||||
try {
|
||||
|
||||
$position->save();
|
||||
flash($request->name . " Staff Position has been updated")->success();
|
||||
return redirect("/staff_positions/");
|
||||
|
||||
} 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) {
|
||||
$position = StaffPositions::find($id);
|
||||
|
||||
if ($position->delete()):
|
||||
flash("Staff Position has been deleted.")->success();
|
||||
return redirect('/staff_positions/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$positions = StaffPositions::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($positions) < 1) {
|
||||
flash()->error("There is no inactive staff position");
|
||||
return redirect('/staff_positions/');
|
||||
} else {
|
||||
return view('clinical_data::staff_positions.inactive', compact('positions'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$position = StaffPositions::withTrashed()->find($id);
|
||||
|
||||
if ($position->restore()):
|
||||
flash("Staff Position has been activated.")->success();
|
||||
return redirect('/staff_positions/inactive');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
<?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\County;
|
||||
use Streamline\Models\Subcounty;
|
||||
|
||||
class SubcountyController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:subcounty-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:subcounty-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:subcounty-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:subcounty-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$sub_counties = Subcounty::orderBy('name', 'asc')->get();
|
||||
$counties = County::pluck('name', 'id');
|
||||
|
||||
return view('clinical_data::sub_counties.index', compact('sub_counties', 'counties'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
|
||||
$counties = County::all(['id', 'name', 'district_id'])->pluck("name_with_district", "id")->prepend('- select -', '')->toArray();
|
||||
|
||||
return view('clinical_data::sub_counties.create', compact('counties'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'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();
|
||||
|
||||
}else{
|
||||
|
||||
$user_id = Auth::user()->id;
|
||||
$sub_county = new Subcounty;
|
||||
|
||||
$sub_county->name = $request->name;
|
||||
$sub_county->county_id = $request->county_id;
|
||||
$sub_county->created_by = $user_id;
|
||||
$sub_county->updated_by = $user_id;
|
||||
|
||||
try {
|
||||
$sub_county->save();
|
||||
flash($request->name . " Sub county has been saved")->success();
|
||||
return redirect("/subcounties/");
|
||||
} 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) {
|
||||
$sub_county = Subcounty::where(['id' => $id])->first();
|
||||
|
||||
$counties = County::all(['id', 'name', 'district_id'])->pluck("name_with_district", "id")->prepend('- select -', '')->toArray();
|
||||
|
||||
if (!$sub_county) {
|
||||
flash()->error("That sub county is not registered");
|
||||
return redirect('/sub_counties/');
|
||||
} else {
|
||||
return view('clinical_data::sub_counties.edit', compact('sub_county', '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',
|
||||
'county_id' => 'required'
|
||||
]);
|
||||
|
||||
$sub_county = Subcounty::find($id);
|
||||
|
||||
$sub_county->name = $request->name;
|
||||
$sub_county->county_id = $request->county_id;
|
||||
$sub_county->updated_by = Auth::user()->id;
|
||||
|
||||
try {
|
||||
$sub_county->save();
|
||||
flash($request->name . " Sub county has been updated")->success();
|
||||
return redirect("/subcounties/");
|
||||
} 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) {
|
||||
$sub_county = Subcounty::find($id);
|
||||
|
||||
if ($sub_county->delete()) {
|
||||
flash("Sub county has been deleted.")->success();
|
||||
return redirect('/subcounties/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$sub_counties = Subcounty::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
$counties = County::pluck('name', 'id');
|
||||
|
||||
if (count($sub_counties) < 1) {
|
||||
flash()->error("There is no inactive sub counties");
|
||||
}
|
||||
|
||||
return view('clinical_data::sub_counties.inactive', compact('counties', 'sub_counties'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$sub_county = Subcounty::withTrashed()->find($id);
|
||||
|
||||
if($sub_county->restore()){
|
||||
flash("Sub county has been activated.")->success();
|
||||
return redirect('/subcounties/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+495
@@ -0,0 +1,495 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Http\Controllers\StreamlineSetupManager;
|
||||
use Streamline\Models\InsuranceClaim;
|
||||
use Streamline\Models\PriceListCategories;
|
||||
use Streamline\Models\Sundry;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Models\GeneralForm;
|
||||
use Streamline\Models\OrderedSundry;
|
||||
use Streamline\Models\User;
|
||||
use Streamline\Services\StreamlineSetupServiceInterface;
|
||||
|
||||
class SundryController extends Controller {
|
||||
protected StreamlineSetupServiceInterface $setupService;
|
||||
public function __construct(StreamlineSetupServiceInterface $setupService) {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:sundry-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:sundry-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:sundry-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:sundry-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
$this->setupService = $setupService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$getSundries = Sundry::get();
|
||||
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
|
||||
$sundries = $getSundries->map(function ($user) {
|
||||
return collect($user->toArray())
|
||||
->all();
|
||||
});
|
||||
|
||||
$ordered_sundries_array = [];
|
||||
$ordered_sundries = OrderedSundry::distinct('sundries_id')->get(['sundries_id']);
|
||||
foreach ($ordered_sundries as $ordered_sundry) {
|
||||
$actual = explode(',', $ordered_sundry->sundries_id);
|
||||
foreach ($actual as $value) $ordered_sundries_array[] = $value;
|
||||
}
|
||||
$ordered_sundries_ids = array_unique($ordered_sundries_array);
|
||||
|
||||
return view('clinical_data::sundries.index', compact('sundries', 'chart_of_accounts', 'ordered_sundries_ids'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$inventory_asset_accounts = ChartOfAccount::where(['type' => 10])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$income_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$forms = ['' => '- select -'] + GeneralForm::where('item_type',2)->pluck('name', 'id')->toArray();
|
||||
|
||||
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
|
||||
$inventory_asset_accounts = ['' => '- select -'] + $inventory_asset_accounts;
|
||||
$income_accounts = ['' => '- select -'] + $income_accounts;
|
||||
|
||||
$sundries = StreamlineSetupManager::get_sundries_array();
|
||||
|
||||
return view('clinical_data::sundries.create', compact('income_accounts','forms', 'inventory_asset_accounts', 'cost_of_goods_accounts','sundries'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
|
||||
if (session()->has('streamline_setup') && isset($request->skip)){
|
||||
//Artisan::call('db:seed', ['--class' => 'SundriesTableSeeder']);
|
||||
//update the streamline setup table with the new finished step
|
||||
$this->setupService->saveStep("sundries registration", 1);
|
||||
return redirect("general_settings/edit");
|
||||
} else {
|
||||
|
||||
/*request()->validate([
|
||||
'name' => 'required',
|
||||
'price' => 'required',
|
||||
'account_id' => 'required'
|
||||
]);*/
|
||||
//dd($request->all());
|
||||
|
||||
// get all current price lists
|
||||
$price_list = PriceListCategories::withTrashed()->select('id')->get();
|
||||
$price_list_category = [];
|
||||
$price_list_price = [];
|
||||
|
||||
foreach ($price_list as $record){
|
||||
array_push($price_list_category, $record->id);
|
||||
array_push($price_list_price, $request->non_insured_price);
|
||||
}
|
||||
|
||||
//validation passed
|
||||
$sundry = new Sundry;
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$sundry->name = $request->name;
|
||||
$sundry->insurance = 0;
|
||||
$sundry->available = $request->available;
|
||||
$sundry->cost_price = $request->price;
|
||||
$sundry->form_id=$request->form_id;
|
||||
$sundry->insured_price = 0;
|
||||
$sundry->non_insured_price = $request->non_insured_price;
|
||||
|
||||
if (isset($request->price_list_category_id) && isset($request->price_list_price)) {
|
||||
$sundry->price_list_category = !is_null($request->price_list_category_id) ? implode(",", $request->price_list_category_id) : null;
|
||||
$sundry->price_list_price = !is_null($request->price_list_price) ? implode(",", $request->price_list_price) : null;
|
||||
} else {
|
||||
$sundry->price_list_category = implode(",", $price_list_category);
|
||||
$sundry->price_list_price = implode(",", $price_list_price);
|
||||
}
|
||||
|
||||
$sundry->account_id = $request->account_id;
|
||||
$sundry->inventory_account = $request->inventory_account;
|
||||
$sundry->cost_of_goods_account = $request->cog_account;
|
||||
$sundry->created_by = $logged_in_user_id;
|
||||
$sundry->updated_by = $logged_in_user_id;
|
||||
$sundry->created_at = Carbon::now();
|
||||
$sundry->updated_at = Carbon::now();
|
||||
|
||||
try {
|
||||
if ($sundry->name != "" && !is_null($sundry->name)) {
|
||||
$sundry->save();
|
||||
}
|
||||
|
||||
flash($request->name . " Sundry has been saved")->success();
|
||||
|
||||
if (session()->has('streamline_setup')) {
|
||||
if (isset($request->selected_sundries)) {
|
||||
$selected_sundries_array = $request->selected_sundries;
|
||||
if (!empty($selected_sundries_array)) {
|
||||
|
||||
for ($i=0; $i < count($selected_sundries_array) ; $i++) {
|
||||
$default_sundry = new Sundry;
|
||||
$default_sundry->name = $selected_sundries_array[$i];
|
||||
$default_sundry->account_id = 12; //12 == Sundry chart of account
|
||||
$default_sundry->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//update the streamline setup table with the new finished step
|
||||
$this->setupService->saveStep("sundries registration", 1);
|
||||
return redirect("general_settings/edit");
|
||||
}
|
||||
return redirect("/sundries/");
|
||||
} 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) {
|
||||
$sundry = Sundry::where(['id' => $id])->first();
|
||||
|
||||
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$inventory_asset_accounts = ChartOfAccount::where(['type' => 10])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$income_accounts = ChartOfAccount::where(['type' => 1])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
$forms = ['' => '- select -'] + GeneralForm::where('item_type',2)->pluck('name', 'id')->toArray();
|
||||
|
||||
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
|
||||
$inventory_asset_accounts = ['' => '- select -'] + $inventory_asset_accounts;
|
||||
$income_accounts = ['' => '- select -'] + $income_accounts;
|
||||
|
||||
if (!$sundry) {
|
||||
flash()->error("Sundry not found");
|
||||
return redirect('/sundries/');
|
||||
} else {
|
||||
return view('clinical_data::sundries.edit', compact('sundry','forms', 'cost_of_goods_accounts', 'inventory_asset_accounts', 'income_accounts'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'price' => 'required',
|
||||
'account_id' => 'required'
|
||||
]);
|
||||
|
||||
//validation passed
|
||||
$sundry = Sundry::find($id);
|
||||
|
||||
$sundry->name = $request->name;
|
||||
$sundry->insurance = 0;
|
||||
$sundry->cost_price = $request->price;
|
||||
$sundry->available = $request->available;
|
||||
$sundry->form_id=$request->form_id;
|
||||
$sundry->insured_price = 0;
|
||||
$sundry->non_insured_price = $request->non_insured_price;
|
||||
$sundry->price_list_category = !is_null($request->price_list_category_id) ? implode(",", $request->price_list_category_id) : null;
|
||||
$sundry->price_list_price = !is_null($request->price_list_price) ? implode(",", $request->price_list_price) : null;
|
||||
$sundry->account_id = $request->account_id;
|
||||
$sundry->inventory_account = $request->inventory_account;
|
||||
$sundry->cost_of_goods_account = $request->cog_account;
|
||||
|
||||
try {
|
||||
$sundry->save();
|
||||
flash($request->name . " Sundry has been updated")->success();
|
||||
return redirect("/sundries/");
|
||||
} 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) {
|
||||
$sundry = Sundry::find($id);
|
||||
if(empty($sundry->pharmacy_stock) && empty($sundry->store_stock) && empty($sundry->opening_stock)){
|
||||
if ($sundry->delete()):
|
||||
flash("Sundry has been deleted.")->success();
|
||||
return redirect('/sundries/');
|
||||
endif;
|
||||
}else {
|
||||
flash()->error($sundry->name ." is still in stock.");
|
||||
return redirect('/sundries/');
|
||||
}
|
||||
}
|
||||
|
||||
public function inactive() {
|
||||
$sundries = Sundry::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')->pluck('name', 'id');
|
||||
|
||||
if (empty($sundries)) {
|
||||
flash()->error("There is no inactive sundry");
|
||||
return redirect('/sundries/');
|
||||
} else {
|
||||
return view('clinical_data::sundries.inactive', compact('sundries', 'chart_of_accounts'));
|
||||
}
|
||||
}
|
||||
|
||||
public function activate($id) {
|
||||
$sundry = Sundry::withTrashed()->find($id);
|
||||
|
||||
if ($sundry->restore()):
|
||||
flash("Sundry has been activated.")->success();
|
||||
return redirect('/sundries/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
/*
|
||||
* order sundries for the patient
|
||||
*/
|
||||
public function order_sundries() {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$episode_id = session()->get('episode_id');
|
||||
$patient = Patient::where('id', $patient_id)->first();
|
||||
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id");
|
||||
$sundries = Sundry::where('available', 1)->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$ordered_sundries = DB::table('ordered_sundries')
|
||||
->whereNull('deleted_at')
|
||||
->where(['patient_id'=>$patient_id, 'episode_id'=>$episode_id, 'payment_status' => 0])
|
||||
->first();
|
||||
|
||||
$users_collection = DB::table('users')->orderBy("first_name","asc")->select("id")->get()->toArray();
|
||||
$users_array = [];
|
||||
|
||||
foreach ($users_collection as $value){
|
||||
$user = User::find($value->id);
|
||||
if (!is_null($user)) {
|
||||
$users_array[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
||||
}
|
||||
}
|
||||
|
||||
$users_array = ['' => '- select -'] + $users_array;
|
||||
|
||||
$employees = DB::table('users')->whereNull('deleted_at')->orderBy('first_name', 'asc')->get();
|
||||
|
||||
return view('clinical_data::sundries.order_sundries',compact('patient_id','episode_id','patient','categories','employees','sundries','ordered_sundries', 'users_array'));
|
||||
}
|
||||
|
||||
/*
|
||||
* store ordered sundries for a patient episode
|
||||
*/
|
||||
public function store_ordered_sundries(Request $request) {
|
||||
if(is_null($request->sundries_id) || is_null($request->sundries_id[0])) {
|
||||
flash("No sundry has been selected")->error();
|
||||
return back()->withInput();
|
||||
} else {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$episode_id = session()->get('episode_id');
|
||||
$patient_insurance_status = $request->patient_insurance_status ?? 0;
|
||||
|
||||
$sundry_ids_array = $request->sundries_id;
|
||||
$quantity_array = $request->item_quantity;
|
||||
if (isset($request->order_id) && get_name($request->order_id, 'id', 'payment_status', 'ordered_sundries') == 0) {
|
||||
$sundry_order = OrderedSundry::find($request->order_id);
|
||||
} else {
|
||||
$sundry_order = new OrderedSundry;
|
||||
$sundry_order->patient_id = $patient_id;
|
||||
$sundry_order->episode_id = $episode_id;
|
||||
$sundry_order->payment_status = 0; //0 by default to mean not paid
|
||||
$sundry_order->created_by = auth()->user()->id;
|
||||
}
|
||||
|
||||
/* === save current selling price for future billing not to use the original selling price == */
|
||||
$unit_selling_prices_array = [];
|
||||
$price_list_id = is_patient_category_attached_to_price_list($patient_id);
|
||||
for ($i=0; $i < count($sundry_ids_array) ; $i++) {
|
||||
if($patient_insurance_status == 1 && $patient_id != 0 && is_numeric($patient_id)) {
|
||||
$opd_sundry_amount = get_item_insurance_co_payment($patient_id, $sundry_ids_array[$i], 5, false, 0);
|
||||
} else {
|
||||
if ($price_list_id) {
|
||||
$opd_sundry_amount = get_price_list_category_price($price_list_id, 5, $sundry_ids_array[$i]);
|
||||
} else {
|
||||
$opd_sundry_amount = get_name($sundry_ids_array[$i], "id", "non_insured_price", "sundries");
|
||||
}
|
||||
}
|
||||
$unit_selling_prices_array[] = $opd_sundry_amount;
|
||||
}
|
||||
/* ================ */
|
||||
|
||||
$sundry_order->sundries_id = implode(",", $sundry_ids_array);
|
||||
$sundry_order->quantity = implode(",", $quantity_array);
|
||||
$sundry_order->sundries_amount = implode(",", $unit_selling_prices_array);
|
||||
$sundry_order->save();
|
||||
//removed sundry stock reduction to only reduce at payment irrespective of the setting.
|
||||
// if (get_inventory_reduction_point() == 1) {
|
||||
// for ($i=0; $i < count($sundry_ids_array) ; $i++) {
|
||||
// $sundry = \Streamline\Models\Sundry::withTrashed()->find($sundry_ids_array[$i]);
|
||||
// $current_stock = $sundry->store_stock;
|
||||
// $new_stock = $current_stock - $quantity_array[$i];
|
||||
// $sundry->store_stock = $new_stock;
|
||||
// $sundry->update();
|
||||
// }
|
||||
// }
|
||||
|
||||
// create an insurance claim for the ordered items
|
||||
if ($request->patient_insurance_status == 1) {
|
||||
generate_insurance_claim($sundry_order->id, 5);
|
||||
}
|
||||
|
||||
flash("Sundries have been saved")->success();
|
||||
|
||||
// redirect to consultation or patient_episode page depending on where the user is from
|
||||
if (session()->has('redirect_to_consultation')) {
|
||||
$url = session()->get('redirect_to_consultation');
|
||||
session()->forget('redirect_to_consultation');
|
||||
return redirect($url);
|
||||
} elseif (session()->has('anc_visit_redirect')) {
|
||||
$url = session()->get('anc_visit_redirect');
|
||||
session()->forget('anc_visit_redirect');
|
||||
return redirect($url);
|
||||
} else {
|
||||
return redirect("/patient_episodes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function cancel_ordered_sundries($order_id) {
|
||||
$ordered_sundries = OrderedSundry::find($order_id);
|
||||
|
||||
try {
|
||||
$ordered_sundries->delete();
|
||||
|
||||
// check if there are any insurance claims available
|
||||
$claim = InsuranceClaim::where('order_id', $order_id)->where('item_type', 5)->first();
|
||||
|
||||
if ($claim) {
|
||||
$claim->delete();
|
||||
}
|
||||
|
||||
return 1;
|
||||
} catch (\Exception $exception) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function expiring_sundries(Request $request) {
|
||||
$today = Carbon::now();
|
||||
|
||||
if ($request->time_period == 0) {
|
||||
$sundries = Sundry::where('expiry_date', '<', DATE($today))
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($sundries) < 1) {
|
||||
flash()->error("There are no expired sundries");
|
||||
}
|
||||
} elseif ($request->time_period == 1) {
|
||||
$sundries = Sundry::whereBetween('expiry_date', [DATE($today), DATE($today->addWeek())])
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($sundries) < 1) {
|
||||
flash()->error("There are no sundries expiring in a week");
|
||||
}
|
||||
} elseif ($request->time_period == 2) {
|
||||
$sundries = Sundry::whereBetween('expiry_date', [DATE($today), DATE($today->addWeeks(2))])
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($sundries) < 1) {
|
||||
flash()->error("There are no sundries expiring in two weeks");
|
||||
}
|
||||
} elseif ($request->time_period == 4) {
|
||||
$sundries = Sundry::whereBetween('expiry_date', [DATE($today), DATE($today->addWeeks(4))])
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($sundries) < 1) {
|
||||
flash()->error("There are no sundries expiring in a month");
|
||||
}
|
||||
} else {
|
||||
$sundries = Sundry::where('expiry_date', '<', DATE($today))
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($sundries) < 1) {
|
||||
flash()->error("There are no expired sundries");
|
||||
}
|
||||
}
|
||||
|
||||
return view('clinical_data::sundries.expiring_sundries', compact('sundries'));
|
||||
}
|
||||
|
||||
public function get_sundry_details(Request $request) {
|
||||
$patient_id = $request->patient_id;
|
||||
$patient_insurance_status = $request->patient_insurance_status ?? 0;
|
||||
$ward_id = $request->ward_id ?? 0;
|
||||
|
||||
$sundry = DB::table('sundries')->find($request->sundry_id);
|
||||
|
||||
if(is_numeric($patient_insurance_status) && $patient_insurance_status == 1 && $patient_id != 0 && is_numeric($patient_id)) {
|
||||
$selling_price = get_item_insurance_co_payment($patient_id, $sundry->id, 5, false, $ward_id);
|
||||
} else {
|
||||
// check if the patient category is attached to a price list
|
||||
$price_list_id = is_patient_category_attached_to_price_list($patient_id);
|
||||
if ($price_list_id) {
|
||||
$selling_price = get_price_list_category_price($price_list_id, 5, $sundry->id);
|
||||
} else {
|
||||
$selling_price = $sundry->non_insured_price;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_chi_enabled() && is_patient_item_covered($patient_id, $sundry->id, 5)) {
|
||||
$covered_by_chi = ' <br><span style="color: darkgreen"><b>Covered by CHI</b></span>';
|
||||
} else {
|
||||
$covered_by_chi = "";
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
"selling_price" => $selling_price,
|
||||
"covered_by_chi" => $covered_by_chi,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\GeneralForm;
|
||||
use Streamline\Models\PriceListCategories;
|
||||
use Streamline\Models\Sundry;
|
||||
use Streamline\Http\Controllers\StreamlineSetupManager;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
//use Log;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Models\PatientEpisode;
|
||||
use Streamline\Models\OrderedSundry;
|
||||
use Streamline\Models\Consultation;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Streamline\Models\User;
|
||||
|
||||
class SundryFormController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:sundry-form-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:sundry-form-create', ['only' => ['create', 'store']]);
|
||||
// $this->middleware('permission:sundry-form-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:sundry-form-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$sundry_forms = GeneralForm::get_all_forms_type(2);
|
||||
return view('clinical_data::sundry_form.index', compact('sundry_forms'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
|
||||
return view('clinical_data::sundry_form.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
$data['name']=$request->name;
|
||||
$data['type']= 2;
|
||||
try{
|
||||
//create new radiology form
|
||||
$new_form = GeneralForm::add_new_form((object)$data);
|
||||
flash("Sundry form has been created successfully")->success();
|
||||
return redirect('/sundry_form');
|
||||
} catch (QueryException $e){
|
||||
flash("Something went wrong. Please try again")->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) {
|
||||
$sundry = GeneralForm::find($id);
|
||||
|
||||
if (!$sundry) {
|
||||
flash()->error("Sundry Form not found");
|
||||
return redirect('/sundry_form/');
|
||||
} else {
|
||||
return view('clinical_data::sundry_form.edit', compact('sundry'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
]);
|
||||
|
||||
//validation passed
|
||||
$data['name']=$request->name;
|
||||
$data['type']= 2;
|
||||
try{
|
||||
//update sundry form
|
||||
$form = GeneralForm::find($id);
|
||||
$form->update($data);
|
||||
flash($request->name . " Sundry Form has been updated")->success();
|
||||
return redirect('/sundry_form');
|
||||
}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) {
|
||||
$sundry = GeneralForm::find($id);
|
||||
if ($sundry->delete()):
|
||||
flash("Sundry Form has been deleted.")->success();
|
||||
return redirect('/sundry_form');
|
||||
endif;
|
||||
}
|
||||
|
||||
public function inactive() {
|
||||
$sundries = GeneralForm::onlyTrashed()
|
||||
->where('item_type', 2)
|
||||
->orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
if (empty($sundries)) {
|
||||
flash()->error("There is no inactive sundry");
|
||||
return redirect()->route('sundry_form.index');
|
||||
} else {
|
||||
return view('clinical_data::sundry_form.inactive', compact('sundries'));
|
||||
}
|
||||
}
|
||||
|
||||
public function activate($id) {
|
||||
$sundry = GeneralForm::withTrashed()->find($id);
|
||||
|
||||
if ($sundry->restore()):
|
||||
flash("Sundry Form has been activated.")->success();
|
||||
return redirect()-route('sundry_forms.inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\Supplier;
|
||||
use Streamline\Models\Quotation;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class SupplierController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:suppliers-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:suppliers-detail', ['only' => ['show']]);
|
||||
$this->middleware('permission:suppliers-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:suppliers-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:suppliers-delete', ['only' => ['destroy']]);
|
||||
$this->middleware('permission:suppliers-status', ['only' => ['activate, inactive']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$suppliers = Supplier::orderBy('name', 'asc')
|
||||
->paginate(500);
|
||||
|
||||
$quotations = Quotation::distinct('supplier_id')->pluck('supplier_id', 'supplier_id')->toArray();
|
||||
return view('clinical_data::suppliers.index', compact('suppliers', 'quotations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::suppliers.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
//'mobile_number' => 'regex:/07\d{2} \d{3} \d{3}/'
|
||||
//'mobile_number' => 'regex:/(07)[0-9]{8}/'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
$supplier = new Supplier;
|
||||
|
||||
$supplier->name = $request->name;
|
||||
$supplier->available = $request->available;
|
||||
$supplier->company = $request->company;
|
||||
$supplier->mobile_number = $request->mobile_number;
|
||||
$supplier->address = $request->address;
|
||||
$supplier->created_by = $logged_in_user_id;
|
||||
$supplier->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$supplier->save();
|
||||
flash($request->name . " Supplier has been saved")->success();
|
||||
return redirect("/suppliers/");
|
||||
} 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) {
|
||||
$supplier = Supplier::where(['id' => $id])->first();
|
||||
|
||||
if (!$supplier) {
|
||||
flash()->error("There is no such supplier");
|
||||
return redirect('/suppliers/');
|
||||
} else {
|
||||
return view('clinical_data::suppliers.edit', compact('supplier'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), [
|
||||
'name' => 'required',
|
||||
'mobile_number' => 'regex:/07\d{2} \d{3} \d{3}/'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$supplier = Supplier::find($id);
|
||||
$supplier->name = $request->name;
|
||||
$supplier->available = $request->available;
|
||||
$supplier->company = $request->company;
|
||||
$supplier->mobile_number = $request->mobile_number;
|
||||
$supplier->address = $request->address;
|
||||
$supplier->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$supplier->save();
|
||||
flash($request->name . " Supplier has been updated")->success();
|
||||
return redirect("/suppliers/");
|
||||
} 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) {
|
||||
$supplier = Supplier::find($id);
|
||||
|
||||
if ($supplier->delete()):
|
||||
flash("Supplier has been deleted.")->success();
|
||||
return redirect('/suppliers/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
|
||||
$suppliers = Supplier::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (empty($suppliers)) {
|
||||
flash()->error("There is no inactive supplier");
|
||||
return redirect('/suppliers/');
|
||||
} else {
|
||||
return view('clinical_data::suppliers.inactive', compact('suppliers'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$supplier = Supplier::withTrashed()->find($id);
|
||||
|
||||
if ($supplier->restore()):
|
||||
flash("Supplier has been activated.")->success();
|
||||
return redirect('/suppliers/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+316
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\Symptom;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Streamline\Models\Triage;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class SymptomController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:symptom-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:symptom-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:symptom-edit', ['only' => ['edit', 'update', 'edit_all', 'update_all']]);
|
||||
$this->middleware('permission:symptom-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$symptoms = Symptom::orderBy('name', 'asc')->paginate(2000);
|
||||
$symptom_data = [];
|
||||
$triage_symptoms = Triage::distinct('symptoms')->get(['symptoms']);
|
||||
foreach ($triage_symptoms as $value) {
|
||||
$actual_symptoms = explode(',', $value->symptoms);
|
||||
foreach ($actual_symptoms as $actual_symptom) if(!empty($actual_symptom) && !in_array($actual_symptom, $symptom_data)) $symptom_data[] = $actual_symptom;
|
||||
}
|
||||
|
||||
return view('clinical_data::symptoms.index', compact('symptoms', 'symptom_data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::symptoms.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;
|
||||
$symptom = new Symptom;
|
||||
|
||||
$symptom->name = $request->name;
|
||||
$symptom->prompts = $request->prompts;
|
||||
$symptom->reference_text = implode(',', $request->reference_text);
|
||||
$symptom->reference_link = implode(',', $request->reference_link);
|
||||
$symptom->created_by = $logged_in_user_id;
|
||||
$symptom->available = $request->available;
|
||||
|
||||
try {
|
||||
$symptom->save();
|
||||
flash($request->name . " Symptom has been saved")->success();
|
||||
return redirect("/symptoms/");
|
||||
} 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) {
|
||||
$symptom = Symptom::where(['id' => $id])->first();
|
||||
|
||||
if (!$symptom) {
|
||||
flash()->error("There is no such symptom");
|
||||
return redirect('/symptoms/');
|
||||
} else {
|
||||
return view('clinical_data::symptoms.edit', compact('symptom'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$symptom = Symptom::find($id);
|
||||
$symptom->name = $request->name;
|
||||
$symptom->prompts = $request->prompts;
|
||||
$symptom->reference_text = $request->reference_text;
|
||||
$symptom->reference_link = $request->reference_link;
|
||||
$symptom->available = $request->available;
|
||||
$symptom->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$symptom->save();
|
||||
flash($request->name . " Symptom has been updated")->success();
|
||||
return redirect("/symptoms/");
|
||||
} 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) {
|
||||
$symptom = Symptom::find($id);
|
||||
|
||||
if ($symptom->delete()){
|
||||
flash("Symptom has been deleted.")->success();
|
||||
return redirect('/symptoms/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$symptoms = Symptom::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (empty($symptoms)) {
|
||||
flash()->error("There is no inactive symptom");
|
||||
return redirect('/symptoms/');
|
||||
} else {
|
||||
return view('clinical_data::symptoms.inactive', compact('symptoms'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$symptom = Symptom::withTrashed()->find($id);
|
||||
|
||||
if ($symptom->restore()){
|
||||
flash("Symptom has been activated.")->success();
|
||||
return redirect('/symptoms/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search a resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function search(Request $request) {
|
||||
$query_name = $request->query_name;
|
||||
$query_active = $request->query_active;
|
||||
|
||||
if ($query_name != "") {
|
||||
$symptoms = Symptom::where([
|
||||
['active', '=', $query_active],
|
||||
['name', 'LIKE', '%' . $query_name . '%']
|
||||
])
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(10)
|
||||
->setPath('');
|
||||
|
||||
$symptoms->appends(array(
|
||||
'query_name' => $query_name,
|
||||
'query_active' => $query_active
|
||||
));
|
||||
|
||||
if (count($symptoms)) {
|
||||
if ($query_active) {
|
||||
return view('clinical_data::symptoms.index', compact('symptoms'))//;
|
||||
->withDetails($symptoms)
|
||||
->withQuery($query_name, $query_active);
|
||||
} else {
|
||||
return view('clinical_data::symptoms.inactive', compact('symptoms'))//;
|
||||
->withDetails($symptoms)
|
||||
->withQuery($query_name, $query_active);
|
||||
}
|
||||
}
|
||||
}
|
||||
flash()->error("No Details found. Try searching again!");
|
||||
return redirect('/symptoms/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the active resources for bulk editing.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit_all() {
|
||||
$symptoms = Symptom::orderBy('name', 'asc')->paginate(2000);
|
||||
|
||||
if (count($symptoms) < 1) {
|
||||
flash()->error("There is no active symptom");
|
||||
return redirect('/symptoms/');
|
||||
} else {
|
||||
return view('clinical_data::symptoms.edit.all', compact('symptoms'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all the resources in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update_all(Request $request) {
|
||||
request()->validate([
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth()->user()->id;
|
||||
|
||||
$id_array = $request->id;
|
||||
$name_array = $request->name;
|
||||
$prompts_array = $request->prompts;
|
||||
$reference_text_array = $request->reference_text;
|
||||
$reference_link_array = $request->reference_link;
|
||||
|
||||
for ($x = 0; $x < count($id_array); $x++){
|
||||
$symptom = Symptom::find($id_array[$x]);
|
||||
|
||||
$symptom->name = $name_array[$x];
|
||||
$symptom->prompts = $prompts_array[$x];
|
||||
$symptom->reference_text = $reference_text_array[$x];
|
||||
$symptom->reference_link = $reference_link_array[$x];
|
||||
$symptom->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$symptom->save();
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
flash("Symptoms have been updated")->success();
|
||||
return redirect("/symptoms/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return String
|
||||
*/
|
||||
public function get_prompt($id) {
|
||||
$prompts = DB::table('symptoms')->where('id', $id)->value('prompts');
|
||||
$reference_text = DB::table('symptoms')->where('id', $id)->value('reference_text');
|
||||
$data = $prompts.'&&&&<a style="color: blue;" href="'.$reference_text.'" target="_blank">Ref 1</a>';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function get_symptoms(){
|
||||
//code to be returned to view
|
||||
$code = "<option> -- select -- </option>";
|
||||
|
||||
$symptoms = Symptom::orderBy('name', 'asc')->get();
|
||||
|
||||
foreach ($symptoms as $symptom) {
|
||||
$code .= "<option value='" . $symptom->id . "'>" . $symptom->name . "</option>";
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/* test server side scolling with datatables */
|
||||
public function datatable_test(){
|
||||
$symptoms = Symptom::orderBy('name', 'asc')->get();
|
||||
|
||||
return response()->json($symptoms);
|
||||
}
|
||||
}
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\UnitOfMeasure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class UnitOfMeasureController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:unit-of-measure-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:unit-of-measure-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:unit-of-measure-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:unit-of-measure-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$units_of_measure = UnitOfMeasure::orderBy('name', 'asc')->paginate(50);
|
||||
|
||||
return view('clinical_data::unit_of_measure.index', compact('units_of_measure'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
return view('clinical_data::unit_of_measure.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;
|
||||
$unit_of_measure = new UnitOfMeasure;
|
||||
|
||||
$unit_of_measure->name = $request->name;
|
||||
$unit_of_measure->created_by = $logged_in_user_id;
|
||||
$unit_of_measure->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$unit_of_measure->save();
|
||||
flash($request->name . " Unit of Measure has been saved")->success();
|
||||
return redirect("/unit_of_measure/");
|
||||
} 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) {
|
||||
$unit_of_measure = UnitOfMeasure::where(['id' => $id])->first();
|
||||
|
||||
if (!$unit_of_measure) {
|
||||
flash()->error("There is no such Unit of Measure");
|
||||
return redirect('/unit_of_measure/');
|
||||
} else {
|
||||
return view('clinical_data::unit_of_measure.edit', compact('unit_of_measure'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
$unit_of_measure = UnitOfMeasure::find($id);
|
||||
|
||||
$unit_of_measure->name = $request->name;
|
||||
$unit_of_measure->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$unit_of_measure->save();
|
||||
flash($request->name . " Unit of Measure has been updated")->success();
|
||||
return redirect("/unit_of_measure/");
|
||||
} 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) {
|
||||
$unit_of_measure = UnitOfMeasure::find($id);
|
||||
|
||||
if ($unit_of_measure->delete()):
|
||||
flash("Unit of Measure has been deleted.")->success();
|
||||
return redirect('/unit_of_measure/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$units_of_measure = UnitOfMeasure::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($units_of_measure) < 1) {
|
||||
flash()->error("There is no inactive Unit of Measure");
|
||||
return redirect('/unit_of_measure/');
|
||||
} else {
|
||||
return view('clinical_data::unit_of_measure.inactive', compact('units_of_measure'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$unit_of_measure = UnitOfMeasure::withTrashed()->find($id);
|
||||
|
||||
if ($unit_of_measure->restore()):
|
||||
flash("Unit of Measure has been activated.")->success();
|
||||
return redirect('/unit_of_measure/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ClinicalData\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Streamline\Models\Parish;
|
||||
use Streamline\Models\Village;
|
||||
|
||||
class VillageController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:village-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:village-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:village-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:village-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$villages = Village::orderBy('name', 'asc')->paginate(5000);
|
||||
|
||||
$parishes = Parish::pluck('name', 'id');
|
||||
|
||||
return view('clinical_data::villages.index', compact('villages', 'parishes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
$parishes = Parish::all(['id', 'name', 'subcounty_id'])->pluck("name_with_subcounty", "id")->prepend('- select -', '')->toArray();
|
||||
|
||||
return view('clinical_data::villages.create', compact('parishes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'parish_id' => 'required'
|
||||
]);
|
||||
|
||||
$user_id = Auth::user()->id;
|
||||
$village = new Village;
|
||||
|
||||
$village->name = $request->name;
|
||||
$village->parish_id = $request->parish_id;
|
||||
$village->created_by = $user_id;
|
||||
$village->updated_by = $user_id;
|
||||
|
||||
try {
|
||||
$village->save();
|
||||
flash($request->name . " Village has been saved")->success();
|
||||
return redirect("/villages/");
|
||||
} 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) {
|
||||
$village = Village::where(['id' => $id])->first();
|
||||
|
||||
$parishes = Parish::all(['id', 'name', 'subcounty_id'])->pluck("name_with_subcounty", "id")->prepend('- select -', '')->toArray();
|
||||
|
||||
if (!$village) {
|
||||
flash()->error("That village is not registered");
|
||||
return redirect('/villages/');
|
||||
} else {
|
||||
return view('clinical_data::villages.edit', compact('village', 'parishes'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'parish_id' => 'required'
|
||||
]);
|
||||
|
||||
$village = Village::find($id);
|
||||
|
||||
$village->name = $request->name;
|
||||
$village->parish_id = $request->parish_id;
|
||||
$village->updated_by = Auth::user()->id;
|
||||
|
||||
try {
|
||||
$village->save();
|
||||
flash($request->name . " Village has been updated")->success();
|
||||
return redirect("/villages/");
|
||||
} 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) {
|
||||
$village = Village::find($id);
|
||||
|
||||
if ($village->delete()) {
|
||||
flash("Village has been deleted.")->success();
|
||||
return redirect('/villages/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
$villages = Village::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->get();
|
||||
|
||||
$parishes = Parish::pluck('name', 'id');
|
||||
|
||||
if (count($villages) < 1) {
|
||||
flash()->error("There is no inactive villages");
|
||||
return redirect('/villages/');
|
||||
} else {
|
||||
return view('clinical_data::villages.inactive', compact('villages', 'parishes'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$village = Village::withTrashed()->find($id);
|
||||
|
||||
if($village->restore()){
|
||||
flash("Village has been activated.")->success();
|
||||
return redirect('/villages/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user