Assignment
Data Entity
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.
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
Columns: assigned_to_user_id
idx_assignments_contact_id
Columns: contact_id
idx_assignments_organization_id
Columns: organization_id
idx_assignments_status
Columns: status
idx_assignments_dispatched_at
Columns: dispatched_at
idx_assignments_org_user_status
Columns: organization_id, assigned_to_user_id, status
idx_assignments_reminder_check
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
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
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
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
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 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
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
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
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
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.