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:
Executable
+188
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Investigations\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Streamline\Models\Investigation;
|
||||
use Streamline\Models\InvestigationResultTemplate;
|
||||
|
||||
class InvestigationResultTemplateController extends Controller {
|
||||
|
||||
public function index() {
|
||||
$result_templates = InvestigationResultTemplate::orderBy('template', 'asc')->get();
|
||||
$investigations = Investigation::get();
|
||||
|
||||
return view('investigations::investigation_result_templates.index', compact('result_templates', 'investigations'));
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$investigations = DB::table("investigations")->whereNull("deleted_at")->orderBy("name")->pluck("name", "id")->toArray();
|
||||
$investigations = [0 => 'All Investigations'] + $investigations;
|
||||
$investigations = ['' => '- select -'] + $investigations;
|
||||
|
||||
return view('investigations::investigation_result_templates.create', compact('investigations'));
|
||||
}
|
||||
|
||||
public function store(Request $request) {
|
||||
request()->validate([
|
||||
'investigation_id' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
if ($request->is_specialised_variable == 1) {
|
||||
$ids = $request->investigation_specialised_variable;
|
||||
$templates = $request->template_var;
|
||||
|
||||
for($x = 0; $x < count($ids); $x++) {
|
||||
$result_template = new InvestigationResultTemplate;
|
||||
$result_template->investigation_id = $ids[$x];
|
||||
$result_template->template = $templates[$x];
|
||||
$result_template->is_specialised_variable = 1;
|
||||
$result_template->created_by = $logged_in_user_id;
|
||||
$result_template->updated_by = $logged_in_user_id;
|
||||
$result_template->save();
|
||||
}
|
||||
} else {
|
||||
$result_template = new InvestigationResultTemplate;
|
||||
$result_template->template = $request->template;
|
||||
$result_template->investigation_id = $request->investigation_id;
|
||||
$result_template->is_specialised_variable = $request->is_specialised_variable;
|
||||
$result_template->created_by = $logged_in_user_id;
|
||||
$result_template->updated_by = $logged_in_user_id;
|
||||
$result_template->save();
|
||||
}
|
||||
|
||||
flash("Result Template has been saved")->success();
|
||||
return redirect("/result_templates/");
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
public function edit($id) {
|
||||
$result_template = InvestigationResultTemplate::where(['id' => $id])->first();
|
||||
|
||||
if (!$result_template) {
|
||||
flash()->error("Result Template not found");
|
||||
return redirect('/result_templates/');
|
||||
} else {
|
||||
return view('investigations::investigation_result_templates.edit', compact('result_template'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, $id) {
|
||||
request()->validate([
|
||||
'template' => 'required'
|
||||
]);
|
||||
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
$result_template = InvestigationResultTemplate::find($id);
|
||||
|
||||
$result_template->template = $request->template;
|
||||
$result_template->created_by = $logged_in_user_id;
|
||||
$result_template->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$result_template->save();
|
||||
|
||||
flash($request->name . "Result Template has been saved")->success();
|
||||
return redirect("/result_templates/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred. Please try again")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id) {
|
||||
$result_template = InvestigationResultTemplate::find($id);
|
||||
|
||||
if ($result_template->delete()){
|
||||
flash("Result Template has been deleted.")->error();
|
||||
return redirect('/result_templates/');
|
||||
} else {
|
||||
flash("An error occurred. Please try again")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function inactive() {
|
||||
$result_templates = InvestigationResultTemplate::onlyTrashed()
|
||||
->paginate(50);
|
||||
|
||||
if (count($result_templates) < 1) {
|
||||
flash()->error("There is no inactive Result Templates");
|
||||
return redirect('/result_templates/');
|
||||
} else {
|
||||
return view('investigations::investigation_result_templates.inactive', compact('result_templates'));
|
||||
}
|
||||
}
|
||||
|
||||
public function activate($id) {
|
||||
$result_template = InvestigationResultTemplate::withTrashed()->find($id);
|
||||
|
||||
if ($result_template->restore()){
|
||||
flash("Result Template has been activated.")->success();
|
||||
return redirect('/result_templates/');
|
||||
} else {
|
||||
flash("An error occurred. Please try again")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function check_investigation_speciality_type($id, $counter) {
|
||||
if (get_name($id, 'id', 'type', 'investigations') == 1){
|
||||
$code = "<label for='investigation_specialised_variable'>Investigation Specialised Variable</label>";
|
||||
$code .= "<select name='investigation_specialised_variable[]' class='form-control' id='" . $counter . "'>";
|
||||
$code .= "<option value=''> --select-- </option>";
|
||||
|
||||
$variables = DB::table('investigation_specialised_variables')
|
||||
->where('investigation_id', $id)
|
||||
->whereNull('deleted_at')
|
||||
->get();
|
||||
|
||||
foreach ($variables as $variable){
|
||||
$code .= "<option value='" . $variable->id . "'>" . $variable->name . "</option>";
|
||||
}
|
||||
|
||||
$code .= "</select><br><br>";
|
||||
|
||||
$code .= "<label for='template'>Template</label>";
|
||||
$code .= "<textarea class='form-control' rows='3' name='template_var[]'></textarea><br><br>";
|
||||
} else {
|
||||
$code = "0";
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function get_templates_for_investigation($id, $is_variable) {
|
||||
$templates = DB::table('investigation_result_templates')
|
||||
->whereIn('investigation_id', [$id, 0])
|
||||
->where('is_specialised_variable', $is_variable)
|
||||
->whereNull('deleted_at')
|
||||
->get();
|
||||
|
||||
$code = "<table class='table color-bordered-table success-bordered-table'>";
|
||||
$code .= "<thead><tr>";
|
||||
$code .= "<th>Template</th><th>Action</th>";
|
||||
$code .= "</tr></thead><tbody>";
|
||||
|
||||
foreach($templates as $template) {
|
||||
$code .= "<tr>";
|
||||
$code .= "<td id='template_" . $template->id . "'>" . $template->template . "</td>";
|
||||
$code .= "<td>";
|
||||
$code .= "<button class='btn btn-rounded btn-success btn-sm' onclick='confirm_selection(" . '"' . $template->id . '"' . ")'>select</button>";
|
||||
$code .= "</td>";
|
||||
$code .= "</tr>";
|
||||
}
|
||||
|
||||
$code .= "</tbody></table>";
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user