core PK: id 8 required 1 unique

Description

A person receiving peer mentor support. Represents the core operational subject of a peer mentor's work — the individual they visit, call, or interact with. Scoped to the owning peer mentor and their organization. Display label is overrideable per organization via the Organization Labels system (e.g. 'Familie', 'Bruker', 'Kontakt').

21
Attributes
6
Indexes
9
Validation Rules
25
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Primary key, generated client-side (offline-first UUID v4)
PKrequiredunique
user_id uuid Foreign key to the peer mentor (users) who owns this contact record
required
organization_id uuid Foreign key to the organization this contact belongs to — enforces tenant isolation
required
first_name string Contact's first name
required
last_name string Contact's last name
required
phone string Primary phone number in E.164 format
-
email string Email address
-
date_of_birth datetime Date of birth — used for age-based eligibility checks and Bufdir demographic reporting
-
gender enum Self-reported gender — used in Bufdir reporting demographics
-
address_line string Street address — used for home visit logging context
-
postal_code string Norwegian postal code (4 digits)
-
city string City or municipality
-
disability_category string High-level disability or health category relevant to the peer mentor program — used for matching and Bufdir reporting. Free text; not a controlled enum as categories vary by organization.
-
is_active boolean Whether this contact is currently active. Inactive contacts are hidden from default lists but retained for historical reporting.
required
notes text Free-text field for the peer mentor to record general context about the contact. Not shown to coordinators by default — respects privacy minimization.
-
preferred_contact_method enum How the contact prefers to be reached — used in activity wizard pre-fill and notification routing
-
local_id string Client-generated offline UUID used during optimistic creation before server sync. Stored to support ID mapping for offline-created activities referencing this contact.
-
synced_at datetime Timestamp of last successful sync from server — used by Drift offline layer to detect staleness
-
created_at datetime Record creation timestamp (server time)
required
updated_at datetime Last modification timestamp
required
deleted_at datetime Soft-delete timestamp. NULL = active. Set on deletion to preserve referential integrity with activities and caregiver_contacts.
-

Database Indexes

idx_contacts_user_id
btree

Columns: user_id

idx_contacts_organization_id
btree

Columns: organization_id

idx_contacts_user_org
btree

Columns: user_id, organization_id

idx_contacts_name_search
btree

Columns: first_name, last_name

idx_contacts_active
btree

Columns: user_id, is_active, deleted_at

idx_contacts_deleted_at
btree

Columns: deleted_at

Validation Rules

name_required error

Validation failed

phone_format error

Validation failed

email_format error

Validation failed

postal_code_format error

Validation failed

date_of_birth_not_future error

Validation failed

at_least_one_contact_method warning

Validation failed

notes_length_limit error

Validation failed

sensitive_field_readout_warning info

Validation failed

conflict_resolution_on_sync warning

Validation failed

Business Rules

tenant_isolation
on_create

A contact must belong to the same organization as the peer mentor who created it. Cross-organization contact access is never permitted.

peer_mentor_ownership
always

Peer mentors can only read and edit their own contacts. Coordinators can read all contacts within their organization but cannot edit contacts owned by other peer mentors.

soft_delete_only
on_delete

Contacts are never hard-deleted. Deletion sets deleted_at timestamp to preserve referential integrity with activities, caregiver_contacts, and Bufdir reports.

active_contact_required_for_activity
always

An activity can only be logged against a contact where is_active=true and deleted_at IS NULL. Inactive or deleted contacts are excluded from the activity wizard contact picker.

offline_optimistic_create
on_create

Contact creation is optimistic — the record is committed locally via Drift before the API call returns. local_id is stored for ID mapping when the server assigns the canonical UUID.

coordinator_visibility_scope
always

Coordinators see all contacts in their organization to support proxy reporting and team oversight, but the UI distinguishes between their own contacts and contacts owned by other peer mentors.

label_override
always

The display label for 'Contact' is resolved at runtime via the Organization Labels system. The term 'Kontakt' may be overridden to 'Familie', 'Bruker', or another org-specific label. The entity ID and schema field names remain 'contacts' regardless.

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
by_user
Retention
Permanent Storage