*/ public function toArray(Request $request): array { // Определяем источник данных $isFromArchive = $this->resource['in_archive'] ?? false; $isTemporary = $this->resource['is_temporary'] ?? false; $historyType = $this->resource['history_type'] ?? 'mis'; // Формируем ФИО $family = $this->resource['family'] ?? ''; $name = $this->resource['name'] ?? ''; $ot = $this->resource['ot'] ?? ''; $misCardNumber = $this->resource['mis_card_number']; $foxproCardNumber = $this->resource['foxpro_card_number']; $hasDividerCardNumber = isset($misCardNumber) && isset($foxproCardNumber); $cardNumber = $hasDividerCardNumber ? "$misCardNumber / $foxproCardNumber" : $misCardNumber ?? $foxproCardNumber; // Для временных записей (не в архиве) используем данные из MIS if ($isTemporary) { // Данные из stt_medicalhistory (не в архиве) $fullName = trim("{$family} {$name} {$ot}"); $birthDate = $this->resource['birth_date'] ?? null; $dateExtract = $this->resource['date_extract'] ?? null; $dateRecipient = $this->resource['date_recipient'] ?? null; $archiveNum = null; $postIn = null; $status = $this->resource['status_text'] ?? 'Не в архиве'; } else { // Данные из archive_infos (в архиве) $fullName = trim("{$family} {$name} {$ot}"); $birthDate = $this->resource['birth_date'] ?? null; // Для архивных записей date_extract может быть из MIS или FoxPro $dateExtract = $this->resource['date_extract'] ?? null; $dateRecipient = $this->resource['date_recipient'] ?? null; $archiveNum = $this->resource['archive_num'] ?? null; $postIn = $this->resource['post_in'] ?? null; $status = $this->resource['status_text'] ?? 'Неизвестно'; } // Форматирование дат $formattedBirthDate = $birthDate ? Carbon::parse($birthDate)->format('d.m.Y') : null; $formattedDateRecipient = $dateRecipient ? Carbon::parse($dateRecipient)->format('d.m.Y') : null; $formattedDateExtract = $dateExtract ? Carbon::parse($dateExtract)->format('d.m.Y') : null; $formattedPostIn = $postIn ? Carbon::parse($postIn)->format('d.m.Y') : null; $id = $historyType === 'mis' ? $this->resource['mis_history_id'] : $this->resource['foxpro_history_id']; return [ 'id' => $id, 'history_type' => $historyType, 'in_archive' => $isFromArchive, 'is_temporary' => $isTemporary, 'source' => $this->resource['source'] ?? 'archive', // Основные данные 'fullname' => $fullName, 'family' => $family, 'name' => $name, 'ot' => $ot, 'dr' => $formattedBirthDate, 'daterecipient' => $formattedDateRecipient, 'dateextract' => $formattedDateExtract, // Номера карт 'medcardnum' => $cardNumber, // MIS номер или FoxPro номер 'mis_card_number' => $this->resource['mis_card_number'] ?? null, // Оригинальный MIS номер 'foxpro_card_number' => $this->resource['foxpro_card_number'] ?? null, // Оригинальный FoxPro номер 'card_num' => $archiveNum, // Архивный номер 'datearhiv' => $formattedPostIn, // Статус и возможности 'status' => $status, 'status_id' => $this->resource['status_id'] ?? 0, 'can_be_issued' => $this->resource['can_be_issued'] ?? false, 'can_add_to_archive' => $this->resource['can_add_to_archive'] ?? false, // Дополнительные идентификаторы 'mis_history_id' => $this->resource['mis_history_id'] ?? null, 'foxpro_history_id' => $this->resource['foxpro_history_id'] ?? null, // Дополнительные данные 'snils' => $this->resource['snils'] ?? null, 'enp' => $this->resource['enp'] ?? null, // 'created_at' => $this->resource->created_at ? Carbon::parse($this->resource->created_at)->format('d.m.Y H:i') : null, // 'updated_at' => $this->resource->updated_at ? Carbon::parse($this->resource->updated_at)->format('d.m.Y H:i') : null, // Стили для фронта 'row_class' => $this->resource['row_class'] ?? '', 'status_color' => $this->getStatusColor($this->resource['status_id'] ?? 0, $isFromArchive), ]; } /** * Получение цвета статуса для фронта */ private function getStatusColor(int $statusId, bool $inArchive): string { if (!$inArchive) { return 'warning'; // Желтый для не в архиве } return match($statusId) { 1 => 'success', // Зеленый для в архиве 2 => 'info', // Синий для выдано 3, 4 => 'danger', // Красный для утрачено/списано default => 'secondary', }; } }