core PK: id 11 required 1 unique

Description

Encrypted sensitive data dispatch from a coordinator to a peer mentor, representing a formal assignment of a contact case. Contains encrypted personal information (name, address, medical summary) requiring secure delivery with read/delivery confirmation and threshold-based honorarium tracking.

20
Attributes
7
Indexes
8
Validation Rules
12
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Primary key — unique assignment identifier
PKrequiredunique
organization_id uuid FK to organizations — enforces tenant isolation; assignment only visible within dispatching org
required
contact_id uuid FK to contacts — the person being assigned to a peer mentor for support
required
assigned_to_user_id uuid FK to users — the peer mentor receiving the assignment
required
dispatched_by_user_id uuid FK to users — the coordinator who created and dispatched the assignment
required
encrypted_payload text AES-256 encrypted blob containing sensitive personal data: name, address, medical summary (epikrise), and any other sensitive case details. Never stored or transmitted in plaintext.
required
encryption_key_id string Reference to the encryption key in secure key storage used to encrypt/decrypt the payload. Enables key rotation without re-encrypting all payloads.
required
status enum Current lifecycle status of the assignment. Controls what actions are available and triggers notification scenarios.
required
assignment_number integer Sequential count of assignments completed by this peer mentor within the organization. Used for threshold-based honorarium calculation (triggers at 3rd and 15th completed assignment).
-
honorarium_tier integer Honorarium tier unlocked by this assignment. 0 = no honorarium, 1 = base tier (3rd assignment), 2 = higher tier (15th assignment). Null until assignment is completed.
-
dispatched_at datetime Timestamp when the coordinator dispatched the assignment. Starts the 10-day contact deadline clock.
required
delivered_at datetime Timestamp when the push notification or delivery confirmation was received by the peer mentor's device. Null until delivery is confirmed.
-
read_at datetime Timestamp when the peer mentor opened and viewed the assignment detail screen. Null until read.
-
accepted_at datetime Timestamp when the peer mentor explicitly accepted the assignment. Null until accepted.
-
completed_at datetime Timestamp when the peer mentor marked the assignment as completed (contact established and case closed). Triggers honorarium threshold evaluation.
-
expires_at datetime Optional expiry datetime after which the assignment transitions to 'expired' if not accepted. Defaults to 30 days after dispatch if not set explicitly.
-
reminder_sent_at datetime Timestamp when the 10-day inactivity reminder was sent to the peer mentor. Null if no reminder has been sent yet. Prevents duplicate reminder dispatch.
-
coordinator_notes text Unencrypted internal notes from the coordinator for context visible to coordinators only. Does NOT contain sensitive personal data — that goes in encrypted_payload.
-
created_at datetime Record creation timestamp
required
updated_at datetime Last modification timestamp, updated on any status transition or field change
required

Database Indexes

idx_assignments_assigned_to_user_id
btree

Columns: assigned_to_user_id

idx_assignments_contact_id
btree

Columns: contact_id

idx_assignments_organization_id
btree

Columns: organization_id

idx_assignments_status
btree

Columns: status

idx_assignments_dispatched_at
btree

Columns: dispatched_at

idx_assignments_org_user_status
btree

Columns: organization_id, assigned_to_user_id, status

idx_assignments_reminder_check
btree

Columns: status, dispatched_at, reminder_sent_at

Validation Rules

peer_mentor_role_required error

Validation failed

contact_exists_in_org error

Validation failed

encrypted_payload_non_empty error

Validation failed

encryption_key_id_valid error

Validation failed

coordinator_notes_length error

Validation failed

expires_at_future error

Validation failed

honorarium_tier_range error

Validation failed

status_enum_values error

Validation failed

Business Rules

coordinator_dispatch_only
on_create

Only users with Coordinator or higher role within the same organization may create (dispatch) assignments. Peer mentors cannot self-assign or create assignments.

same_organization_constraint
on_create

The assigned_to_user_id (peer mentor), contact_id, and dispatched_by_user_id must all belong to the same organization_id. Cross-organization assignment dispatch is prohibited.

encrypted_payload_mandatory
on_create

All sensitive personal data (name, address, medical summary) must be encrypted using the organization's AES-256 key before the assignment record is persisted. Plaintext storage of sensitive fields is strictly prohibited.

ten_day_inactivity_reminder
always

If the assignment remains in 'delivered' or 'pending' status for 10 days without the peer mentor establishing contact (i.e., no transition to 'accepted' or 'completed'), an automatic reminder notification is dispatched. reminder_sent_at is set to prevent duplicate reminders.

honorarium_threshold_evaluation
on_update

On assignment completion, the peer mentor's total completed assignment count for the organization is evaluated. If the count reaches 3, honorarium_tier is set to 1 (base). If it reaches 15, honorarium_tier is set to 2 (higher rate). A log entry is written to honorarium_log_repository.

valid_status_transitions
on_update

Status transitions must follow the defined lifecycle: pending → delivered → read → accepted → completed. Transitions to 'expired' or 'cancelled' are allowed from any non-terminal status. Reverting to a prior status is prohibited.

read_only_access_for_peer_mentor
always

The assigned peer mentor may only read their own assignments. They cannot view assignments dispatched to other peer mentors. Coordinators may view all assignments within their organization.

expiry_auto_transition
always

If expires_at is reached and the assignment has not been accepted or completed, a scheduled job transitions status to 'expired' and notifies the dispatching coordinator.

cancellation_coordinator_only
on_update

Only coordinators or org admins can cancel an active assignment. Cancellation is a soft status change (to 'cancelled'), not a hard delete, to preserve audit trail.

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
by_date
Retention
archive_after_1year