This commit is contained in:
Dr Masroor Ehsan 2025-01-12 02:34:37 +06:00
parent 40351f7a0e
commit ec256b5225
2 changed files with 39 additions and 4 deletions

View File

@ -15,7 +15,7 @@ protected function handle(): string
$filename = $this->filename(); $filename = $this->filename();
$filepath = ReportStorage::customFilepath($this->study, $filename); $filepath = ReportStorage::customFilepath($this->study, $filename);
if (ReportStorage::exists($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')); $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, 'ACC_NUM' => $this->report->study->accession_number,
'REF_DOC' => $this->report->study->referring_physician_name, 'REF_DOC' => $this->report->study->referring_physician_name,
'STUDY_DATE' => $this->report->created_at->toDateString(), 'STUDY_DATE' => $this->report->created_at->toDateString(),
// 'report' => $this->report,
]; ];
$options = ['parseLineBreaks' => true, 'target' => 'header']; $img = ['parseLineBreaks' => true, 'target' => 'header'];
$docx->replaceVariableByText($variables, $options); $docx->replaceVariableByText($variables, $img);
$docx->embedHTML($this->report->getContent()); $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)); $docx->createDocx(ReportStorage::abspath($filepath));
return $filepath; return $filepath;

View File

@ -0,0 +1,27 @@
<?php
namespace App\Services\Report;
use App\Models\User;
final class StampService
{
private User $user;
public function __construct(User|int|null $user = null)
{
$this->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);
}
}