download
This commit is contained in:
parent
8f6859e275
commit
50d657004e
@ -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'));
|
||||
}
|
||||
}
|
||||
|
23
app/Http/Controllers/Staff/ReportDownloadController.php
Normal file
23
app/Http/Controllers/Staff/ReportDownloadController.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Staff;
|
||||
|
||||
use App\Domain\ACL\Permission;
|
||||
use App\Domain\Report\ExportFormat;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\StudyReport;
|
||||
use App\Services\Export\Exporters;
|
||||
use App\Services\ReportStorage;
|
||||
|
||||
final class ReportDownloadController extends Controller
|
||||
{
|
||||
public function __invoke(string $uuid, string $format)
|
||||
{
|
||||
abort_unless(me()->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));
|
||||
}
|
||||
}
|
@ -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 '~';
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -5,7 +5,9 @@
|
||||
<td>{{ $report->report_status->name }}</td>
|
||||
<td>{{ $report->radiologist?->name }}</td>
|
||||
<td><a class="btn btn-primary btn-xs" target="_blank" href="{{ $report->viewUrl() }}">VW</a></td>
|
||||
<td><a class="btn btn-info btn-xs" target="_blank" href="{{ $report->downloadUrl() }}">DL</a></td>
|
||||
<td><a class="btn btn-info btn-xs" target="_blank" href="{{ $report->wordDownloadUrl() }}">doc</a></td>
|
||||
<td><a class="btn btn-danger btn-xs" target="_blank" href="{{ $report->pdfDownloadUrl() }}">pdf</a></td>
|
||||
<td><a class="btn btn-warning btn-xs" target="_blank" href="{{ $report->htmlDownloadUrl() }}">htm</a></td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
{!! $report->getContent() !!}
|
||||
</body>
|
||||
</html>
|
36
resources/views/staff/reports/viewer/html-report.blade.php
Normal file
36
resources/views/staff/reports/viewer/html-report.blade.php
Normal file
@ -0,0 +1,36 @@
|
||||
@extends('staff.reports.viewer.layout')
|
||||
|
||||
@section('content')
|
||||
<table class="table table-bordered table-sm border-dark mb-4">
|
||||
<tr>
|
||||
<td class="fw-semibold text-bg-light">Patient Name</td>
|
||||
<td>{{ $report->study->patient_name }}</td>
|
||||
<td class="fw-semibold text-bg-light">Patient ID</td>
|
||||
<td>{{ $report->study->patient_id }}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="fw-semibold text-bg-light">Accession No</td>
|
||||
<td>{{ $report->study->accession_number }}</td>
|
||||
<td class="fw-semibold text-bg-light">Age/Gender</td>
|
||||
<td>{{ $report->study->sexAge() }}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="fw-semibold text-bg-light">Referred By</td>
|
||||
<td>{{ $report->study->referring_physician_name }}</td>
|
||||
<td class="fw-semibold text-bg-light">Date</td>
|
||||
<td>{{ $report->created_at->format('d-M-Y') }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h6 style="text-align: center">
|
||||
{{ $report->study->modality }} REPORT
|
||||
</h6>
|
||||
|
||||
<h3 style="text-align: center">
|
||||
{{ $report->study->study_description }}
|
||||
</h3>
|
||||
|
||||
{!! $report->getContent() !!}
|
||||
@endsection
|
29
resources/views/staff/reports/viewer/layout.blade.php
Normal file
29
resources/views/staff/reports/viewer/layout.blade.php
Normal file
@ -0,0 +1,29 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" crossorigin="anonymous">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400..900&display=swap" rel="stylesheet">
|
||||
<title>{{ $title }}</title>
|
||||
<style>
|
||||
body {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
font-family: "Inter", serif;
|
||||
font-optical-sizing: auto;
|
||||
}
|
||||
</style>
|
||||
@stack('header')
|
||||
</head>
|
||||
<body>
|
||||
<div class="container py-4 px-3 mx-auto">
|
||||
@yield('content')
|
||||
</div>
|
||||
|
||||
@stack('footer')
|
||||
</body>
|
||||
</html>
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user