From bec65959a73ca7502a880da4d2c803c0e00d168a Mon Sep 17 00:00:00 2001 From: MingNian <1281442923@qq.com> Date: Thu, 21 May 2026 15:54:16 +0800 Subject: [PATCH] fix: notification click navigates to related page, report interpretation notifies patient --- .../Services/ReportService.cs | 11 ++++++++ .../notifications/NotificationListPage.tsx | 27 +++++++++++++++++-- frontend-patient/src/types/notification.ts | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/backend/src/HealthManager.Application/Services/ReportService.cs b/backend/src/HealthManager.Application/Services/ReportService.cs index 2904337..a204c18 100644 --- a/backend/src/HealthManager.Application/Services/ReportService.cs +++ b/backend/src/HealthManager.Application/Services/ReportService.cs @@ -1,6 +1,7 @@ using HealthManager.Domain.Entities; using HealthManager.Infrastructure.Data; using Microsoft.EntityFrameworkCore; +using Notification = HealthManager.Domain.Entities.Notification; namespace HealthManager.Application.Services; @@ -78,6 +79,16 @@ public class ReportService(AppDbContext db) }); } + // Notify patient + db.Notifications.Add(new Notification + { + UserId = report.PatientId, + Type = "report", + Title = "报告已解读", + Content = $"您的报告「{report.Title}」已有解读结果", + RelatedId = reportId, + }); + await db.SaveChangesAsync(); return report; } diff --git a/frontend-patient/src/pages/notifications/NotificationListPage.tsx b/frontend-patient/src/pages/notifications/NotificationListPage.tsx index ad7f2dc..b0fd448 100644 --- a/frontend-patient/src/pages/notifications/NotificationListPage.tsx +++ b/frontend-patient/src/pages/notifications/NotificationListPage.tsx @@ -1,10 +1,11 @@ import { useEffect, useState } from 'react'; +import { useNavigate } from 'react-router-dom'; import { PageHeader } from '@/components/layout/PageHeader'; import { Card } from '@/components/common/Card'; import { Empty } from '@/components/common/Empty'; import { useNotificationStore } from '@/stores/notification.store'; import { formatRelative } from '@/utils/format'; -import type { NotificationType } from '@/types'; +import type { NotificationType, Notification } from '@/types'; import styles from './NotificationListPage.module.css'; const TYPE_TABS: { key: NotificationType | 'all'; label: string }[] = [ @@ -15,7 +16,23 @@ const TYPE_TABS: { key: NotificationType | 'all'; label: string }[] = [ { key: 'system', label: '系统' }, ]; +function getNavPath(n: Notification): string | null { + switch (n.type) { + case 'consultation': + return '/services/consultation'; + case 'medication': + return '/health/medications'; + case 'followup': + return '/services/follow-ups'; + case 'report': + return n.relatedId ? `/services/reports/${n.relatedId}` : '/services/reports'; + default: + return null; + } +} + export function NotificationListPage() { + const navigate = useNavigate(); const { notifications, unreadCount, fetchNotifications, markRead, markAllRead } = useNotificationStore(); const [tab, setTab] = useState('all'); @@ -27,6 +44,12 @@ export function NotificationListPage() { ? notifications : notifications.filter((n) => n.type === tab); + const handleClick = (n: Notification) => { + if (!n.isRead) markRead(n.id); + const path = getNavPath(n); + if (path) navigate(path); + }; + return (
{ if (!n.isRead) markRead(n.id); }} + onClick={() => handleClick(n)} >
{n.title} diff --git a/frontend-patient/src/types/notification.ts b/frontend-patient/src/types/notification.ts index 2180551..f96d67a 100644 --- a/frontend-patient/src/types/notification.ts +++ b/frontend-patient/src/types/notification.ts @@ -1,4 +1,4 @@ -export type NotificationType = 'medication' | 'followup' | 'consultation' | 'system'; +export type NotificationType = 'medication' | 'followup' | 'consultation' | 'report' | 'system'; export interface Notification { id: string;