may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove, Permission::ReportDownload]), 403); $this->decodeKeys(); $study = Study::with(['reports.radiologist', 'reports.study', 'assignedPhysicians'])->findOrFail($this->key); 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(CreateReportRequest $request) { abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove]), 403); $this->decodeKeys(); $study = Study::findOrFail($this->key); $reportStatus = ReportStatus::from($request->integer('report_status')); $report = StudyReport::make([ 'study_id' => $study->id, 'institute_id' => $study->institute_id, 'facility_id' => $study->facility_id, 'report_status' => $reportStatus->value, 'read_by_id' => me()->id, ]); $report->saveContent(request('content')); $report->save(); if ($reportStatus->value >= ReportStatus::Finalized) { // todo: log activities $report->setStatus($reportStatus); $study->setReportStatus($reportStatus); $study->unlockStudy(); } return view('staff.reports.close-window'); } public function create() { abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove]), 403); $this->decodeKeys(); $study = Study::findOrFail($this->key); if (! $study->canEditReport()) { return redirect()->back()->with('error', 'Report is already approved.'); } $report = StudyReport::where('study_id', $study->id) ->where('report_status', ReportStatus::Preliminary->value) ->latest() ->first(); $close = false; return view('staff.reports.create', compact('study', 'report', 'close')); } public function edit(string $uuid) { abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove]), 403); $report = StudyReport::with(['study', 'radiologist'])->where('accession_number', $uuid)->firstOrFail(); $study = $report->study; $title = 'View Report'; $close = false; return view('staff.reports.create', compact('study', 'report', 'close')); } public function view(string $uuid) { abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove, Permission::ReportDownload]), 403); $report = StudyReport::with(['study', 'radiologist'])->where('accession_number', $uuid)->firstOrFail(); $title = 'View Report'; return view('staff.reports.viewer.html-report', compact('report', 'title')); } }