diff --git a/app/Http/Controllers/Staff/ReportController.php b/app/Http/Controllers/Staff/ReportController.php index 91893ac..e8ebb3a 100644 --- a/app/Http/Controllers/Staff/ReportController.php +++ b/app/Http/Controllers/Staff/ReportController.php @@ -3,14 +3,11 @@ namespace App\Http\Controllers\Staff; use App\Domain\ACL\Permission; -use App\Domain\Report\ExportFormat; use App\Domain\Report\ReportStatus; use App\Http\Controllers\HashidControllerBase; use App\Http\Requests\CreateReportRequest; use App\Models\Study; use App\Models\StudyReport; -use App\Services\Export\Exporters; -use App\Services\ReportStorage; class ReportController extends HashidControllerBase { @@ -63,21 +60,11 @@ public function create() } public function view(string $uuid) - { - abort_unless(me()->may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove, Permission::ReportDownload]), 403); - // $study = Study::with(['reports.radiologist', 'readingPhysician'])->where('accession_number', $uuid)->firstOrFail(); - $report = StudyReport::where('accession_number', $uuid)->firstOrFail(); - - return view('staff.reports.view', compact('report')); - } - - public function download(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'; - $path = Exporters::make($report->study, $report, ExportFormat::Word2007); - - return response()->download(ReportStorage::abspath($path)); + return view('staff.reports.viewer.html-report', compact('report', 'title')); } } diff --git a/app/Http/Controllers/Staff/ReportDownloadController.php b/app/Http/Controllers/Staff/ReportDownloadController.php new file mode 100644 index 0000000..535b6bc --- /dev/null +++ b/app/Http/Controllers/Staff/ReportDownloadController.php @@ -0,0 +1,23 @@ +may([Permission::ReportEdit, Permission::ReportDictate, Permission::ReportApprove, Permission::ReportDownload]), 403); + $report = StudyReport::with(['study', 'radiologist'])->where('accession_number', $uuid)->firstOrFail(); + + $path = Exporters::make($report->study, $report, ExportFormat::from(strtolower($format))); + + return response()->download(ReportStorage::abspath($path)); + } +} diff --git a/app/Models/Study.php b/app/Models/Study.php index 06df51b..89d7919 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -92,10 +92,16 @@ public function getMetadataLink(): string return '#'; } - public function sexAge(): string + public function getAge(): ?string { $dob = $this->patient_birthdate; - $age = $dob ? (int) Carbon::make($dob)->diffInYears() . 'Y' : null; + + return $dob ? (int) Carbon::make($dob)->diffInYears() . 'Y' : null; + } + + public function sexAge(): string + { + $age = $this->getAge(); if (blank($age) && blank($this->patient_sex)) { return '~'; } diff --git a/app/Models/StudyReport.php b/app/Models/StudyReport.php index 1667db4..26e7b6a 100644 --- a/app/Models/StudyReport.php +++ b/app/Models/StudyReport.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Domain\Report\ExportFormat; use App\Domain\Report\ReportStatus; use App\Services\ReportStorage; use Illuminate\Database\Eloquent\Concerns\HasTimestamps; @@ -47,9 +48,19 @@ public function setStatus(ReportStatus $status, User|int|null $user = null): voi $this->update($params); } - public function downloadUrl(): string + public function wordDownloadUrl(): string { - return route('staff.report.download', $this->accession_number); + return route('staff.report.download', ['uuid' => $this->accession_number, 'format' => ExportFormat::Word2007->value]); + } + + public function pdfDownloadUrl(): string + { + return route('staff.report.download', ['uuid' => $this->accession_number, 'format' => ExportFormat::Pdf->value]); + } + + public function htmlDownloadUrl(): string + { + return route('staff.report.download', ['uuid' => $this->accession_number, 'format' => ExportFormat::Html->value]); } public function viewUrl(): string diff --git a/app/Services/Export/ExportDocumentBase.php b/app/Services/Export/ExportDocumentBase.php index b6e7d4c..52d59bb 100644 --- a/app/Services/Export/ExportDocumentBase.php +++ b/app/Services/Export/ExportDocumentBase.php @@ -4,6 +4,7 @@ use App\Models\Study; use App\Models\StudyReport; +use Illuminate\Support\Str; abstract class ExportDocumentBase implements IExportDocument { @@ -20,6 +21,6 @@ abstract protected function getExtension(): string; protected function filename(): string { - return $this->report->accession_number . '.' . $this->getExtension(); + return Str::slug($this->report->accession_number) . '.' . $this->getExtension(); } } diff --git a/app/Services/Export/Formats/HtmlExport.php b/app/Services/Export/Formats/HtmlExport.php index 9a5379c..76d7577 100644 --- a/app/Services/Export/Formats/HtmlExport.php +++ b/app/Services/Export/Formats/HtmlExport.php @@ -5,6 +5,7 @@ use App\Domain\Report\ExportFormat; use App\Services\Export\ExportDocumentBase; use App\Services\ReportStorage; +use Illuminate\Support\Facades\Blade; final class HtmlExport extends ExportDocumentBase { @@ -16,7 +17,8 @@ protected function handle(): string return $filepath; } - $html = $this->report->getContent(); + $title = 'View Report'; + $html = Blade::render('staff.reports.viewer.html-report', ['report' => $this->report, 'title' => $title]); file_put_contents(ReportStorage::abspath($filepath), $html); return $filepath; diff --git a/app/Services/Export/Formats/PdfExport.php b/app/Services/Export/Formats/PdfExport.php index cf180de..c2d5d9a 100644 --- a/app/Services/Export/Formats/PdfExport.php +++ b/app/Services/Export/Formats/PdfExport.php @@ -5,6 +5,7 @@ use App\Domain\Report\ExportFormat; use App\Services\Export\ExportDocumentBase; use App\Services\ReportStorage; +use Barryvdh\DomPDF\Facade\Pdf; final class PdfExport extends ExportDocumentBase { @@ -16,9 +17,11 @@ protected function handle(): string return $filepath; } - $html = $this->report->getContent(); - // todo: implement pdf generation - file_put_contents(ReportStorage::abspath($filepath), $html); + $data = ['report' => $this->report, 'title' => 'PDF VIEW']; + Pdf::loadView('staff.reports.viewer.html-report', $data) + ->setPaper('a4', 'landscape') + ->setWarnings(false) + ->save(ReportStorage::abspath($filepath)); return $filepath; } diff --git a/composer.json b/composer.json index ad9bf81..a644960 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "license": "MIT", "require": { "php": ">=8.3", + "barryvdh/laravel-dompdf": "^3.0", "culturegr/presenter": "^1.4", "hashids/hashids": "^5.0", "laravel/framework": "^11.31", diff --git a/resources/views/staff/reports/popup.blade.php b/resources/views/staff/reports/popup.blade.php index 92ef65c..be0878a 100644 --- a/resources/views/staff/reports/popup.blade.php +++ b/resources/views/staff/reports/popup.blade.php @@ -5,7 +5,9 @@ {{ $report->report_status->name }} {{ $report->radiologist?->name }} VW - DL + doc + pdf + htm @endforeach diff --git a/resources/views/staff/reports/view.blade.php b/resources/views/staff/reports/view.blade.php deleted file mode 100644 index 0d37138..0000000 --- a/resources/views/staff/reports/view.blade.php +++ /dev/null @@ -1,5 +0,0 @@ - - - {!! $report->getContent() !!} - - diff --git a/resources/views/staff/reports/viewer/html-report.blade.php b/resources/views/staff/reports/viewer/html-report.blade.php new file mode 100644 index 0000000..ed6f236 --- /dev/null +++ b/resources/views/staff/reports/viewer/html-report.blade.php @@ -0,0 +1,36 @@ +@extends('staff.reports.viewer.layout') + +@section('content') + + + + + + + + + + + + + + + + + + + + + +
Patient Name{{ $report->study->patient_name }}Patient ID{{ $report->study->patient_id }}
Accession No{{ $report->study->accession_number }}Age/Gender{{ $report->study->sexAge() }}
Referred By{{ $report->study->referring_physician_name }}Date{{ $report->created_at->format('d-M-Y') }}
+ +
+ {{ $report->study->modality }} REPORT +
+ +

+ {{ $report->study->study_description }} +

+ + {!! $report->getContent() !!} +@endsection diff --git a/resources/views/staff/reports/viewer/layout.blade.php b/resources/views/staff/reports/viewer/layout.blade.php new file mode 100644 index 0000000..cb54edb --- /dev/null +++ b/resources/views/staff/reports/viewer/layout.blade.php @@ -0,0 +1,29 @@ + + + + + + + + + + + {{ $title }} + + @stack('header') + + +
+ @yield('content') +
+ + @stack('footer') + + diff --git a/routes/web.php b/routes/web.php index d677c3f..2ef432b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,6 +9,7 @@ use App\Http\Controllers\Staff\DicomViewerController; use App\Http\Controllers\Staff\HistoryController; use App\Http\Controllers\Staff\ReportController; +use App\Http\Controllers\Staff\ReportDownloadController; use App\Http\Controllers\Staff\StudiesController; use App\Http\Controllers\Staff\WorklistController; use App\Http\Controllers\StudyMetadataController; @@ -86,9 +87,9 @@ Route::group(['prefix' => 'report', 'as' => 'report.'], function () { Route::get('popup', [ReportController::class, 'popup'])->name('popup'); Route::get('view/{uuid}', [ReportController::class, 'view'])->name('view'); - Route::get('download/{uuid}', [ReportController::class, 'download'])->name('download'); Route::get('create/{hashid}', [ReportController::class, 'create'])->name('create'); Route::post('save', [ReportController::class, 'save'])->name('save'); + Route::get('download/{uuid}/{format}', ReportDownloadController::class)->name('download'); }); });