103 lines
2.2 KiB
PHP
103 lines
2.2 KiB
PHP
<?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 STAFF_COUNT = 17;
|
|
|
|
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];
|
|
}
|
|
}
|