refactoring
This commit is contained in:
parent
2de9bc1388
commit
49c1882a5a
18
app/Http/Controllers/HashedStudyControllerBase.php
Normal file
18
app/Http/Controllers/HashedStudyControllerBase.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Study;
|
||||
|
||||
class HashedStudyControllerBase extends HashidControllerBase
|
||||
{
|
||||
protected ?Study $study = null;
|
||||
|
||||
protected function getStudy(): Study
|
||||
{
|
||||
$this->decodeKeys();
|
||||
$this->study = Study::findOrFail($this->key);
|
||||
|
||||
return $this->study;
|
||||
}
|
||||
}
|
@ -4,18 +4,17 @@
|
||||
|
||||
use App\Domain\ACL\Permission;
|
||||
use App\Domain\Report\ReportStatus;
|
||||
use App\Http\Controllers\HashidControllerBase;
|
||||
use App\Http\Controllers\HashedStudyControllerBase;
|
||||
use App\Http\Requests\StudyMetadataUpdateRequest;
|
||||
use App\Models\Study;
|
||||
use App\Services\AuditTrail\Activity;
|
||||
|
||||
class MetadataController extends HashidControllerBase
|
||||
class MetadataController extends HashedStudyControllerBase
|
||||
{
|
||||
public function view()
|
||||
{
|
||||
abort_unless(auth()->user()->may(Permission::StudyMetadataView), 403);
|
||||
$this->decodeKeys();
|
||||
$study = Study::findOrFail($this->key);
|
||||
$study = $this->getStudy();
|
||||
|
||||
return view('staff.meta.view', compact('study'));
|
||||
}
|
||||
@ -23,8 +22,7 @@ public function view()
|
||||
public function edit()
|
||||
{
|
||||
abort_unless(auth()->user()->may(Permission::StudyMetadataEdit), 403);
|
||||
$this->decodeKeys();
|
||||
$study = Study::findOrFail($this->key);
|
||||
$study = $this->getStudy();
|
||||
|
||||
if ($study->isReportReady()) {
|
||||
return view('content.pages.notice', [
|
||||
@ -41,9 +39,9 @@ public function edit()
|
||||
public function save(StudyMetadataUpdateRequest $request)
|
||||
{
|
||||
abort_unless(auth()->user()->may(Permission::StudyMetadataEdit), 403);
|
||||
$this->decodeKeys();
|
||||
$study = Study::findOrFail($this->key);
|
||||
$study = $this->getStudy();
|
||||
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']);
|
||||
@ -53,6 +51,7 @@ public function save(StudyMetadataUpdateRequest $request)
|
||||
$payload['locked_at'] = now();
|
||||
unset($payload['cancel_read']);
|
||||
}
|
||||
|
||||
$study->update($payload);
|
||||
audit()
|
||||
->on($study)
|
||||
|
Loading…
Reference in New Issue
Block a user