<?php

namespace Modules\ClinicCore\Entities;

use Illuminate\Database\Eloquent\Model;

/**
 * SIFA P3-T1 — a "home medication" the patient is taking outside our own
 * prescriptions (for med reconciliation). Not linked to clc_prescriptions.
 */
class ClcPatientMedication extends Model
{
    protected $table = 'clc_patient_medications';
    protected $guarded = ['id'];

    protected $casts = [
        'ongoing'    => 'boolean',
        'start_date' => 'date',
        'end_date'   => 'date',
    ];

    public function patient()
    {
        return $this->belongsTo(ClcPatient::class, 'patient_id');
    }

    public function scopeOngoing($query)
    {
        return $query->where('ongoing', true);
    }
}
