54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Staff;
|
|
|
|
use App\Http\Controllers\HashidControllerBase;
|
|
use App\Http\Requests\AssignPhysicianRequest;
|
|
use App\Models\Enums\UserRole;
|
|
use App\Models\Study;
|
|
use App\Models\User;
|
|
use App\Services\AuditTrail\Activity;
|
|
|
|
class StudyAssignmentController extends HashidControllerBase
|
|
{
|
|
public function show()
|
|
{
|
|
$this->decodeKeys();
|
|
$study = Study::with('assignedPhysician')->findOrFail($this->key);
|
|
$rads = User::active()->role(UserRole::Radiologist)->get(['id', 'display_name', 'profile_photo_path', 'first_name', 'last_name']);
|
|
|
|
return view('staff.studies.assign-form', compact('study', 'rads'));
|
|
}
|
|
|
|
public function remove()
|
|
{
|
|
$this->decodeKeys();
|
|
$study = Study::with('assignedPhysician')->findOrFail($this->key);
|
|
if ($study->assigned_physician_id !== null) {
|
|
$study->update(['assigned_physician_id' => null]);
|
|
audit()
|
|
->did(Activity::Unassign_Physician)
|
|
->notes("Unassigned: {$study->assignedPhysician?->display_name}")
|
|
->on($study)
|
|
->log();
|
|
}
|
|
|
|
return redirect()->route('staff.worklist.index')->with('success', 'Removed assignment');
|
|
}
|
|
|
|
public function save(AssignPhysicianRequest $request)
|
|
{
|
|
$this->decodeKeys();
|
|
$study = Study::findOrFail($this->key);
|
|
$rad = User::active()->findOrFail($request->input('rad_id'));
|
|
$study->update(['assigned_physician_id' => $rad->id]);
|
|
audit()
|
|
->did(Activity::Assign_Physician)
|
|
->on($study)
|
|
->notes("Assigned: {$rad->display_name}")
|
|
->log();
|
|
|
|
return redirect()->route('staff.worklist.index')->with('success', "Assigned study to {$rad->display_name}");
|
|
}
|
|
}
|