Профиль хирургии
This commit is contained in:
43
app/Factories/MetricCalculatorFactory.php
Normal file
43
app/Factories/MetricCalculatorFactory.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// app/Factories/MetricCalculatorFactory.php
|
||||
|
||||
namespace App\Factories;
|
||||
|
||||
use App\Contracts\MetricCalculatorInterface;
|
||||
use App\Services\MetricCalculators\PreoperativeDaysCalculator;
|
||||
use App\Services\MetricCalculators\LethalityCalculator;
|
||||
use App\Services\MetricCalculators\AverageBedDaysCalculator;
|
||||
use RuntimeException;
|
||||
|
||||
class MetricCalculatorFactory
|
||||
{
|
||||
protected array $calculators = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->calculators = [
|
||||
18 => AverageBedDaysCalculator::class,
|
||||
19 => LethalityCalculator::class,
|
||||
21 => PreoperativeDaysCalculator::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function getCalculator(int $metricId): MetricCalculatorInterface
|
||||
{
|
||||
if (!isset($this->calculators[$metricId])) {
|
||||
throw new RuntimeException("No calculator for metric ID: {$metricId}");
|
||||
}
|
||||
|
||||
$class = $this->calculators[$metricId];
|
||||
return app($class);
|
||||
}
|
||||
|
||||
public function getAllCalculators(): array
|
||||
{
|
||||
$calculators = [];
|
||||
foreach (array_keys($this->calculators) as $metricId) {
|
||||
$calculators[$metricId] = $this->getCalculator($metricId);
|
||||
}
|
||||
return $calculators;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user