* добавил исход спец контингенту

* оптимизация обновления при редактировании спец контингента
* добавил поддержку заключительных диагнозов
* изменил определение законченной операции
* добавил поддержку исхода операции
* добавил определение отмены для операции через назначение
* работа над диапазонами календарей, подсчет статистики
* добавил статусы отчетов и подкорректировал привязку спец контингента к отчету
* добавил новые сервисы для будущего кеширования
* частичное разделение логики подсчета пациентов
This commit is contained in:
brusnitsyn
2026-04-22 20:35:39 +09:00
parent 2041ab54ea
commit 719eb1403f
39 changed files with 1458 additions and 763 deletions

View File

@@ -27,6 +27,12 @@ class SnapshotService
*/
public function createPatientSnapshots(Report $report, User $user, array $dates, $fillableAuto = false): void
{
$this->logSnapshotMemory('snapshots:start', [
'report_id' => $report->report_id,
'department_id' => $report->rf_department_id,
'fillable_auto' => (bool) $fillableAuto,
]);
$department = Department::query()->where('department_id', $report->rf_department_id)->first() ?? $user->department;
$branchId = $department
? $this->getBranchId($department->rf_mis_department_id)
@@ -39,11 +45,15 @@ class SnapshotService
MedicalHistorySnapshot::query()
->where('rf_report_id', $report->report_id)
->delete();
$this->logSnapshotMemory('snapshots:after_delete_old', [
'report_id' => $report->report_id,
]);
[$startDate, $endDate] = $this->parseDates($dates);
$dateRange = $this->dateRangeService->getNormalizedDateRange($user, $startDate, $endDate);
$metrics = [];
$this->logSnapshotMemory('snapshots:before_plan_load', ['report_id' => $report->report_id]);
$planPatients = $this->unifiedPatientService->getLivePatientsByStatus(
$department,
$user,
@@ -52,11 +62,18 @@ class SnapshotService
$branchId,
false,
!$fillableAuto,
$fillableAuto
$fillableAuto,
true
);
$this->logSnapshotMemory('snapshots:after_plan_load', [
'report_id' => $report->report_id,
'count' => $planPatients->count(),
]);
$this->createSnapshotsForType($report, 'plan', $planPatients);
$this->logSnapshotMemory('snapshots:after_plan_save', ['report_id' => $report->report_id]);
$metrics[4] = $planPatients->count();
$this->logSnapshotMemory('snapshots:before_emergency_load', ['report_id' => $report->report_id]);
$emergencyPatients = $this->unifiedPatientService->getLivePatientsByStatus(
$department,
$user,
@@ -65,11 +82,18 @@ class SnapshotService
$branchId,
false,
!$fillableAuto,
$fillableAuto
$fillableAuto,
true
);
$this->logSnapshotMemory('snapshots:after_emergency_load', [
'report_id' => $report->report_id,
'count' => $emergencyPatients->count(),
]);
$this->createSnapshotsForType($report, 'emergency', $emergencyPatients);
$this->logSnapshotMemory('snapshots:after_emergency_save', ['report_id' => $report->report_id]);
$metrics[12] = $emergencyPatients->count();
$this->logSnapshotMemory('snapshots:before_discharged_load', ['report_id' => $report->report_id]);
$dischargedPatients = $this->unifiedPatientService->getLivePatientsByStatus(
$department,
$user,
@@ -78,11 +102,18 @@ class SnapshotService
$branchId,
false,
null,
$fillableAuto
$fillableAuto,
true
);
$this->logSnapshotMemory('snapshots:after_discharged_load', [
'report_id' => $report->report_id,
'count' => $dischargedPatients->count(),
]);
$this->createSnapshotsForType($report, 'discharged', $dischargedPatients);
$this->logSnapshotMemory('snapshots:after_discharged_save', ['report_id' => $report->report_id]);
$metrics[15] = $dischargedPatients->count();
$this->logSnapshotMemory('snapshots:before_transferred_load', ['report_id' => $report->report_id]);
$transferredPatients = $this->unifiedPatientService->getLivePatientsByStatus(
$department,
$user,
@@ -91,11 +122,18 @@ class SnapshotService
$branchId,
false,
null,
$fillableAuto
$fillableAuto,
true
);
$this->logSnapshotMemory('snapshots:after_transferred_load', [
'report_id' => $report->report_id,
'count' => $transferredPatients->count(),
]);
$this->createSnapshotsForType($report, 'transferred', $transferredPatients);
$this->logSnapshotMemory('snapshots:after_transferred_save', ['report_id' => $report->report_id]);
$metrics[13] = $transferredPatients->count();
$this->logSnapshotMemory('snapshots:before_deceased_load', ['report_id' => $report->report_id]);
$deceasedPatients = $this->unifiedPatientService->getLivePatientsByStatus(
$department,
$user,
@@ -104,10 +142,17 @@ class SnapshotService
$branchId,
false,
null,
$fillableAuto
$fillableAuto,
true
);
$this->logSnapshotMemory('snapshots:after_deceased_load', [
'report_id' => $report->report_id,
'count' => $deceasedPatients->count(),
]);
$this->createSnapshotsForType($report, 'deceased', $deceasedPatients);
$this->logSnapshotMemory('snapshots:after_deceased_save', ['report_id' => $report->report_id]);
$this->logSnapshotMemory('snapshots:before_recipient_load', ['report_id' => $report->report_id]);
$recipientPatients = $this->unifiedPatientService->getLivePatientsByStatus(
$department,
$user,
@@ -116,10 +161,17 @@ class SnapshotService
$branchId,
false,
null,
$fillableAuto
$fillableAuto,
true
);
$this->logSnapshotMemory('snapshots:after_recipient_load', [
'report_id' => $report->report_id,
'count' => $recipientPatients->count(),
]);
$this->createSnapshotsForType($report, 'recipient', $recipientPatients);
$this->logSnapshotMemory('snapshots:after_recipient_save', ['report_id' => $report->report_id]);
$this->logSnapshotMemory('snapshots:before_current_load', ['report_id' => $report->report_id]);
$currentPatients = $this->unifiedPatientService->getLivePatientsByStatus(
$department,
$user,
@@ -128,9 +180,15 @@ class SnapshotService
$branchId,
false,
null,
$fillableAuto
$fillableAuto,
true
);
$this->logSnapshotMemory('snapshots:after_current_load', [
'report_id' => $report->report_id,
'count' => $currentPatients->count(),
]);
$this->createSnapshotsForType($report, 'current', $currentPatients);
$this->logSnapshotMemory('snapshots:after_current_save', ['report_id' => $report->report_id]);
$planSurgeryCount = $this->patientService->getSurgicalPatients(
'plan',
@@ -146,6 +204,17 @@ class SnapshotService
);
$this->saveMetrics($report, $metrics);
$this->logSnapshotMemory('snapshots:after_save_metrics', ['report_id' => $report->report_id]);
}
private function logSnapshotMemory(string $stage, array $context = []): void
{
\Log::info('report.snapshot.memory', [
'stage' => $stage,
'memory_mb' => round(memory_get_usage(true) / 1024 / 1024, 2),
'peak_mb' => round(memory_get_peak_usage(true) / 1024 / 1024, 2),
...$context,
]);
}
/**