Профиль хирургии

This commit is contained in:
brusnitsyn
2026-03-25 17:37:32 +09:00
parent 52a80ccd3b
commit f566ab96df
75 changed files with 3841 additions and 1009 deletions

View File

@@ -0,0 +1,47 @@
<?php
// app/Services/MetricCalculators/AverageBedDaysCalculator.php
namespace App\Services\MetricCalculators;
use App\Services\Base\BaseMetricService;
use App\Contracts\MetricCalculatorInterface;
use Illuminate\Support\Facades\DB;
class AverageBedDaysCalculator extends BaseMetricService implements MetricCalculatorInterface
{
public function getMetricId(): int
{
return 18;
}
public function calculate(array $departmentIds, string $startDate, string $endDate): array
{
if (empty($departmentIds)) {
return [];
}
$results = DB::table('reports as r')
->join('metrika_results as mr', 'r.report_id', '=', 'mr.rf_report_id')
->whereIn('r.rf_department_id', $departmentIds)
->where('mr.rf_metrika_item_id', 18)
// ->whereBetween('r.created_at', [$startDate, $endDate])
->where('r.sent_at', '>', $startDate)
->where('r.sent_at', '<=', $endDate)
->select(
'r.rf_department_id',
DB::raw('AVG(CAST(mr.value AS DECIMAL)) as avg_value')
)
->groupBy('r.rf_department_id')
->get()
->keyBy('rf_department_id');
$averages = [];
foreach ($departmentIds as $deptId) {
$averages[$deptId] = isset($results[$deptId])
? round((float)$results[$deptId]->avg_value, 1)
: 0;
}
return $averages;
}
}