Новая логика поисковой выдачи
И добавлена кнопка Добавить карту в архив
This commit is contained in:
85
app/Http/Resources/IndexSttMedicalHistoryResource.php
Normal file
85
app/Http/Resources/IndexSttMedicalHistoryResource.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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;
|
||||
|
||||
return [
|
||||
'id' => $id,
|
||||
'history_type' => $historyType,
|
||||
|
||||
// Основные данные
|
||||
'fullname' => $fio,
|
||||
'family' => $family,
|
||||
'name' => $im,
|
||||
'ot' => $ot,
|
||||
'dr' => $formattedBirthDate,
|
||||
'daterecipient' => $formattedDateRecipient,
|
||||
'dateextract' => $formattedDateExtract,
|
||||
|
||||
// Номера карт
|
||||
'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,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user