Skip to main content

Communication Service — Domain Model

Status: populated Owner: TBD Last updated: 2026-04-17 Companion: Service Template · 02 DDD · 04 Event-Driven

1. Aggregates

AggregateRoot entityResponsibilityInvariants
MessageThreadMessageThreadOrdered conversation between ≥ 2 participants, optional patient/encounter linkageA thread MUST have ≥ 1 active participant; archived threads reject new messages; patient-linked thread visibility requires chart read permission
Message (inside MessageThread)MessageOne utterance in a thread with body, urgency, sender, optional attachmentsCannot edit a message once sent (only retract); body non-empty; urgency ∈ {routine, urgent, emergent}
NotificationIntentNotificationIntentOne dispatch request keyed by (tenantId, correlationId, category, channel, recipientRef)Idempotent on its key; never contains PHI in structured fields once persisted
DispatchRecordDispatchRecordPer-channel outcome ledger for a NotificationIntentAppend-only; DLR callback upserts status but never removes a record
VirtualSessionVirtualSessionVirtual encounter with participants, waiting room, active session, end stateState machine enforced; terminal states are ended, cancelled, failed; cannot re-open a terminal session
VirtualParticipant (inside VirtualSession)VirtualParticipantOne invitee with role (provider/patient/observer) and admit stateOnly ADMITTED participants receive a valid join token

2. Entities & Value Objects

TypeKindNotes
ThreadIdVO (branded ULID thr_)
MessageIdVO (branded ULID msg_)
NotificationIntentIdVO (branded ULID nti_)
DispatchRecordIdVO (branded ULID dsp_)
SessionIdVO (branded ULID vcs_)
ParticipantIdVO (branded ULID vcp_)
JoinTokenVOShort-lived (≤ 5 min) signed token; one-time use
UrgencyVO enumroutine / urgent / emergent
ChannelVO enumpush / sms / email / in_app
CategoryVO enumsecure_message / appointment_reminder / critical_result / marketing / operational
ParticipantEntity{userId, role, addedAt, mutedUntil?}
ReadReceiptEntity{messageId, userId, readAt}
AttachmentEntity{fileRef, mimeType, sizeBytes, hash, scanStatus}
DeliveryOutcomeVOdelivered / failed / deferred / unknown; with providerMessageId, errorCode?

3. State machines

3.1 MessageThread

3.2 VirtualSession

3.3 NotificationIntent dispatch

4. Domain events

EventWhenCanonical type
ThreadCreatedThread openedghasi.digital_communication.thread.created
MessageSentFirst message in threadghasi.digital_communication.message.sent
MessageRepliedSubsequent messageghasi.digital_communication.message.replied
MessagesReadRead receipts appliedghasi.digital_communication.message.read
ThreadEscalatedEscalation triggeredghasi.digital_communication.thread.escalated
ThreadArchivedArchivedghasi.digital_communication.thread.archived
NotificationQueuedIntent acceptedghasi.digital_communication.notification.queued
NotificationDispatchedProvider acceptedghasi.digital_communication.notification.dispatched
NotificationDeliveredDLR successghasi.digital_communication.notification.delivered
NotificationFailedDLR failed or adapter errorghasi.digital_communication.notification.failed
VirtualSessionCreatedghasi.digital_communication.virtual_session.created
VirtualSessionStartedFirst admitghasi.digital_communication.virtual_session.started
VirtualSessionEndedghasi.digital_communication.virtual_session.ended
VirtualSessionFailedInfra failureghasi.digital_communication.virtual_session.failed
VirtualSessionFallbackInitiatedFallback thread spawnedghasi.digital_communication.virtual_session.fallback.initiated

5. Ubiquitous language

TermDefinition
ThreadConversation container; the Communication FHIR resource maps to a message within this container.
ParticipantAny user (provider, patient, system) listed on a thread or virtual session.
UrgencyPolicy-controlled classification that may short-circuit notification channel defaults.
IntentA request-to-dispatch; carries no PHI beyond opaque ids and template keys.
DispatchA concrete attempt at delivery through a single channel + provider.
DLRDelivery Receipt / Delivery Report returned by the channel provider.
Fallback threadMessaging thread automatically created when a virtual session cannot complete.
Join tokenShort-lived signed token permitting one participant to enter a virtual session.
CategoryBusiness classification of a notification driving channel policy.