fix: notification click navigates to related page, report interpretation notifies patient

This commit is contained in:
MingNian
2026-05-21 15:54:16 +08:00
parent 204bc19ce5
commit bec65959a7
3 changed files with 37 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
using HealthManager.Domain.Entities; using HealthManager.Domain.Entities;
using HealthManager.Infrastructure.Data; using HealthManager.Infrastructure.Data;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Notification = HealthManager.Domain.Entities.Notification;
namespace HealthManager.Application.Services; 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(); await db.SaveChangesAsync();
return report; return report;
} }

View File

@@ -1,10 +1,11 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { PageHeader } from '@/components/layout/PageHeader'; import { PageHeader } from '@/components/layout/PageHeader';
import { Card } from '@/components/common/Card'; import { Card } from '@/components/common/Card';
import { Empty } from '@/components/common/Empty'; import { Empty } from '@/components/common/Empty';
import { useNotificationStore } from '@/stores/notification.store'; import { useNotificationStore } from '@/stores/notification.store';
import { formatRelative } from '@/utils/format'; import { formatRelative } from '@/utils/format';
import type { NotificationType } from '@/types'; import type { NotificationType, Notification } from '@/types';
import styles from './NotificationListPage.module.css'; import styles from './NotificationListPage.module.css';
const TYPE_TABS: { key: NotificationType | 'all'; label: string }[] = [ const TYPE_TABS: { key: NotificationType | 'all'; label: string }[] = [
@@ -15,7 +16,23 @@ const TYPE_TABS: { key: NotificationType | 'all'; label: string }[] = [
{ key: 'system', label: '系统' }, { 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() { export function NotificationListPage() {
const navigate = useNavigate();
const { notifications, unreadCount, fetchNotifications, markRead, markAllRead } = useNotificationStore(); const { notifications, unreadCount, fetchNotifications, markRead, markAllRead } = useNotificationStore();
const [tab, setTab] = useState<NotificationType | 'all'>('all'); const [tab, setTab] = useState<NotificationType | 'all'>('all');
@@ -27,6 +44,12 @@ export function NotificationListPage() {
? notifications ? notifications
: notifications.filter((n) => n.type === tab); : 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 ( return (
<div className="page--no-tab"> <div className="page--no-tab">
<PageHeader <PageHeader
@@ -59,7 +82,7 @@ export function NotificationListPage() {
<Card <Card
key={n.id} key={n.id}
className={`${styles.notifCard} ${!n.isRead ? styles.unread : ''}`} className={`${styles.notifCard} ${!n.isRead ? styles.unread : ''}`}
onClick={() => { if (!n.isRead) markRead(n.id); }} onClick={() => handleClick(n)}
> >
<div className={styles.notifHeader}> <div className={styles.notifHeader}>
<span className={styles.notifTitle}>{n.title}</span> <span className={styles.notifTitle}>{n.title}</span>

View File

@@ -1,4 +1,4 @@
export type NotificationType = 'medication' | 'followup' | 'consultation' | 'system'; export type NotificationType = 'medication' | 'followup' | 'consultation' | 'report' | 'system';
export interface Notification { export interface Notification {
id: string; id: string;