Убрал дату смерти при переводе

This commit is contained in:
brusnitsyn
2026-06-09 17:06:58 +09:00
parent 7824b05ec1
commit 1eb3cfd918

View File

@@ -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 = [];
@@ -670,7 +695,7 @@ class DutyReportService
'diagnosis_id' => $m['diagnosis_id'],
'diagnosis_code' => $m['diagnosis_code'],
'diagnosis_name' => $m['diagnosis_name'],
'interrupted_event_id'=> $m['interrupted_event_id'],
'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'],