61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Staff;
|
|
|
|
use App\Domain\ACL\Permission;
|
|
use App\Domain\Report\ReportStatus;
|
|
use App\Http\Controllers\HashedStudyControllerBase;
|
|
use App\Http\Requests\StudyMetadataUpdateRequest;
|
|
use App\Models\Study;
|
|
use App\Services\AuditTrail\Activity;
|
|
|
|
class MetadataController extends HashedStudyControllerBase
|
|
{
|
|
public function view()
|
|
{
|
|
abort_unless(auth()->user()->may(Permission::StudyMetadataView), 403);
|
|
$study = $this->getStudy();
|
|
|
|
return view('staff.meta.view', compact('study'));
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
abort_unless(auth()->user()->may(Permission::StudyMetadataEdit), 403);
|
|
$study = $this->getStudy();
|
|
if ($study->isReportReady()) {
|
|
return $this->lockedNotice();
|
|
}
|
|
|
|
return view('staff.meta.edit', compact('study'));
|
|
}
|
|
|
|
public function save(StudyMetadataUpdateRequest $request)
|
|
{
|
|
abort_unless(auth()->user()->may(Permission::StudyMetadataEdit), 403);
|
|
$study = $this->getStudy();
|
|
if ($study->isReportReady()) {
|
|
return $this->lockedNotice();
|
|
}
|
|
|
|
$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');
|
|
}
|
|
}
|