Убран фильтр по номеру карты Добавлена загрузка связи visitResult Правка размеров колонок Добавлена колонка исход Исправлено определение последнего движения в SttMedicalHistory
92 lines
3.6 KiB
PHP
92 lines
3.6 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Resources;
|
||
|
||
use App\Models\ArchiveStatus;
|
||
use Carbon\Carbon;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Http\Resources\Json\JsonResource;
|
||
|
||
class IndexSttMedicalHistoryResource extends JsonResource
|
||
{
|
||
/**
|
||
* Transform the resource into an array.
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function toArray(Request $request): array
|
||
{
|
||
// Получаем оригинальную модель
|
||
$model = $this->resource;
|
||
|
||
$archiveInfo = $model->archiveInfo;
|
||
$historyType = $archiveInfo->historyType();
|
||
|
||
$inArchive = $archiveInfo->exists;
|
||
$hasMisType = $historyType === 'mis';
|
||
|
||
$family = $hasMisType ? $model->FAMILY : $model->fam;
|
||
$im = $hasMisType ? $this->Name : $this->im;
|
||
$ot = $hasMisType ? $this->OT : $this->ot;
|
||
|
||
$fio = "$family $im $ot";
|
||
|
||
$birthDate = $hasMisType ? $this->BD : $this->dr;
|
||
$dateRecipient = $hasMisType ? $this->DateRecipient : $this->mpostdate;
|
||
$dateExtract = $hasMisType ? $this->DateExtract : $this->menddate;
|
||
$postIn = $inArchive ? $archiveInfo->post_in : null;
|
||
|
||
$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->MedicalHistoryID : $this->keykarta;
|
||
$archiveNum = $inArchive ? $archiveInfo->archive_num : null;
|
||
$status = $inArchive ? $archiveInfo->status : ArchiveStatus::find(5)->first();
|
||
|
||
$misCardNumber = $this->MedCardNum;
|
||
$foxproCardNumber = $this->nkarta;
|
||
|
||
$archiveInfoMisCardNumber = $inArchive ? $archiveInfo->mis_num : null;
|
||
$archiveInfoFoxproCardNumber = $inArchive ? $archiveInfo->foxpro_num : null;
|
||
|
||
$hasDividerCardNumber = isset($archiveInfoMisCardNumber) && isset($archiveInfoFoxproCardNumber);
|
||
|
||
$cardNumber = $hasDividerCardNumber
|
||
? "$archiveInfoMisCardNumber / $archiveInfoFoxproCardNumber"
|
||
: $archiveInfoMisCardNumber ?? $archiveInfoFoxproCardNumber;
|
||
|
||
$department = $historyType === 'mis' ? $model->outcomeMigration?->first()?->stationarBranch->department : null;
|
||
|
||
$visitResult = $historyType === 'mis' ? $this->visitResult->NAME : null;
|
||
|
||
return [
|
||
'id' => $id,
|
||
'history_type' => $historyType,
|
||
|
||
// Основные данные
|
||
'fullname' => $fio,
|
||
'family' => $family,
|
||
'name' => $im,
|
||
'ot' => $ot,
|
||
'dr' => $formattedBirthDate,
|
||
'daterecipient' => $formattedDateRecipient,
|
||
'dateextract' => $formattedDateExtract,
|
||
'department' => $department ? '[' . $department->DepartmentCODE . '] ' . $department->DepartmentNAME : 'Н/д',
|
||
'visitresult' => $visitResult,
|
||
|
||
// Номера карт
|
||
'medcardnum' => $cardNumber, // MIS номер или 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,
|
||
];
|
||
}
|
||
}
|