mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
317 lines
9.7 KiB
PHP
Executable File
317 lines
9.7 KiB
PHP
Executable File
<?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);
|
|
}
|
|
}
|