Skip to content

feat: implementare NotificationService per reminder e segnalazioni interne #81

@artcava

Description

@artcava

🎯 Obiettivo

Implementare un servizio di notifiche interne per gestire reminder, segnalazioni e alert all'interno dell'applicazione (non email/SMS esterni, ma notifiche UI).

📋 Contesto

Scenari d'uso:

  • Reminder visite imminenti: "Hai 2 visite programmate domani"
  • Segnalazione progetti in scadenza: "Il progetto PTRP-2023-015 termina tra 7 giorni"
  • Alert visite mancate non giustificate: "3 visite mancate senza registrazione nel mese corrente"
  • Notifiche sync: "Nuovo pacchetto disponibile per l'importazione"
  • Alert validazione: "5 progetti attivi senza educatori assegnati"

Queste notifiche appaiono:

  • nella Dashboard come "notification center"
  • come badge su icone sidebar
  • come snackbar temporanee per eventi critici.

📦 Servizio da Implementare

INotificationService + NotificationService

Metodi principali (proposta):

public interface INotificationService
{
    // Recupero notifiche
    Task<IReadOnlyList<NotificationDto>> GetUnreadNotificationsAsync(
        Guid operatorId,
        CancellationToken ct = default);
    
    Task<IReadOnlyList<NotificationDto>> GetAllNotificationsAsync(
        Guid operatorId,
        int maxCount = 50,
        CancellationToken ct = default);
    
    // Creazione notifiche
    Task CreateNotificationAsync(
        Guid targetOperatorId,
        string title,
        string message,
        NotificationPriority priority,
        string? actionUrl = null,
        CancellationToken ct = default);
    
    // Gestione stato
    Task MarkAsReadAsync(Guid notificationId, CancellationToken ct = default);
    Task MarkAllAsReadAsync(Guid operatorId, CancellationToken ct = default);
    Task DismissAsync(Guid notificationId, CancellationToken ct = default);
    
    // Generazione automatica notifiche
    Task GenerateUpcomingVisitRemindersAsync(CancellationToken ct = default);
    Task GenerateExpiringProjectAlertsAsync(CancellationToken ct = default);
    Task GenerateMissedVisitAlertsAsync(CancellationToken ct = default);
}

public record NotificationDto(
    Guid Id,
    Guid TargetOperatorId,
    string Title,
    string Message,
    NotificationPriority Priority,
    DateTime CreatedAt,
    bool IsRead,
    string? ActionUrl // es. "/patients/{id}" per navigare alla scheda paziente
);

public enum NotificationPriority
{
    Info,
    Warning,
    Error,
    Critical
}

Modello Dati Notification

public class Notification
{
    public Guid Id { get; set; }
    public Guid TargetOperatorId { get; set; }
    public ProfessionalEducatorModel TargetOperator { get; set; } = null!;
    
    public string Title { get; set; } = string.Empty;
    public string Message { get; set; } = string.Empty;
    
    public NotificationPriority Priority { get; set; }
    
    public DateTime CreatedAt { get; set; }
    public bool IsRead { get; set; }
    public DateTime? ReadAt { get; set; }
    public bool IsDismissed { get; set; }
    
    public string? ActionUrl { get; set; }
    public string? RelatedEntityType { get; set; } // es. "Patient", "TherapyProject"
    public Guid? RelatedEntityId { get; set; }
}

📋 Tasks

  • Creare entità Notification in PTRP.Models/
  • Creare enum NotificationPriority in PTRP.Models/Enums/
  • Creare migration EF Core per tabella Notifications
  • Definire INotificationService in PTRP.Services/Interfaces/
  • Implementare NotificationService in PTRP.Services/
  • Implementare repository INotificationRepository in PTRP.Data/
  • Implementare logiche di generazione automatica:
    • Reminder visite (eseguito giornalmente via background task)
    • Alert progetti in scadenza (eseguito settimanalmente)
    • Alert visite mancate (eseguito mensilmente)
  • Registrare servizio in DI container
  • Aggiungere unit tests per generazione notifiche

🎯 UI Integration (FASE 2-4)

  • Aggiungere "Notification Center" nella top bar di MainWindow
  • Badge con numero notifiche non lette
  • Dropdown/panel con lista notifiche recenti
  • Click su notifica naviga all'entità correlata (se ActionUrl presente)
  • Snackbar automatica per notifiche critiche
  • Integrazione con DashboardViewModel per mostrare notifiche in Dashboard

✅ Acceptance Criteria

  • Possibile creare notifiche programmaticamente
  • Notifiche recuperabili per operatore (filtro unread/all)
  • Generazione automatica reminder visite funzionante (almeno 1 giorno prima)
  • Generazione alert progetti in scadenza funzionante (almeno 7 giorni prima)
  • UI mostra badge con numero notifiche non lette
  • Click su notifica marca come letta e naviga all'entità (se ActionUrl presente)
  • Test coverage ≥ 70% per logiche di generazione

🔗 Riferimenti


CLUSTER: Services & Orchestrazione (gap 5.2)
FASE: 2-3 - Core Business / Polish
PRIORITÀ: 🔵 MEDIA
DIPENDENZE: #72, #73, #46
OPZIONALE: Migliora UX ma non bloccante per funzionalità core

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions