Перевод на доменную архитектуру
This commit is contained in:
100
app/Domain/Reports/ValueObjects/MetrikaConfig.php
Normal file
100
app/Domain/Reports/ValueObjects/MetrikaConfig.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\ValueObjects;
|
||||
|
||||
final class MetrikaConfig
|
||||
{
|
||||
public const BEDS = 1;
|
||||
|
||||
public const RECIPIENT = 3;
|
||||
|
||||
public const PLAN = 4;
|
||||
|
||||
public const OUTCOME = 7;
|
||||
|
||||
public const CURRENT = 8;
|
||||
|
||||
public const DECEASED = 9;
|
||||
|
||||
public const EMERGENCY_SURGERY = 10;
|
||||
|
||||
public const PLAN_SURGERY = 11;
|
||||
|
||||
public const EMERGENCY = 12;
|
||||
|
||||
public const TRANSFERRED = 13;
|
||||
|
||||
public const OBSERVATION = 14;
|
||||
|
||||
public const DISCHARGED = 15;
|
||||
|
||||
public const UNWANTED_EVENTS = 16;
|
||||
|
||||
public const AVERAGE_BED_DAYS = 18;
|
||||
|
||||
public const PREOPERATIVE_AVERAGE_DAYS = 21;
|
||||
|
||||
public const DEPARTMENT_LOADED = 22;
|
||||
|
||||
public const TOTAL_BED_DAYS = 25;
|
||||
|
||||
public const TOTAL_PREOPERATIVE_DAYS = 26;
|
||||
|
||||
public const PREOPERATIVE_PATIENT_COUNT = 27;
|
||||
|
||||
public static function payloadKey(int $metricId): string
|
||||
{
|
||||
return 'metrika_item_'.$metricId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string, int|float|string|null> $metrics
|
||||
* @return array<int, int|float|string|null>
|
||||
*/
|
||||
public static function normalizeMetrics(array $metrics): array
|
||||
{
|
||||
$normalized = [];
|
||||
|
||||
foreach ($metrics as $key => $value) {
|
||||
$metricId = self::extractMetricId($key);
|
||||
|
||||
if ($metricId === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$normalized[$metricId] = $value;
|
||||
}
|
||||
|
||||
ksort($normalized);
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, int|float|string|null> $metrics
|
||||
* @return array<string, int|float|string|null>
|
||||
*/
|
||||
public static function toPayloadMetrics(array $metrics): array
|
||||
{
|
||||
$payload = [];
|
||||
|
||||
foreach (self::normalizeMetrics($metrics) as $metricId => $value) {
|
||||
$payload[self::payloadKey($metricId)] = $value;
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
public static function extractMetricId(int|string $key): ?int
|
||||
{
|
||||
if (is_int($key) || ctype_digit((string) $key)) {
|
||||
return (int) $key;
|
||||
}
|
||||
|
||||
if (preg_match('/^metrika_item_(\d+)$/', (string) $key, $matches) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $matches[1];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user