<?php

namespace App\Models;

use App\Traits\Auditable;

use Illuminate\Database\Eloquent\Model;

/**
 * @property string $id
 * @property string $patients_id
 * @property string $description
 * @property string $created_at
 * @property string $updated_at
 * @property Patient $patient
 * @property Especiality $especiality
 */
class MedicalReport extends Model
{
    use Auditable;
    /**
     * The table associated with the model.
     * 
     * @var string
     */
    protected $table = 'medical_report';

    /**
     * The "type" of the auto-incrementing ID.
     * 
     * @var string
     */
    protected $keyType = 'string';

    /**
     * Indicates if the IDs are auto-incrementing.
     * 
     * @var bool
     */
    public $incrementing = false;

    /**
     * @var array
     */
    protected $fillable = ['id','users_id','patients_id', 'description', 'created_at', 'especiality', 'updated_at'];


    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function patient()
    {
        return $this->belongsTo('App\Models\Patients', 'patients_id');
    }

     /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo('App\Models\User', 'users_id');
    }

    /**
     * 
     */
    public function especiality()
    {
        return $this->belongsTo('App\Models\Especiality', 'especiality');
    }

    /**
     * 
     */
    public static function getMedicalReportsForPatientSelected(){
        $patientId = session(config('constants.keysSessions.medicalReportsIdPatient'));
        return MedicalReport::where("patients_id",$patientId)->orderBy('created_at','DESC');
    }
}
