Много чего

This commit is contained in:
brusnitsyn
2025-12-25 17:30:50 +09:00
parent c4bb7ec6f9
commit a5209f45c8
25 changed files with 1521 additions and 574 deletions

View File

@@ -2,9 +2,9 @@
namespace App\Http\Resources\Mis;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;
class SttMedicalHistoryResource extends JsonResource
{
@@ -15,17 +15,114 @@ class SttMedicalHistoryResource extends JsonResource
*/
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'] ?? '';
// Для временных записей (не в архиве) используем данные из MIS
if ($isTemporary) {
// Данные из stt_medicalhistory (не в архиве)
$fullName = trim("{$family} {$name} {$ot}");
$birthDate = $this->resource['birth_date'] ?? null;
$dateExtract = $this->resource['date_extract'] ?? null;
$dateRecipient = null; // Для MIS записей не в архиве может не быть
$cardNumber = $this->resource['card_number'] ?? 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;
// Для MIS записей в архиве
if ($historyType === 'mis') {
$dateRecipient = $this->resource['date_recipient'] ?? null;
} else {
// Для FoxPro записей в архиве
$dateRecipient = $this->resource['mpostdate'] ?? null;
}
$cardNumber = $this->resource['card_number'] ?? 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;
return [
'id' => $this->MedicalHistoryID,
'fullname' => $this->getFullNameAttribute(),
'daterecipient' => Carbon::parse($this->DateRecipient)->format('d.m.Y'),
'dateextract' => Carbon::parse($this->DateExtract)->format('d.m.Y'),
'card_num' => $this->archiveInfo->num ?? null,
'status' => $this->archiveInfo->status ?? null,
'datearhiv' => $this->whenLoaded('archiveInfo') ? Carbon::parse($this->archiveInfo->post_in)->format('d.m.Y') : null,
'medcardnum' => $this->MedCardNum,
'dr' => Carbon::parse($this->BD)->format('d.m.Y'),
'can_be_issue' => $this->canBeIssued()
'id' => $this->resource['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',
};
}
}