From 1eb3cfd918a0368e1335a6e9e700818be9eca692 Mon Sep 17 00:00:00 2001 From: brusnitsyn Date: Tue, 9 Jun 2026 17:06:58 +0900 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B4=D0=B0?= =?UTF-8?q?=D1=82=D1=83=20=D1=81=D0=BC=D0=B5=D1=80=D1=82=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/DutyReportService.php | 65 +++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/app/Services/DutyReportService.php b/app/Services/DutyReportService.php index 0b9d26c..e355fc0 100644 --- a/app/Services/DutyReportService.php +++ b/app/Services/DutyReportService.php @@ -432,11 +432,11 @@ class DutyReportService if ($hasRecipientInPeriod) { $totalStats['admitted']['today']++; $totalStats['by_status']['recipient'] = ($totalStats['by_status']['recipient'] ?? 0) + 1; - if ($patient['urgency_id'] == 2) { + if ($patient['urgency_id'] == 1) { $totalStats['admitted']['planned']++; $totalStats['planned']++; } - if ($patient['urgency_id'] == 1) { + if ($patient['urgency_id'] == 2) { $totalStats['admitted']['urgent']++; } } @@ -635,16 +635,41 @@ class DutyReportService &$savedMigrations, &$savedReanimations ) { + // Получаем дату отчета + $reportDate = DB::table('report_duties') + ->where('id', $reportDutyId) + ->value('period_end'); + // === 1. UPSERT пациентов === $patientUniqueBy = ['report_duty_id', 'source_type', 'original_id']; - $patientUpdateColumns = array_diff(array_keys($patientBatch[0]), $patientUniqueBy); + // Модифицируем patientBatch перед сохранением + $filteredPatientBatch = array_map(function($patient) use ($reportDutyId, $reportDate) { + // Очищаем death_date, если она есть + if (!empty($patient['death_date'])) { + // Проверяем, была ли смерть на момент отчета + $deathDate = Carbon::parse($patient['death_date']); + $extractDate = Carbon::parse($patient['extract_date']); + + // Если дата смерти ПОЗЖЕ даты отчета - удаляем + if ($deathDate->gt($reportDate)) { + $patient['death_date'] = null; + } + // Если дата смерти в тот же день или раньше - оставляем + } + + // extract_date оставляем всегда (это дата перевода/выбытия из отделения) + // Она может быть в пределах отчетного периода + + return $patient; + }, $patientBatch); + $patientUpdateColumns = array_diff(array_keys($filteredPatientBatch[0]), $patientUniqueBy); DB::table('report_duty_patients')->upsert( - $patientBatch, + $filteredPatientBatch, $patientUniqueBy, $patientUpdateColumns ); - $savedPatients = count($patientBatch); + $savedPatients = count($filteredPatientBatch); // === 2. Получаем ID сохранённых пациентов для связи с миграциями === $patientIds = []; @@ -663,21 +688,21 @@ class DutyReportService $originalId = $m['_temp_key']['original_id']; if (isset($patientIds[$originalId])) { $finalMigrations[] = [ - 'medical_history_id' => $patientIds[$originalId], - 'original_id' => $m['original_id'] ?? null, - 'ingoing_date' => $m['ingoing_date'], - 'out_date' => $m['out_date'], - 'diagnosis_id' => $m['diagnosis_id'], - 'diagnosis_code' => $m['diagnosis_code'], - 'diagnosis_name' => $m['diagnosis_name'], - 'interrupted_event_id'=> $m['interrupted_event_id'], - 'stationar_branch_id' => $m['stationar_branch_id'], - 'department_id' => $m['department_id'], - 'visit_result_id' => $m['visit_result_id'], - 'stat_cure_result_id' => $m['stat_cure_result_id'], - 'user_id' => $m['user_id'], - 'mis_user_id' => $m['mis_user_id'], - 'comment' => $m['comment'], + 'medical_history_id' => $patientIds[$originalId], + 'original_id' => $m['original_id'] ?? null, + 'ingoing_date' => $m['ingoing_date'], + 'out_date' => $m['out_date'], + 'diagnosis_id' => $m['diagnosis_id'], + 'diagnosis_code' => $m['diagnosis_code'], + 'diagnosis_name' => $m['diagnosis_name'], + 'interrupted_event_id' => $m['interrupted_event_id'], + 'stationar_branch_id' => $m['stationar_branch_id'], + 'department_id' => $m['department_id'], + 'visit_result_id' => $m['visit_result_id'], + 'stat_cure_result_id' => $m['stat_cure_result_id'], + 'user_id' => $m['user_id'], + 'mis_user_id' => $m['mis_user_id'], + 'comment' => $m['comment'], ]; } }