This commit is contained in:
Dr Masroor Ehsan 2025-01-12 11:53:49 +06:00
parent 5b412be4f8
commit b460b048e7
5 changed files with 24 additions and 40 deletions

View File

@ -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());
}
}

View File

@ -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
{

View File

@ -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

View File

@ -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;

View File

@ -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);
}
}