first commit
This commit is contained in:
38
app/Support/MedicalReport/StructuredTemplateRegistry.php
Normal file
38
app/Support/MedicalReport/StructuredTemplateRegistry.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user