user()->may(Permission::StudyMetadataView), 403); $this->decodeKeys(); $study = Study::findOrFail($this->key); return view('staff.meta.view', compact('study')); } public function edit() { abort_unless(auth()->user()->may(Permission::StudyMetadataEdit), 403); $this->decodeKeys(); $study = Study::findOrFail($this->key); if (in_array($study->report_status->value, [ ReportStatus::Finalized->value, ReportStatus::Approved->value, ], true)) { return view('content.pages.notice', [ 'title' => 'Study Locked', 'color' => 'danger', 'heading' => 'Study Locked', 'message' => 'Study metadata cannot be edited once the report has been finalized.', ]); } return view('staff.meta.edit', compact('study')); } public function save(StudyMetadataUpdateRequest $request) { abort_unless(auth()->user()->may(Permission::StudyMetadataEdit), 403); $this->decodeKeys(); $study = Study::findOrFail($this->key); abort_if($study->report_status->value >= ReportStatus::Finalized->value, 403); $payload = array_trim_strings($request->validated()); $payload['body_part_examined'] = strtoupper($payload['body_part_examined']); $payload['patient_sex'] = strtoupper($payload['patient_sex']); if ($request->has('cancel_read')) { // lock the study if report is not needed $payload['report_status'] = ReportStatus::Cancelled->value; $payload['locked_at'] = now(); unset($payload['cancel_read']); } $study->update($payload); audit() ->on($study) ->did(Activity::Study_Metadata_Edit) ->log(); // return redirect()->route('staff.history.view', _h($this->key)); return view('content.pages.close-window'); } }