39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Support\MedicalReport;
|
|
|
|
class StructuredTemplateRegistry
|
|
{
|
|
public function __construct(
|
|
private readonly DatabaseStructuredTemplateFactory $databaseStructuredTemplateFactory,
|
|
private readonly SourceStructuredTemplateFactory $sourceStructuredTemplateFactory,
|
|
private readonly DepartmentCatalog $departmentCatalog,
|
|
private readonly ReportInputTypeBlueprintFactory $reportInputTypeBlueprintFactory,
|
|
) {}
|
|
|
|
/**
|
|
* @return array<string, mixed>|null
|
|
*/
|
|
public function templateForDepartment(string $reportDepartmentKey): ?array
|
|
{
|
|
return $this->databaseStructuredTemplateFactory->templateForDepartment($reportDepartmentKey)
|
|
?? $this->blueprintTemplate($reportDepartmentKey)
|
|
?? $this->sourceStructuredTemplateFactory->templateForDepartment($reportDepartmentKey);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>|null
|
|
*/
|
|
private function blueprintTemplate(string $reportDepartmentKey): ?array
|
|
{
|
|
$department = collect($this->departmentCatalog->departments())
|
|
->firstWhere('key', $reportDepartmentKey);
|
|
|
|
if ($department === null) {
|
|
return null;
|
|
}
|
|
|
|
return $this->reportInputTypeBlueprintFactory->templateForDepartment($department);
|
|
}
|
|
}
|