diff --git a/app/Services/DutyReportService.php b/app/Services/DutyReportService.php index 24cf6f2..ac6a888 100644 --- a/app/Services/DutyReportService.php +++ b/app/Services/DutyReportService.php @@ -330,8 +330,17 @@ class DutyReportService } } - // Если есть выбытие по миграции ИЛИ по карте - $hasOutcomeInPeriod = $hasExtractInPeriod || $hasDischargeInMigration; + // Умер в периоде (по дате смерти из карты) + $hasDeathInPeriod = false; + if (!empty($patient['death_date'])) { + $deathDateCarbon = Carbon::parse($patient['death_date']); + if ($deathDateCarbon >= $periodStartCarbon && $deathDateCarbon <= $periodEndCarbon) { + $hasDeathInPeriod = true; + } + } + + // Если есть выбытие по миграции, по карте ИЛИ смерть в периоде + $hasOutcomeInPeriod = $hasExtractInPeriod || $hasDischargeInMigration || $hasDeathInPeriod; if ($hasOutcomeInPeriod) { // Приоритет: данные из миграции (если есть), иначе из карты @@ -348,7 +357,6 @@ class DutyReportService // Флаги для пациента $hasRecipientInPeriod = false; - $hasDeathInPeriod = false; $hasTransferInPeriod = false; $hasDischargeInPeriod = false; $hasActiveMigrationInPeriod = false; @@ -372,18 +380,14 @@ class DutyReportService } } - // Умер в периоде - if (!empty($patient['death_date'])) { - $deathDateCarbon = Carbon::parse($patient['death_date']); - if ($deathDateCarbon >= $periodStartCarbon && $deathDateCarbon <= $periodEndCarbon) { - $hasDeathInPeriod = true; - } - } - // Выбытие в периоде (есть out_date в периоде) if ($outDate && $this->dateRangeService->dateInPeriod($outDate, $dateRange)) { + // Смерть (коды 5, 15) + if (in_array($visitResultId, [5, 15])) { + $hasDeathInPeriod = true; + } // Перевод (коды 4, 14) - if (in_array($visitResultId, [4, 14])) { + elseif (in_array($visitResultId, [4, 14])) { $hasTransferInPeriod = true; } // Выписка @@ -669,8 +673,11 @@ class DutyReportService } } - // extract_date оставляем всегда (это дата перевода/выбытия из отделения) - // Она может быть в пределах отчетного периода + // Если пациент умер, а дата выбытия из отделения не проставлена + // (миграция в МИС еще не закрыта) - используем дату смерти как дату выбытия + if (!empty($patient['death_date']) && empty($patient['extract_date'])) { + $patient['extract_date'] = $patient['death_date']; + } return $patient; }, $patientBatch);