phpdocx
This commit is contained in:
parent
8ba1c4ef56
commit
fb472f29c5
@ -9,6 +9,7 @@
|
|||||||
use App\Models\Study;
|
use App\Models\Study;
|
||||||
use App\Models\StudyReport;
|
use App\Models\StudyReport;
|
||||||
use App\Services\DocumentGenerator\Word;
|
use App\Services\DocumentGenerator\Word;
|
||||||
|
use App\Services\ReportStorage;
|
||||||
|
|
||||||
class ReportController extends HashidControllerBase
|
class ReportController extends HashidControllerBase
|
||||||
{
|
{
|
||||||
@ -75,6 +76,8 @@ public function download(string $uuid)
|
|||||||
// $study = Study::with(['reports.radiologist', 'readingPhysician'])->where('accession_number', $uuid)->firstOrFail();
|
// $study = Study::with(['reports.radiologist', 'readingPhysician'])->where('accession_number', $uuid)->firstOrFail();
|
||||||
$report = StudyReport::where('accession_number', $uuid)->firstOrFail();
|
$report = StudyReport::where('accession_number', $uuid)->firstOrFail();
|
||||||
|
|
||||||
return Word::make($report->study, $report);
|
$path = Word::make($report->study, $report);
|
||||||
|
|
||||||
|
return response()->download(ReportStorage::abspath($path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,36 +4,24 @@
|
|||||||
|
|
||||||
use App\Models\Study;
|
use App\Models\Study;
|
||||||
use App\Models\StudyReport;
|
use App\Models\StudyReport;
|
||||||
use PhpOffice\PhpWord\IOFactory;
|
use App\Services\ReportStorage;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use CreateDocx;
|
||||||
use PhpOffice\PhpWord\Shared\Html;
|
|
||||||
|
|
||||||
class Word
|
final readonly class Word
|
||||||
{
|
{
|
||||||
public static function make(Study $study, StudyReport $report)
|
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();
|
$html = $report->getContent();
|
||||||
|
$docx = new CreateDocx;
|
||||||
$phpWord = new PhpWord;
|
$docx->embedHTML($html);
|
||||||
$section = $phpWord->addSection();
|
$docx->createDocx(ReportStorage::abspath($filepath));
|
||||||
|
|
||||||
// Add HTML content to the section
|
|
||||||
Html::addHtml($section, $html, false, false);
|
|
||||||
|
|
||||||
// Save the document as a DOCX file
|
|
||||||
// $filename = 'report.docx';
|
|
||||||
$writer = IOFactory::createWriter($phpWord, 'Word2007');
|
|
||||||
ob_start();
|
|
||||||
$writer->save('php://output');
|
|
||||||
$content = ob_get_clean();
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
|
|
||||||
$content = view('staff.reports.word', compact('study', 'report'))->render();
|
|
||||||
$filepath = ReportStorage::reportFilepath($study, '.docx');
|
|
||||||
Storage::put($filepath, $content);
|
|
||||||
|
|
||||||
return $filepath;
|
return $filepath;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,8 @@
|
|||||||
"Tests\\": "tests/"
|
"Tests\\": "tests/"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"app/helpers.php"
|
"app/helpers.php",
|
||||||
|
"src/phpdocx/src/CreateDocx.php"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -90,6 +91,7 @@
|
|||||||
"composer clear-all",
|
"composer clear-all",
|
||||||
"composer cache-all"
|
"composer cache-all"
|
||||||
],
|
],
|
||||||
|
"clr": "composer clear-all",
|
||||||
"fix": "php-cs-fixer fix",
|
"fix": "php-cs-fixer fix",
|
||||||
"dev": [
|
"dev": [
|
||||||
"Composer\\Config::disableProcessTimeout",
|
"Composer\\Config::disableProcessTimeout",
|
||||||
|
Loading…
Reference in New Issue
Block a user