radfusion/app/Services/DocumentGenerator/Word.php
2025-01-10 12:15:16 +06:00

28 lines
683 B
PHP

<?php
namespace App\Services\DocumentGenerator;
use App\Models\Study;
use App\Models\StudyReport;
use App\Services\ReportStorage;
use CreateDocx;
final readonly class Word
{
public static function make(Study $study, StudyReport $report): string
{
$filename = $report->accession_number . '.docx';
$filepath = ReportStorage::customFilepath($study, $filename);
if (ReportStorage::exists($study, $filename)) {
return $filepath;
}
$html = $report->getContent();
$docx = new CreateDocx;
$docx->embedHTML($html);
$docx->createDocx(ReportStorage::abspath($filepath));
return $filepath;
}
}