* оптимизировал запросы выдачи пациентов, сохранения снапшотов

* доработал страницу отчета дежурного
* переделал "действия" над пациентом
* подключил виджеты на странице отчета дежурного
This commit is contained in:
brusnitsyn
2026-05-08 17:04:56 +09:00
parent 6cf1ffbb2b
commit 90e0d04dfd
17 changed files with 818 additions and 292 deletions

View File

@@ -64,10 +64,10 @@ class DutyReportService
/**
* Сохранить снимок пациентов за период
*/
public function saveSnapshot(DateRange $dateRange, ReportNurse $reportNurse, ?int $departmentId = null, ?int $userId = null): array
public function saveSnapshot(DateRange $dateRange, ReportDuty $reportDuty, ?int $departmentId = null, ?int $userId = null): array
{
$departmentId = $departmentId ?? $reportNurse->department->rf_mis_department_id;
$userId = $userId ?? $reportNurse->rf_user_id;
$departmentId = $departmentId ?? $reportDuty->department->rf_mis_department_id;
$userId = $userId ?? $reportDuty->rf_user_id;
$startYear = Carbon::now()->startOfYear()->format('Y-m-d');
$query = MedicalHistory::query()
@@ -87,7 +87,7 @@ class DutyReportService
// Получаем данные (chunk для памяти, если пациентов > 1000)
$patients = $query->cursor();
$savedStats = $this->saveReportSnapshot($reportNurse->id, $patients, $userId);
$savedStats = $this->saveReportSnapshot($reportDuty->id, $patients, $userId);
return [
...$savedStats,
@@ -109,9 +109,9 @@ class DutyReportService
foreach ($patients as $patient) {
// Подготовка данных пациента
$patientBatch[] = [
'report_nurse_id' => $reportDutyId,
'source_type' => $patient->source_type,
'original_id' => $patient->original_id,
'report_duty_id' => $reportDutyId,
'source_type' => 'mis',
'original_id' => $patient->id,
'medical_card_number' => $patient->medical_card_number,
'full_name' => $patient->full_name,
'birth_date' => $patient->birth_date,
@@ -184,7 +184,7 @@ class DutyReportService
$patientUniqueBy = ['report_duty_id', 'source_type', 'original_id'];
$patientUpdateColumns = array_diff(array_keys($patientBatch[0]), $patientUniqueBy);
DB::table('report_nurse_patients')->upsert(
DB::table('report_duty_patients')->upsert(
$patientBatch,
$patientUniqueBy,
$patientUpdateColumns