Убрал дату смерти при переводе
This commit is contained in:
@@ -432,11 +432,11 @@ class DutyReportService
|
|||||||
if ($hasRecipientInPeriod) {
|
if ($hasRecipientInPeriod) {
|
||||||
$totalStats['admitted']['today']++;
|
$totalStats['admitted']['today']++;
|
||||||
$totalStats['by_status']['recipient'] = ($totalStats['by_status']['recipient'] ?? 0) + 1;
|
$totalStats['by_status']['recipient'] = ($totalStats['by_status']['recipient'] ?? 0) + 1;
|
||||||
if ($patient['urgency_id'] == 2) {
|
if ($patient['urgency_id'] == 1) {
|
||||||
$totalStats['admitted']['planned']++;
|
$totalStats['admitted']['planned']++;
|
||||||
$totalStats['planned']++;
|
$totalStats['planned']++;
|
||||||
}
|
}
|
||||||
if ($patient['urgency_id'] == 1) {
|
if ($patient['urgency_id'] == 2) {
|
||||||
$totalStats['admitted']['urgent']++;
|
$totalStats['admitted']['urgent']++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -635,16 +635,41 @@ class DutyReportService
|
|||||||
&$savedMigrations,
|
&$savedMigrations,
|
||||||
&$savedReanimations
|
&$savedReanimations
|
||||||
) {
|
) {
|
||||||
|
// Получаем дату отчета
|
||||||
|
$reportDate = DB::table('report_duties')
|
||||||
|
->where('id', $reportDutyId)
|
||||||
|
->value('period_end');
|
||||||
|
|
||||||
// === 1. UPSERT пациентов ===
|
// === 1. UPSERT пациентов ===
|
||||||
$patientUniqueBy = ['report_duty_id', 'source_type', 'original_id'];
|
$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(
|
DB::table('report_duty_patients')->upsert(
|
||||||
$patientBatch,
|
$filteredPatientBatch,
|
||||||
$patientUniqueBy,
|
$patientUniqueBy,
|
||||||
$patientUpdateColumns
|
$patientUpdateColumns
|
||||||
);
|
);
|
||||||
$savedPatients = count($patientBatch);
|
$savedPatients = count($filteredPatientBatch);
|
||||||
|
|
||||||
// === 2. Получаем ID сохранённых пациентов для связи с миграциями ===
|
// === 2. Получаем ID сохранённых пациентов для связи с миграциями ===
|
||||||
$patientIds = [];
|
$patientIds = [];
|
||||||
@@ -663,21 +688,21 @@ class DutyReportService
|
|||||||
$originalId = $m['_temp_key']['original_id'];
|
$originalId = $m['_temp_key']['original_id'];
|
||||||
if (isset($patientIds[$originalId])) {
|
if (isset($patientIds[$originalId])) {
|
||||||
$finalMigrations[] = [
|
$finalMigrations[] = [
|
||||||
'medical_history_id' => $patientIds[$originalId],
|
'medical_history_id' => $patientIds[$originalId],
|
||||||
'original_id' => $m['original_id'] ?? null,
|
'original_id' => $m['original_id'] ?? null,
|
||||||
'ingoing_date' => $m['ingoing_date'],
|
'ingoing_date' => $m['ingoing_date'],
|
||||||
'out_date' => $m['out_date'],
|
'out_date' => $m['out_date'],
|
||||||
'diagnosis_id' => $m['diagnosis_id'],
|
'diagnosis_id' => $m['diagnosis_id'],
|
||||||
'diagnosis_code' => $m['diagnosis_code'],
|
'diagnosis_code' => $m['diagnosis_code'],
|
||||||
'diagnosis_name' => $m['diagnosis_name'],
|
'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'],
|
'stationar_branch_id' => $m['stationar_branch_id'],
|
||||||
'department_id' => $m['department_id'],
|
'department_id' => $m['department_id'],
|
||||||
'visit_result_id' => $m['visit_result_id'],
|
'visit_result_id' => $m['visit_result_id'],
|
||||||
'stat_cure_result_id' => $m['stat_cure_result_id'],
|
'stat_cure_result_id' => $m['stat_cure_result_id'],
|
||||||
'user_id' => $m['user_id'],
|
'user_id' => $m['user_id'],
|
||||||
'mis_user_id' => $m['mis_user_id'],
|
'mis_user_id' => $m['mis_user_id'],
|
||||||
'comment' => $m['comment'],
|
'comment' => $m['comment'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user