<?php

namespace Modules\Internal\Transformers;

use Illuminate\Http\Resources\Json\JsonResource;

class EncounterResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {
        $encounter = parent::toArray($request);

        $encounter['class_name'] = $this->service->name;
        $encounter['primary_diagnosis'] = $this->primaryDiagnoses->first();
        $encounter['primary_doctor'] = $this->doctors->first()
            ? array_merge(
                $this->doctors->first()->person->toArray(),
                $this->doctors->first()->toArray()
            ) 
            : null;
        $encounter['medical_record_number'] = @$this->meta->MEDRECID ?? null;
        
        return $encounter;
    }
}
