Files
onboard/app/Http/Resources/Mis/FormattedPatientResource.php
brusnitsyn cb43c74a72 * добавлены операции и услуги операций
* добавлена выборка и подсчет по датам для роли зав.
* переключатель ролей
* выбор отделений для роли зав.
2026-01-22 17:58:27 +09:00

44 lines
1.6 KiB
PHP

<?php
namespace App\Http\Resources\Mis;
use App\Models\MisSurgicalOperation;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
class FormattedPatientResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->MedicalHistoryID,
'num' => $this->num,
'mkb' => $this->whenLoaded('migrations', function () {
return [
'ds' => $this->migrations()->first()->diagnosis()->first()?->mkb()->first()->DS ?? null,
'name' => $this->migrations()->first()->diagnosis()->first()?->mkb()->first()->NAME ?? null,
];
}),
'operations' => $this->whenLoaded('surgicalOperations', function () {
return $this->surgicalOperations()->where('rf_StationarBranchID', $this->misStationarBranchId)
->get()
->map(function (MisSurgicalOperation $operation) {
return [
'code' => $operation->serviceMedical->ServiceMedicalCode ?? null,
];
});
}),
'fullname' => Str::ucwords(Str::lower("$this->FAMILY $this->Name $this->OT")),
'age' => Carbon::parse($this->BD)->diff(Carbon::now())->format('%y'),
'birth_date' => Carbon::parse($this->BD)->format('d.m.Y'),
];
}
}