diff --git a/app/Domain/ACL/Permission.php b/app/Domain/ACL/Permission.php index e16f6c3..5d9a18b 100644 --- a/app/Domain/ACL/Permission.php +++ b/app/Domain/ACL/Permission.php @@ -16,6 +16,7 @@ enum Permission: string case ReportEdit = 'report_edit'; case ReportDictate = 'report_dictate'; case ReportDownload = 'report_download'; + case ReportApprove = 'report_approve'; case StudyNotesCreate = 'study_notes_create'; case StudyNotesView = 'study_notes_view'; case AttachmentUpload = 'attachment_upload'; diff --git a/app/Http/Controllers/Staff/ReportController.php b/app/Http/Controllers/Staff/ReportController.php index 878f023..9dfaff8 100644 --- a/app/Http/Controllers/Staff/ReportController.php +++ b/app/Http/Controllers/Staff/ReportController.php @@ -3,8 +3,11 @@ 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 { @@ -12,7 +15,7 @@ public function popup() { abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportDownload]), 403); $this->decodeKeys(); - $study = Study::with('reports')->findOrFail($this->key); + $study = Study::with(['reports.radiologist', 'readingPhysician'])->findOrFail($this->key); if (me()->isRadiologist()) { abort_unless($study->isAssignedTo(), 403); } @@ -20,4 +23,39 @@ public function popup() 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->setContent(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')); + } } diff --git a/app/Http/Requests/CreateReportRequest.php b/app/Http/Requests/CreateReportRequest.php new file mode 100644 index 0000000..79bccc1 --- /dev/null +++ b/app/Http/Requests/CreateReportRequest.php @@ -0,0 +1,23 @@ + ['required', new ExistsByHash(Study::class)], + 'content' => 'required', + ]; + } +} diff --git a/app/Models/Study.php b/app/Models/Study.php index d7aec90..58fd839 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -131,7 +131,7 @@ public function getReportStatusLedAttribute(): string { $color = match ($this->report_status) { ReportStatus::Unread => 'bg-white', - ReportStatus::Opened => 'bg-secondary', + // ReportStatus::Opened => 'bg-secondary', ReportStatus::Preliminary => 'bg-info', ReportStatus::Finalized => 'bg-primary', ReportStatus::Approved => 'bg-success', diff --git a/resources/views/staff/reports/create.blade.php b/resources/views/staff/reports/create.blade.php new file mode 100644 index 0000000..ab93106 --- /dev/null +++ b/resources/views/staff/reports/create.blade.php @@ -0,0 +1,367 @@ + + +
+ + +{{ $report->created_at }} | {{ $report->report_status->name }} | {{ $report->radiologist?->name }} | + |