diff --git a/app/Http/Controllers/Staff/ReportController.php b/app/Http/Controllers/Staff/ReportController.php index fc72606..22577f6 100644 --- a/app/Http/Controllers/Staff/ReportController.php +++ b/app/Http/Controllers/Staff/ReportController.php @@ -56,13 +56,14 @@ public function create() { abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove]), 403); $this->decodeKeys(); - $study = Study::findOrFail($this->key); + $study = Study::select(['id', 'patient_name', 'patient_id', 'patient_sex', 'patient_birthdate', 'study_description'])->findOrFail($this->key); if (! $study->canEditReport()) { return redirect()->back()->with('error', 'Report is already approved.'); } - $report = StudyReport::where('study_id', $study->id) + $report = StudyReport::forStudy($study) ->where('report_status', ReportStatus::Preliminary->value) + ->select(['id', 'accession_number', 'file_path']) ->latest() ->first(); $close = false; diff --git a/app/Models/StudyReport.php b/app/Models/StudyReport.php index f19415b..2a9c003 100644 --- a/app/Models/StudyReport.php +++ b/app/Models/StudyReport.php @@ -5,6 +5,7 @@ use App\Domain\Report\ExportFormat; use App\Domain\Report\ReportStatus; use App\Services\Report\ReportStorage; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Concerns\HasTimestamps; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Support\Facades\Storage; @@ -28,6 +29,13 @@ public function approver(): BelongsTo return $this->belongsTo(User::class, 'approved_by_id'); } + public function scopeForStudy(Builder $query, Study|int $study): Builder + { + $query->where('study_id', $study instanceof Study ? $study->id : $study); + + return $query; + } + public function setStatus(ReportStatus $status, User|int|null $user = null): void { $user_id = me($user)->id; diff --git a/resources/views/staff/reports/create.blade.php b/resources/views/staff/reports/create.blade.php index 64e92bd..f974ab4 100644 --- a/resources/views/staff/reports/create.blade.php +++ b/resources/views/staff/reports/create.blade.php @@ -13,8 +13,21 @@
-HEADER
+Patient Name | +{{ $study->patient_name }} | +Patient Sex | +{{ $study->patient_sex }} | +
ID | +{{ $study->patient_id }} | +Description | +{{ $study->study_description }} | +