72 lines
2.7 KiB
PHP
72 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Staff;
|
|
|
|
use App\Domain\ACL\Permission;
|
|
use App\Domain\Report\ReportStatus;
|
|
use App\Http\Controllers\HashidControllerBase;
|
|
use App\Http\Requests\CreateReportRequest;
|
|
use App\Models\Study;
|
|
use App\Models\StudyReport;
|
|
|
|
class ReportController extends HashidControllerBase
|
|
{
|
|
public function popup()
|
|
{
|
|
abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove, Permission::ReportDownload]), 403);
|
|
$this->decodeKeys();
|
|
$study = Study::with(['reports.radiologist', 'reports.study', 'assignedPhysicians'])->findOrFail($this->key);
|
|
if (me()->isRadiologist()) {
|
|
// abort_unless($study->isAssigned(), 403);
|
|
abort_unless($study->isUserInStudyAssignmentsOrReadingPhysician(), 403);
|
|
}
|
|
$reports = $study->reports->sortByDesc('created_at');
|
|
|
|
return view('staff.reports.popup', compact('study', 'reports'));
|
|
}
|
|
|
|
public function save(CreateReportRequest $request)
|
|
{
|
|
abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove]), 403);
|
|
$this->decodeKeys();
|
|
$study = Study::findOrFail($this->key);
|
|
|
|
$report = StudyReport::make([
|
|
'study_id' => $study->id,
|
|
'institute_id' => $study->institute_id,
|
|
'facility_id' => $study->facility_id,
|
|
'report_status' => ReportStatus::Preliminary->value,
|
|
'read_by_id' => me()->id,
|
|
]);
|
|
$report->saveContent(request('content'));
|
|
$report->save();
|
|
|
|
return redirect()->back()->with('success', 'Report saved successfully.');
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove]), 403);
|
|
$this->decodeKeys();
|
|
$study = Study::findOrFail($this->key);
|
|
if ($study->report_status >= ReportStatus::Finalized) {
|
|
return redirect()->back()->with('error', 'Report is already approved.');
|
|
}
|
|
$report = StudyReport::where('study_id', $study->id)
|
|
->where('report_status', ReportStatus::Preliminary->value)
|
|
->latest()
|
|
->first();
|
|
|
|
return view('staff.reports.create', compact('study', 'report'));
|
|
}
|
|
|
|
public function view(string $uuid)
|
|
{
|
|
abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove, Permission::ReportDownload]), 403);
|
|
$report = StudyReport::with(['study', 'radiologist'])->where('accession_number', $uuid)->firstOrFail();
|
|
$title = 'View Report';
|
|
|
|
return view('staff.reports.viewer.html-report', compact('report', 'title'));
|
|
}
|
|
}
|