core PK: id 9 required 1 unique

Description

A next-of-kin or caregiver record associated with a contact — particularly important for organizations like Barnekreftforeningen and NHF whose contacts include children, elderly, or people with complex care needs. Tracks relationship type, contact details, and notification consent status.

14
Attributes
4
Indexes
10
Validation Rules
17
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Primary key. Globally unique identifier for the caregiver record, generated server-side on creation.
PKrequiredunique
contact_id uuid Foreign key referencing the contact (beneficiary) this caregiver is associated with. A contact may have multiple caregivers.
required
first_name string Caregiver's given name. Used in all display contexts and notification addressal.
required
last_name string Caregiver's family name. Combined with first_name for full display.
required
relationship_type enum The relationship between the caregiver and the contact. Determines how the caregiver is described in UI and reports.
required
phone string Caregiver's phone number, formatted for Norwegian locale (e.g. +47XXXXXXXX). Used for quick-dial shortcuts in the Caregiver List Screen.
-
email string Caregiver's email address. Used for direct email shortcuts and notification delivery when consent is given.
-
notification_consent boolean Whether the caregiver has given explicit consent to receive notifications about the contact's activities or care status. Must be explicitly set — defaults to false (opt-out by default). Required for GDPR compliance.
required
notification_consent_updated_at datetime Timestamp recording when notification_consent was last changed. Used for consent audit trails and GDPR data subject request handling.
-
is_primary_contact boolean Flags this caregiver as the primary point of contact for the associated contact record. Only one caregiver per contact may be primary. Used to prioritize contact information in the Contact Detail Screen.
required
notes text Free-text field for additional context about the caregiver relationship, special instructions, or care arrangements. Not included in notification payloads.
-
created_at datetime UTC timestamp when the caregiver record was created. Immutable after creation.
required
updated_at datetime UTC timestamp of the most recent update to any field. Maintained automatically via trigger.
required
deleted_at datetime Soft-delete timestamp. When non-null, the record is treated as deleted and excluded from all standard queries. Preserved for audit compliance.
-

Database Indexes

idx_caregiver_contact_id
btree

Columns: contact_id

idx_caregiver_deleted_at
btree

Columns: deleted_at

idx_caregiver_contact_primary
btree

Columns: contact_id, is_primary_contact

idx_caregiver_notification_consent
btree

Columns: contact_id, notification_consent

Validation Rules

email_format error

Validation failed

email_format_on_update error

Validation failed

phone_format error

Validation failed

phone_format_on_update error

Validation failed

first_name_not_blank error

Validation failed

last_name_not_blank error

Validation failed

contact_id_exists error

Validation failed

relationship_type_valid error

Validation failed

relationship_type_valid_on_update error

Validation failed

notification_consent_explicit warning

Validation failed

Business Rules

at_least_one_contact_method
on_create

Every caregiver record must provide at least one of phone or email. A caregiver with neither cannot be notified and provides limited utility. Enforced at both service and API levels.

single_primary_per_contact
on_create

At most one caregiver per contact may have is_primary_contact = true. When a new caregiver is created or updated with is_primary_contact = true, any existing primary caregiver for the same contact_id is automatically demoted to false within the same transaction.

single_primary_per_contact_on_update
on_update

Same primary uniqueness constraint applied on update — if is_primary_contact is changed to true, the previous primary for this contact is demoted in the same transaction.

consent_audit_trail
on_update

Whenever notification_consent changes value, notification_consent_updated_at must be set to the current UTC timestamp. This provides a GDPR-compliant record of when consent was given or withdrawn.

soft_delete_only
on_delete

Caregivers must never be hard-deleted. Setting deleted_at to the current timestamp marks the record as deleted. This preserves historical contact relationships for audit and Bufdir reporting purposes.

role_scoped_access
always

Caregiver records are accessible only to authenticated users with a valid role (Peer Mentor, Coordinator, Organization Administrator, or Global Administrator) who have access to the parent contact. Peer mentors may only access caregivers linked to their own assigned contacts. Coordinators may access all caregivers within their local association scope.

cascade_delete_on_contact_deletion
on_delete

When a contact is deleted (soft or hard), all associated caregiver records must also be soft-deleted. This is enforced at the database level via ON DELETE CASCADE for hard deletes, and via service logic for soft deletes.

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
No Partitioning
Retention
Permanent Storage

Entity Relationships

contact
incoming one_to_many

A contact can have multiple caregivers or next-of-kin associated with them

optional