Files
onboard/app/Services/ReportPageService.php
2026-04-21 10:08:14 +09:00

45 lines
1.6 KiB
PHP

<?php
namespace App\Services;
use App\Models\Department;
use App\Models\MetrikaItem;
use App\Models\User;
class ReportPageService
{
public function __construct(
protected ReportService $reportService,
) {}
public function build(Department $department, User $user, DateRange $dateRange): array
{
$statistics = $this->reportService->getReportStatistics($department, $user, $dateRange);
$reportInfo = $this->reportService->getCurrentReportInfo($department, $user, $dateRange);
$recipientPlanOfYear = $this->reportService->getRecipientPlanOfYear($department, $dateRange);
return [
'department' => [
'department_name' => $department->name_full,
'department_id' => $department->department_id,
'beds' => $department->beds,
'percentLoadedBeds' => ($statistics['beds'] ?? 0) > 0
? round((($statistics['currentCount'] ?? 0) * 100) / $statistics['beds'])
: 0,
'recipientPlanOfYear' => $recipientPlanOfYear['plan'],
'progressPlanOfYear' => $recipientPlanOfYear['progress'],
...$statistics,
],
'dates' => [
'startAt' => $dateRange->startTimestamp(),
'endAt' => $dateRange->endTimestamp(),
],
'report' => $reportInfo,
'metrikaItems' => MetrikaItem::whereIn('metrika_item_id', [3, 7, 8, 17])->get(),
'patients' => [],
'userId' => $reportInfo['userId'],
'userName' => $reportInfo['userName'],
];
}
}