Overview
OdontologyApp includes a comprehensive notification system that delivers both personal and global notifications to users based on their roles and activities. The system supports different notification types and automatically manages read/unread states.Features
Notification Types
The system supports four notification types:- info: General information messages (blue theme)
- success: Success confirmations (green theme)
- warning: Important warnings (amber theme)
- error: Error notifications (red theme)
Personal vs Global Notifications
Personal Notifications
Targeted to specific users for individual actions like appointment updates, payment confirmations, or personal alerts
Global Notifications
Broadcast to all users with specific roles (admin, doctor, secretary) for system-wide announcements
Database Schema
The notification system uses two tables:notifications table
Stores personal notifications for individual users.global_notifications table
Stores system-wide notifications targeted by role.API Endpoints
The notification system is accessible through/api/notifications
GET /api/notifications
Retrieve all notifications for the current user (both personal and global)./src/routes/api/notifications/+server.js:5
The GET endpoint uses the stored procedure
sp_get_user_notifications which automatically merges personal and global notifications based on user role.POST /api/notifications
Create a new personal notification./src/routes/api/notifications/+server.js:28
PATCH /api/notifications
Mark notifications as read./src/routes/api/notifications/+server.js:49
Stored Procedures
sp_get_user_notifications
Retrieves merged personal and global notifications for a user.- Returns personal notifications for the user
- Unions with global notifications matching the user’s role
- Global notifications from last 7 days only
- Orders by created_at DESC
- Limits to 25 most recent
/migrate_sps_phase10.cjs:96
sp_create_notification
Creates a new personal notification./migrate_sps_phase10.cjs:117
sp_mark_notifications_read
Marks one or all notifications as read./migrate_sps_phase10.cjs:132
Setup Instructions
Create Tables
Run the setup script to create notification tables:This creates both
notifications and global_notifications tables.Configuration Options
Notification type:
info, success, warning, or errorNotification title (max 200 characters)
Detailed notification message
Optional navigation link when notification is clicked
For global notifications: Array of roles to target
["admin", "doctor", "secretary"]Integration Examples
Triggering Notifications from Backend
System-wide Notifications
Frontend Integration
Best Practices
Keep Messages Concise
Keep Messages Concise
Notification titles should be under 50 characters when possible. Use the message field for detailed information.
Use Appropriate Types
Use Appropriate Types
error: Only for actual errors requiring immediate attentionwarning: Important but not critical informationsuccess: Confirmation of completed actionsinfo: General informational messages
Include Navigation Links
Include Navigation Links
Global Notification Retention
Global Notification Retention
Global notifications are only shown for 7 days to prevent notification overload. For permanent announcements, consider using a different mechanism.
Related Features
Reminders
Automated appointment reminders via WhatsApp and email
Webhooks
Event-driven integrations with external systems
