diff --git a/app/Http/Controllers/Staff/ReportController.php b/app/Http/Controllers/Staff/ReportController.php index 5b7e33f..e0cf329 100644 --- a/app/Http/Controllers/Staff/ReportController.php +++ b/app/Http/Controllers/Staff/ReportController.php @@ -73,19 +73,42 @@ public function create() { abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove]), 403); $this->decodeKeys(); - $study = Study::select(['id', 'patient_name', 'patient_id', 'patient_sex', 'patient_birthdate', 'study_description', 'report_status', 'study_status'])->findOrFail($this->key); + $study = Study::select(['id', 'patient_name', 'patient_id', 'patient_sex', 'patient_birthdate', 'study_description', 'report_status', 'study_status', 'dicomServer'])->findOrFail($this->key); if (! $study->canEditReport()) { - return redirect()->back()->with('error', 'Report is already approved.'); + return view('content.pages.notice', [ + 'color' => 'warning', + 'title' => 'Read Completed', + 'heading' => 'Read Completed', + 'message' => 'Reading has been completed already.', + ]); } + if (! $study->canObtainLock()) { + return view('content.pages.notice', [ + 'color' => 'warning', + 'title' => 'Study Locked', + 'heading' => 'Study Locked', + 'message' => 'Study is locked by another user.', + ]); + } + + if ($study->isUnlocked()) { + $study->lockStudy(); + audit() + ->on($study) + ->did(Activity::Study_Lock) + ->log(); + } + + // todo: study_status: Read in Progress + $report = StudyReport::forStudy($study) ->where('report_status', ReportStatus::Preliminary->value) ->select(['id', 'accession_number', 'file_path']) ->latest() ->first(); - $close = false; - return view('staff.reports.create', compact('study', 'report', 'close')); + return view('staff.reports.create', compact('study', 'report')); } public function edit(string $uuid) diff --git a/app/Models/Study.php b/app/Models/Study.php index 7c41014..80b9c4e 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -404,6 +404,14 @@ public function isLockedBy(User|int|null $user = null): bool return $this->locking_physician_id === me($user)->id; } + /** + * Returns true if study has been locked by the given user or is unlocked. Returns false if the study was locked by another user. + */ + public function canObtainLock(User|int|null $user = null): bool + { + return $this->isUnlocked() || $this->isLockedBy($user); + } + public function setReportStatus(ReportStatus $status, User|int|null $user = null): void { $user_id = me($user)->id; diff --git a/resources/views/content/pages/notice.blade.php b/resources/views/content/pages/notice.blade.php new file mode 100644 index 0000000..71afa01 --- /dev/null +++ b/resources/views/content/pages/notice.blade.php @@ -0,0 +1,46 @@ + + + + + + + {{ $title }} + + + +
+ +
+
+
+

{{ $heading }}

+

{{ $message }}

+
+
+
+ + + diff --git a/resources/views/staff/reports/create.blade.php b/resources/views/staff/reports/create.blade.php index f37321e..0f0ac13 100644 --- a/resources/views/staff/reports/create.blade.php +++ b/resources/views/staff/reports/create.blade.php @@ -3,7 +3,7 @@ - SAVE + {{ $study->getPatientDemographic() }} @vite([ 'resources/assets/vendor/scss/core.scss', @@ -18,13 +18,13 @@ Patient Name {{ $study->patient_name }} - Patient Sex - {{ $study->patient_sex }} + Age / Sex + {{ $study->sexAge() }} ID {{ $study->patient_id }} - Description + Study {{ $study->study_description }}