// ===================================================== // NOTIFICATION HELPERS (Phase 6) // ===================================================== /** * Create an in-app notification with dedup. * Returns true if inserted, false if duplicate. */ function notify_user( int $userId, string $type, string $title, ?string $body = null, ?string $link = null, string $priority = 'normal', ?string $refType = null, ?int $refId = null, ?string $dedupKey = null ): bool { // Check dedup if ($dedupKey !== null) { $exists = db_fetch("SELECT id FROM notifications WHERE dedup_key = ? LIMIT 1", [$dedupKey]); if ($exists) return false; } try { db_insert('notifications', [ 'user_id' => $userId, 'type' => $type, 'priority' => $priority, 'title' => $title, 'body' => $body, 'link' => $link, 'ref_type' => $refType, 'ref_id' => $refId, 'dedup_key' => $dedupKey, 'created_at' => now(), ]); return true; } catch (Throwable $e) { error_log('notify_user failed: ' . $e->getMessage()); return false; } } /** * Log reminder send (prevents duplicate cron sends). */ function reminder_log_try(string $dedupKey, int $patientId, string $reminderType, ?string $refType = null, ?int $refId = null): bool { try { db_insert('reminder_log', [ 'dedup_key' => $dedupKey, 'patient_id' => $patientId, 'reminder_type' => $reminderType, 'ref_type' => $refType, 'ref_id' => $refId, 'sent_at' => now(), ]); return true; } catch (Throwable $e) { // Duplicate key = already sent, safe return false; } } /** * Count unread notifications for a user. */ function unread_notification_count(int $userId): int { $row = db_fetch( "SELECT COUNT(*) c FROM notifications WHERE user_id = ? AND read_at IS NULL", [$userId] ); return (int) ($row['c'] ?? 0); } /** * Get user_settings row, creating default if missing. */ function user_settings(int $userId): array { $row = db_fetch("SELECT * FROM user_settings WHERE user_id = ? LIMIT 1", [$userId]); if ($row) return $row; db_insert('user_settings', ['user_id' => $userId]); return db_fetch("SELECT * FROM user_settings WHERE user_id = ? LIMIT 1", [$userId]) ?? []; } DB Debug — SuPav Health

DB Debug Panel

DB_HOST localhost
DB_PORT 3306
DB_NAME u423425225_health
DB_USER u423425225_health
DB_PASS_length 11
APP_ENV production
pdo_connect OK
mt_count 7
total_tables 25
tables_sample
Array
(
    [0] => access_logs
    [1] => doctor_notes
    [2] => doctor_visits
    [3] => doctors
    [4] => emergency_profiles
)
db_helper OK