diff --git a/app/Http/Controllers/Staff/ReportController.php b/app/Http/Controllers/Staff/ReportController.php index 2a01c9c..099c7a8 100644 --- a/app/Http/Controllers/Staff/ReportController.php +++ b/app/Http/Controllers/Staff/ReportController.php @@ -30,18 +30,26 @@ public function save(CreateReportRequest $request) abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove]), 403); $this->decodeKeys(); $study = Study::findOrFail($this->key); + $reportStatus = ReportStatus::from($request->integer('report_status')); $report = StudyReport::make([ 'study_id' => $study->id, 'institute_id' => $study->institute_id, 'facility_id' => $study->facility_id, - 'report_status' => ReportStatus::Preliminary->value, + 'report_status' => $reportStatus->value, 'read_by_id' => me()->id, ]); $report->saveContent(request('content')); $report->save(); - return redirect()->back()->with('success', 'Report saved successfully.'); + if ($reportStatus->value >= ReportStatus::Finalized) { + // todo: log activities + $report->setStatus($reportStatus); + $study->setReportStatus($reportStatus); + $study->unlockStudy(); + } + + return view('staff.reports.close-window'); } public function create() @@ -56,8 +64,9 @@ public function create() ->where('report_status', ReportStatus::Preliminary->value) ->latest() ->first(); + $close = false; - return view('staff.reports.create', compact('study', 'report')); + return view('staff.reports.create', compact('study', 'report', 'close')); } public function edit(string $uuid) @@ -66,8 +75,9 @@ public function edit(string $uuid) $report = StudyReport::with(['study', 'radiologist'])->where('accession_number', $uuid)->firstOrFail(); $study = $report->study; $title = 'View Report'; + $close = false; - return view('staff.reports.create', compact('study', 'report')); + return view('staff.reports.create', compact('study', 'report', 'close')); } public function view(string $uuid) diff --git a/app/Http/Requests/CreateReportRequest.php b/app/Http/Requests/CreateReportRequest.php index 79bccc1..ceb2fb2 100644 --- a/app/Http/Requests/CreateReportRequest.php +++ b/app/Http/Requests/CreateReportRequest.php @@ -2,9 +2,11 @@ namespace App\Http\Requests; +use App\Domain\Report\ReportStatus; use App\Models\Study; use App\Rules\ExistsByHash; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Rule; class CreateReportRequest extends FormRequest { @@ -18,6 +20,11 @@ public function rules(): array return [ 'hashid' => ['required', new ExistsByHash(Study::class)], 'content' => 'required', + 'report_status' => ['required', + + Rule::enum(ReportStatus::class) + ->only([ReportStatus::Preliminary, ReportStatus::Finalized, ReportStatus::Approved]), + ], ]; } } diff --git a/app/Models/StudyReport.php b/app/Models/StudyReport.php index cf7adb6..f19415b 100644 --- a/app/Models/StudyReport.php +++ b/app/Models/StudyReport.php @@ -102,11 +102,10 @@ public function canRemove(User|int|null $user = null): bool public function canEdit(User|int|null $user = null): bool { - if ($this->study->canEditReport() && - $this->report_status->value < ReportStatus::Finalized->value) { - if ($this->read_by_id === me($user)->id) { - return true; - } + if ($this->report_status->value < ReportStatus::Finalized->value && + $this->study->canEditReport() && + $this->read_by_id === me($user)->id) { + return true; } return false; diff --git a/public/ck.css b/public/ck.css index b9471b9..165c73f 100644 --- a/public/ck.css +++ b/public/ck.css @@ -55,9 +55,6 @@ .editor-container_include-word-count.editor-container_classic-editor .editor-con border-radius: 0; } - - - /* Let's give the editor some space and limits using a border. */ .ck-editor { margin: 0 0 1em; diff --git a/resources/views/ck.blade.php b/resources/views/ck.blade.php index 7994f81..1d6b2c7 100644 --- a/resources/views/ck.blade.php +++ b/resources/views/ck.blade.php @@ -16,30 +16,24 @@
-
+
+ -
-
-
-
-
-
-
-
+ +
+
+
+
+
+
- -