*/ public function toArray(Request $request): array { return [ 'id' => $this->MedicalHistoryID, 'num' => $this->num, 'mkb' => [ 'ds' => $this->outcomeMigration->first()->mainDiagnosis?->mkb?->DS, 'name' => $this->outcomeMigration->first()->mainDiagnosis?->mkb?->NAME ], 'operations' => $this->surgicalOperations->map(function ($operation) { return [ 'code' => $operation->serviceMedical->ServiceMedicalCode, 'name' => $operation->serviceMedical->ServiceMedicalName, ]; }), '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'), 'outcome_type' => $this->when($this->outcome_type, $this->outcome_type), 'comment' => $this->when($this->comment, $this->comment) ]; } }