'datetime', 'attachments_count' => 'integer' ]; /** * Get the client associated with the intervention. */ public function client(): BelongsTo { return $this->belongsTo(Client::class); } /** * Get the deceased associated with the intervention. */ public function deceased(): BelongsTo { return $this->belongsTo(Deceased::class); } /** * Get the location associated with the intervention. */ public function location(): BelongsTo { return $this->belongsTo(ClientLocation::class); } /** * Get the practitioners assigned to the intervention. */ public function practitioners(): BelongsToMany { return $this->belongsToMany(Thanatopractitioner::class, 'intervention_practitioner', 'intervention_id', 'practitioner_id') ->withPivot('role', 'assigned_at') ->withTimestamps(); } /** * Alias for practitioners relationship (for backward compatibility). */ public function assignedPractitioner(): BelongsToMany { return $this->practitioners(); } /** * Get the principal practitioner assigned to the intervention. */ public function principalPractitioner(): BelongsToMany { return $this->belongsToMany(Thanatopractitioner::class, 'intervention_practitioner', 'intervention_id', 'practitioner_id') ->wherePivot('role', 'principal') ->withPivot('role', 'assigned_at') ->withTimestamps(); } /** * Get the assistant practitioners assigned to the intervention. */ public function assistantPractitioners(): BelongsToMany { return $this->belongsToMany(Thanatopractitioner::class, 'intervention_practitioner', 'intervention_id', 'practitioner_id') ->wherePivot('role', 'assistant') ->withPivot('role', 'assigned_at') ->withTimestamps(); } /** * Get the user who created the intervention. */ public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } /** * Get the attachments for the intervention (legacy support). */ public function attachments(): HasMany { return $this->hasMany(InterventionAttachment::class); } /** * Get the file attachments for the intervention (polymorphic). */ public function fileAttachments() { return $this->morphMany(FileAttachment::class, 'attachable')->orderBy('sort_order'); } /** * Get the files attached to this intervention. */ public function attachedFiles() { return $this->fileAttachments()->with('file'); } /** * Get the notifications for the intervention. */ public function notifications(): HasMany { return $this->hasMany(InterventionNotification::class); } }