This commit is contained in:
Dr Masroor Ehsan 2025-01-12 11:54:04 +06:00
parent b460b048e7
commit bfbed52332

View File

@ -0,0 +1,39 @@
<?php
namespace app\Services\Export\Formats;
use App\Services\Export\ExportDocumentBase;
use App\Services\Report\StampService;
use CreateDocx;
use CreateDocxFromTemplate;
use Illuminate\Support\Facades\Storage;
abstract class TemplatedDocExportBase extends ExportDocumentBase
{
protected function renderDocument(): CreateDocx
{
$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);
}
return $docx;
}
}