<?php

namespace Modules\Internal\Transformers;
use App\Models\DiagnosisSecondaryClaimHistoryCare;
use App\Models\Icd;

use Illuminate\Http\Resources\Json\JsonResource;

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

        $secondaryDiagnosis = DiagnosisSecondaryClaimHistoryCare::where('claim_history_care_id', $claim['id'])->with(['icd'])->get()->toArray();

        $data = [
            'id' => $claim['id'],
            'service_code' => $claim['service_code'],
            'admission_date' => $claim['admission_date'],
            'discharge_date' => $claim['discharge_date'],
            'claim_id' => $claim['claim_id'],
            'organization_id' => $claim['organization_id'],
            'organization_name' => $claim['organization'] ? $claim['organization']['name'] : '-',
            'practitioner_id' => $claim['practitioner_id'],
            'practitioner_name' => $claim['practitioner'] ? $claim['practitioner']['person']['name'] : '-',
            'medical_record_number' => $claim['medical_record_number'],
            'symptoms' => $claim['symptoms'],
            'sign' => $claim['sign'],
            'main_diagnosis_id' => $claim['main_diagnosis_id'],
            'main_diagnosis_name' => $claim['icd'] ? $claim['icd']['name'] : '-',
            'status' => $claim['status'],
            'secondary_diagnosis' => $secondaryDiagnosis,
        ];

        return $data;
    }
}
