%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/klinisol/klinisol-api/app/Models/
Upload File :
Create Path :
Current File : /var/www/html/klinisol/klinisol-api/app/Models/Patient.php

<?php

namespace App\Models;

use App\Notifications\PatientAddedNotification;
use App\Notifications\SentCodeToPatientNotification;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Magros\Encryptable\Encryptable;

/**
 * @property integer id
 * @property string code
 * @property string name
 * @property string email
 * @property string phone
 */
class Patient extends Authenticatable
{
    use  Notifiable, HasApiTokens, Encryptable;

    const TEST_CODES = [
        '8u71r4m4',
    ];

    protected $table = 'patients';

    protected $fillable = [
        'name',
        'surname',
        'email',
        'phone',
        'code',
    ];

    protected $encryptable = [
        'name',
        'surname',
        'email',
        'phone',
    ];

    protected $camelcase = [
        'name',
        'surname',
    ];

    protected $casts = [
        'id'      => 'integer',
        'name'    => 'string',
        'surname' => 'string',
        'email'   => 'string',
        'phone'   => 'string',
        'code'    => 'string',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function hospitals()
    {
        return $this->belongsToMany('App\Models\Hospital', 'patient_hospital');
    }


    /**
     * @return mixed
     */
    public function hospital()
    {
        return $this->hospitals()
                    ->first();
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function protocols()
    {
        return $this->belongsToMany('App\Models\Protocol', 'patient_protocol')
                    ->withPivot('status', 'patient_signed_at');
    }

    /**
     *
     */
    public function patientAddedNotification()
    {
        $this->notify(new PatientAddedNotification($this));
    }

    /**
     * @param $code
     */
    public function sendCodeViaSms($code)
    {
        $this->notify(new SentCodeToPatientNotification($code));
    }

    /**
     * @param $notification
     * @return mixed
     */
    public function routeNotificationForNexmo($notification)
    {
        return $this->phone;
    }

    public function routeNotificationForTwilio()
    {
        return $this->phone;
    }

    public function isTestCode()
    {
        return in_array($this->code, self::TEST_CODES);
    }

    /**
     * @return string
     */
    public function fullName()
    {
        return $this->name . ' ' . $this->surname;
    }
}

Zerion Mini Shell 1.0