*/ protected $fillable = [ 'employee_id', 'diploma_number', 'diploma_date', 'authorization_number', 'authorization_issue_date', 'authorization_expiry_date', 'notes', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'diploma_date' => 'date', 'authorization_issue_date' => 'date', 'authorization_expiry_date' => 'date', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * Get the employee that owns the thanatopractitioner. */ public function employee(): BelongsTo { return $this->belongsTo(Employee::class); } /** * Get all documents associated with the thanatopractitioner. */ public function documents(): HasMany { return $this->hasMany(PractitionerDocument::class, 'practitioner_id'); } /** * Get the interventions assigned to the thanatopractitioner. */ public function interventions(): BelongsToMany { return $this->belongsToMany(Intervention::class, 'intervention_practitioner') ->withPivot('role', 'assigned_at') ->withTimestamps(); } /** * Get the interventions where this practitioner is the principal. */ public function principalInterventions(): BelongsToMany { return $this->belongsToMany(Intervention::class, 'intervention_practitioner') ->wherePivot('role', 'principal') ->withPivot('role', 'assigned_at') ->withTimestamps(); } /** * Get the interventions where this practitioner is an assistant. */ public function assistantInterventions(): BelongsToMany { return $this->belongsToMany(Intervention::class, 'intervention_practitioner') ->wherePivot('role', 'assistant') ->withPivot('role', 'assigned_at') ->withTimestamps(); } /** * Scope a query to only include practitioners with valid authorization. */ public function scopeWithValidAuthorization($query) { return $query->where('authorization_expiry_date', '>=', now()); } /** * Scope a query to only include practitioners with expired authorization. */ public function scopeWithExpiredAuthorization($query) { return $query->where('authorization_expiry_date', '<', now()); } /** * Check if the authorization is still valid. */ public function getIsAuthorizationValidAttribute(): bool { if (!$this->authorization_expiry_date) { return false; } return $this->authorization_expiry_date >= now(); } }