decodeKeys(); $study = Study::with(['reports.radiologist', 'reports.study', 'assignedPhysicians'])->findOrFail($this->key); if ($study->reports->isEmpty()) { return view('content.pages.partials._alert-div', [ 'color' => 'secondary', 'heading' => 'Unread study', 'message' => 'This study has not been interpreted yet. No reports are available.', ]); } if (me()->isRadiologist()) { // abort_unless($study->isAssigned(), 403); abort_unless($study->isUserInStudyAssignmentsOrReadingPhysician(), 403); } $reports = $study->reports->sortByDesc('created_at'); return view('staff.reports.popup', compact('study', 'reports')); } public function save(StoreReportRequest $request) { ReportManager::ensureEditAccess(); $this->decodeKeys(); $manager = ReportManager::make($this->key); $reportStatus = ReportStatus::from($request->integer('report_status')); $report = $manager->createReport(request('content'), $reportStatus); if ($reportStatus->value === ReportStatus::Finalized->value) { $manager->finalizeReport($report); } return view('content.pages.close-window'); } public function create() { ReportManager::ensureEditAccess(); $this->decodeKeys(); $manager = ReportManager::make($this->key); $view = $manager->check(); if ($view) { return $view; } $manager->lockStudyIfRequired(); $study = $manager->getStudy(); $report = $manager->latestReport(); // todo: study_status: Read in Progress return view('staff.reports.create', compact('study', 'report')); } public function edit(string $uuid) { ReportManager::ensureEditAccess(); $manager = ReportManager::fromReport($uuid); $view = $manager->check(); if ($view) { return $view; } $manager->lockStudyIfRequired(); $study = $manager->getStudy(); $report = $manager->getReport(); return view('staff.reports.create', compact('study', 'report')); } public function view(string $uuid) { ReportManager::ensureDownloadAccess(); $manager = ReportManager::fromReport($uuid); $title = 'Report Quick View ' . $manager->getStudy()->getPatientDemographic(); $report = $manager->getReportForViewing(); $copy_button = false; if ($report->isFinalized()) { $stamper = new StampService($report->read_by_id); $signature = $stamper->hasSignatureImage() ? $stamper->signatureImageUrl() : null; $notice = null; $copy_button = true; } else { $signature = null; $notice = 'This is a preliminary radiology interpretation that has not been finalized or approved by a radiologist. It is not intended for diagnostic purposes.'; } return view('staff.reports.viewer.html-report', compact('report', 'title', 'signature', 'notice', 'copy_button')); } }