diff --git a/app/Services/Export/ExportDocumentBase.php b/app/Services/Export/ExportDocumentBase.php index cc23954..e339a13 100644 --- a/app/Services/Export/ExportDocumentBase.php +++ b/app/Services/Export/ExportDocumentBase.php @@ -19,8 +19,8 @@ abstract protected function handle(): string; abstract protected function getExtension(): string; - protected function filename(): string + protected function filename(?string $ext = null): string { - return sprintf('exp_%s.%s', Str::slug($this->report->accession_number), $this->getExtension()); + return sprintf('exp_%s.%s', Str::slug($this->report->accession_number), $ext ?? $this->getExtension()); } } diff --git a/app/Services/Export/Exporters.php b/app/Services/Export/Exporters.php index e55d12c..91edc28 100644 --- a/app/Services/Export/Exporters.php +++ b/app/Services/Export/Exporters.php @@ -7,8 +7,8 @@ use App\Models\StudyReport; use app\Services\Export\Formats\HtmlExport; use app\Services\Export\Formats\PdfExport; -use app\Services\Export\Formats\Word2003Export; use app\Services\Export\Formats\Word2007Export; +use app\Services\Export\Formats\Word2003Export; final readonly class Exporters { diff --git a/app/Services/Export/Formats/PdfExport.php b/app/Services/Export/Formats/PdfExport.php index fc6c8ed..7e8bf47 100644 --- a/app/Services/Export/Formats/PdfExport.php +++ b/app/Services/Export/Formats/PdfExport.php @@ -3,28 +3,37 @@ namespace app\Services\Export\Formats; use App\Domain\Report\ExportFormat; -use App\Services\Export\ExportDocumentBase; use App\Services\Report\ReportStorage; -use Barryvdh\DomPDF\Facade\Pdf; -final class PdfExport extends ExportDocumentBase +final class PdfExport extends TemplatedDocExportBase { protected function handle(): string { $filename = $this->filename(); - $filepath = ReportStorage::customFilepath($this->study, $filename); + $pdf_path = ReportStorage::customFilepath($this->study, $filename); if (ReportStorage::exists($this->study, $filename)) { - return $filepath; + return $pdf_path; } + $docx_path = ReportStorage::customFilepath($this->study, $this->filename('docx')); + $docx = $this->renderDocument(); + $docx->createDocx(ReportStorage::abspath($docx_path)); + $docx->transformDocument(ReportStorage::abspath($docx_path), ReportStorage::abspath($pdf_path)); + + return $pdf_path; + + /* + $dompdf = new Dompdf\Dompdf; + $transform = new TransformDocAdvNative; + $transform->transformDocument('document.docx', 'document.pdf', ['dompdf' => $dompdf]); + $data = ['report' => $this->report, 'title' => 'PDF VIEW']; Pdf::loadView('staff.reports.viewer.html-report', $data) ->setPaper('a4', 'landscape') ->setWarnings(false) ->setOption('defaultFont', 'Courier') - ->save(ReportStorage::abspath($filepath)); - - return $filepath; + ->save(ReportStorage::abspath($pdf_path)); + */ } protected function getExtension(): string diff --git a/app/Services/Export/Formats/Word2007Export.php b/app/Services/Export/Formats/Word2007Export.php index 82b47f6..87f975f 100644 --- a/app/Services/Export/Formats/Word2007Export.php +++ b/app/Services/Export/Formats/Word2007Export.php @@ -3,13 +3,9 @@ namespace app\Services\Export\Formats; use App\Domain\Report\ExportFormat; -use App\Services\Export\ExportDocumentBase; use App\Services\Report\ReportStorage; -use App\Services\Report\StampService; -use CreateDocxFromTemplate; -use Illuminate\Support\Facades\Storage; -final class Word2007Export extends ExportDocumentBase +final class Word2007Export extends TemplatedDocExportBase { protected function handle(): string { @@ -19,28 +15,7 @@ protected function handle(): string return $filepath; } - $docx = new CreateDocxFromTemplate(Storage::disk('local')->path(config('services.report.word2007.template'))); - $variables = [ - 'PAT_NAME' => $this->report->study->patient_name, - 'PAT_ID' => $this->report->study->patient_id, - 'PAT_AGE' => $this->report->study->sexAge(), - 'ACC_NUM' => $this->report->study->accession_number, - 'REF_DOC' => $this->report->study->referring_physician_name, - 'STUDY_DATE' => $this->report->created_at->toDateString(), - ]; - $img = ['parseLineBreaks' => true, 'target' => 'header']; - $docx->replaceVariableByText($variables, $img); - $docx->embedHTML($this->report->getContent()); - - $stamper = new StampService($this->report->read_by_id); - if ($stamper->hasSignatureImage()) { - $img = [ - 'src' => $stamper->signatureImagePath(), - 'textWrap' => 0, - ]; - $docx->addImage($img); - } - + $docx = $this->renderDocument(); $docx->createDocx(ReportStorage::abspath($filepath)); return $filepath; diff --git a/app/Services/Report/StampService.php b/app/Services/Report/StampService.php index 270977b..fac7e47 100644 --- a/app/Services/Report/StampService.php +++ b/app/Services/Report/StampService.php @@ -18,11 +18,11 @@ public function hasSignatureImage(): bool { $path = $this->user->radiologistProfile?->signature_image_path; - return $path !== null && Storage::disk('local')->exists($path); + return $path !== null && Storage::disk('public')->exists($path); } public function signatureImagePath(): string { - return Storage::disk('local')->path($this->user->radiologistProfile?->signature_image_path); + return Storage::disk('public')->path($this->user->radiologistProfile?->signature_image_path); } }