[Изменено]: столбец Выбыло в статистике #3
This commit is contained in:
@@ -10,23 +10,21 @@ use App\Models\Report;
|
||||
use App\Models\ReportDuty;
|
||||
use App\Models\User;
|
||||
use App\Models\UserDepartment;
|
||||
use App\Services\MetricCalculators\PlanCalculator;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StatisticsService
|
||||
{
|
||||
public function __construct(
|
||||
protected BedDayService $bedDayService
|
||||
protected BedDayService $bedDayService,
|
||||
protected PlanCalculator $planCalculator,
|
||||
) {}
|
||||
|
||||
public function getStatisticsData(User $user, string $startDate, string $endDate, bool $isRangeOneDay): array
|
||||
{
|
||||
$this->bedDayService->clearMemoryCache();
|
||||
|
||||
// Годовой план
|
||||
$recipientPlanOfYear = 0;
|
||||
$progressPlanOfYear = 0;
|
||||
|
||||
// 1. Получаем отделения
|
||||
$departments = Department::select('department_id', 'name_short', 'rf_department_type', 'user_name', 'order')
|
||||
->with('departmentType')
|
||||
@@ -41,11 +39,6 @@ class StatisticsService
|
||||
return $this->emptyResponse();
|
||||
}
|
||||
|
||||
// Рассчитываем коэффициент периода (дни периода / 365)
|
||||
$start = Carbon::parse($startDate);
|
||||
$end = Carbon::parse($endDate);
|
||||
$monthsInPeriod = ceil($start->diffInMonths($end));
|
||||
|
||||
$allDeptIds = $departments->flatten()->pluck('department_id')->toArray();
|
||||
|
||||
// 2а. Нежелательные события по отделениям за период (прямой запрос)
|
||||
@@ -114,6 +107,8 @@ class StatisticsService
|
||||
$grandRecipientPlan = 0;
|
||||
$grandProgressPlan = 0;
|
||||
|
||||
$departmentsPlans = $this->planCalculator->calculate($allDeptIds, $startDate, $endDate);
|
||||
|
||||
foreach ($departments as $typeName => $deptList) {
|
||||
$groupedData[$typeName] = [];
|
||||
$totalsByType[$typeName] = $this->initTypeTotals();
|
||||
@@ -136,14 +131,6 @@ class StatisticsService
|
||||
$bedsCount = (int) ($beds[$deptId]->value ?? 0);
|
||||
$currentCount = (int) ($currentPatients[$deptId]->value ?? 0);
|
||||
|
||||
// Получаем годовой план
|
||||
$annualPlanModel = $dept->recipientPlanOfYear();
|
||||
$annualPlan = $annualPlanModel ? (int) $annualPlanModel->value : 0;
|
||||
$oneMonthPlan = ceil($annualPlan / 12);
|
||||
|
||||
// Рассчитываем план на период
|
||||
$periodPlan = round($oneMonthPlan * $monthsInPeriod);
|
||||
|
||||
// Счетчики
|
||||
$plan = 0;
|
||||
$emergency = 0;
|
||||
@@ -200,11 +187,6 @@ class StatisticsService
|
||||
}
|
||||
}
|
||||
|
||||
$grandRecipientPlan += $periodPlan;
|
||||
$grandProgressPlan += $outcome;
|
||||
|
||||
$percentPlanOfYear = $periodPlan > 0 ? round($outcome * 100 / $periodPlan) : 0;
|
||||
|
||||
// Расчеты
|
||||
$allCount = $plan + $emergency;
|
||||
$percentLoaded = $bedsCount > 0 ? round($currentCount * 100 / $bedsCount) : 0;
|
||||
@@ -225,8 +207,6 @@ class StatisticsService
|
||||
|
||||
$departmentName = $dept->user_name ?? $dept->name_short;
|
||||
|
||||
$progressPlanOfYear += $outcome;
|
||||
|
||||
$data = [
|
||||
'department' => $departmentName,
|
||||
'department_id' => $deptId,
|
||||
@@ -255,12 +235,25 @@ class StatisticsService
|
||||
'preoperativeDays' => $preoperativeValue,
|
||||
'preoperativeSum' => $preoperativeSum,
|
||||
'preoperativePatientCount' => $preoperativePatientCount,
|
||||
'plan' => $departmentsPlans[$deptId],
|
||||
|
||||
'progressPlanOfYear' => $periodPlan,
|
||||
'percentPlanOfYear' => $percentPlanOfYear,
|
||||
'needPlanOfYear' => $periodPlan > 0 && $periodPlan > $outcome
|
||||
? $periodPlan - $outcome
|
||||
: 0,
|
||||
// 'progressPlanOfYear' => $cumulativePlan,
|
||||
// 'percentPlanOfYear' => $percentPlanOfYear,
|
||||
// 'needPlanOfYear' => $cumulativePlan > 0 && $cumulativePlan > $outcome
|
||||
// ? $cumulativePlan - $outcome
|
||||
// : 0,
|
||||
// Плановые показатели
|
||||
// 'cumulative_plan' => $cumulativePlan, // План с начала года нарастающим (включая текущий месяц)
|
||||
// 'current_month_plan_only' => $currentMonthPlanOnly, // План только на текущий месяц
|
||||
// 'debt_from_year_start' => $debtFromYearStart, // Долг с начала года (невыполненный план за прошлые месяцы)
|
||||
// 'total_debt' => $totalDebt, // ИТОГО долг = план на текущий месяц + долг с начала года
|
||||
// 'currentMonthDebt' => $currentMonthDebt, // Выписать по плану в текущем месяце
|
||||
|
||||
// Фактические показатели
|
||||
// 'actual_year_to_date' => $actualToDate, // Факт с начала года (включая текущий месяц)
|
||||
|
||||
// Процент выполнения
|
||||
// 'cumulative_percent' => $cumulativePlan > 0 ? round($actualToDate * 100 / $cumulativePlan, 2) : 0,
|
||||
'lethality' => $lethality,
|
||||
'type' => $typeName,
|
||||
'isDepartment' => true,
|
||||
|
||||
Reference in New Issue
Block a user