From ec256b5225dcf10cdc9fd25391d7061adbd0263d Mon Sep 17 00:00:00 2001 From: Dr Masroor Ehsan Date: Sun, 12 Jan 2025 02:34:37 +0600 Subject: [PATCH] stamp --- .../Export/Formats/Word2007Export.php | 16 ++++++++--- app/Services/Report/StampService.php | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 app/Services/Report/StampService.php diff --git a/app/Services/Export/Formats/Word2007Export.php b/app/Services/Export/Formats/Word2007Export.php index d607f15..d0715ba 100644 --- a/app/Services/Export/Formats/Word2007Export.php +++ b/app/Services/Export/Formats/Word2007Export.php @@ -15,7 +15,7 @@ protected function handle(): string $filename = $this->filename(); $filepath = ReportStorage::customFilepath($this->study, $filename); if (ReportStorage::exists($this->study, $filename)) { - // return $filepath; + return $filepath; } $docx = new CreateDocxFromTemplate(Storage::disk('local')->path('report/report-template-gray.docx')); @@ -26,12 +26,20 @@ protected function handle(): string 'ACC_NUM' => $this->report->study->accession_number, 'REF_DOC' => $this->report->study->referring_physician_name, 'STUDY_DATE' => $this->report->created_at->toDateString(), - // 'report' => $this->report, ]; - $options = ['parseLineBreaks' => true, 'target' => 'header']; - $docx->replaceVariableByText($variables, $options); + $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->createDocx(ReportStorage::abspath($filepath)); return $filepath; diff --git a/app/Services/Report/StampService.php b/app/Services/Report/StampService.php new file mode 100644 index 0000000..6711cbe --- /dev/null +++ b/app/Services/Report/StampService.php @@ -0,0 +1,27 @@ +user = me($user); + } + + public function hasSignatureImage(): bool + { + $path = $this->user->radiologistProfile?->signature_image_path; + + return $path !== null && Storage::disk('local')->exists($path); + } + + public function signatureImagePath(): string + { + return Storage::disk('local')->path($this->user->radiologistProfile?->signature_image_path); + } +}