feat: 医生端Web后台 + SignalR实时问诊
- 新增 doctor_web/ React前端 (dashboard/患者/问诊/报告/随访) - 后端新增 doctor_endpoints (14个医生API) + ConsultationHub (SignalR) - Flutter端 SignalR 替换轮询实现实时聊天
This commit is contained in:
502
backend/src/Health.WebApi/Endpoints/doctor_endpoints.cs
Normal file
502
backend/src/Health.WebApi/Endpoints/doctor_endpoints.cs
Normal file
@@ -0,0 +1,502 @@
|
||||
using Health.Domain.Entities;
|
||||
using Health.Domain.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Health.WebApi.Endpoints;
|
||||
|
||||
/// <summary>
|
||||
/// 医生端 API(开发阶段 hardcode 王建国为当前医生)
|
||||
/// </summary>
|
||||
public static class DoctorEndpoints
|
||||
{
|
||||
private static async Task<Doctor> GetDoctor(AppDbContext db)
|
||||
{
|
||||
return await db.Doctors.FirstAsync(d => d.Name == "王建国" && d.IsActive);
|
||||
}
|
||||
|
||||
public static void MapDoctorEndpoints(this WebApplication app)
|
||||
{
|
||||
var group = app.MapGroup("/api/doctor");
|
||||
|
||||
// ===== 工作台 =====
|
||||
group.MapGet("/dashboard", async (AppDbContext db) =>
|
||||
{
|
||||
var doctor = await GetDoctor(db);
|
||||
var totalPatients = await db.Users.CountAsync();
|
||||
var activeConsultations = await db.Consultations.CountAsync(c => c.DoctorId == doctor.Id && c.Status != ConsultationStatus.Closed);
|
||||
var pendingReports = await db.Reports.CountAsync(r => r.Status == ReportStatus.PendingDoctor);
|
||||
var todayStart = DateTime.UtcNow.Date;
|
||||
var todayEnd = todayStart.AddDays(1);
|
||||
var todayFollowUps = await db.FollowUps.CountAsync(f => f.ScheduledAt >= todayStart && f.ScheduledAt < todayEnd && f.Status == FollowUpStatus.Upcoming);
|
||||
|
||||
return Results.Ok(new
|
||||
{
|
||||
code = 0,
|
||||
data = new
|
||||
{
|
||||
doctorName = doctor.Name,
|
||||
doctorTitle = doctor.Title,
|
||||
doctorDepartment = doctor.Department,
|
||||
totalPatients,
|
||||
activeConsultations,
|
||||
pendingReports,
|
||||
todayFollowUps
|
||||
},
|
||||
message = (string?)null
|
||||
});
|
||||
});
|
||||
|
||||
// ===== 患者列表 =====
|
||||
group.MapGet("/patients", async (string? search, AppDbContext db) =>
|
||||
{
|
||||
var query = db.Users.AsQueryable();
|
||||
if (!string.IsNullOrWhiteSpace(search))
|
||||
{
|
||||
query = query.Where(u =>
|
||||
(u.Name != null && u.Name.Contains(search)) ||
|
||||
u.Phone.Contains(search));
|
||||
}
|
||||
var patients = await query.OrderByDescending(u => u.CreatedAt).Select(u => new
|
||||
{
|
||||
u.Id,
|
||||
u.Phone,
|
||||
u.Name,
|
||||
u.Gender,
|
||||
u.BirthDate,
|
||||
hasArchive = u.HealthArchive != null
|
||||
}).ToListAsync();
|
||||
|
||||
return Results.Ok(new { code = 0, data = patients, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 患者详情 =====
|
||||
group.MapGet("/patients/{id:guid}", async (Guid id, AppDbContext db) =>
|
||||
{
|
||||
var user = await db.Users
|
||||
.Include(u => u.HealthArchive)
|
||||
.FirstOrDefaultAsync(u => u.Id == id);
|
||||
if (user == null)
|
||||
return Results.Ok(new { code = 404, data = (object?)null, message = "患者不存在" });
|
||||
|
||||
// 最新健康指标
|
||||
var latestRecords = await db.HealthRecords
|
||||
.Where(r => r.UserId == id)
|
||||
.GroupBy(r => r.MetricType)
|
||||
.Select(g => g.OrderByDescending(r => r.RecordedAt).First())
|
||||
.ToListAsync();
|
||||
|
||||
// 最近30天健康数据(用于趋势图)
|
||||
var thirtyDaysAgo = DateTime.UtcNow.AddDays(-30);
|
||||
var trendRecords = await db.HealthRecords
|
||||
.Where(r => r.UserId == id && r.RecordedAt >= thirtyDaysAgo)
|
||||
.OrderBy(r => r.RecordedAt)
|
||||
.Select(r => new
|
||||
{
|
||||
r.Id,
|
||||
MetricType = r.MetricType.ToString(),
|
||||
r.Systolic,
|
||||
r.Diastolic,
|
||||
r.Value,
|
||||
r.Unit,
|
||||
r.RecordedAt,
|
||||
r.IsAbnormal
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
// 用药
|
||||
var medications = await db.Medications
|
||||
.Where(m => m.UserId == id && m.IsActive)
|
||||
.OrderByDescending(m => m.StartDate)
|
||||
.Select(m => new { m.Id, m.Name, m.Dosage, Frequency = m.Frequency.ToString(), m.TimeOfDay, m.StartDate, m.EndDate })
|
||||
.ToListAsync();
|
||||
|
||||
// 最近饮食
|
||||
var dietRecords = await db.DietRecords
|
||||
.Where(d => d.UserId == id)
|
||||
.OrderByDescending(d => d.RecordedAt)
|
||||
.Take(7)
|
||||
.Include(d => d.FoodItems)
|
||||
.ToListAsync();
|
||||
|
||||
// 运动计划
|
||||
var exercisePlans = await db.ExercisePlans
|
||||
.Where(p => p.UserId == id)
|
||||
.OrderByDescending(p => p.WeekStartDate)
|
||||
.Take(1)
|
||||
.Include(p => p.Items)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
// 报告
|
||||
var reports = await db.Reports
|
||||
.Where(r => r.UserId == id)
|
||||
.OrderByDescending(r => r.CreatedAt)
|
||||
.Select(r => new
|
||||
{
|
||||
r.Id,
|
||||
r.FileUrl,
|
||||
FileType = r.FileType.ToString(),
|
||||
Category = r.Category.ToString(),
|
||||
Status = r.Status.ToString(),
|
||||
r.AiSummary,
|
||||
r.AiIndicators,
|
||||
r.DoctorComment,
|
||||
r.DoctorName,
|
||||
r.ReviewedAt,
|
||||
r.CreatedAt
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
// 随访
|
||||
var followUps = await db.FollowUps
|
||||
.Where(f => f.UserId == id)
|
||||
.OrderByDescending(f => f.ScheduledAt)
|
||||
.Select(f => new
|
||||
{
|
||||
f.Id,
|
||||
f.Title,
|
||||
f.DoctorName,
|
||||
f.Department,
|
||||
f.ScheduledAt,
|
||||
f.Notes,
|
||||
Status = f.Status.ToString(),
|
||||
f.CreatedAt
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Ok(new
|
||||
{
|
||||
code = 0,
|
||||
data = new
|
||||
{
|
||||
profile = new
|
||||
{
|
||||
user.Id,
|
||||
user.Phone,
|
||||
user.Name,
|
||||
user.Gender,
|
||||
BirthDate = user.BirthDate?.ToString("yyyy-MM-dd"),
|
||||
user.AvatarUrl
|
||||
},
|
||||
archive = user.HealthArchive == null ? null : new
|
||||
{
|
||||
user.HealthArchive.Diagnosis,
|
||||
user.HealthArchive.SurgeryType,
|
||||
SurgeryDate = user.HealthArchive.SurgeryDate?.ToString("yyyy-MM-dd"),
|
||||
user.HealthArchive.Allergies,
|
||||
user.HealthArchive.DietRestrictions,
|
||||
user.HealthArchive.ChronicDiseases,
|
||||
user.HealthArchive.FamilyHistory
|
||||
},
|
||||
latestRecords,
|
||||
trendRecords,
|
||||
medications,
|
||||
dietRecords = dietRecords.Select(d => new
|
||||
{
|
||||
d.Id,
|
||||
MealType = d.MealType.ToString(),
|
||||
d.TotalCalories,
|
||||
d.HealthScore,
|
||||
d.RecordedAt,
|
||||
foods = d.FoodItems.Select(f => new { f.Name, f.Portion, f.Calories, f.Warning })
|
||||
}),
|
||||
exercisePlan = exercisePlans == null ? null : new
|
||||
{
|
||||
exercisePlans.WeekStartDate,
|
||||
items = exercisePlans.Items.Select(i => new
|
||||
{
|
||||
i.DayOfWeek,
|
||||
i.ExerciseType,
|
||||
i.DurationMinutes,
|
||||
i.IsCompleted,
|
||||
i.IsRestDay,
|
||||
i.CompletedAt
|
||||
})
|
||||
},
|
||||
reports,
|
||||
followUps
|
||||
},
|
||||
message = (string?)null
|
||||
});
|
||||
});
|
||||
|
||||
// ===== 问诊列表 =====
|
||||
group.MapGet("/consultations", async (AppDbContext db) =>
|
||||
{
|
||||
var doctor = await GetDoctor(db);
|
||||
var consultations = await db.Consultations
|
||||
.Where(c => c.DoctorId == doctor.Id)
|
||||
.OrderByDescending(c => c.CreatedAt)
|
||||
.Select(c => new
|
||||
{
|
||||
c.Id,
|
||||
c.UserId,
|
||||
PatientName = c.User.Name,
|
||||
PatientPhone = c.User.Phone,
|
||||
Status = c.Status.ToString(),
|
||||
c.CreatedAt,
|
||||
c.ClosedAt,
|
||||
LastMessage = c.Messages.OrderByDescending(m => m.CreatedAt).Select(m => new { m.Content, m.SenderType, m.CreatedAt }).FirstOrDefault()
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Ok(new { code = 0, data = consultations, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 问诊消息 =====
|
||||
group.MapGet("/consultations/{id:guid}/messages", async (Guid id, AppDbContext db) =>
|
||||
{
|
||||
var messages = await db.ConsultationMessages
|
||||
.Where(m => m.ConsultationId == id)
|
||||
.OrderBy(m => m.CreatedAt)
|
||||
.Select(m => new
|
||||
{
|
||||
m.Id,
|
||||
SenderType = m.SenderType.ToString(),
|
||||
m.SenderName,
|
||||
m.Content,
|
||||
m.CreatedAt
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var consultation = await db.Consultations.FirstOrDefaultAsync(c => c.Id == id);
|
||||
|
||||
return Results.Ok(new
|
||||
{
|
||||
code = 0,
|
||||
data = new
|
||||
{
|
||||
status = consultation?.Status.ToString() ?? "Closed",
|
||||
messages
|
||||
},
|
||||
message = (string?)null
|
||||
});
|
||||
});
|
||||
|
||||
// ===== 医生发送消息(同时通过 SignalR 广播)=====
|
||||
group.MapPost("/consultations/{id:guid}/messages", async (Guid id, HttpContext http, AppDbContext db, CancellationToken ct) =>
|
||||
{
|
||||
var doctor = await GetDoctor(db);
|
||||
var consultation = await db.Consultations.FirstOrDefaultAsync(c => c.Id == id, ct);
|
||||
if (consultation == null)
|
||||
return Results.Ok(new { code = 404, data = (object?)null, message = "问诊不存在" });
|
||||
|
||||
// 读请求 body
|
||||
using var reader = new StreamReader(http.Request.Body);
|
||||
var body = await reader.ReadToEndAsync(ct);
|
||||
var json = System.Text.Json.JsonDocument.Parse(body);
|
||||
var content = json.RootElement.GetProperty("content").GetString() ?? "";
|
||||
|
||||
// 保存消息
|
||||
var msg = new ConsultationMessage
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
ConsultationId = id,
|
||||
SenderType = ConsultationSenderType.Doctor,
|
||||
SenderName = $"医生 · {doctor.Name}",
|
||||
Content = content,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
db.ConsultationMessages.Add(msg);
|
||||
|
||||
// 更新问诊状态
|
||||
if (consultation.Status == ConsultationStatus.AiTalking || consultation.Status == ConsultationStatus.WaitingDoctor)
|
||||
{
|
||||
consultation.Status = ConsultationStatus.DoctorReplied;
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
||||
// 通过 SignalR 广播(如果 Hub 已注册)
|
||||
var hubContext = http.RequestServices.GetService<Microsoft.AspNetCore.SignalR.IHubContext<Hubs.ConsultationHub>>();
|
||||
if (hubContext != null)
|
||||
{
|
||||
await hubContext.Clients.Group(id.ToString()).SendAsync("ReceiveMessage", new
|
||||
{
|
||||
msg.Id,
|
||||
consultationId = id.ToString(),
|
||||
senderType = "Doctor",
|
||||
senderName = msg.SenderName,
|
||||
content,
|
||||
msg.CreatedAt
|
||||
});
|
||||
}
|
||||
|
||||
return Results.Ok(new { code = 0, data = new { msg.Id }, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 报告列表 =====
|
||||
group.MapGet("/reports", async (string? status, AppDbContext db) =>
|
||||
{
|
||||
var query = db.Reports.AsQueryable();
|
||||
if (!string.IsNullOrWhiteSpace(status) && Enum.TryParse<ReportStatus>(status, out var s))
|
||||
query = query.Where(r => r.Status == s);
|
||||
|
||||
var reports = await query
|
||||
.OrderByDescending(r => r.CreatedAt)
|
||||
.Select(r => new
|
||||
{
|
||||
r.Id,
|
||||
r.UserId,
|
||||
PatientName = r.User.Name,
|
||||
r.FileUrl,
|
||||
FileType = r.FileType.ToString(),
|
||||
Category = r.Category.ToString(),
|
||||
Status = r.Status.ToString(),
|
||||
r.AiSummary,
|
||||
r.DoctorComment,
|
||||
r.ReviewedAt,
|
||||
r.CreatedAt
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Ok(new { code = 0, data = reports, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 报告详情 =====
|
||||
group.MapGet("/reports/{id:guid}", async (Guid id, AppDbContext db) =>
|
||||
{
|
||||
var report = await db.Reports
|
||||
.Where(r => r.Id == id)
|
||||
.Select(r => new
|
||||
{
|
||||
r.Id,
|
||||
r.UserId,
|
||||
PatientName = r.User.Name,
|
||||
r.FileUrl,
|
||||
FileType = r.FileType.ToString(),
|
||||
Category = r.Category.ToString(),
|
||||
Status = r.Status.ToString(),
|
||||
r.AiSummary,
|
||||
r.AiIndicators,
|
||||
r.DoctorComment,
|
||||
r.DoctorName,
|
||||
r.ReviewedAt,
|
||||
r.CreatedAt
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (report == null)
|
||||
return Results.Ok(new { code = 404, data = (object?)null, message = "报告不存在" });
|
||||
|
||||
return Results.Ok(new { code = 0, data = report, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 审阅报告 =====
|
||||
group.MapPost("/reports/{id:guid}/review", async (Guid id, HttpContext http, AppDbContext db, CancellationToken ct) =>
|
||||
{
|
||||
var doctor = await GetDoctor(db);
|
||||
var report = await db.Reports.FirstOrDefaultAsync(r => r.Id == id, ct);
|
||||
if (report == null)
|
||||
return Results.Ok(new { code = 404, data = (object?)null, message = "报告不存在" });
|
||||
|
||||
using var reader = new StreamReader(http.Request.Body);
|
||||
var body = await reader.ReadToEndAsync(ct);
|
||||
var json = System.Text.Json.JsonDocument.Parse(body);
|
||||
var comment = json.RootElement.GetProperty("comment").GetString() ?? "";
|
||||
|
||||
report.DoctorComment = comment;
|
||||
report.DoctorName = doctor.Name;
|
||||
report.ReviewedAt = DateTime.UtcNow;
|
||||
report.Status = ReportStatus.DoctorReviewed;
|
||||
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
||||
return Results.Ok(new { code = 0, data = new { success = true }, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 随访列表 =====
|
||||
group.MapGet("/follow-ups", async (string? status, string? patientId, AppDbContext db) =>
|
||||
{
|
||||
var query = db.FollowUps.AsQueryable();
|
||||
if (!string.IsNullOrWhiteSpace(status) && Enum.TryParse<FollowUpStatus>(status, out var s))
|
||||
query = query.Where(f => f.Status == s);
|
||||
if (Guid.TryParse(patientId, out var pid))
|
||||
query = query.Where(f => f.UserId == pid);
|
||||
|
||||
var followUps = await query
|
||||
.OrderByDescending(f => f.ScheduledAt)
|
||||
.Select(f => new
|
||||
{
|
||||
f.Id,
|
||||
f.UserId,
|
||||
PatientName = f.User.Name,
|
||||
f.Title,
|
||||
f.DoctorName,
|
||||
f.Department,
|
||||
f.ScheduledAt,
|
||||
f.Notes,
|
||||
Status = f.Status.ToString(),
|
||||
f.CreatedAt
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Ok(new { code = 0, data = followUps, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 创建随访 =====
|
||||
group.MapPost("/follow-ups", async (HttpContext http, AppDbContext db, CancellationToken ct) =>
|
||||
{
|
||||
var doctor = await GetDoctor(db);
|
||||
using var reader = new StreamReader(http.Request.Body);
|
||||
var body = await reader.ReadToEndAsync(ct);
|
||||
var json = System.Text.Json.JsonDocument.Parse(body);
|
||||
|
||||
var followUp = new FollowUp
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.Parse(json.RootElement.GetProperty("userId").GetString()!),
|
||||
Title = json.RootElement.GetProperty("title").GetString() ?? "",
|
||||
DoctorName = doctor.Name,
|
||||
Department = doctor.Department,
|
||||
ScheduledAt = DateTime.Parse(json.RootElement.GetProperty("scheduledAt").GetString()!),
|
||||
Notes = json.RootElement.TryGetProperty("notes", out var n) ? n.GetString() : null,
|
||||
Status = FollowUpStatus.Upcoming,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
db.FollowUps.Add(followUp);
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
||||
return Results.Ok(new { code = 0, data = new { followUp.Id }, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 更新随访 =====
|
||||
group.MapPut("/follow-ups/{id:guid}", async (Guid id, HttpContext http, AppDbContext db, CancellationToken ct) =>
|
||||
{
|
||||
var followUp = await db.FollowUps.FirstOrDefaultAsync(f => f.Id == id, ct);
|
||||
if (followUp == null)
|
||||
return Results.Ok(new { code = 404, data = (object?)null, message = "随访不存在" });
|
||||
|
||||
using var reader = new StreamReader(http.Request.Body);
|
||||
var body = await reader.ReadToEndAsync(ct);
|
||||
var json = System.Text.Json.JsonDocument.Parse(body);
|
||||
|
||||
if (json.RootElement.TryGetProperty("title", out var title)) followUp.Title = title.GetString() ?? followUp.Title;
|
||||
if (json.RootElement.TryGetProperty("scheduledAt", out var sat)) followUp.ScheduledAt = DateTime.Parse(sat.GetString()!);
|
||||
if (json.RootElement.TryGetProperty("notes", out var notes)) followUp.Notes = notes.GetString();
|
||||
if (json.RootElement.TryGetProperty("status", out var st) && Enum.TryParse<FollowUpStatus>(st.GetString(), out var fs))
|
||||
followUp.Status = fs;
|
||||
|
||||
await db.SaveChangesAsync(ct);
|
||||
return Results.Ok(new { code = 0, data = new { success = true }, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 删除随访 =====
|
||||
group.MapDelete("/follow-ups/{id:guid}", async (Guid id, AppDbContext db, CancellationToken ct) =>
|
||||
{
|
||||
var followUp = await db.FollowUps.FirstOrDefaultAsync(f => f.Id == id, ct);
|
||||
if (followUp == null)
|
||||
return Results.Ok(new { code = 404, data = (object?)null, message = "随访不存在" });
|
||||
|
||||
db.FollowUps.Remove(followUp);
|
||||
await db.SaveChangesAsync(ct);
|
||||
return Results.Ok(new { code = 0, data = new { success = true }, message = (string?)null });
|
||||
});
|
||||
|
||||
// ===== 患者列表(简版,给随访选患者用)=====
|
||||
group.MapGet("/patients-simple", async (AppDbContext db) =>
|
||||
{
|
||||
var patients = await db.Users.OrderBy(u => u.Name).Select(u => new { u.Id, u.Name, u.Phone }).ToListAsync();
|
||||
return Results.Ok(new { code = 0, data = patients, message = (string?)null });
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
global using Health.Domain.Entities;
|
||||
global using Health.Domain.Enums;
|
||||
global using Health.Infrastructure.Data;
|
||||
global using Microsoft.AspNetCore.SignalR;
|
||||
global using Microsoft.EntityFrameworkCore;
|
||||
global using System.Text.Json;
|
||||
|
||||
36
backend/src/Health.WebApi/Hubs/ConsultationHub.cs
Normal file
36
backend/src/Health.WebApi/Hubs/ConsultationHub.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Health.WebApi.Hubs;
|
||||
|
||||
/// <summary>
|
||||
/// 问诊实时通信 Hub(开发阶段跳过认证)
|
||||
/// </summary>
|
||||
public sealed class ConsultationHub : Hub
|
||||
{
|
||||
public async Task JoinConsultation(string consultationId)
|
||||
{
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, consultationId);
|
||||
}
|
||||
|
||||
public async Task LeaveConsultation(string consultationId)
|
||||
{
|
||||
await Groups.RemoveFromGroupAsync(Context.ConnectionId, consultationId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息到问诊房间
|
||||
/// </summary>
|
||||
public async Task SendMessage(string consultationId, string senderType, string? senderName, string content)
|
||||
{
|
||||
// 广播给组内所有人(包括自己)
|
||||
await Clients.Group(consultationId).SendAsync("ReceiveMessage", new
|
||||
{
|
||||
id = Guid.NewGuid(),
|
||||
consultationId,
|
||||
senderType,
|
||||
senderName,
|
||||
content,
|
||||
createdAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -87,14 +87,16 @@ builder.Services.AddHostedService<CleanupService>();
|
||||
// ---- OpenAPI ----
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
// ---- CORS ----
|
||||
// ---- SignalR ----
|
||||
builder.Services.AddSignalR();
|
||||
|
||||
// ---- CORS(SignalR 需要明确 origins + AllowCredentials)----
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddDefaultPolicy(policy =>
|
||||
{
|
||||
policy.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
|
||||
policy.SetIsOriginAllowed(_ => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
|
||||
});
|
||||
// 生产环境:policy.WithOrigins("https://yourdomain.com").AllowAnyMethod().AllowAnyHeader();
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
@@ -129,5 +131,9 @@ app.MapUserEndpoints();
|
||||
app.MapAiChatEndpoints();
|
||||
app.MapFileEndpoints();
|
||||
app.MapCalendarEndpoints();
|
||||
app.MapDoctorEndpoints();
|
||||
|
||||
// SignalR Hub
|
||||
app.MapHub<Health.WebApi.Hubs.ConsultationHub>("/hubs/consultation");
|
||||
|
||||
app.Run();
|
||||
|
||||
24
doctor_web/.gitignore
vendored
Normal file
24
doctor_web/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
73
doctor_web/README.md
Normal file
73
doctor_web/README.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
22
doctor_web/eslint.config.js
Normal file
22
doctor_web/eslint.config.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs.flat.recommended,
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
||||
13
doctor_web/index.html
Normal file
13
doctor_web/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>doctor_web</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
3437
doctor_web/package-lock.json
generated
Normal file
3437
doctor_web/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
doctor_web/package.json
Normal file
34
doctor_web/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "doctor_web",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/signalr": "^10.0.0",
|
||||
"react": "^19.2.6",
|
||||
"react-dom": "^19.2.6",
|
||||
"react-router-dom": "^7.17.0",
|
||||
"recharts": "^3.8.1",
|
||||
"zustand": "^5.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@types/node": "^24.12.3",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^6.0.1",
|
||||
"eslint": "^10.3.0",
|
||||
"eslint-plugin-react-hooks": "^7.1.1",
|
||||
"eslint-plugin-react-refresh": "^0.5.2",
|
||||
"globals": "^17.6.0",
|
||||
"typescript": "~6.0.2",
|
||||
"typescript-eslint": "^8.59.2",
|
||||
"vite": "^8.0.12"
|
||||
}
|
||||
}
|
||||
1
doctor_web/public/favicon.svg
Normal file
1
doctor_web/public/favicon.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 9.3 KiB |
24
doctor_web/public/icons.svg
Normal file
24
doctor_web/public/icons.svg
Normal file
@@ -0,0 +1,24 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<symbol id="bluesky-icon" viewBox="0 0 16 17">
|
||||
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
|
||||
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
|
||||
</symbol>
|
||||
<symbol id="discord-icon" viewBox="0 0 20 19">
|
||||
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
|
||||
</symbol>
|
||||
<symbol id="documentation-icon" viewBox="0 0 21 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
|
||||
</symbol>
|
||||
<symbol id="github-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
<symbol id="social-icon" viewBox="0 0 20 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
|
||||
</symbol>
|
||||
<symbol id="x-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
7
doctor_web/src/App.tsx
Normal file
7
doctor_web/src/App.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { RouterProvider } from 'react-router-dom';
|
||||
import { router } from './router';
|
||||
import './index.css';
|
||||
|
||||
export default function App() {
|
||||
return <RouterProvider router={router} />;
|
||||
}
|
||||
BIN
doctor_web/src/assets/hero.png
Normal file
BIN
doctor_web/src/assets/hero.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
1
doctor_web/src/assets/react.svg
Normal file
1
doctor_web/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
1
doctor_web/src/assets/vite.svg
Normal file
1
doctor_web/src/assets/vite.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.5 KiB |
124
doctor_web/src/components/layout/DoctorLayout.module.css
Normal file
124
doctor_web/src/components/layout/DoctorLayout.module.css
Normal file
@@ -0,0 +1,124 @@
|
||||
.layout {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* ---- 侧边栏 ---- */
|
||||
.sidebar {
|
||||
width: 224px;
|
||||
background: #FFF;
|
||||
border-right: 1px solid #EDF0F7;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.brand {
|
||||
padding: 24px 20px 20px;
|
||||
border-bottom: 1px solid #EDF0F7;
|
||||
}
|
||||
|
||||
.brandTitle {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: #1A1D28;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.brandSub {
|
||||
font-size: 12px;
|
||||
color: #9BA0B4;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.nav {
|
||||
flex: 1;
|
||||
padding: 12px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.navItem {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 10px;
|
||||
text-decoration: none;
|
||||
color: #5A6072;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.navItem:hover {
|
||||
background: #F5F6FA;
|
||||
color: #1A1D28;
|
||||
}
|
||||
|
||||
.navItem.active {
|
||||
background: #EDF0FD;
|
||||
color: #4F6EF7;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.navIcon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: 16px 20px;
|
||||
border-top: 1px solid #EDF0F7;
|
||||
background: #FAFBFD;
|
||||
}
|
||||
|
||||
.doctorInfo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 10px;
|
||||
background: linear-gradient(135deg, #4F6EF7, #6C8AFF);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #FFF;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.doctorName {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #1A1D28;
|
||||
}
|
||||
|
||||
.doctorMeta {
|
||||
font-size: 12px;
|
||||
color: #9BA0B4;
|
||||
}
|
||||
|
||||
/* ---- 内容区 ---- */
|
||||
.content {
|
||||
flex: 1;
|
||||
background: #F2F5FA;
|
||||
min-width: 0;
|
||||
animation: fadeIn 0.25s ease;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(6px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
70
doctor_web/src/components/layout/DoctorLayout.tsx
Normal file
70
doctor_web/src/components/layout/DoctorLayout.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
import { NavLink, Outlet, useLocation } from 'react-router-dom';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { api } from '../../services/api-client';
|
||||
import type { DashboardStats } from '../../types';
|
||||
import styles from './DoctorLayout.module.css';
|
||||
|
||||
const NAV_ITEMS = [
|
||||
{ to: '/dashboard', label: '工作台', icon: '📊' },
|
||||
{ to: '/patients', label: '患者管理', icon: '👥' },
|
||||
{ to: '/consultations', label: '在线问诊', icon: '💬' },
|
||||
{ to: '/reports', label: '报告审核', icon: '📋' },
|
||||
{ to: '/follow-ups', label: '复查随访', icon: '📅' },
|
||||
];
|
||||
|
||||
export default function DoctorLayout() {
|
||||
const location = useLocation();
|
||||
const [doctor, setDoctor] = useState<DashboardStats | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
api.get<DashboardStats>('/api/doctor/dashboard').then(setDoctor).catch(() => {});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={styles.layout}>
|
||||
{/* 侧边栏 */}
|
||||
<aside className={styles.sidebar}>
|
||||
<div className={styles.brand}>
|
||||
<div className={styles.brandTitle}>
|
||||
<span>❤️</span> 健康管家
|
||||
</div>
|
||||
<div className={styles.brandSub}>医生工作台</div>
|
||||
</div>
|
||||
|
||||
<nav className={styles.nav}>
|
||||
{NAV_ITEMS.map(item => (
|
||||
<NavLink
|
||||
key={item.to}
|
||||
to={item.to}
|
||||
className={({ isActive }) =>
|
||||
`${styles.navItem} ${isActive ? styles.active : ''}`
|
||||
}
|
||||
>
|
||||
<span className={styles.navIcon}>{item.icon}</span>
|
||||
{item.label}
|
||||
</NavLink>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<div className={styles.footer}>
|
||||
<div className={styles.doctorInfo}>
|
||||
<div className={styles.avatar}>
|
||||
{doctor?.doctorName?.[0] ?? '王'}
|
||||
</div>
|
||||
<div>
|
||||
<div className={styles.doctorName}>{doctor?.doctorName ?? '王建国'}</div>
|
||||
<div className={styles.doctorMeta}>
|
||||
{doctor?.doctorTitle ?? '主任医师'} · {doctor?.doctorDepartment ?? '心血管内科'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{/* 内容区 */}
|
||||
<main className={styles.content} key={location.pathname}>
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
5
doctor_web/src/index.css
Normal file
5
doctor_web/src/index.css
Normal file
@@ -0,0 +1,5 @@
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; color: #1A1D28; background: #F2F5FA; -webkit-font-smoothing: antialiased; }
|
||||
a { text-decoration: none; color: inherit; }
|
||||
button { cursor: pointer; font-family: inherit; }
|
||||
input, textarea, select { font-family: inherit; }
|
||||
9
doctor_web/src/main.tsx
Normal file
9
doctor_web/src/main.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { StrictMode } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import App from './App';
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
);
|
||||
167
doctor_web/src/pages/consultations/ChatPage.tsx
Normal file
167
doctor_web/src/pages/consultations/ChatPage.tsx
Normal file
@@ -0,0 +1,167 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { api } from '../../services/api-client';
|
||||
import { getConnection, startConnection } from '../../services/signalr';
|
||||
import type { ConsultationMessage } from '../../types';
|
||||
|
||||
export default function ChatPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const [messages, setMessages] = useState<ConsultationMessage[]>([]);
|
||||
const [status, setStatus] = useState('');
|
||||
const [text, setText] = useState('');
|
||||
const [connected, setConnected] = useState(false);
|
||||
const bottomRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// 加载历史消息
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
api.get<{ status: string; messages: ConsultationMessage[] }>(`/api/doctor/consultations/${id}/messages`)
|
||||
.then(data => {
|
||||
setMessages(data.messages);
|
||||
setStatus(data.status);
|
||||
})
|
||||
.catch(() => {});
|
||||
}, [id]);
|
||||
|
||||
// 建立 SignalR 连接
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
let disposed = false;
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const conn = getConnection();
|
||||
await startConnection();
|
||||
if (disposed) return;
|
||||
|
||||
// 加入问诊房间
|
||||
await conn.invoke('JoinConsultation', id);
|
||||
setConnected(true);
|
||||
|
||||
// 注册消息接收
|
||||
const handler = (msg: ConsultationMessage & { consultationId: string }) => {
|
||||
if (msg.consultationId !== id) return;
|
||||
setMessages(prev => {
|
||||
if (prev.some(m => m.id === msg.id)) return prev; // 去重
|
||||
return [...prev, msg];
|
||||
});
|
||||
};
|
||||
conn.on('ReceiveMessage', handler);
|
||||
|
||||
// 重连时重新加入房间
|
||||
conn.onreconnected(() => {
|
||||
conn.invoke('JoinConsultation', id);
|
||||
});
|
||||
} catch { /* ignore */ }
|
||||
})();
|
||||
|
||||
return () => {
|
||||
disposed = true;
|
||||
const conn = getConnection();
|
||||
if (conn.state === 'Connected') {
|
||||
conn.invoke('LeaveConsultation', id).catch(() => {});
|
||||
conn.off('ReceiveMessage');
|
||||
}
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
// 自动滚到底部
|
||||
useEffect(() => {
|
||||
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||
}, [messages]);
|
||||
|
||||
async function sendMessage() {
|
||||
if (!text.trim() || !id) return;
|
||||
const content = text.trim();
|
||||
setText('');
|
||||
|
||||
// 通过 HTTP 发送(后端会通过 SignalR 广播)
|
||||
try {
|
||||
await api.post(`/api/doctor/consultations/${id}/messages`, { content });
|
||||
} catch {
|
||||
// fallback: 直接通过 SignalR 发送
|
||||
try {
|
||||
await getConnection().invoke('SendMessage', id, 'Doctor', '医生 · 王建国', content);
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
|
||||
{/* 顶栏 */}
|
||||
<div style={{ background: '#FFF', padding: '16px 24px', borderBottom: '1px solid #EDF0F7', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 16, fontWeight: 600 }}>问诊对话</div>
|
||||
<div style={{ fontSize: 12, color: '#9BA0B4', marginTop: 2 }}>
|
||||
{status === 'AiTalking' ? 'AI 分身对话中' : status === 'WaitingDoctor' ? '等待医生回复' : status === 'DoctorReplied' ? '医生已回复' : status === 'Closed' ? '已结束' : status}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<div style={{ width: 8, height: 8, borderRadius: 4, background: connected ? '#20C997' : '#EF4444' }} />
|
||||
<span style={{ fontSize: 12, color: '#9BA0B4' }}>{connected ? '已连接' : '未连接'}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 消息列表 */}
|
||||
<div style={{ flex: 1, overflow: 'auto', padding: '20px 24px' }}>
|
||||
{messages.map((msg, i) => {
|
||||
const isDoctor = msg.senderType === 'Doctor';
|
||||
const isAi = msg.senderType === 'Ai';
|
||||
return (
|
||||
<div key={msg.id || i} style={{ display: 'flex', flexDirection: 'column', alignItems: isDoctor ? 'flex-end' : 'flex-start', marginBottom: 16 }}>
|
||||
{/* 发送者名称 */}
|
||||
{!isDoctor && msg.senderName && (
|
||||
<div style={{ fontSize: 11, color: '#9BA0B4', marginBottom: 4, marginLeft: 8 }}>{msg.senderName}</div>
|
||||
)}
|
||||
{/* 气泡 */}
|
||||
<div style={{
|
||||
maxWidth: '70%',
|
||||
padding: '12px 18px',
|
||||
borderRadius: isDoctor ? '18px 4px 18px 18px' : '4px 18px 18px 18px',
|
||||
background: isDoctor ? '#4F6EF7' : isAi ? '#F5F5F5' : '#FFF',
|
||||
color: isDoctor ? '#FFF' : '#1A1D28',
|
||||
border: isDoctor ? 'none' : '1px solid #EDF0F7',
|
||||
fontSize: 15,
|
||||
lineHeight: 1.6,
|
||||
whiteSpace: 'pre-wrap',
|
||||
wordBreak: 'break-word',
|
||||
}}>
|
||||
{msg.content}
|
||||
</div>
|
||||
{/* AI 标记 */}
|
||||
{isAi && (
|
||||
<div style={{ fontSize: 10, color: '#F9A825', marginTop: 4, marginLeft: 8, background: '#FFF8E1', padding: '2px 8px', borderRadius: 6 }}>
|
||||
AI 分析,仅供参考
|
||||
</div>
|
||||
)}
|
||||
{/* 时间 */}
|
||||
<div style={{ fontSize: 11, color: '#CCC', marginTop: 4, marginLeft: 8, marginRight: 8 }}>
|
||||
{new Date(msg.createdAt).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<div ref={bottomRef} />
|
||||
</div>
|
||||
|
||||
{/* 输入栏 */}
|
||||
<div style={{ background: '#FFF', padding: '14px 24px', borderTop: '1px solid #EDF0F7' }}>
|
||||
<div style={{ display: 'flex', gap: 12 }}>
|
||||
<input
|
||||
value={text}
|
||||
onChange={e => setText(e.target.value)}
|
||||
onKeyDown={e => e.key === 'Enter' && sendMessage()}
|
||||
placeholder="输入回复..."
|
||||
style={{ flex: 1, padding: '12px 18px', border: '1px solid #E1E5ED', borderRadius: 12, fontSize: 15, outline: 'none' }}
|
||||
/>
|
||||
<button
|
||||
onClick={sendMessage}
|
||||
disabled={!text.trim()}
|
||||
style={{ padding: '12px 24px', background: text.trim() ? '#4F6EF7' : '#E1E5ED', color: text.trim() ? '#FFF' : '#9BA0B4', border: 'none', borderRadius: 12, fontSize: 15, fontWeight: 600 }}>
|
||||
发送
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
57
doctor_web/src/pages/consultations/ConsultationListPage.tsx
Normal file
57
doctor_web/src/pages/consultations/ConsultationListPage.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { api } from '../../services/api-client';
|
||||
import type { Consultation } from '../../types';
|
||||
|
||||
const STATUS_MAP: Record<string, { label: string; color: string }> = {
|
||||
AiTalking: { label: 'AI 对话中', color: '#9BA0B4' },
|
||||
WaitingDoctor: { label: '等待医生', color: '#F59E0B' },
|
||||
DoctorReplied: { label: '医生已回复', color: '#20C997' },
|
||||
Closed: { label: '已结束', color: '#CCC' },
|
||||
};
|
||||
|
||||
export default function ConsultationListPage() {
|
||||
const [list, setList] = useState<Consultation[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
api.get<Consultation[]>('/api/doctor/consultations').then(setList).catch(() => {});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div style={{ padding: 32, maxWidth: 1200 }}>
|
||||
<h1 style={{ fontSize: 24, fontWeight: 700, marginBottom: 24 }}>在线问诊</h1>
|
||||
|
||||
{list.length === 0 ? (
|
||||
<div style={{ color: '#9BA0B4', padding: 40, textAlign: 'center' }}>暂无问诊记录</div>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
{list.map(c => {
|
||||
const st = STATUS_MAP[c.status] ?? { label: c.status, color: '#9BA0B4' };
|
||||
return (
|
||||
<Link key={c.id} to={`/consultations/${c.id}`}
|
||||
style={{ background: '#FFF', borderRadius: 14, padding: '18px 20px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 16 }}>
|
||||
<div style={{ width: 44, height: 44, borderRadius: 12, background: '#EDF0FD', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 18, fontWeight: 700, color: '#4F6EF7', flexShrink: 0 }}>
|
||||
{(c.patientName || '患')[0]}
|
||||
</div>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontWeight: 600, fontSize: 15 }}>{c.patientName || c.patientPhone}</div>
|
||||
<div style={{ fontSize: 13, color: '#9BA0B4', marginTop: 2 }}>
|
||||
{c.lastMessage?.content?.slice(0, 40) || '暂无消息'}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ textAlign: 'right' }}>
|
||||
<span style={{ padding: '3px 12px', borderRadius: 10, fontSize: 12, fontWeight: 500, background: `${st.color}18`, color: st.color }}>
|
||||
{st.label}
|
||||
</span>
|
||||
<div style={{ fontSize: 11, color: '#CCC', marginTop: 4 }}>
|
||||
{new Date(c.createdAt).toLocaleDateString('zh-CN')}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
72
doctor_web/src/pages/dashboard/DashboardPage.tsx
Normal file
72
doctor_web/src/pages/dashboard/DashboardPage.tsx
Normal file
@@ -0,0 +1,72 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { api } from '../../services/api-client';
|
||||
import type { DashboardStats } from '../../types';
|
||||
|
||||
const CARD_CONFIG = [
|
||||
{ key: 'totalPatients', label: '患者总数', color: '#4F6EF7', bg: '#EDF0FD' },
|
||||
{ key: 'activeConsultations', label: '进行中问诊', color: '#20C997', bg: '#E6F9F2' },
|
||||
{ key: 'pendingReports', label: '待审核报告', color: '#F59E0B', bg: '#FFF8E6' },
|
||||
{ key: 'todayFollowUps', label: '今日随访', color: '#845EF7', bg: '#F3E8FF' },
|
||||
];
|
||||
|
||||
const QUICK_LINKS = [
|
||||
{ to: '/patients', label: '患者列表', color: '#4F6EF7' },
|
||||
{ to: '/consultations', label: '在线问诊', color: '#20C997' },
|
||||
{ to: '/reports', label: '报告审核', color: '#F59E0B' },
|
||||
{ to: '/follow-ups', label: '随访管理', color: '#845EF7' },
|
||||
];
|
||||
|
||||
export default function DashboardPage() {
|
||||
const [stats, setStats] = useState<DashboardStats | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
api.get<DashboardStats>('/api/doctor/dashboard').then(setStats).catch(() => {});
|
||||
}, []);
|
||||
|
||||
if (!stats) return <div style={{ padding: 40, color: '#9BA0B4' }}>加载中...</div>;
|
||||
|
||||
return (
|
||||
<div style={{ padding: 32, maxWidth: 1200 }}>
|
||||
{/* 欢迎 */}
|
||||
<div style={{ marginBottom: 32 }}>
|
||||
<h1 style={{ fontSize: 24, fontWeight: 700 }}>欢迎回来,{stats.doctorName}</h1>
|
||||
<p style={{ color: '#9BA0B4', marginTop: 4 }}>{stats.doctorTitle} · {stats.doctorDepartment}</p>
|
||||
</div>
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: 20, marginBottom: 32 }}>
|
||||
{CARD_CONFIG.map(c => (
|
||||
<div key={c.key} style={{ background: '#FFF', borderRadius: 16, padding: '24px 20px', position: 'relative', overflow: 'hidden', boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
<div style={{ position: 'absolute', top: 0, left: 0, width: 4, height: '100%', background: c.color }} />
|
||||
<div style={{ fontSize: 30, fontWeight: 800, color: c.color }}>{(stats as any)[c.key]}</div>
|
||||
<div style={{ fontSize: 13, color: '#5A6072', marginTop: 4 }}>{c.label}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 快捷操作 */}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '2fr 1fr', gap: 20 }}>
|
||||
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
<h2 style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}>快捷操作</h2>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
|
||||
{QUICK_LINKS.map(l => (
|
||||
<Link key={l.to} to={l.to} style={{ padding: '14px 16px', borderRadius: 12, border: `1px solid ${l.color}20`, color: l.color, fontWeight: 500, textAlign: 'center', transition: 'all 0.15s', fontSize: 14 }}>
|
||||
{l.label}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
<h2 style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}>今日待办</h2>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
<div style={{ fontSize: 14, color: '#5A6072' }}>📋 待审核报告 <b style={{ color: '#F59E0B' }}>{stats.pendingReports}</b> 份</div>
|
||||
<div style={{ fontSize: 14, color: '#5A6072' }}>💬 进行中问诊 <b style={{ color: '#20C997' }}>{stats.activeConsultations}</b> 个</div>
|
||||
<div style={{ fontSize: 14, color: '#5A6072' }}>📅 今日随访 <b style={{ color: '#845EF7' }}>{stats.todayFollowUps}</b> 个</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
105
doctor_web/src/pages/followups/FollowUpEditPage.tsx
Normal file
105
doctor_web/src/pages/followups/FollowUpEditPage.tsx
Normal file
@@ -0,0 +1,105 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { api } from '../../services/api-client';
|
||||
|
||||
interface PatientSimple { id: string; name: string; phone: string; }
|
||||
|
||||
export default function FollowUpEditPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const nav = useNavigate();
|
||||
const isEdit = !!id;
|
||||
|
||||
const [patients, setPatients] = useState<PatientSimple[]>([]);
|
||||
const [userId, setUserId] = useState('');
|
||||
const [title, setTitle] = useState('');
|
||||
const [scheduledAt, setScheduledAt] = useState('');
|
||||
const [notes, setNotes] = useState('');
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// 加载患者列表
|
||||
api.get<PatientSimple[]>('/api/doctor/patients-simple').then(setPatients).catch(() => {});
|
||||
// 编辑模式:加载现有随访
|
||||
if (id) {
|
||||
api.get<any[]>(`/api/doctor/follow-ups`).then(list => {
|
||||
const item = list.find(f => f.id === id);
|
||||
if (item) {
|
||||
setUserId(item.userId);
|
||||
setTitle(item.title);
|
||||
// datetime-local 格式
|
||||
const d = new Date(item.scheduledAt);
|
||||
setScheduledAt(d.toISOString().slice(0, 16));
|
||||
setNotes(item.notes || '');
|
||||
}
|
||||
}).catch(() => {});
|
||||
}
|
||||
}, [id]);
|
||||
|
||||
async function save() {
|
||||
if (!userId || !title || !scheduledAt) return alert('请填写完整信息');
|
||||
setSaving(true);
|
||||
try {
|
||||
const body = { userId, title, scheduledAt: new Date(scheduledAt).toISOString(), notes };
|
||||
if (isEdit) {
|
||||
await api.put(`/api/doctor/follow-ups/${id}`, body);
|
||||
} else {
|
||||
await api.post('/api/doctor/follow-ups', body);
|
||||
}
|
||||
nav('/follow-ups');
|
||||
} catch { alert('保存失败'); }
|
||||
setSaving(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ padding: 32, maxWidth: 600 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 24 }}>
|
||||
<button onClick={() => nav(-1)} style={{ color: '#4F6EF7', fontSize: 14, border: 'none', background: 'none' }}>← 返回</button>
|
||||
<h1 style={{ fontSize: 24, fontWeight: 700 }}>{isEdit ? '编辑随访' : '新建随访'}</h1>
|
||||
</div>
|
||||
|
||||
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
{/* 患者选择 */}
|
||||
<div style={{ marginBottom: 20 }}>
|
||||
<label style={{ display: 'block', fontSize: 14, fontWeight: 500, marginBottom: 6, color: '#5A6072' }}>患者</label>
|
||||
<select value={userId} onChange={e => setUserId(e.target.value)}
|
||||
style={{ width: '100%', padding: '10px 14px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none' }}>
|
||||
<option value="">请选择患者</option>
|
||||
{patients.map(p => (
|
||||
<option key={p.id} value={p.id}>{p.name || '未设置'} ({p.phone})</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* 标题 */}
|
||||
<div style={{ marginBottom: 20 }}>
|
||||
<label style={{ display: 'block', fontSize: 14, fontWeight: 500, marginBottom: 6, color: '#5A6072' }}>随访标题</label>
|
||||
<input value={title} onChange={e => setTitle(e.target.value)} placeholder="如:PCI术后1个月随访"
|
||||
style={{ width: '100%', padding: '10px 14px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none' }} />
|
||||
</div>
|
||||
|
||||
{/* 时间 */}
|
||||
<div style={{ marginBottom: 20 }}>
|
||||
<label style={{ display: 'block', fontSize: 14, fontWeight: 500, marginBottom: 6, color: '#5A6072' }}>计划时间</label>
|
||||
<input type="datetime-local" value={scheduledAt} onChange={e => setScheduledAt(e.target.value)}
|
||||
style={{ width: '100%', padding: '10px 14px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none' }} />
|
||||
</div>
|
||||
|
||||
{/* 备注 */}
|
||||
<div style={{ marginBottom: 24 }}>
|
||||
<label style={{ display: 'block', fontSize: 14, fontWeight: 500, marginBottom: 6, color: '#5A6072' }}>备注</label>
|
||||
<textarea value={notes} onChange={e => setNotes(e.target.value)} placeholder="备注信息..."
|
||||
rows={3}
|
||||
style={{ width: '100%', padding: '10px 14px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none', resize: 'vertical' }} />
|
||||
</div>
|
||||
|
||||
<button onClick={save} disabled={saving}
|
||||
style={{
|
||||
width: '100%', padding: '14px', background: saving ? '#E1E5ED' : 'linear-gradient(135deg, #4F6EF7, #6C8AFF)',
|
||||
color: saving ? '#9BA0B4' : '#FFF', border: 'none', borderRadius: 12, fontSize: 16, fontWeight: 600,
|
||||
}}>
|
||||
{saving ? '保存中...' : '保存'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
94
doctor_web/src/pages/followups/FollowUpListPage.tsx
Normal file
94
doctor_web/src/pages/followups/FollowUpListPage.tsx
Normal file
@@ -0,0 +1,94 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { api } from '../../services/api-client';
|
||||
import type { FollowUp } from '../../types';
|
||||
|
||||
const STATUS_MAP: Record<string, { label: string; color: string }> = {
|
||||
Upcoming: { label: '即将到来', color: '#4F6EF7' },
|
||||
Completed: { label: '已完成', color: '#20C997' },
|
||||
Cancelled: { label: '已取消', color: '#EF4444' },
|
||||
};
|
||||
|
||||
export default function FollowUpListPage() {
|
||||
const [list, setList] = useState<FollowUp[]>([]);
|
||||
const [filter, setFilter] = useState('');
|
||||
const nav = useNavigate();
|
||||
|
||||
useEffect(() => { loadList(); }, [filter]);
|
||||
|
||||
async function loadList() {
|
||||
const q = filter ? `?status=${filter}` : '';
|
||||
try { setList(await api.get<FollowUp[]>(`/api/doctor/follow-ups${q}`)); } catch { setList([]); }
|
||||
}
|
||||
|
||||
async function deleteItem(id: string) {
|
||||
if (!confirm('确定删除?')) return;
|
||||
try {
|
||||
await api.del(`/api/doctor/follow-ups/${id}`);
|
||||
setList(prev => prev.filter(f => f.id !== id));
|
||||
} catch { alert('删除失败'); }
|
||||
}
|
||||
|
||||
async function markComplete(id: string) {
|
||||
try {
|
||||
await api.put(`/api/doctor/follow-ups/${id}`, { status: 'Completed' });
|
||||
loadList();
|
||||
} catch { alert('操作失败'); }
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ padding: 32, maxWidth: 1200 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
|
||||
<h1 style={{ fontSize: 24, fontWeight: 700 }}>复查随访</h1>
|
||||
<button onClick={() => nav('/follow-ups/new')}
|
||||
style={{ padding: '10px 24px', background: 'linear-gradient(135deg, #4F6EF7, #6C8AFF)', color: '#FFF', border: 'none', borderRadius: 12, fontSize: 14, fontWeight: 600 }}>
|
||||
+ 新建随访
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 筛选 */}
|
||||
<div style={{ display: 'flex', gap: 8, marginBottom: 20 }}>
|
||||
{[{ k: '', l: '全部' }, { k: 'Upcoming', l: '即将到来' }, { k: 'Completed', l: '已完成' }, { k: 'Cancelled', l: '已取消' }].map(t => (
|
||||
<button key={t.k} onClick={() => setFilter(t.k)}
|
||||
style={{ padding: '6px 18px', borderRadius: 10, border: 'none', fontSize: 13, fontWeight: 500,
|
||||
background: filter === t.k ? '#4F6EF7' : '#F2F3F7', color: filter === t.k ? '#FFF' : '#5A6072' }}>
|
||||
{t.l}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{list.length === 0 ? (
|
||||
<div style={{ color: '#9BA0B4', padding: 40, textAlign: 'center' }}>暂无随访安排</div>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
{list.map(f => {
|
||||
const st = STATUS_MAP[f.status] ?? { label: f.status, color: '#9BA0B4' };
|
||||
return (
|
||||
<div key={f.id} style={{ background: '#FFF', borderRadius: 14, padding: '18px 20px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 16 }}>
|
||||
<span style={{ fontSize: 24 }}>📅</span>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontWeight: 600, fontSize: 15 }}>{f.title}</div>
|
||||
<div style={{ fontSize: 13, color: '#5A6072', marginTop: 2 }}>
|
||||
{f.patientName || '-'} · {new Date(f.scheduledAt).toLocaleString('zh-CN')}
|
||||
</div>
|
||||
{f.notes && <div style={{ fontSize: 12, color: '#9BA0B4', marginTop: 2 }}>{f.notes}</div>}
|
||||
</div>
|
||||
<span style={{ padding: '3px 12px', borderRadius: 10, fontSize: 12, fontWeight: 500, background: `${st.color}18`, color: st.color }}>
|
||||
{st.label}
|
||||
</span>
|
||||
{/* 操作按钮 */}
|
||||
<div style={{ display: 'flex', gap: 6 }}>
|
||||
{f.status === 'Upcoming' && (
|
||||
<button onClick={() => markComplete(f.id)} style={{ padding: '4px 12px', borderRadius: 8, border: '1px solid #20C997', background: '#E6F9F2', color: '#20C997', fontSize: 12 }}>完成</button>
|
||||
)}
|
||||
<Link to={`/follow-ups/${f.id}/edit`} style={{ padding: '4px 12px', borderRadius: 8, border: '1px solid #E1E5ED', color: '#5A6072', fontSize: 12 }}>编辑</Link>
|
||||
<button onClick={() => deleteItem(f.id)} style={{ padding: '4px 12px', borderRadius: 8, border: '1px solid #FEE2E2', background: '#FFF5F5', color: '#EF4444', fontSize: 12 }}>删除</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
273
doctor_web/src/pages/patients/PatientDetailPage.tsx
Normal file
273
doctor_web/src/pages/patients/PatientDetailPage.tsx
Normal file
@@ -0,0 +1,273 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { api } from '../../services/api-client';
|
||||
import type { PatientDetail, TrendRecord } from '../../types';
|
||||
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from 'recharts';
|
||||
|
||||
const METRIC_LABELS: Record<string, string> = {
|
||||
BloodPressure: '血压', HeartRate: '心率', Glucose: '血糖', SpO2: '血氧', Weight: '体重',
|
||||
};
|
||||
|
||||
const METRIC_COLORS: Record<string, string> = {
|
||||
BloodPressure: '#EF4444', HeartRate: '#F59E0B', Glucose: '#4F6EF7', SpO2: '#20C997', Weight: '#845EF7',
|
||||
};
|
||||
|
||||
const DAY_LABELS = ['日', '一', '二', '三', '四', '五', '六'];
|
||||
|
||||
export default function PatientDetailPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const [data, setData] = useState<PatientDetail | null>(null);
|
||||
const [chartMetric, setChartMetric] = useState<string>('BloodPressure');
|
||||
|
||||
useEffect(() => {
|
||||
if (id) api.get<PatientDetail>(`/api/doctor/patients/${id}`).then(setData).catch(() => {});
|
||||
}, [id]);
|
||||
|
||||
if (!data) return <div style={{ padding: 40, color: '#9BA0B4' }}>加载中...</div>;
|
||||
|
||||
const p = data.profile;
|
||||
const a = data.archive;
|
||||
|
||||
// 趋势图数据(用 any 兼容不同指标的数据结构)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const chartData: any[] = buildChartData(data.trendRecords, chartMetric);
|
||||
|
||||
return (
|
||||
<div style={{ padding: 32, maxWidth: 1200 }}>
|
||||
{/* 标题 */}
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 24 }}>
|
||||
<Link to="/patients" style={{ color: '#4F6EF7', fontSize: 14 }}>← 返回列表</Link>
|
||||
<h1 style={{ fontSize: 24, fontWeight: 700 }}>{p.name || '未设置'} 的健康档案</h1>
|
||||
</div>
|
||||
|
||||
{/* 基本信息卡片 */}
|
||||
<InfoCard p={p} a={a} />
|
||||
|
||||
{/* 健康指标 */}
|
||||
<Section title="最新健康指标">
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: 16 }}>
|
||||
{data.latestRecords.map(r => (
|
||||
<div key={r.id} style={{ background: '#FFF', borderRadius: 14, padding: 20, position: 'relative', overflow: 'hidden', boxShadow: '0 1px 8px rgba(0,0,0,0.04)' }}>
|
||||
<div style={{ position: 'absolute', top: 0, left: 0, width: 3, height: '100%', background: METRIC_COLORS[r.metricType] || '#9BA0B4' }} />
|
||||
<div style={{ fontSize: 12, color: '#9BA0B4', marginBottom: 4 }}>{METRIC_LABELS[r.metricType] || r.metricType}</div>
|
||||
<div style={{ fontSize: 26, fontWeight: 700, color: r.isAbnormal ? '#EF4444' : '#1A1D28' }}>
|
||||
{r.metricType === 'BloodPressure' ? `${r.systolic}/${r.diastolic}` : r.value}
|
||||
<span style={{ fontSize: 14, fontWeight: 400, color: '#9BA0B4', marginLeft: 4 }}>{r.unit}</span>
|
||||
</div>
|
||||
<div style={{ fontSize: 11, color: '#9BA0B4', marginTop: 4 }}>
|
||||
{new Date(r.recordedAt).toLocaleDateString('zh-CN')}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{data.latestRecords.length === 0 && <Empty text="暂无健康数据" />}
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* 趋势图 */}
|
||||
<Section title="健康趋势(30天)">
|
||||
<div style={{ display: 'flex', gap: 8, marginBottom: 16 }}>
|
||||
{Object.keys(METRIC_LABELS).map(m => (
|
||||
<button key={m} onClick={() => setChartMetric(m)}
|
||||
style={{
|
||||
padding: '6px 14px', borderRadius: 8, border: 'none', fontSize: 13, fontWeight: 500,
|
||||
background: chartMetric === m ? METRIC_COLORS[m] : '#F2F3F7',
|
||||
color: chartMetric === m ? '#FFF' : '#5A6072',
|
||||
}}>
|
||||
{METRIC_LABELS[m]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{chartData.length > 0 ? (
|
||||
<div style={{ background: '#FFF', borderRadius: 14, padding: 24, boxShadow: '0 1px 8px rgba(0,0,0,0.04)' }}>
|
||||
<ResponsiveContainer width="100%" height={300}>
|
||||
<LineChart data={chartData}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="#F0F0F0" />
|
||||
<XAxis dataKey="date" tick={{ fontSize: 12 }} />
|
||||
<YAxis tick={{ fontSize: 12 }} />
|
||||
<Tooltip />
|
||||
<Legend />
|
||||
{chartMetric === 'BloodPressure' ? (
|
||||
<>
|
||||
<Line type="monotone" dataKey="systolic" stroke="#EF4444" name="收缩压" strokeWidth={2} dot={{ r: 3 }} />
|
||||
<Line type="monotone" dataKey="diastolic" stroke="#F59E0B" name="舒张压" strokeWidth={2} dot={{ r: 3 }} />
|
||||
</>
|
||||
) : (
|
||||
<Line type="monotone" dataKey="value" stroke={METRIC_COLORS[chartMetric]} name={METRIC_LABELS[chartMetric]} strokeWidth={2} dot={{ r: 4 }} />
|
||||
)}
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
) : <Empty text="暂无趋势数据" />}
|
||||
</Section>
|
||||
|
||||
{/* 用药 */}
|
||||
<Section title="当前用药">
|
||||
{data.medications.length > 0 ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{data.medications.map(m => (
|
||||
<div key={m.id} style={{ background: '#FFF', borderRadius: 12, padding: '14px 18px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<span style={{ fontSize: 20 }}>💊</span>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontWeight: 600 }}>{m.name} <span style={{ fontWeight: 400, color: '#5A6072', fontSize: 14 }}>{m.dosage}</span></div>
|
||||
<div style={{ fontSize: 12, color: '#9BA0B4' }}>{m.frequency} · {m.timeOfDay?.join(', ')}</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : <Empty text="暂无用药" />}
|
||||
</Section>
|
||||
|
||||
{/* 饮食 + 运动 双列 */}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24, marginBottom: 24 }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 12 }}>🍽️ 近期饮食</div>
|
||||
{data.dietRecords.length > 0 ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{data.dietRecords.map(d => (
|
||||
<div key={d.id} style={{ background: '#FFF', borderRadius: 12, padding: '12px 16px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)' }}>
|
||||
<div style={{ fontSize: 13, fontWeight: 500 }}>{d.foods.map(f => f.name).join('、')}</div>
|
||||
<div style={{ fontSize: 12, color: '#9BA0B4', marginTop: 4 }}>
|
||||
{d.mealType === 'Breakfast' ? '早餐' : d.mealType === 'Lunch' ? '午餐' : d.mealType === 'Dinner' ? '晚餐' : '加餐'}
|
||||
{' · '}{d.totalCalories}kcal · 评分 {d.healthScore}/5
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : <Empty text="暂无饮食记录" />}
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 12 }}>🏃 运动计划</div>
|
||||
{data.exercisePlan ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
{data.exercisePlan.items.map((item, i) => (
|
||||
<div key={i} style={{ background: '#FFF', borderRadius: 12, padding: '10px 16px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 10, opacity: item.isRestDay ? 0.5 : 1 }}>
|
||||
<span style={{ fontSize: 12, color: '#9BA0B4', minWidth: 36 }}>周{DAY_LABELS[item.dayOfWeek]}</span>
|
||||
<span style={{ flex: 1, fontSize: 13 }}>
|
||||
{item.isRestDay ? '休息' : `${item.exerciseType} ${item.durationMinutes}分钟`}
|
||||
</span>
|
||||
{item.isCompleted && <span style={{ color: '#20C997', fontSize: 12, fontWeight: 500 }}>✓ 已完成</span>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : <Empty text="暂无运动计划" />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 报告 */}
|
||||
<Section title="📋 检查报告">
|
||||
{data.reports.length > 0 ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{data.reports.map(r => (
|
||||
<Link key={r.id} to={`/reports/${r.id}`} style={{ background: '#FFF', borderRadius: 12, padding: '14px 18px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<span style={{ fontSize: 20 }}>📄</span>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontWeight: 500, fontSize: 14 }}>{r.category} 报告</div>
|
||||
<div style={{ fontSize: 12, color: '#9BA0B4' }}>{new Date(r.createdAt).toLocaleDateString('zh-CN')}</div>
|
||||
</div>
|
||||
<StatusBadge status={r.status} map={{ PendingDoctor: ['待审核', '#F59E0B'], DoctorReviewed: ['已审核', '#20C997'] }} />
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
) : <Empty text="暂无报告" />}
|
||||
</Section>
|
||||
|
||||
{/* 随访 */}
|
||||
<Section title="📅 复查随访">
|
||||
{data.followUps.length > 0 ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{data.followUps.map(f => (
|
||||
<div key={f.id} style={{ background: '#FFF', borderRadius: 12, padding: '14px 18px', boxShadow: '0 1px 8px rgba(0,0,0,0.04)', display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<span style={{ fontSize: 20 }}>📅</span>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontWeight: 500, fontSize: 14 }}>{f.title}</div>
|
||||
<div style={{ fontSize: 12, color: '#9BA0B4' }}>
|
||||
{new Date(f.scheduledAt).toLocaleString('zh-CN')}
|
||||
{f.doctorName ? ` · ${f.doctorName}` : ''}
|
||||
{f.notes ? ` · ${f.notes}` : ''}
|
||||
</div>
|
||||
</div>
|
||||
<StatusBadge status={f.status} map={{ Upcoming: ['即将到来', '#4F6EF7'], Completed: ['已完成', '#20C997'], Cancelled: ['已取消', '#EF4444'] }} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : <Empty text="暂无随访安排" />}
|
||||
</Section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 子组件 =====
|
||||
|
||||
function InfoCard({ p, a }: { p: PatientDetail['profile']; a: PatientDetail['archive'] }) {
|
||||
return (
|
||||
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, marginBottom: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
<div style={{ display: 'flex', gap: 24 }}>
|
||||
<div style={{ width: 64, height: 64, borderRadius: 16, background: 'linear-gradient(135deg, #4F6EF7, #6C8AFF)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#FFF', fontSize: 28, fontWeight: 700, flexShrink: 0 }}>
|
||||
{p.name?.[0] ?? '?'}
|
||||
</div>
|
||||
<div style={{ flex: 1 }}>
|
||||
<div style={{ fontSize: 20, fontWeight: 700 }}>{p.name || '未设置'}</div>
|
||||
<div style={{ fontSize: 13, color: '#9BA0B4', marginTop: 2 }}>{p.phone} · {p.gender || '未知'} · {p.birthDate || '未知'}</div>
|
||||
{a && (
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '4px 24px', marginTop: 12, fontSize: 13 }}>
|
||||
<Row label="诊断" value={a.diagnosis} />
|
||||
<Row label="手术类型" value={a.surgeryType} />
|
||||
<Row label="手术日期" value={a.surgeryDate} />
|
||||
<Row label="过敏史" value={a.allergies?.join('、')} />
|
||||
<Row label="饮食限制" value={a.dietRestrictions?.join('、')} />
|
||||
<Row label="慢病史" value={a.chronicDiseases?.join('、')} />
|
||||
<Row label="家族病史" value={a.familyHistory} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Row({ label, value }: { label: string; value?: string | null }) {
|
||||
return (
|
||||
<div>
|
||||
<span style={{ color: '#9BA0B4' }}>{label}:</span>
|
||||
<span style={{ color: value ? '#1A1D28' : '#CCC' }}>{value || '未填写'}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Section({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<div style={{ marginBottom: 24 }}>
|
||||
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 12 }}>{title}</div>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Empty({ text }: { text: string }) {
|
||||
return <div style={{ color: '#CCC', fontSize: 13, padding: 16, textAlign: 'center' }}>{text}</div>;
|
||||
}
|
||||
|
||||
function StatusBadge({ status, map }: { status: string; map: Record<string, [string, string]> }) {
|
||||
const [label, color] = map[status] ?? [status, '#9BA0B4'];
|
||||
return (
|
||||
<span style={{ padding: '3px 12px', borderRadius: 10, fontSize: 12, fontWeight: 500, background: `${color}18`, color }}>
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// 构建趋势图数据
|
||||
function buildChartData(records: TrendRecord[], metric: string) {
|
||||
const filtered = records.filter(r => r.metricType === metric);
|
||||
if (metric === 'BloodPressure') {
|
||||
return filtered.map(r => ({
|
||||
date: new Date(r.recordedAt).toLocaleDateString('zh-CN', { month: 'short', day: 'numeric' }),
|
||||
systolic: r.systolic,
|
||||
diastolic: r.diastolic,
|
||||
}));
|
||||
}
|
||||
return filtered.map(r => ({
|
||||
date: new Date(r.recordedAt).toLocaleDateString('zh-CN', { month: 'short', day: 'numeric' }),
|
||||
value: r.value,
|
||||
}));
|
||||
}
|
||||
80
doctor_web/src/pages/patients/PatientListPage.tsx
Normal file
80
doctor_web/src/pages/patients/PatientListPage.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { api } from '../../services/api-client';
|
||||
import type { Patient } from '../../types';
|
||||
|
||||
export default function PatientListPage() {
|
||||
const [patients, setPatients] = useState<Patient[]>([]);
|
||||
const [search, setSearch] = useState('');
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => { loadPatients(); }, []);
|
||||
|
||||
async function loadPatients(s?: string) {
|
||||
setLoading(true);
|
||||
try {
|
||||
const q = s !== undefined ? s : search;
|
||||
const data = await api.get<Patient[]>(`/api/doctor/patients${q ? `?search=${encodeURIComponent(q)}` : ''}`);
|
||||
setPatients(data);
|
||||
} catch { setPatients([]); }
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ padding: 32, maxWidth: 1200 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
|
||||
<h1 style={{ fontSize: 24, fontWeight: 700 }}>患者管理</h1>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<input
|
||||
value={search}
|
||||
onChange={e => setSearch(e.target.value)}
|
||||
onKeyDown={e => e.key === 'Enter' && loadPatients()}
|
||||
placeholder="搜索姓名或手机号..."
|
||||
style={{ padding: '8px 16px', border: '1px solid #E1E5ED', borderRadius: 10, fontSize: 14, outline: 'none', width: 240 }}
|
||||
/>
|
||||
<button onClick={() => loadPatients()} style={{ padding: '8px 20px', background: '#4F6EF7', color: '#FFF', border: 'none', borderRadius: 10, fontSize: 14, fontWeight: 500 }}>
|
||||
搜索
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div style={{ color: '#9BA0B4', padding: 40 }}>加载中...</div>
|
||||
) : patients.length === 0 ? (
|
||||
<div style={{ color: '#9BA0B4', padding: 40, textAlign: 'center' }}>暂无患者数据</div>
|
||||
) : (
|
||||
<div style={{ background: '#FFF', borderRadius: 16, overflow: 'hidden', boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
|
||||
<thead>
|
||||
<tr style={{ background: '#FAFBFD', borderBottom: '1px solid #EDF0F7' }}>
|
||||
{['姓名', '手机号', '性别', '出生日期', '健康档案', '操作'].map(h => (
|
||||
<th key={h} style={{ padding: '14px 16px', textAlign: 'left', fontWeight: 600, color: '#5A6072', fontSize: 13 }}>{h}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{patients.map(p => (
|
||||
<tr key={p.id} style={{ borderBottom: '1px solid #F2F3F7' }}>
|
||||
<td style={{ padding: '12px 16px', fontWeight: 500 }}>{p.name || '未设置'}</td>
|
||||
<td style={{ padding: '12px 16px', color: '#5A6072' }}>{p.phone}</td>
|
||||
<td style={{ padding: '12px 16px', color: '#5A6072' }}>{p.gender || '-'}</td>
|
||||
<td style={{ padding: '12px 16px', color: '#5A6072' }}>{p.birthDate || '-'}</td>
|
||||
<td style={{ padding: '12px 16px' }}>
|
||||
<span style={{ padding: '2px 10px', borderRadius: 10, fontSize: 12, background: p.hasArchive ? '#E6F9F2' : '#FFF3E0', color: p.hasArchive ? '#20C997' : '#F59E0B' }}>
|
||||
{p.hasArchive ? '已建立' : '未建立'}
|
||||
</span>
|
||||
</td>
|
||||
<td style={{ padding: '12px 16px' }}>
|
||||
<Link to={`/patients/${p.id}`} style={{ color: '#4F6EF7', fontWeight: 500, fontSize: 13 }}>
|
||||
查看详情 →
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
133
doctor_web/src/pages/reports/ReportDetailPage.tsx
Normal file
133
doctor_web/src/pages/reports/ReportDetailPage.tsx
Normal file
@@ -0,0 +1,133 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { api } from '../../services/api-client';
|
||||
import type { Report } from '../../types';
|
||||
|
||||
export default function ReportDetailPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const nav = useNavigate();
|
||||
const [report, setReport] = useState<Report | null>(null);
|
||||
const [comment, setComment] = useState('');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [success, setSuccess] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (id) api.get<Report>(`/api/doctor/reports/${id}`).then(r => { setReport(r); setComment(r.doctorComment || ''); }).catch(() => {});
|
||||
}, [id]);
|
||||
|
||||
async function submitReview() {
|
||||
if (!id) return;
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await api.post(`/api/doctor/reports/${id}/review`, { comment });
|
||||
setSuccess(true);
|
||||
} catch { alert('提交失败'); }
|
||||
setSubmitting(false);
|
||||
}
|
||||
|
||||
if (!report) return <div style={{ padding: 40, color: '#9BA0B4' }}>加载中...</div>;
|
||||
|
||||
// 解析 AI 指标
|
||||
let indicators: any[] = [];
|
||||
try { indicators = JSON.parse(report.aiIndicators || '[]'); } catch {}
|
||||
|
||||
return (
|
||||
<div style={{ padding: 32, maxWidth: 900 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 24 }}>
|
||||
<button onClick={() => nav(-1)} style={{ color: '#4F6EF7', fontSize: 14, border: 'none', background: 'none', cursor: 'pointer' }}>← 返回</button>
|
||||
<h1 style={{ fontSize: 24, fontWeight: 700 }}>报告详情</h1>
|
||||
</div>
|
||||
|
||||
{/* 基本信息 */}
|
||||
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, marginBottom: 20, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '8px 24px', fontSize: 14 }}>
|
||||
<div><span style={{ color: '#9BA0B4' }}>患者:</span>{report.patientName || '-'}</div>
|
||||
<div><span style={{ color: '#9BA0B4' }}>类型:</span>{report.category}</div>
|
||||
<div><span style={{ color: '#9BA0B4' }}>上传时间:</span>{new Date(report.createdAt).toLocaleString('zh-CN')}</div>
|
||||
<div>
|
||||
<span style={{ color: '#9BA0B4' }}>状态:</span>
|
||||
<span style={{ padding: '2px 10px', borderRadius: 10, fontSize: 12, background: report.status === 'PendingDoctor' ? '#FFF8E6' : '#E6F9F2', color: report.status === 'PendingDoctor' ? '#F59E0B' : '#20C997' }}>
|
||||
{report.status === 'PendingDoctor' ? '待审核' : '已审核'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{report.fileUrl && (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<a href={`http://localhost:5000${report.fileUrl}`} target="_blank" rel="noopener noreferrer"
|
||||
style={{ color: '#4F6EF7', fontSize: 13, textDecoration: 'underline' }}>
|
||||
📎 查看原始文件
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* AI 预解读 */}
|
||||
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, marginBottom: 20, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
<h2 style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}>🤖 AI 预解读</h2>
|
||||
{report.aiSummary && (
|
||||
<div style={{ fontSize: 14, lineHeight: 1.7, color: '#5A6072', marginBottom: 16, padding: '12px 16px', background: '#FAFBFD', borderRadius: 10 }}>
|
||||
{report.aiSummary}
|
||||
</div>
|
||||
)}
|
||||
{indicators.length > 0 && (
|
||||
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 13 }}>
|
||||
<thead>
|
||||
<tr style={{ borderBottom: '2px solid #EDF0F7' }}>
|
||||
{['指标', '结果', '单位', '参考范围', '状态'].map(h => (
|
||||
<th key={h} style={{ padding: '8px 12px', textAlign: 'left', color: '#9BA0B4', fontWeight: 500 }}>{h}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{indicators.map((ind: any, i: number) => {
|
||||
const abnormal = ind.status === 'high' || ind.status === 'abnormal';
|
||||
const low = ind.status === 'low';
|
||||
return (
|
||||
<tr key={i} style={{ borderBottom: '1px solid #F2F3F7' }}>
|
||||
<td style={{ padding: '8px 12px' }}>{ind.name}</td>
|
||||
<td style={{ padding: '8px 12px', fontWeight: 500, color: abnormal ? '#EF4444' : low ? '#F59E0B' : '#20C997' }}>{ind.value}</td>
|
||||
<td style={{ padding: '8px 12px', color: '#5A6072' }}>{ind.unit || '-'}</td>
|
||||
<td style={{ padding: '8px 12px', color: '#5A6072' }}>{ind.range || '-'}</td>
|
||||
<td style={{ padding: '8px 12px' }}>
|
||||
<span style={{ padding: '2px 8px', borderRadius: 8, fontSize: 11, background: abnormal ? '#FEE2E2' : low ? '#FFF8E6' : '#E6F9F2', color: abnormal ? '#EF4444' : low ? '#F59E0B' : '#20C997' }}>
|
||||
{abnormal ? '偏高' : low ? '偏低' : '正常'}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 医生审核 */}
|
||||
<div style={{ background: '#FFF', borderRadius: 16, padding: 24, boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
<h2 style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}>👨⚕️ 医生审核意见</h2>
|
||||
{success && (
|
||||
<div style={{ marginBottom: 16, padding: '12px 18px', background: '#E6F9F2', borderRadius: 10, color: '#20C997', fontWeight: 500, fontSize: 14 }}>
|
||||
✓ 审核已提交
|
||||
</div>
|
||||
)}
|
||||
<textarea
|
||||
value={comment}
|
||||
onChange={e => setComment(e.target.value)}
|
||||
placeholder="请输入您的专业解读意见..."
|
||||
rows={5}
|
||||
style={{ width: '100%', padding: 14, border: '1px solid #E1E5ED', borderRadius: 12, fontSize: 14, outline: 'none', resize: 'vertical' }}
|
||||
/>
|
||||
<div style={{ marginTop: 16, display: 'flex', justifyContent: 'flex-end' }}>
|
||||
<button onClick={submitReview} disabled={submitting || !comment.trim()}
|
||||
style={{
|
||||
padding: '12px 32px',
|
||||
background: submitting || !comment.trim() ? '#E1E5ED' : 'linear-gradient(135deg, #4F6EF7, #6C8AFF)',
|
||||
color: submitting || !comment.trim() ? '#9BA0B4' : '#FFF',
|
||||
border: 'none', borderRadius: 12, fontSize: 15, fontWeight: 600,
|
||||
}}>
|
||||
{submitting ? '提交中...' : '提交审核意见'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
75
doctor_web/src/pages/reports/ReportListPage.tsx
Normal file
75
doctor_web/src/pages/reports/ReportListPage.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { api } from '../../services/api-client';
|
||||
import type { Report } from '../../types';
|
||||
|
||||
const STATUS_MAP: Record<string, { label: string; color: string }> = {
|
||||
PendingDoctor: { label: '待审核', color: '#F59E0B' },
|
||||
DoctorReviewed: { label: '已审核', color: '#20C997' },
|
||||
};
|
||||
|
||||
export default function ReportListPage() {
|
||||
const [reports, setReports] = useState<Report[]>([]);
|
||||
const [filter, setFilter] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const q = filter ? `?status=${filter}` : '';
|
||||
api.get<Report[]>(`/api/doctor/reports${q}`).then(setReports).catch(() => {});
|
||||
}, [filter]);
|
||||
|
||||
return (
|
||||
<div style={{ padding: 32, maxWidth: 1200 }}>
|
||||
<h1 style={{ fontSize: 24, fontWeight: 700, marginBottom: 24 }}>报告审核</h1>
|
||||
|
||||
{/* 筛选标签 */}
|
||||
<div style={{ display: 'flex', gap: 8, marginBottom: 20 }}>
|
||||
{[{ k: '', l: '全部' }, { k: 'PendingDoctor', l: '待审核' }, { k: 'DoctorReviewed', l: '已审核' }].map(t => (
|
||||
<button key={t.k} onClick={() => setFilter(t.k)}
|
||||
style={{ padding: '6px 18px', borderRadius: 10, border: 'none', fontSize: 13, fontWeight: 500,
|
||||
background: filter === t.k ? '#4F6EF7' : '#F2F3F7', color: filter === t.k ? '#FFF' : '#5A6072' }}>
|
||||
{t.l}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{reports.length === 0 ? (
|
||||
<div style={{ color: '#9BA0B4', padding: 40, textAlign: 'center' }}>暂无报告</div>
|
||||
) : (
|
||||
<div style={{ background: '#FFF', borderRadius: 16, overflow: 'hidden', boxShadow: '0 2px 12px rgba(0,0,0,0.04)' }}>
|
||||
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
|
||||
<thead>
|
||||
<tr style={{ background: '#FAFBFD', borderBottom: '1px solid #EDF0F7' }}>
|
||||
{['患者', '类型', '状态', 'AI 摘要', '上传时间', '操作'].map(h => (
|
||||
<th key={h} style={{ padding: '14px 16px', textAlign: 'left', fontWeight: 600, color: '#5A6072', fontSize: 13 }}>{h}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{reports.map(r => {
|
||||
const st = STATUS_MAP[r.status] ?? { label: r.status, color: '#9BA0B4' };
|
||||
return (
|
||||
<tr key={r.id} style={{ borderBottom: '1px solid #F2F3F7' }}>
|
||||
<td style={{ padding: '12px 16px', fontWeight: 500 }}>{r.patientName || '-'}</td>
|
||||
<td style={{ padding: '12px 16px', color: '#5A6072' }}>{r.category}</td>
|
||||
<td style={{ padding: '12px 16px' }}>
|
||||
<span style={{ padding: '3px 12px', borderRadius: 10, fontSize: 12, fontWeight: 500, background: `${st.color}18`, color: st.color }}>{st.label}</span>
|
||||
</td>
|
||||
<td style={{ padding: '12px 16px', color: '#5A6072', maxWidth: 240, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{r.aiSummary?.slice(0, 40) || '-'}
|
||||
</td>
|
||||
<td style={{ padding: '12px 16px', color: '#9BA0B4', fontSize: 13 }}>{new Date(r.createdAt).toLocaleDateString('zh-CN')}</td>
|
||||
<td style={{ padding: '12px 16px' }}>
|
||||
<Link to={`/reports/${r.id}`} style={{ color: '#4F6EF7', fontWeight: 500, fontSize: 13 }}>
|
||||
{r.status === 'PendingDoctor' ? '审核 →' : '查看 →'}
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
31
doctor_web/src/router/index.tsx
Normal file
31
doctor_web/src/router/index.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { createBrowserRouter, Navigate } from 'react-router-dom';
|
||||
import DoctorLayout from '../components/layout/DoctorLayout';
|
||||
import DashboardPage from '../pages/dashboard/DashboardPage';
|
||||
import PatientListPage from '../pages/patients/PatientListPage';
|
||||
import PatientDetailPage from '../pages/patients/PatientDetailPage';
|
||||
import ConsultationListPage from '../pages/consultations/ConsultationListPage';
|
||||
import ChatPage from '../pages/consultations/ChatPage';
|
||||
import ReportListPage from '../pages/reports/ReportListPage';
|
||||
import ReportDetailPage from '../pages/reports/ReportDetailPage';
|
||||
import FollowUpListPage from '../pages/followups/FollowUpListPage';
|
||||
import FollowUpEditPage from '../pages/followups/FollowUpEditPage';
|
||||
|
||||
export const router = createBrowserRouter([
|
||||
{
|
||||
path: '/',
|
||||
element: <DoctorLayout />,
|
||||
children: [
|
||||
{ index: true, element: <Navigate to="/dashboard" replace /> },
|
||||
{ path: 'dashboard', element: <DashboardPage /> },
|
||||
{ path: 'patients', element: <PatientListPage /> },
|
||||
{ path: 'patients/:id', element: <PatientDetailPage /> },
|
||||
{ path: 'consultations', element: <ConsultationListPage /> },
|
||||
{ path: 'consultations/:id', element: <ChatPage /> },
|
||||
{ path: 'reports', element: <ReportListPage /> },
|
||||
{ path: 'reports/:id', element: <ReportDetailPage /> },
|
||||
{ path: 'follow-ups', element: <FollowUpListPage /> },
|
||||
{ path: 'follow-ups/new', element: <FollowUpEditPage /> },
|
||||
{ path: 'follow-ups/:id/edit', element: <FollowUpEditPage /> },
|
||||
],
|
||||
},
|
||||
]);
|
||||
29
doctor_web/src/services/api-client.ts
Normal file
29
doctor_web/src/services/api-client.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
const BASE_URL = 'http://localhost:5000';
|
||||
|
||||
async function request<T>(method: string, path: string, body?: unknown): Promise<T> {
|
||||
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
||||
|
||||
const res = await fetch(`${BASE_URL}${path}`, {
|
||||
method,
|
||||
headers,
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error(text || `HTTP ${res.status}`);
|
||||
}
|
||||
|
||||
const json = await res.json();
|
||||
if (json.code !== 0) {
|
||||
throw new Error(json.message || `Error code ${json.code}`);
|
||||
}
|
||||
return json.data as T;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
get: <T>(path: string) => request<T>('GET', path),
|
||||
post: <T>(path: string, body?: unknown) => request<T>('POST', path, body),
|
||||
put: <T>(path: string, body?: unknown) => request<T>('PUT', path, body),
|
||||
del: <T>(path: string) => request<T>('DELETE', path),
|
||||
};
|
||||
30
doctor_web/src/services/signalr.ts
Normal file
30
doctor_web/src/services/signalr.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { HubConnectionBuilder, HubConnection, LogLevel } from '@microsoft/signalr';
|
||||
|
||||
const HUB_URL = 'http://localhost:5000/hubs/consultation';
|
||||
|
||||
let connection: HubConnection | null = null;
|
||||
|
||||
export function getConnection(): HubConnection {
|
||||
if (!connection) {
|
||||
connection = new HubConnectionBuilder()
|
||||
.withUrl(HUB_URL)
|
||||
.withAutomaticReconnect()
|
||||
.configureLogging(LogLevel.Information)
|
||||
.build();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
export async function startConnection(): Promise<void> {
|
||||
const conn = getConnection();
|
||||
if (conn.state === 'Disconnected') {
|
||||
await conn.start();
|
||||
}
|
||||
}
|
||||
|
||||
export async function stopConnection(): Promise<void> {
|
||||
if (connection && connection.state !== 'Disconnected') {
|
||||
await connection.stop();
|
||||
connection = null;
|
||||
}
|
||||
}
|
||||
158
doctor_web/src/types/index.ts
Normal file
158
doctor_web/src/types/index.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
// 患者
|
||||
export interface Patient {
|
||||
id: string;
|
||||
phone: string;
|
||||
name: string | null;
|
||||
gender: string | null;
|
||||
birthDate: string | null;
|
||||
hasArchive: boolean;
|
||||
}
|
||||
|
||||
// 患者详情
|
||||
export interface PatientDetail {
|
||||
profile: {
|
||||
id: string;
|
||||
phone: string;
|
||||
name: string | null;
|
||||
gender: string | null;
|
||||
birthDate: string | null;
|
||||
avatarUrl: string | null;
|
||||
};
|
||||
archive: {
|
||||
diagnosis: string | null;
|
||||
surgeryType: string | null;
|
||||
surgeryDate: string | null;
|
||||
allergies: string[];
|
||||
dietRestrictions: string[];
|
||||
chronicDiseases: string[];
|
||||
familyHistory: string | null;
|
||||
} | null;
|
||||
latestRecords: HealthRecord[];
|
||||
trendRecords: TrendRecord[];
|
||||
medications: Medication[];
|
||||
dietRecords: DietRecord[];
|
||||
exercisePlan: ExercisePlan | null;
|
||||
reports: Report[];
|
||||
followUps: FollowUp[];
|
||||
}
|
||||
|
||||
// 健康记录
|
||||
export interface HealthRecord {
|
||||
id: string;
|
||||
metricType: string;
|
||||
systolic: number | null;
|
||||
diastolic: number | null;
|
||||
value: number | null;
|
||||
unit: string;
|
||||
recordedAt: string;
|
||||
isAbnormal: boolean;
|
||||
}
|
||||
|
||||
// 趋势数据
|
||||
export interface TrendRecord {
|
||||
id: string;
|
||||
metricType: string;
|
||||
systolic: number | null;
|
||||
diastolic: number | null;
|
||||
value: number | null;
|
||||
unit: string;
|
||||
recordedAt: string;
|
||||
isAbnormal: boolean;
|
||||
}
|
||||
|
||||
// 用药
|
||||
export interface Medication {
|
||||
id: string;
|
||||
name: string;
|
||||
dosage: string;
|
||||
frequency: string;
|
||||
timeOfDay: string[];
|
||||
startDate: string;
|
||||
endDate: string | null;
|
||||
}
|
||||
|
||||
// 饮食记录
|
||||
export interface DietRecord {
|
||||
id: string;
|
||||
mealType: string;
|
||||
totalCalories: number;
|
||||
healthScore: number;
|
||||
recordedAt: string;
|
||||
foods: { name: string; portion: string; calories: number; warning: string | null }[];
|
||||
}
|
||||
|
||||
// 运动计划
|
||||
export interface ExercisePlan {
|
||||
weekStartDate: string;
|
||||
items: {
|
||||
dayOfWeek: number;
|
||||
exerciseType: string | null;
|
||||
durationMinutes: number;
|
||||
isCompleted: boolean;
|
||||
isRestDay: boolean;
|
||||
completedAt: string | null;
|
||||
}[];
|
||||
}
|
||||
|
||||
// 报告
|
||||
export interface Report {
|
||||
id: string;
|
||||
userId: string;
|
||||
patientName?: string;
|
||||
fileUrl: string;
|
||||
fileType: string;
|
||||
category: string;
|
||||
status: string;
|
||||
aiSummary: string | null;
|
||||
aiIndicators: string | null;
|
||||
doctorComment: string | null;
|
||||
doctorName: string | null;
|
||||
reviewedAt: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
// 随访
|
||||
export interface FollowUp {
|
||||
id: string;
|
||||
userId: string;
|
||||
patientName?: string;
|
||||
title: string;
|
||||
doctorName: string | null;
|
||||
department: string | null;
|
||||
scheduledAt: string;
|
||||
notes: string | null;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
// 问诊
|
||||
export interface Consultation {
|
||||
id: string;
|
||||
userId: string;
|
||||
patientName?: string;
|
||||
patientPhone?: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
closedAt: string | null;
|
||||
lastMessage: { content: string; senderType: string; createdAt: string } | null;
|
||||
}
|
||||
|
||||
// 问诊消息
|
||||
export interface ConsultationMessage {
|
||||
id: string;
|
||||
senderType: string;
|
||||
senderName: string | null;
|
||||
content: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
// Dashboard
|
||||
export interface DashboardStats {
|
||||
doctorName: string;
|
||||
doctorTitle: string;
|
||||
doctorDepartment: string;
|
||||
totalPatients: number;
|
||||
activeConsultations: number;
|
||||
pendingReports: number;
|
||||
todayFollowUps: number;
|
||||
}
|
||||
25
doctor_web/tsconfig.app.json
Normal file
25
doctor_web/tsconfig.app.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "es2023",
|
||||
"lib": ["ES2023", "DOM"],
|
||||
"module": "esnext",
|
||||
"types": ["vite/client"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
7
doctor_web/tsconfig.json
Normal file
7
doctor_web/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
24
doctor_web/tsconfig.node.json
Normal file
24
doctor_web/tsconfig.node.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "es2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "esnext",
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
7
doctor_web/vite.config.ts
Normal file
7
doctor_web/vite.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
@@ -103,7 +103,7 @@ class _DoctorChatPageState extends ConsumerState<DoctorChatPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
ref.read(consultationChatProvider.notifier).stopPolling();
|
||||
ref.read(consultationChatProvider.notifier).stop();
|
||||
_textCtrl.dispose();
|
||||
_scrollCtrl.dispose();
|
||||
super.dispose();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:signalr_netcore/signalr_client.dart';
|
||||
import '../core/api_client.dart' show baseUrl;
|
||||
import 'auth_provider.dart';
|
||||
|
||||
class ConsultationMsg {
|
||||
@@ -8,7 +10,6 @@ class ConsultationMsg {
|
||||
final String? senderName;
|
||||
final String content;
|
||||
final DateTime createdAt;
|
||||
final List<String>? quickOptions;
|
||||
|
||||
ConsultationMsg({
|
||||
required this.id,
|
||||
@@ -16,7 +17,6 @@ class ConsultationMsg {
|
||||
this.senderName,
|
||||
required this.content,
|
||||
required this.createdAt,
|
||||
this.quickOptions,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class ConsultationChatState {
|
||||
final List<ConsultationMsg> messages;
|
||||
final bool isLoading;
|
||||
final bool isSending;
|
||||
final bool isConnected;
|
||||
final int quotaRemaining;
|
||||
final int quotaTotal;
|
||||
|
||||
@@ -43,6 +44,7 @@ class ConsultationChatState {
|
||||
this.messages = const [],
|
||||
this.isLoading = true,
|
||||
this.isSending = false,
|
||||
this.isConnected = false,
|
||||
this.quotaRemaining = 3,
|
||||
this.quotaTotal = 3,
|
||||
});
|
||||
@@ -57,6 +59,7 @@ class ConsultationChatState {
|
||||
List<ConsultationMsg>? messages,
|
||||
bool? isLoading,
|
||||
bool? isSending,
|
||||
bool? isConnected,
|
||||
int? quotaRemaining,
|
||||
int? quotaTotal,
|
||||
}) =>
|
||||
@@ -70,6 +73,7 @@ class ConsultationChatState {
|
||||
messages: messages ?? this.messages,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
isSending: isSending ?? this.isSending,
|
||||
isConnected: isConnected ?? this.isConnected,
|
||||
quotaRemaining: quotaRemaining ?? this.quotaRemaining,
|
||||
quotaTotal: quotaTotal ?? this.quotaTotal,
|
||||
);
|
||||
@@ -80,7 +84,8 @@ final consultationChatProvider =
|
||||
ConsultationChatNotifier.new);
|
||||
|
||||
class ConsultationChatNotifier extends Notifier<ConsultationChatState> {
|
||||
Timer? _pollTimer;
|
||||
HubConnection? _hub;
|
||||
String get _hubUrl => '$baseUrl/hubs/consultation';
|
||||
|
||||
@override
|
||||
ConsultationChatState build() => const ConsultationChatState();
|
||||
@@ -127,12 +132,54 @@ class ConsultationChatNotifier extends Notifier<ConsultationChatState> {
|
||||
state = state.copyWith(consultationId: consultationId, isLoading: false);
|
||||
}
|
||||
|
||||
_startPolling();
|
||||
// 建立 SignalR 连接
|
||||
await _connectHub(consultationId);
|
||||
} catch (_) {
|
||||
state = state.copyWith(isLoading: false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _connectHub(String consultationId) async {
|
||||
try {
|
||||
_hub?.stop();
|
||||
_hub = HubConnectionBuilder()
|
||||
.withUrl(_hubUrl)
|
||||
.withAutomaticReconnect()
|
||||
.build();
|
||||
|
||||
// 注册消息接收
|
||||
_hub!.on('ReceiveMessage', (args) {
|
||||
if (args == null || args.isEmpty) return;
|
||||
final data = args[0] as Map<String, dynamic>;
|
||||
final msgConsultationId = data['consultationId']?.toString() ?? '';
|
||||
if (msgConsultationId != consultationId) return;
|
||||
|
||||
final msg = ConsultationMsg(
|
||||
id: data['id']?.toString() ?? DateTime.now().millisecondsSinceEpoch.toString(),
|
||||
senderType: data['senderType']?.toString() ?? 'Ai',
|
||||
senderName: data['senderName']?.toString(),
|
||||
content: data['content']?.toString() ?? '',
|
||||
createdAt: data['createdAt'] != null
|
||||
? DateTime.tryParse(data['createdAt'].toString()) ?? DateTime.now()
|
||||
: DateTime.now(),
|
||||
);
|
||||
|
||||
// 去重
|
||||
final existingIds = state.messages.map((m) => m.id).toSet();
|
||||
if (!existingIds.contains(msg.id)) {
|
||||
state = state.copyWith(messages: [...state.messages, msg]);
|
||||
}
|
||||
});
|
||||
|
||||
await _hub!.start();
|
||||
await _hub!.invoke('JoinConsultation', args: [consultationId]);
|
||||
state = state.copyWith(isConnected: true);
|
||||
} catch (_) {
|
||||
// SignalR 连接失败,回退到轮询
|
||||
_startPolling();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadDoctorInfo(String doctorId) async {
|
||||
try {
|
||||
final api = ref.read(apiClientProvider);
|
||||
@@ -185,27 +232,37 @@ class ConsultationChatNotifier extends Notifier<ConsultationChatState> {
|
||||
);
|
||||
|
||||
try {
|
||||
// 优先通过 SignalR 发送
|
||||
if (_hub != null && _hub!.state == HubConnectionState.Connected) {
|
||||
await _hub!.invoke('SendMessage',
|
||||
args: <Object>[state.consultationId!, 'User', '', text]);
|
||||
} else {
|
||||
// 回退到 HTTP
|
||||
final api = ref.read(apiClientProvider);
|
||||
await api.post('/api/consultations/${state.consultationId}/messages', data: {'content': text});
|
||||
state = state.copyWith(isSending: false);
|
||||
_pollMessages();
|
||||
await api.post('/api/consultations/${state.consultationId}/messages',
|
||||
data: {'content': text});
|
||||
}
|
||||
} catch (_) {
|
||||
// 静默失败,消息已显示在本地
|
||||
}
|
||||
state = state.copyWith(isSending: false);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 轮询回退(SignalR 不可用时)----
|
||||
Timer? _pollTimer;
|
||||
|
||||
void _startPolling() {
|
||||
_pollTimer?.cancel();
|
||||
_pollTimer = Timer.periodic(const Duration(seconds: 15), (_) => _pollMessages());
|
||||
_pollTimer = Timer.periodic(const Duration(seconds: 5), (_) => _pollMessages());
|
||||
}
|
||||
|
||||
Future<void> _pollMessages() async {
|
||||
if (state.consultationId == null) return;
|
||||
if (state.consultationId == null || state.isConnected) return;
|
||||
try {
|
||||
final api = ref.read(apiClientProvider);
|
||||
final lastId = state.messages.isNotEmpty ? state.messages.last.id : null;
|
||||
final params = <String, dynamic>{};
|
||||
if (lastId != null && lastId.startsWith('greeting_') == false) {
|
||||
if (lastId != null && !lastId.startsWith('greeting_')) {
|
||||
params['after'] = lastId;
|
||||
}
|
||||
final res = await api.get(
|
||||
@@ -224,7 +281,8 @@ class ConsultationChatNotifier extends Notifier<ConsultationChatState> {
|
||||
senderType: map['senderType']?.toString() ?? 'User',
|
||||
senderName: map['senderName']?.toString(),
|
||||
content: map['content']?.toString() ?? '',
|
||||
createdAt: DateTime.tryParse(map['createdAt']?.toString() ?? '') ?? DateTime.now(),
|
||||
createdAt:
|
||||
DateTime.tryParse(map['createdAt']?.toString() ?? '') ?? DateTime.now(),
|
||||
);
|
||||
})
|
||||
.where((m) => !existingIds.contains(m.id))
|
||||
@@ -236,7 +294,9 @@ class ConsultationChatNotifier extends Notifier<ConsultationChatState> {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
void stopPolling() {
|
||||
void stop() {
|
||||
_hub?.stop();
|
||||
_hub = null;
|
||||
_pollTimer?.cancel();
|
||||
_pollTimer = null;
|
||||
}
|
||||
|
||||
@@ -209,6 +209,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.3+5"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fixnum
|
||||
sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
fl_chart:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -448,6 +456,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.11.1"
|
||||
message_pack_dart:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: message_pack_dart
|
||||
sha256: "71b9f0ff60e5896e60b337960bb535380d7dba3297b457ac763ccae807385b59"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -568,6 +584,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
signalr_netcore:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: signalr_netcore
|
||||
sha256: "8d59dc61284c5ff8aa27c4e3e802fcf782367f06cf42b39d5ded81680b72f8b8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.4"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@@ -637,6 +661,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.0"
|
||||
sse:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sse
|
||||
sha256: fcc97470240bb37377f298e2bd816f09fd7216c07928641c0560719f50603643
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.1.8"
|
||||
sse_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sse_channel
|
||||
sha256: "9aad5d4eef63faf6ecdefb636c0f857bd6f74146d2196087dcf4b17ab5b49b1b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.1"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -709,6 +749,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.12"
|
||||
tuple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: tuple
|
||||
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -717,6 +765,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
uuid:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: uuid
|
||||
sha256: "1fef9e8e11e2991bb773070d4656b7bd5d850967a2456cfc83cf47925ba79489"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.5.3"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -35,6 +35,7 @@ dependencies:
|
||||
|
||||
# 基础图标
|
||||
cupertino_icons: ^1.0.8
|
||||
signalr_netcore: ^1.4.4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user