Ремонт сохранения снапшотов
This commit is contained in:
@@ -42,7 +42,7 @@ class NurseReportController extends Controller
|
|||||||
->where('period_end', '<=', $dateRange->endSql())
|
->where('period_end', '<=', $dateRange->endSql())
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
$hasReport = $existsReport;
|
$hasReport = $existsReport && $isPastPeriod;
|
||||||
|
|
||||||
if ($hasReport) {
|
if ($hasReport) {
|
||||||
$inDepartmentHistories = $this->nurseMedicalHistoryService->getDepartmentHistories($dateRange, $department->rf_mis_department_id);
|
$inDepartmentHistories = $this->nurseMedicalHistoryService->getDepartmentHistories($dateRange, $department->rf_mis_department_id);
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ class UnifiedMedicalHistory extends MaterializedViewModel
|
|||||||
->latest('ingoing_date');
|
->latest('ingoing_date');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function latestMigrationInDepartment($query, $departmentId)
|
||||||
|
{
|
||||||
|
return $query->where('department_id', $departmentId)
|
||||||
|
->latest('ingoing_date');
|
||||||
|
}
|
||||||
|
|
||||||
public function operationsInDepartment($query, $departmentId)
|
public function operationsInDepartment($query, $departmentId)
|
||||||
{
|
{
|
||||||
return $this->operations()->where('department_id', $departmentId);
|
return $this->operations()->where('department_id', $departmentId);
|
||||||
|
|||||||
@@ -77,29 +77,12 @@ class NurseReportService
|
|||||||
// пребывание пересекается с отчётным периодом
|
// пребывание пересекается с отчётным периодом
|
||||||
->where('ingoing_date', '<=', $dateRange->endSql())
|
->where('ingoing_date', '<=', $dateRange->endSql())
|
||||||
->where('ingoing_date', '>=', $startYear)
|
->where('ingoing_date', '>=', $startYear)
|
||||||
->where(function ($sub) use ($dateRange) {
|
|
||||||
$sub->whereNull('out_date')
|
|
||||||
->orWhere('out_date', '>=', $dateRange->startSql())
|
|
||||||
->where('out_date', '<=', $dateRange->endSql());
|
|
||||||
})
|
|
||||||
->where(function ($sub) use ($dateRange) {
|
->where(function ($sub) use ($dateRange) {
|
||||||
$sub->whereNull('out_date')
|
$sub->whereNull('out_date')
|
||||||
->orWhere('out_date', '>=', $dateRange->startSql())
|
->orWhere('out_date', '>=', $dateRange->startSql())
|
||||||
->where('out_date', '<=', $dateRange->endSql());
|
->where('out_date', '<=', $dateRange->endSql());
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
// Подгружаем последнее движение для денормализации
|
|
||||||
->with(['latestMigration' => function ($q) use ($departmentId, $dateRange, $startYear) {
|
|
||||||
$q->where('department_id', $departmentId)
|
|
||||||
->where('ingoing_date', '<=', $dateRange->endSql())
|
|
||||||
->where('ingoing_date', '>=', $startYear)
|
|
||||||
->where(function ($sub) use ($dateRange) {
|
|
||||||
$sub->whereNull('out_date')
|
|
||||||
->orWhere('out_date', '>=', $dateRange->startSql())
|
|
||||||
->where('out_date', '<=', $dateRange->endSql());
|
|
||||||
})
|
|
||||||
->latest('ingoing_date'); // если несколько, берём последнее
|
|
||||||
}]);
|
|
||||||
|
|
||||||
// Получаем данные (chunk для памяти, если пациентов > 1000)
|
// Получаем данные (chunk для памяти, если пациентов > 1000)
|
||||||
$patients = $query->cursor();
|
$patients = $query->cursor();
|
||||||
@@ -144,7 +127,8 @@ class NurseReportService
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Подготовка данных миграции (если есть)
|
// Подготовка данных миграции (если есть)
|
||||||
if (!empty($patient->latestMigration)) {
|
if (!empty($patient->migrations)) {
|
||||||
|
foreach ($patient->migrations as $migration) {
|
||||||
$migrationBatch[] = [
|
$migrationBatch[] = [
|
||||||
// Временный ключ для связи с пациентом (заполним после первого upsert)
|
// Временный ключ для связи с пациентом (заполним после первого upsert)
|
||||||
'_temp_key' => [
|
'_temp_key' => [
|
||||||
@@ -152,21 +136,22 @@ class NurseReportService
|
|||||||
'source_type' => $patient->source_type,
|
'source_type' => $patient->source_type,
|
||||||
'original_id' => $patient->original_id,
|
'original_id' => $patient->original_id,
|
||||||
],
|
],
|
||||||
'ingoing_date' => $patient->latestMigration->ingoing_date,
|
'ingoing_date' => $migration->ingoing_date,
|
||||||
'out_date' => $patient->latestMigration->out_date,
|
'out_date' => $migration->out_date,
|
||||||
'diagnosis_id' => $patient->latestMigration->diagnosis_id,
|
'diagnosis_id' => $migration->diagnosis_id,
|
||||||
'diagnosis_code' => $patient->latestMigration->diagnosis_code,
|
'diagnosis_code' => $migration->diagnosis_code,
|
||||||
'diagnosis_name' => $patient->latestMigration->diagnosis_name,
|
'diagnosis_name' => $migration->diagnosis_name,
|
||||||
'interrupted_event_id' => $patient->latestMigration->interrupted_event_id,
|
'interrupted_event_id' => $migration->interrupted_event_id,
|
||||||
'stationar_branch_id' => $patient->latestMigration->stationar_branch_id,
|
'stationar_branch_id' => $migration->stationar_branch_id,
|
||||||
'department_id' => $patient->latestMigration->department_id,
|
'department_id' => $migration->department_id,
|
||||||
'visit_result_id' => $patient->latestMigration->visit_result_id,
|
'visit_result_id' => $migration->visit_result_id,
|
||||||
'stat_cure_result_id' => $patient->latestMigration->stat_cure_result_id,
|
'stat_cure_result_id' => $migration->stat_cure_result_id,
|
||||||
'user_id' => $patient->latestMigration->user_id,
|
'user_id' => $migration->user_id,
|
||||||
'mis_user_id' => $patient->latestMigration->mis_user_id,
|
'mis_user_id' => $migration->mis_user_id,
|
||||||
'comment' => $patient->latestMigration->comment,
|
'comment' => $migration->comment,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Пакетная запись каждые $batchSize записей
|
// Пакетная запись каждые $batchSize записей
|
||||||
if (count($patientBatch) >= $batchSize) {
|
if (count($patientBatch) >= $batchSize) {
|
||||||
@@ -246,7 +231,7 @@ class NurseReportService
|
|||||||
|
|
||||||
if (!empty($finalMigrations)) {
|
if (!empty($finalMigrations)) {
|
||||||
// UPSERT миграций
|
// UPSERT миграций
|
||||||
$migrationUniqueBy = ['medical_history_id'];
|
$migrationUniqueBy = ['medical_history_id', 'ingoing_date'];
|
||||||
$migrationUpdateColumns = array_diff(array_keys($finalMigrations[0]), $migrationUniqueBy);
|
$migrationUpdateColumns = array_diff(array_keys($finalMigrations[0]), $migrationUniqueBy);
|
||||||
|
|
||||||
DB::table('report_nurse_migration_patients')->upsert(
|
DB::table('report_nurse_migration_patients')->upsert(
|
||||||
|
|||||||
Reference in New Issue
Block a user