%PDF- %PDF-
Direktori : /var/www/html/klinisol/klinisol-api/app/Models/ |
Current File : /var/www/html/klinisol/klinisol-api/app/Models/Protocol.php |
<?php namespace App\Models; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; /** * @property integer id * @property string code * @property string name * @property string description * @property boolean is_enabled * @property string template_id * @property string irb_number * @property mixed irb_approval_date * @property mixed irb_expiration_date */ class Protocol extends BaseModel implements HasMedia { use InteractsWithMedia; const COLLECTION_NAME = 'protocols'; const DISK = 's3'; const PROTOCOL_DATA = 'PROTOCOL_DATA'; const STUDY_PLAN = 'STUDY_PLAN'; const STUDY_CONTACT_PERSONNEL = 'STUDY_CONTACT_PERSONNEL'; protected $table = 'protocols'; protected $fillable = [ 'code', 'name', 'description', 'is_enabled', 'template_id', 'irb_number', 'irb_approval_date', 'irb_expiration_date', ]; protected $casts = [ 'id' => 'integer', 'code' => 'string', 'name' => 'string', 'description' => 'string', 'is_enabled' => 'boolean', 'template_id' => 'string', 'irb_number' => 'string', 'irb_approval_date' => 'date', 'irb_expiration_date' => 'date', ]; /** * @return BelongsToMany */ public function patients() { return $this->belongsToMany('App\Models\Patient', 'patient_protocol'); } /** * @return $this */ public function enable() { $this->is_enabled = true; $this->save(); return $this; } /** * @return $this */ public function disable() { $this->is_enabled = false; $this->save(); return $this; } /*public function setIrbApprovalDateAttribute($value) { try { $this->attributes['irb_approval_date'] = (new Carbon($value))->format('mm/dd/yyyy'); } catch (\Exception $e) { $this->attributes['irb_approval_date'] = $value; } }*/ public function questions() { return $this->hasMany(Question::class); } public function getMediaByType($type) { return $this->getMedia(Protocol::COLLECTION_NAME, function (Media $media) use ($type) { return isset($media->custom_properties['type']) && $media->custom_properties['type'] === $type; }) ->first(); } }