mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-12 19:21:33 +00:00
resolved conflicts
This commit is contained in:
+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');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user