Initial commit: HealthManager full-stack health management platform
Backend: .NET 10 + PostgreSQL + EF Core + JWT + SignalR Frontend patient: React 19 + TypeScript + Vite (mobile H5) Frontend doctor: React 19 + TypeScript + Vite (desktop web)
11
.claude/launch.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.0.1",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "健康管家 Web Demo",
|
||||||
|
"runtimeExecutable": "cmd.exe",
|
||||||
|
"runtimeArgs": ["/c", "D:\\nodejs\\npm.cmd", "run", "dev"],
|
||||||
|
"port": 5175
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
7
.claude/settings.local.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"allow": [
|
||||||
|
"Bash(winget install *)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
38
.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Build outputs
|
||||||
|
dist/
|
||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
|
||||||
|
# Data (large files)
|
||||||
|
data/
|
||||||
|
|
||||||
|
# Environment
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.vs/
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
pg.log
|
||||||
|
|
||||||
|
# Temp
|
||||||
|
*.tmp
|
||||||
|
tmp/
|
||||||
8
backend/HealthManager.slnx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<Solution>
|
||||||
|
<Folder Name="/src/">
|
||||||
|
<Project Path="src/HealthManager.Application/HealthManager.Application.csproj" />
|
||||||
|
<Project Path="src/HealthManager.Domain/HealthManager.Domain.csproj" />
|
||||||
|
<Project Path="src/HealthManager.Infrastructure/HealthManager.Infrastructure.csproj" />
|
||||||
|
<Project Path="src/HealthManager.WebApi/HealthManager.WebApi.csproj" />
|
||||||
|
</Folder>
|
||||||
|
</Solution>
|
||||||
19
backend/src/HealthManager.Application/DTOs/AuthDtos.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace HealthManager.Application.DTOs.Auth;
|
||||||
|
|
||||||
|
public record LoginRequest(string Phone, string SmsCode);
|
||||||
|
|
||||||
|
public record RegisterRequest(string Phone, string SmsCode, string Name);
|
||||||
|
|
||||||
|
public record SendSmsRequest(string Phone);
|
||||||
|
|
||||||
|
public record AuthResponse(Guid UserId, string Name, string Role, string AccessToken, string RefreshToken);
|
||||||
|
|
||||||
|
public record UserProfileResponse(
|
||||||
|
Guid Id, string Name, string Phone, string Role,
|
||||||
|
string? Gender, DateOnly? Birthday, decimal? HeightCm, decimal? WeightKg,
|
||||||
|
List<string>? MedicalHistory, DateOnly? StentDate, string? StentType,
|
||||||
|
string? Department, string? Title, List<string>? Specialty, string? Introduction);
|
||||||
|
|
||||||
|
public record UpdateProfileRequest(
|
||||||
|
string? Name, string? Gender, DateOnly? Birthday,
|
||||||
|
decimal? HeightCm, decimal? WeightKg, List<string>? MedicalHistory);
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace HealthManager.Application.DTOs.Consultation;
|
||||||
|
|
||||||
|
public record ConsultationCreateRequest(Guid DoctorId, string Subject);
|
||||||
|
|
||||||
|
public record ConsultationResponse(
|
||||||
|
Guid Id, Guid PatientId, Guid DoctorId,
|
||||||
|
string PatientName, string DoctorName,
|
||||||
|
string? Subject, string Status, DateTime StartedAt,
|
||||||
|
DateTime? ClosedAt, string? Summary);
|
||||||
|
|
||||||
|
public record SendMessageRequest(string Content, string ContentType = "text", string? ImageUrl = null);
|
||||||
|
|
||||||
|
public record MessageResponse(
|
||||||
|
Guid Id, Guid SenderId, string SenderRole,
|
||||||
|
string ContentType, string Content,
|
||||||
|
string? ImageUrl, bool IsRead, DateTime CreatedAt);
|
||||||
12
backend/src/HealthManager.Application/DTOs/FollowUpDtos.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace HealthManager.Application.DTOs.FollowUp;
|
||||||
|
|
||||||
|
public record FollowUpCreateRequest(
|
||||||
|
string Title, string? Description, DateTime ScheduledAt, bool ReminderEnabled = true);
|
||||||
|
|
||||||
|
public record FollowUpUpdateRequest(
|
||||||
|
string? Title, string? Description, DateTime? ScheduledAt, string? Status, string? Notes);
|
||||||
|
|
||||||
|
public record FollowUpResponse(
|
||||||
|
Guid Id, Guid PatientId, string PatientName, Guid? DoctorId, string? DoctorName,
|
||||||
|
string Title, string? Description, DateTime ScheduledAt, string Status,
|
||||||
|
string? Notes, bool ReminderEnabled, DateTime CreatedAt);
|
||||||
14
backend/src/HealthManager.Application/DTOs/HealthDtos.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace HealthManager.Application.DTOs.Health;
|
||||||
|
|
||||||
|
public record HealthRecordCreateRequest(
|
||||||
|
string Type, string ValueJson, string Unit, DateTime RecordedAt, string? Notes);
|
||||||
|
|
||||||
|
public record HealthRecordResponse(
|
||||||
|
Guid Id, string Type, string ValueJson, string Unit,
|
||||||
|
DateTime RecordedAt, string Source, string? Notes, DateTime CreatedAt);
|
||||||
|
|
||||||
|
public record HealthStatsResponse(
|
||||||
|
string Type, string Unit,
|
||||||
|
HealthRecordResponse? Latest,
|
||||||
|
decimal? WeekAvg, decimal? MonthAvg,
|
||||||
|
string Trend); // up, down, stable
|
||||||
18
backend/src/HealthManager.Application/DTOs/MedicationDtos.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace HealthManager.Application.DTOs.Medication;
|
||||||
|
|
||||||
|
public record MedicationCreateRequest(
|
||||||
|
string DrugName, string Dosage, string Frequency,
|
||||||
|
List<string> TimeSlots, DateOnly StartDate, DateOnly? EndDate, string? Notes);
|
||||||
|
|
||||||
|
public record MedicationResponse(
|
||||||
|
Guid Id, Guid UserId, string DrugName, string Dosage,
|
||||||
|
string Frequency, List<string> TimeSlots,
|
||||||
|
DateOnly StartDate, DateOnly? EndDate, string? Notes,
|
||||||
|
string Status, DateTime CreatedAt);
|
||||||
|
|
||||||
|
public record MedicationRecordResponse(
|
||||||
|
Guid Id, Guid MedicationId, string TimeSlot, DateTime? TakenAt,
|
||||||
|
bool IsTaken, string? SkippedReason, DateTime CreatedAt);
|
||||||
|
|
||||||
|
public record AdherenceResponse(
|
||||||
|
Guid MedicationId, string DrugName, decimal Rate, int TakenDays, int TotalDays);
|
||||||
15
backend/src/HealthManager.Application/DTOs/ReportDtos.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace HealthManager.Application.DTOs.Report;
|
||||||
|
|
||||||
|
public record ReportUploadRequest(string Title, string Category, List<string> ImageUrls);
|
||||||
|
|
||||||
|
public record ReportInterpretRequest(string Summary, List<ReportItemDto> Items, string RiskLevel, string? Suggestions);
|
||||||
|
|
||||||
|
public record ReportResponse(
|
||||||
|
Guid Id, Guid PatientId, string PatientName, string? DoctorName,
|
||||||
|
string Title, string Category, List<string> ImageUrls,
|
||||||
|
string Status, string? RiskLevel, string? Summary, string? Suggestions,
|
||||||
|
List<ReportItemDto> Items, DateTime UploadedAt, DateTime? CompletedAt);
|
||||||
|
|
||||||
|
public record ReportItemDto(
|
||||||
|
string ItemName, string ResultValue, string? Unit,
|
||||||
|
string? ReferenceRange, bool IsAbnormal);
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\HealthManager.Domain\HealthManager.Domain.csproj" />
|
||||||
|
<ProjectReference Include="..\HealthManager.Infrastructure\HealthManager.Infrastructure.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using HealthManager.Domain.Entities;
|
||||||
|
using HealthManager.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace HealthManager.Application.Services;
|
||||||
|
|
||||||
|
public class AuthService(AppDbContext db)
|
||||||
|
{
|
||||||
|
public async Task<User?> GetUserByPhoneAsync(string phone)
|
||||||
|
{
|
||||||
|
return await db.Users.FirstOrDefaultAsync(u => u.Phone == phone && !u.IsDeleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<RefreshToken?> GetRefreshTokenAsync(string token)
|
||||||
|
{
|
||||||
|
return await db.RefreshTokens
|
||||||
|
.Include(rt => rt.User)
|
||||||
|
.FirstOrDefaultAsync(rt => rt.Token == token && rt.RevokedAt == null && rt.ExpiresAt > DateTime.UtcNow);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RevokeRefreshTokenAsync(Guid userId)
|
||||||
|
{
|
||||||
|
var tokens = await db.RefreshTokens
|
||||||
|
.Where(rt => rt.UserId == userId && rt.RevokedAt == null)
|
||||||
|
.ToListAsync();
|
||||||
|
foreach (var t in tokens)
|
||||||
|
t.RevokedAt = DateTime.UtcNow;
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SaveRefreshTokenAsync(Guid userId, string token, DateTime expiresAt)
|
||||||
|
{
|
||||||
|
db.RefreshTokens.Add(new RefreshToken
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
Token = token,
|
||||||
|
ExpiresAt = expiresAt,
|
||||||
|
});
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string HashPassword(string password)
|
||||||
|
{
|
||||||
|
var bytes = SHA256.HashData(Encoding.UTF8.GetBytes(password));
|
||||||
|
return Convert.ToHexStringLower(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool VerifyPassword(string password, string hash)
|
||||||
|
=> HashPassword(password) == hash;
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
using HealthManager.Domain.Entities;
|
||||||
|
using HealthManager.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace HealthManager.Application.Services;
|
||||||
|
|
||||||
|
public class ConsultationService(AppDbContext db)
|
||||||
|
{
|
||||||
|
public async Task<List<Consultation>> GetPatientConsultationsAsync(Guid patientId)
|
||||||
|
=> await db.Consultations
|
||||||
|
.Include(c => c.Doctor)
|
||||||
|
.Where(c => c.PatientId == patientId)
|
||||||
|
.OrderByDescending(c => c.StartedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<List<Consultation>> GetDoctorConsultationsAsync(Guid doctorId)
|
||||||
|
=> await db.Consultations
|
||||||
|
.Include(c => c.Patient)
|
||||||
|
.Where(c => c.DoctorId == doctorId)
|
||||||
|
.OrderByDescending(c => c.StartedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<Consultation?> GetByIdAsync(Guid id)
|
||||||
|
=> await db.Consultations
|
||||||
|
.Include(c => c.Patient)
|
||||||
|
.Include(c => c.Doctor)
|
||||||
|
.FirstOrDefaultAsync(c => c.Id == id);
|
||||||
|
|
||||||
|
public async Task<Consultation> StartAsync(Guid patientId, Guid doctorId, string subject)
|
||||||
|
{
|
||||||
|
var consultation = new Consultation
|
||||||
|
{
|
||||||
|
PatientId = patientId,
|
||||||
|
DoctorId = doctorId,
|
||||||
|
Subject = subject,
|
||||||
|
};
|
||||||
|
db.Consultations.Add(consultation);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return consultation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<ConsultationMessage>> GetMessagesAsync(Guid consultationId)
|
||||||
|
=> await db.ConsultationMessages
|
||||||
|
.Include(m => m.Sender)
|
||||||
|
.Where(m => m.ConsultationId == consultationId)
|
||||||
|
.OrderBy(m => m.CreatedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<ConsultationMessage> SendMessageAsync(Guid consultationId, Guid senderId, string senderRole,
|
||||||
|
string content, string contentType = "text", string? imageUrl = null)
|
||||||
|
{
|
||||||
|
var message = new ConsultationMessage
|
||||||
|
{
|
||||||
|
ConsultationId = consultationId,
|
||||||
|
SenderId = senderId,
|
||||||
|
SenderRole = senderRole,
|
||||||
|
Content = content,
|
||||||
|
ContentType = contentType,
|
||||||
|
ImageUrl = imageUrl,
|
||||||
|
};
|
||||||
|
db.ConsultationMessages.Add(message);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<User>> GetDoctorsAsync(string? department = null)
|
||||||
|
{
|
||||||
|
var query = db.Users.Where(u => u.Role == "doctor" && u.IsAvailable && !u.IsDeleted);
|
||||||
|
if (!string.IsNullOrEmpty(department))
|
||||||
|
query = query.Where(u => u.Department == department);
|
||||||
|
return await query.ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using HealthManager.Domain.Entities;
|
||||||
|
using HealthManager.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace HealthManager.Application.Services;
|
||||||
|
|
||||||
|
public class FollowUpService(AppDbContext db)
|
||||||
|
{
|
||||||
|
public async Task<List<FollowUp>> GetPatientFollowUpsAsync(Guid patientId)
|
||||||
|
=> await db.FollowUps
|
||||||
|
.Include(f => f.Doctor)
|
||||||
|
.Where(f => f.PatientId == patientId)
|
||||||
|
.OrderBy(f => f.ScheduledAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<List<FollowUp>> GetDoctorFollowUpsAsync(Guid doctorId)
|
||||||
|
=> await db.FollowUps
|
||||||
|
.Include(f => f.Patient)
|
||||||
|
.Where(f => f.DoctorId == doctorId)
|
||||||
|
.OrderBy(f => f.ScheduledAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<FollowUp> AddAsync(Guid patientId, string title, string? description, DateTime scheduledAt, bool reminderEnabled, Guid? doctorId = null)
|
||||||
|
{
|
||||||
|
var followUp = new FollowUp
|
||||||
|
{
|
||||||
|
PatientId = patientId,
|
||||||
|
DoctorId = doctorId,
|
||||||
|
Title = title,
|
||||||
|
Description = description,
|
||||||
|
ScheduledAt = DateTime.SpecifyKind(scheduledAt, DateTimeKind.Utc),
|
||||||
|
ReminderEnabled = reminderEnabled,
|
||||||
|
};
|
||||||
|
db.FollowUps.Add(followUp);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return followUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<FollowUp?> GetByIdAsync(Guid id)
|
||||||
|
=> await db.FollowUps
|
||||||
|
.Include(f => f.Patient)
|
||||||
|
.Include(f => f.Doctor)
|
||||||
|
.FirstOrDefaultAsync(f => f.Id == id);
|
||||||
|
|
||||||
|
public async Task<FollowUp?> UpdateAsync(Guid id, Guid doctorId, string? title, string? description,
|
||||||
|
DateTime? scheduledAt, string? status, string? notes)
|
||||||
|
{
|
||||||
|
var followUp = await db.FollowUps.FindAsync(id);
|
||||||
|
if (followUp == null) return null;
|
||||||
|
|
||||||
|
if (title != null) followUp.Title = title;
|
||||||
|
if (description != null) followUp.Description = description;
|
||||||
|
if (scheduledAt.HasValue) followUp.ScheduledAt = DateTime.SpecifyKind(scheduledAt.Value, DateTimeKind.Utc);
|
||||||
|
if (status != null) followUp.Status = status;
|
||||||
|
if (notes != null) followUp.Notes = notes;
|
||||||
|
followUp.DoctorId = doctorId;
|
||||||
|
followUp.UpdatedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return followUp;
|
||||||
|
}
|
||||||
|
}
|
||||||
114
backend/src/HealthManager.Application/Services/HealthService.cs
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using HealthManager.Domain.Entities;
|
||||||
|
using HealthManager.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace HealthManager.Application.Services;
|
||||||
|
|
||||||
|
public class HealthService(AppDbContext db)
|
||||||
|
{
|
||||||
|
public async Task<List<HealthRecord>> GetRecordsAsync(Guid userId, string? type, int days = 30)
|
||||||
|
{
|
||||||
|
var cutoff = DateTime.UtcNow.AddDays(-days);
|
||||||
|
var query = db.HealthRecords.Where(hr => hr.UserId == userId && hr.RecordedAt >= cutoff);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(type))
|
||||||
|
query = query.Where(hr => hr.Type == type);
|
||||||
|
|
||||||
|
return await query.OrderByDescending(hr => hr.RecordedAt).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<HealthRecord?> GetLatestAsync(Guid userId, string type)
|
||||||
|
{
|
||||||
|
return await db.HealthRecords
|
||||||
|
.Where(hr => hr.UserId == userId && hr.Type == type)
|
||||||
|
.OrderByDescending(hr => hr.RecordedAt)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<HealthRecord> AddRecordAsync(Guid userId, string type, string valueJson, string unit, DateTime recordedAt, string? notes)
|
||||||
|
{
|
||||||
|
var record = new HealthRecord
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
Type = type,
|
||||||
|
Value = JsonDocument.Parse(valueJson),
|
||||||
|
Unit = unit,
|
||||||
|
RecordedAt = DateTime.SpecifyKind(recordedAt, DateTimeKind.Utc),
|
||||||
|
Notes = notes,
|
||||||
|
Source = "manual",
|
||||||
|
};
|
||||||
|
db.HealthRecords.Add(record);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Dictionary<string, object>> GetStatsAsync(Guid userId)
|
||||||
|
{
|
||||||
|
var types = new[] { "blood_pressure", "heart_rate", "blood_sugar", "spo2", "weight", "steps" };
|
||||||
|
var result = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
foreach (var type in types)
|
||||||
|
{
|
||||||
|
var latest = await GetLatestAsync(userId, type);
|
||||||
|
var records = await db.HealthRecords
|
||||||
|
.Where(hr => hr.UserId == userId && hr.Type == type)
|
||||||
|
.OrderByDescending(hr => hr.RecordedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
// Calculate trend from last 7 days vs previous 7 days
|
||||||
|
var now = DateTime.UtcNow;
|
||||||
|
var weekAgo = now.AddDays(-7);
|
||||||
|
var twoWeeksAgo = now.AddDays(-14);
|
||||||
|
|
||||||
|
var recentValues = records.Where(r => r.RecordedAt >= weekAgo).ToList();
|
||||||
|
var olderValues = records.Where(r => r.RecordedAt >= twoWeeksAgo && r.RecordedAt < weekAgo).ToList();
|
||||||
|
|
||||||
|
var recentAvg = CalculateAvg(recentValues);
|
||||||
|
var olderAvg = CalculateAvg(olderValues);
|
||||||
|
|
||||||
|
string trend = "stable";
|
||||||
|
if (olderAvg > 0 && recentAvg > 0)
|
||||||
|
{
|
||||||
|
if (recentAvg > olderAvg * 1.03m) trend = "up";
|
||||||
|
else if (recentAvg < olderAvg * 0.97m) trend = "down";
|
||||||
|
}
|
||||||
|
|
||||||
|
result[type] = new
|
||||||
|
{
|
||||||
|
Latest = latest,
|
||||||
|
WeekAvg = recentAvg > 0 ? recentAvg : (decimal?)null,
|
||||||
|
MonthAvg = records.Count > 0 ? CalculateAvg(records) : (decimal?)null,
|
||||||
|
Trend = trend,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static decimal CalculateAvg(List<HealthRecord> records)
|
||||||
|
{
|
||||||
|
if (records.Count == 0) return 0;
|
||||||
|
|
||||||
|
var sum = 0m;
|
||||||
|
var count = 0;
|
||||||
|
foreach (var r in records)
|
||||||
|
{
|
||||||
|
// Blood pressure: { systolic, diastolic, pulse }
|
||||||
|
if (r.Value.RootElement.TryGetProperty("systolic", out var sys) &&
|
||||||
|
r.Value.RootElement.TryGetProperty("diastolic", out var dia))
|
||||||
|
{
|
||||||
|
sum += sys.GetDecimal(); // Use systolic for trend
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
// All other types: { value } — heart_rate, blood_sugar, spo2, weight, steps
|
||||||
|
else if (r.Value.RootElement.TryGetProperty("value", out var val))
|
||||||
|
{
|
||||||
|
sum += val.GetDecimal();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count > 0 ? sum / count : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
using HealthManager.Domain.Entities;
|
||||||
|
using HealthManager.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace HealthManager.Application.Services;
|
||||||
|
|
||||||
|
public class MedicationService(AppDbContext db)
|
||||||
|
{
|
||||||
|
public async Task<List<Medication>> GetUserMedicationsAsync(Guid userId)
|
||||||
|
=> await db.Medications
|
||||||
|
.Where(m => m.UserId == userId)
|
||||||
|
.OrderByDescending(m => m.CreatedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<Medication?> GetByIdAsync(Guid id)
|
||||||
|
=> await db.Medications.FindAsync(id);
|
||||||
|
|
||||||
|
public async Task<Medication> AddAsync(Guid userId, string drugName, string dosage, string frequency,
|
||||||
|
List<string> timeSlots, DateOnly startDate, DateOnly? endDate, string? notes, Guid? doctorId = null)
|
||||||
|
{
|
||||||
|
var med = new Medication
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
DoctorId = doctorId,
|
||||||
|
DrugName = drugName,
|
||||||
|
Dosage = dosage,
|
||||||
|
Frequency = frequency,
|
||||||
|
TimeSlots = timeSlots,
|
||||||
|
StartDate = startDate,
|
||||||
|
EndDate = endDate,
|
||||||
|
Notes = notes,
|
||||||
|
};
|
||||||
|
db.Medications.Add(med);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return med;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<MedicationRecord>> GetRecordsAsync(Guid medicationId)
|
||||||
|
=> await db.MedicationRecords
|
||||||
|
.Where(mr => mr.MedicationId == medicationId)
|
||||||
|
.OrderByDescending(mr => mr.CreatedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<MedicationRecord> MarkTakenAsync(Guid medicationId, Guid userId, string timeSlot)
|
||||||
|
{
|
||||||
|
// Find existing record for today's slot, update it instead of creating duplicate
|
||||||
|
var today = DateTime.UtcNow.Date;
|
||||||
|
var existing = await db.MedicationRecords
|
||||||
|
.FirstOrDefaultAsync(mr =>
|
||||||
|
mr.MedicationId == medicationId &&
|
||||||
|
mr.UserId == userId &&
|
||||||
|
mr.TimeSlot == timeSlot &&
|
||||||
|
mr.TakenAt.HasValue &&
|
||||||
|
mr.TakenAt.Value.Date == today);
|
||||||
|
|
||||||
|
if (existing != null)
|
||||||
|
{
|
||||||
|
existing.TakenAt = DateTime.UtcNow;
|
||||||
|
existing.IsTaken = true;
|
||||||
|
existing.SkippedReason = null;
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
var record = new MedicationRecord
|
||||||
|
{
|
||||||
|
MedicationId = medicationId,
|
||||||
|
UserId = userId,
|
||||||
|
TimeSlot = timeSlot,
|
||||||
|
IsTaken = true,
|
||||||
|
TakenAt = DateTime.UtcNow,
|
||||||
|
};
|
||||||
|
db.MedicationRecords.Add(record);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<decimal> GetAdherenceRateAsync(Guid medicationId, int days = 30)
|
||||||
|
{
|
||||||
|
var medication = await db.Medications.FindAsync(medicationId);
|
||||||
|
if (medication == null) return 0;
|
||||||
|
|
||||||
|
var cutoff = DateTime.UtcNow.AddDays(-days);
|
||||||
|
var allRecords = await db.MedicationRecords
|
||||||
|
.Where(mr => mr.MedicationId == medicationId && mr.CreatedAt >= cutoff)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var takenCount = allRecords.Count(mr => mr.IsTaken);
|
||||||
|
var totalCount = allRecords.Count;
|
||||||
|
|
||||||
|
return totalCount > 0 ? Math.Round((decimal)takenCount / totalCount * 100, 1) : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using HealthManager.Domain.Entities;
|
||||||
|
using HealthManager.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace HealthManager.Application.Services;
|
||||||
|
|
||||||
|
public class NotificationService(AppDbContext db)
|
||||||
|
{
|
||||||
|
public async Task<List<Notification>> GetUserNotificationsAsync(Guid userId)
|
||||||
|
=> await db.Notifications
|
||||||
|
.Where(n => n.UserId == userId)
|
||||||
|
.OrderByDescending(n => n.CreatedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<int> GetUnreadCountAsync(Guid userId)
|
||||||
|
=> await db.Notifications.CountAsync(n => n.UserId == userId && !n.IsRead);
|
||||||
|
|
||||||
|
public async Task MarkAsReadAsync(Guid notificationId)
|
||||||
|
{
|
||||||
|
var notification = await db.Notifications.FindAsync(notificationId);
|
||||||
|
if (notification != null && !notification.IsRead)
|
||||||
|
{
|
||||||
|
notification.IsRead = true;
|
||||||
|
notification.ReadAt = DateTime.UtcNow;
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task MarkAllAsReadAsync(Guid userId)
|
||||||
|
{
|
||||||
|
var unread = await db.Notifications.Where(n => n.UserId == userId && !n.IsRead).ToListAsync();
|
||||||
|
foreach (var n in unread)
|
||||||
|
{
|
||||||
|
n.IsRead = true;
|
||||||
|
n.ReadAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task CreateAsync(Guid userId, string type, string title, string content, Guid? relatedId = null)
|
||||||
|
{
|
||||||
|
db.Notifications.Add(new Notification
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
Type = type,
|
||||||
|
Title = title,
|
||||||
|
Content = content,
|
||||||
|
RelatedId = relatedId,
|
||||||
|
});
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using HealthManager.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace HealthManager.Application.Services;
|
||||||
|
|
||||||
|
public class PatientService(AppDbContext db)
|
||||||
|
{
|
||||||
|
public async Task<List<object>> GetPatientsAsync(string? search, string? department, int page = 1, int pageSize = 20)
|
||||||
|
{
|
||||||
|
var query = db.Users.Where(u => u.Role == "patient" && !u.IsDeleted);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(search))
|
||||||
|
query = query.Where(u => u.Name.Contains(search) || u.Phone.Contains(search));
|
||||||
|
|
||||||
|
var patients = await query
|
||||||
|
.OrderByDescending(u => u.CreatedAt)
|
||||||
|
.Skip((page - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.Select(u => new
|
||||||
|
{
|
||||||
|
u.Id, u.Name, u.Phone, u.Gender, u.Birthday,
|
||||||
|
u.StentDate, u.StentType,
|
||||||
|
u.CreatedAt,
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return patients.Cast<object>().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<object?> GetPatientDetailAsync(Guid patientId)
|
||||||
|
{
|
||||||
|
return await db.Users
|
||||||
|
.Where(u => u.Id == patientId && u.Role == "patient" && !u.IsDeleted)
|
||||||
|
.Select(u => new
|
||||||
|
{
|
||||||
|
u.Id, u.Name, u.Phone, u.Gender, u.Birthday,
|
||||||
|
u.HeightCm, u.WeightKg, u.MedicalHistory,
|
||||||
|
u.StentDate, u.StentType,
|
||||||
|
u.CreatedAt,
|
||||||
|
})
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using HealthManager.Domain.Entities;
|
||||||
|
using HealthManager.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace HealthManager.Application.Services;
|
||||||
|
|
||||||
|
public class ReportService(AppDbContext db)
|
||||||
|
{
|
||||||
|
public async Task<List<Report>> GetPatientReportsAsync(Guid patientId)
|
||||||
|
=> await db.Reports
|
||||||
|
.Include(r => r.Doctor)
|
||||||
|
.Include(r => r.Items)
|
||||||
|
.Where(r => r.PatientId == patientId)
|
||||||
|
.OrderByDescending(r => r.UploadedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<Report?> GetByIdAsync(Guid id)
|
||||||
|
=> await db.Reports
|
||||||
|
.Include(r => r.Patient)
|
||||||
|
.Include(r => r.Doctor)
|
||||||
|
.Include(r => r.Items)
|
||||||
|
.FirstOrDefaultAsync(r => r.Id == id);
|
||||||
|
|
||||||
|
public async Task<Report> UploadAsync(Guid patientId, string title, string category, List<string> imageUrls)
|
||||||
|
{
|
||||||
|
var report = new Report
|
||||||
|
{
|
||||||
|
PatientId = patientId,
|
||||||
|
Title = title,
|
||||||
|
Category = category,
|
||||||
|
ImageUrls = imageUrls,
|
||||||
|
UploadedBy = patientId,
|
||||||
|
};
|
||||||
|
db.Reports.Add(report);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<Report>> GetPendingAsync()
|
||||||
|
=> await db.Reports
|
||||||
|
.Include(r => r.Patient)
|
||||||
|
.Where(r => r.Status == "pending")
|
||||||
|
.OrderByDescending(r => r.UploadedAt)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
public async Task<Report> InterpretAsync(Guid reportId, Guid doctorId, string summary,
|
||||||
|
List<(string name, string value, string? unit, string? range, bool abnormal)> items,
|
||||||
|
string riskLevel, string? suggestions)
|
||||||
|
{
|
||||||
|
var report = await db.Reports.FindAsync(reportId) ?? throw new InvalidOperationException("Report not found");
|
||||||
|
report.DoctorId = doctorId;
|
||||||
|
report.Status = "completed";
|
||||||
|
report.Summary = summary;
|
||||||
|
report.RiskLevel = riskLevel;
|
||||||
|
report.Suggestions = suggestions;
|
||||||
|
report.CompletedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
var order = 0;
|
||||||
|
foreach (var (name, value, unit, range, abnormal) in items)
|
||||||
|
{
|
||||||
|
db.ReportItems.Add(new ReportItem
|
||||||
|
{
|
||||||
|
ReportId = reportId,
|
||||||
|
ItemName = name,
|
||||||
|
ResultValue = value,
|
||||||
|
Unit = unit,
|
||||||
|
ReferenceRange = range,
|
||||||
|
IsAbnormal = abnormal,
|
||||||
|
SortOrder = order++,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
backend/src/HealthManager.Domain/Entities/Consultation.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class Consultation
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid PatientId { get; set; }
|
||||||
|
public Guid DoctorId { get; set; }
|
||||||
|
public string? Subject { get; set; }
|
||||||
|
public string Status { get; set; } = "active"; // active, closed
|
||||||
|
public DateTime StartedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
public DateTime? ClosedAt { get; set; }
|
||||||
|
public Guid? ClosedBy { get; set; }
|
||||||
|
public string? Summary { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public User Patient { get; set; } = null!;
|
||||||
|
public User Doctor { get; set; } = null!;
|
||||||
|
public ICollection<ConsultationMessage> Messages { get; set; } = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class ConsultationMessage
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid ConsultationId { get; set; }
|
||||||
|
public Guid SenderId { get; set; }
|
||||||
|
public string SenderRole { get; set; } = string.Empty; // patient, doctor, system
|
||||||
|
public string ContentType { get; set; } = "text"; // text, image, file, template
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
public string? ImageUrl { get; set; }
|
||||||
|
public string? FileUrl { get; set; }
|
||||||
|
public bool IsRead { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public Consultation Consultation { get; set; } = null!;
|
||||||
|
public User Sender { get; set; } = null!;
|
||||||
|
}
|
||||||
18
backend/src/HealthManager.Domain/Entities/Device.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class Device
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid? UserId { get; set; }
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
public string? MacAddress { get; set; }
|
||||||
|
public string? SerialNumber { get; set; }
|
||||||
|
public bool IsBound { get; set; }
|
||||||
|
public DateTime? BoundAt { get; set; }
|
||||||
|
public DateTime? LastSyncAt { get; set; }
|
||||||
|
public int? BatteryLevel { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public User? User { get; set; }
|
||||||
|
}
|
||||||
16
backend/src/HealthManager.Domain/Entities/DietRecord.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class DietRecord
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public string MealType { get; set; } = string.Empty; // breakfast, lunch, dinner, snack
|
||||||
|
public string FoodName { get; set; } = string.Empty;
|
||||||
|
public string? Portion { get; set; }
|
||||||
|
public int? Calories { get; set; }
|
||||||
|
public string? Notes { get; set; }
|
||||||
|
public DateOnly RecordedAt { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public User User { get; set; } = null!;
|
||||||
|
}
|
||||||
16
backend/src/HealthManager.Domain/Entities/ExerciseRecord.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class ExerciseRecord
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public string ExerciseType { get; set; } = string.Empty;
|
||||||
|
public int DurationMin { get; set; }
|
||||||
|
public string? Intensity { get; set; } // low, moderate, high
|
||||||
|
public int? CaloriesBurned { get; set; }
|
||||||
|
public string? Notes { get; set; }
|
||||||
|
public DateOnly RecordedAt { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public User User { get; set; } = null!;
|
||||||
|
}
|
||||||
19
backend/src/HealthManager.Domain/Entities/FollowUp.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class FollowUp
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid PatientId { get; set; }
|
||||||
|
public Guid? DoctorId { get; set; }
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string? Description { get; set; }
|
||||||
|
public DateTime ScheduledAt { get; set; }
|
||||||
|
public string Status { get; set; } = "upcoming"; // upcoming, completed, cancelled, rescheduled
|
||||||
|
public string? Notes { get; set; }
|
||||||
|
public bool ReminderEnabled { get; set; } = true;
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public User Patient { get; set; } = null!;
|
||||||
|
public User? Doctor { get; set; }
|
||||||
|
}
|
||||||
18
backend/src/HealthManager.Domain/Entities/HealthRecord.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class HealthRecord
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public string Type { get; set; } = string.Empty; // blood_pressure, heart_rate, blood_sugar, spo2, weight, steps
|
||||||
|
public JsonDocument Value { get; set; } = null!;
|
||||||
|
public string Unit { get; set; } = string.Empty;
|
||||||
|
public DateTime RecordedAt { get; set; }
|
||||||
|
public string Source { get; set; } = "manual"; // manual, device, doctor
|
||||||
|
public string? Notes { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public User User { get; set; } = null!;
|
||||||
|
}
|
||||||
22
backend/src/HealthManager.Domain/Entities/Medication.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class Medication
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public Guid? DoctorId { get; set; }
|
||||||
|
public string DrugName { get; set; } = string.Empty;
|
||||||
|
public string Dosage { get; set; } = string.Empty;
|
||||||
|
public string Frequency { get; set; } = string.Empty;
|
||||||
|
public List<string> TimeSlots { get; set; } = [];
|
||||||
|
public DateOnly StartDate { get; set; }
|
||||||
|
public DateOnly? EndDate { get; set; }
|
||||||
|
public string? Notes { get; set; }
|
||||||
|
public string Status { get; set; } = "active"; // active, completed, stopped
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public User User { get; set; } = null!;
|
||||||
|
public User? Doctor { get; set; }
|
||||||
|
public ICollection<MedicationRecord> Records { get; set; } = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class MedicationRecord
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid MedicationId { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public string TimeSlot { get; set; } = string.Empty;
|
||||||
|
public DateTime? TakenAt { get; set; }
|
||||||
|
public bool IsTaken { get; set; }
|
||||||
|
public string? SkippedReason { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public Medication Medication { get; set; } = null!;
|
||||||
|
public User User { get; set; } = null!;
|
||||||
|
}
|
||||||
16
backend/src/HealthManager.Domain/Entities/Notification.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class Notification
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public string Type { get; set; } = string.Empty; // medication_reminder, followup_reminder, consultation_new, report_completed, health_alert, system
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
public Guid? RelatedId { get; set; }
|
||||||
|
public bool IsRead { get; set; }
|
||||||
|
public DateTime? ReadAt { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public User User { get; set; } = null!;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class QuickReplyTemplate
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid DoctorId { get; set; }
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
public string? Category { get; set; }
|
||||||
|
public int SortOrder { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public User Doctor { get; set; } = null!;
|
||||||
|
}
|
||||||
13
backend/src/HealthManager.Domain/Entities/RefreshToken.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class RefreshToken
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public string Token { get; set; } = string.Empty;
|
||||||
|
public DateTime ExpiresAt { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
public DateTime? RevokedAt { get; set; }
|
||||||
|
|
||||||
|
public User User { get; set; } = null!;
|
||||||
|
}
|
||||||
22
backend/src/HealthManager.Domain/Entities/Report.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class Report
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid PatientId { get; set; }
|
||||||
|
public Guid? DoctorId { get; set; }
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string Category { get; set; } = string.Empty;
|
||||||
|
public List<string> ImageUrls { get; set; } = [];
|
||||||
|
public string Status { get; set; } = "pending"; // pending, interpreting, completed
|
||||||
|
public string? RiskLevel { get; set; } // normal, attention, abnormal
|
||||||
|
public string? Summary { get; set; }
|
||||||
|
public string? Suggestions { get; set; }
|
||||||
|
public Guid UploadedBy { get; set; }
|
||||||
|
public DateTime UploadedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
public DateTime? CompletedAt { get; set; }
|
||||||
|
|
||||||
|
public User Patient { get; set; } = null!;
|
||||||
|
public User? Doctor { get; set; }
|
||||||
|
public ICollection<ReportItem> Items { get; set; } = [];
|
||||||
|
}
|
||||||
15
backend/src/HealthManager.Domain/Entities/ReportItem.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class ReportItem
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid ReportId { get; set; }
|
||||||
|
public string ItemName { get; set; } = string.Empty;
|
||||||
|
public string ResultValue { get; set; } = string.Empty;
|
||||||
|
public string? Unit { get; set; }
|
||||||
|
public string? ReferenceRange { get; set; }
|
||||||
|
public bool IsAbnormal { get; set; }
|
||||||
|
public int SortOrder { get; set; }
|
||||||
|
|
||||||
|
public Report Report { get; set; } = null!;
|
||||||
|
}
|
||||||
41
backend/src/HealthManager.Domain/Entities/User.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
namespace HealthManager.Domain.Entities;
|
||||||
|
|
||||||
|
public class User
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Role { get; set; } = string.Empty; // patient, doctor, admin
|
||||||
|
public string Phone { get; set; } = string.Empty;
|
||||||
|
public string PasswordHash { get; set; } = string.Empty;
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public string? AvatarUrl { get; set; }
|
||||||
|
|
||||||
|
// Patient fields
|
||||||
|
public string? Gender { get; set; }
|
||||||
|
public DateOnly? Birthday { get; set; }
|
||||||
|
public decimal? HeightCm { get; set; }
|
||||||
|
public decimal? WeightKg { get; set; }
|
||||||
|
public List<string>? MedicalHistory { get; set; }
|
||||||
|
public DateOnly? StentDate { get; set; }
|
||||||
|
public string? StentType { get; set; }
|
||||||
|
|
||||||
|
// Doctor fields
|
||||||
|
public string? Department { get; set; }
|
||||||
|
public string? Title { get; set; }
|
||||||
|
public List<string>? Specialty { get; set; }
|
||||||
|
public string? Introduction { get; set; }
|
||||||
|
public bool IsAvailable { get; set; } = true;
|
||||||
|
|
||||||
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
public bool IsDeleted { get; set; }
|
||||||
|
public DateTime? DeletedAt { get; set; }
|
||||||
|
|
||||||
|
// Navigation
|
||||||
|
public ICollection<RefreshToken> RefreshTokens { get; set; } = [];
|
||||||
|
public ICollection<HealthRecord> HealthRecords { get; set; } = [];
|
||||||
|
public ICollection<Medication> Medications { get; set; } = [];
|
||||||
|
public ICollection<MedicationRecord> MedicationRecords { get; set; } = [];
|
||||||
|
public ICollection<ExerciseRecord> ExerciseRecords { get; set; } = [];
|
||||||
|
public ICollection<DietRecord> DietRecords { get; set; } = [];
|
||||||
|
public ICollection<Notification> Notifications { get; set; } = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace HealthManager.Domain.Interfaces;
|
||||||
|
|
||||||
|
public interface IJwtProvider
|
||||||
|
{
|
||||||
|
string GenerateAccessToken(Guid userId, string name, string role);
|
||||||
|
string GenerateRefreshToken();
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\HealthManager.Domain\HealthManager.Domain.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.18.0" />
|
||||||
|
<PackageReference Include="Minio" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.1" />
|
||||||
|
<PackageReference Include="StackExchange.Redis" Version="2.13.1" />
|
||||||
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.18.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using HealthManager.Domain.Interfaces;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
||||||
|
namespace HealthManager.Infrastructure.Services;
|
||||||
|
|
||||||
|
public class JwtProvider(IConfiguration configuration) : IJwtProvider
|
||||||
|
{
|
||||||
|
private static readonly JwtSecurityTokenHandler TokenHandler = new();
|
||||||
|
public string GenerateAccessToken(Guid userId, string name, string role)
|
||||||
|
{
|
||||||
|
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Secret"]!));
|
||||||
|
var claims = new[]
|
||||||
|
{
|
||||||
|
new Claim(ClaimTypes.NameIdentifier, userId.ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, name),
|
||||||
|
new Claim(ClaimTypes.Role, role),
|
||||||
|
};
|
||||||
|
|
||||||
|
var token = new JwtSecurityToken(
|
||||||
|
issuer: configuration["Jwt:Issuer"],
|
||||||
|
audience: configuration["Jwt:Audience"],
|
||||||
|
claims: claims,
|
||||||
|
expires: DateTime.UtcNow.AddMinutes(30),
|
||||||
|
signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256));
|
||||||
|
|
||||||
|
return TokenHandler.WriteToken(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GenerateRefreshToken()
|
||||||
|
{
|
||||||
|
var bytes = RandomNumberGenerator.GetBytes(64);
|
||||||
|
return Convert.ToBase64String(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
120
backend/src/HealthManager.WebApi/Controllers/AuthController.cs
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using HealthManager.Application.DTOs.Auth;
|
||||||
|
using HealthManager.Domain.Interfaces;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using HealthManager.Domain.Entities;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HealthManager.WebApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/auth")]
|
||||||
|
public class AuthController(
|
||||||
|
AuthService authService,
|
||||||
|
IJwtProvider jwtProvider) : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpPost("send-sms")]
|
||||||
|
public IActionResult SendSms([FromBody] SendSmsRequest request)
|
||||||
|
{
|
||||||
|
// Demo: always succeed
|
||||||
|
return Ok(new { message = "验证码已发送" });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("login")]
|
||||||
|
public async Task<IActionResult> Login([FromBody] LoginRequest request)
|
||||||
|
{
|
||||||
|
var user = await authService.GetUserByPhoneAsync(request.Phone);
|
||||||
|
if (user == null)
|
||||||
|
return Unauthorized(new { message = "用户不存在" });
|
||||||
|
|
||||||
|
// Demo: accept any SMS code
|
||||||
|
var accessToken = jwtProvider.GenerateAccessToken(user.Id, user.Name, user.Role);
|
||||||
|
var refreshToken = jwtProvider.GenerateRefreshToken();
|
||||||
|
await authService.SaveRefreshTokenAsync(user.Id, refreshToken, DateTime.UtcNow.AddDays(7));
|
||||||
|
|
||||||
|
return Ok(new AuthResponse(user.Id, user.Name, user.Role, accessToken, refreshToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("register")]
|
||||||
|
public async Task<IActionResult> Register([FromBody] RegisterRequest request)
|
||||||
|
{
|
||||||
|
var existing = await authService.GetUserByPhoneAsync(request.Phone);
|
||||||
|
if (existing != null)
|
||||||
|
return Conflict(new { message = "该手机号已注册" });
|
||||||
|
|
||||||
|
var user = new User
|
||||||
|
{
|
||||||
|
Phone = request.Phone,
|
||||||
|
Name = request.Name,
|
||||||
|
Role = "patient",
|
||||||
|
PasswordHash = AuthService.HashPassword("demo123"),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Access DbContext via DI
|
||||||
|
var db = HttpContext.RequestServices.GetRequiredService<Infrastructure.Data.AppDbContext>();
|
||||||
|
db.Users.Add(user);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
var accessToken = jwtProvider.GenerateAccessToken(user.Id, user.Name, user.Role);
|
||||||
|
var refreshToken = jwtProvider.GenerateRefreshToken();
|
||||||
|
await authService.SaveRefreshTokenAsync(user.Id, refreshToken, DateTime.UtcNow.AddDays(7));
|
||||||
|
|
||||||
|
return Ok(new AuthResponse(user.Id, user.Name, user.Role, accessToken, refreshToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("refresh")]
|
||||||
|
public async Task<IActionResult> RefreshToken([FromBody] RefreshTokenRequest request)
|
||||||
|
{
|
||||||
|
var saved = await authService.GetRefreshTokenAsync(request.RefreshToken);
|
||||||
|
if (saved == null)
|
||||||
|
return Unauthorized(new { message = "无效的刷新令牌" });
|
||||||
|
|
||||||
|
await authService.RevokeRefreshTokenAsync(saved.UserId);
|
||||||
|
|
||||||
|
var accessToken = jwtProvider.GenerateAccessToken(saved.User.Id, saved.User.Name, saved.User.Role);
|
||||||
|
var refreshToken = jwtProvider.GenerateRefreshToken();
|
||||||
|
await authService.SaveRefreshTokenAsync(saved.UserId, refreshToken, DateTime.UtcNow.AddDays(7));
|
||||||
|
|
||||||
|
return Ok(new AuthResponse(saved.User.Id, saved.User.Name, saved.User.Role, accessToken, refreshToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("me")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> GetProfile()
|
||||||
|
{
|
||||||
|
var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||||
|
var db = HttpContext.RequestServices.GetRequiredService<Infrastructure.Data.AppDbContext>();
|
||||||
|
var user = await db.Users.FindAsync(userId);
|
||||||
|
if (user == null) return NotFound();
|
||||||
|
|
||||||
|
return Ok(new UserProfileResponse(
|
||||||
|
user.Id, user.Name, user.Phone, user.Role,
|
||||||
|
user.Gender, user.Birthday, user.HeightCm, user.WeightKg,
|
||||||
|
user.MedicalHistory, user.StentDate, user.StentType,
|
||||||
|
user.Department, user.Title, user.Specialty, user.Introduction));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("me")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> UpdateProfile([FromBody] UpdateProfileRequest request)
|
||||||
|
{
|
||||||
|
var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||||
|
var db = HttpContext.RequestServices.GetRequiredService<Infrastructure.Data.AppDbContext>();
|
||||||
|
var user = await db.Users.FindAsync(userId);
|
||||||
|
if (user == null) return NotFound();
|
||||||
|
|
||||||
|
if (request.Name != null) user.Name = request.Name;
|
||||||
|
if (request.Gender != null) user.Gender = request.Gender;
|
||||||
|
if (request.Birthday.HasValue) user.Birthday = request.Birthday;
|
||||||
|
if (request.HeightCm.HasValue) user.HeightCm = request.HeightCm;
|
||||||
|
if (request.WeightKg.HasValue) user.WeightKg = request.WeightKg;
|
||||||
|
if (request.MedicalHistory != null) user.MedicalHistory = request.MedicalHistory;
|
||||||
|
user.UpdatedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return Ok(new { message = "更新成功" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record RefreshTokenRequest(string RefreshToken);
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HealthManager.WebApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/consultations")]
|
||||||
|
[Authorize]
|
||||||
|
public class ConsultationController(ConsultationService consultationService) : ControllerBase
|
||||||
|
{
|
||||||
|
private Guid UserId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||||
|
private string Role => User.FindFirstValue(ClaimTypes.Role)!;
|
||||||
|
|
||||||
|
[HttpGet("doctors")]
|
||||||
|
public async Task<IActionResult> GetDoctors([FromQuery] string? department)
|
||||||
|
{
|
||||||
|
var doctors = await consultationService.GetDoctorsAsync(department);
|
||||||
|
return Ok(doctors.Select(d => new
|
||||||
|
{
|
||||||
|
d.Id, d.Name, d.Department, d.Title, d.Specialty, d.Introduction, d.AvatarUrl,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetConsultations()
|
||||||
|
{
|
||||||
|
var consultations = Role == "doctor"
|
||||||
|
? await consultationService.GetDoctorConsultationsAsync(UserId)
|
||||||
|
: await consultationService.GetPatientConsultationsAsync(UserId);
|
||||||
|
|
||||||
|
return Ok(consultations.Select(c => new
|
||||||
|
{
|
||||||
|
c.Id, c.PatientId, c.DoctorId,
|
||||||
|
PatientName = c.Patient?.Name,
|
||||||
|
DoctorName = c.Doctor?.Name,
|
||||||
|
c.Subject, c.Status, c.StartedAt, c.ClosedAt, c.Summary,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> StartConsultation([FromBody] StartConsultationRequest request)
|
||||||
|
{
|
||||||
|
var consultation = await consultationService.StartAsync(UserId, request.DoctorId, request.Subject);
|
||||||
|
return Ok(new { consultation.Id, consultation.PatientId, consultation.DoctorId, consultation.Status });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:guid}/messages")]
|
||||||
|
public async Task<IActionResult> GetMessages(Guid id)
|
||||||
|
{
|
||||||
|
var messages = await consultationService.GetMessagesAsync(id);
|
||||||
|
return Ok(messages.Select(m => new
|
||||||
|
{
|
||||||
|
m.Id, m.SenderId, m.SenderRole, m.ContentType, m.Content,
|
||||||
|
m.ImageUrl, m.IsRead, m.CreatedAt,
|
||||||
|
SenderName = m.Sender?.Name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("{id:guid}/messages")]
|
||||||
|
public async Task<IActionResult> SendMessage(Guid id, [FromBody] SendMessageRequest request)
|
||||||
|
{
|
||||||
|
var message = await consultationService.SendMessageAsync(id, UserId, Role, request.Content,
|
||||||
|
request.ContentType, request.ImageUrl);
|
||||||
|
return Ok(new { message.Id, message.SenderId, message.SenderRole, message.Content, message.CreatedAt });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record StartConsultationRequest(Guid DoctorId, string Subject);
|
||||||
|
public record SendMessageRequest(string Content, string ContentType = "text", string? ImageUrl = null);
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HealthManager.WebApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/follow-ups")]
|
||||||
|
[Authorize]
|
||||||
|
public class FollowUpController(FollowUpService followUpService) : ControllerBase
|
||||||
|
{
|
||||||
|
private Guid UserId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||||
|
private string Role => User.FindFirstValue(ClaimTypes.Role)!;
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetFollowUps()
|
||||||
|
{
|
||||||
|
var followUps = Role == "doctor"
|
||||||
|
? await followUpService.GetDoctorFollowUpsAsync(UserId)
|
||||||
|
: await followUpService.GetPatientFollowUpsAsync(UserId);
|
||||||
|
|
||||||
|
return Ok(followUps.Select(f => new
|
||||||
|
{
|
||||||
|
f.Id, f.PatientId, f.DoctorId, f.Title, f.Description,
|
||||||
|
f.ScheduledAt, f.Status, f.Notes, f.ReminderEnabled, f.CreatedAt,
|
||||||
|
PatientName = f.Patient?.Name,
|
||||||
|
DoctorName = f.Doctor?.Name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:guid}")]
|
||||||
|
public async Task<IActionResult> GetFollowUp(Guid id)
|
||||||
|
{
|
||||||
|
var followUp = await followUpService.GetByIdAsync(id);
|
||||||
|
if (followUp == null) return NotFound(new { message = "复查不存在" });
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
followUp.Id, followUp.PatientId, followUp.DoctorId, followUp.Title,
|
||||||
|
followUp.Description, followUp.ScheduledAt, followUp.Status,
|
||||||
|
followUp.Notes, followUp.ReminderEnabled, followUp.CreatedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> AddFollowUp([FromBody] FollowUpCreateRequest request)
|
||||||
|
{
|
||||||
|
var followUp = await followUpService.AddAsync(UserId, request.Title, request.Description,
|
||||||
|
request.ScheduledAt, request.ReminderEnabled);
|
||||||
|
return Ok(new { followUp.Id, followUp.Title, followUp.Status });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("{id:guid}")]
|
||||||
|
[Authorize(Roles = "doctor")]
|
||||||
|
public async Task<IActionResult> UpdateFollowUp(Guid id, [FromBody] FollowUpUpdateRequest request)
|
||||||
|
{
|
||||||
|
var followUp = await followUpService.UpdateAsync(id, UserId, request.Title, request.Description,
|
||||||
|
request.ScheduledAt, request.Status, request.Notes);
|
||||||
|
if (followUp == null) return NotFound(new { message = "复查不存在" });
|
||||||
|
return Ok(new { followUp.Id, followUp.Title, followUp.Status });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record FollowUpCreateRequest(string Title, string? Description, DateTime ScheduledAt, bool ReminderEnabled = true);
|
||||||
|
|
||||||
|
public record FollowUpUpdateRequest(
|
||||||
|
string? Title, string? Description, DateTime? ScheduledAt, string? Status, string? Notes);
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using System.Text.Json;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HealthManager.WebApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/health-records")]
|
||||||
|
[Authorize]
|
||||||
|
public class HealthController(HealthService healthService) : ControllerBase
|
||||||
|
{
|
||||||
|
private Guid UserId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||||
|
private string Role => User.FindFirstValue(ClaimTypes.Role)!;
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetRecords([FromQuery] string? type, [FromQuery] int days = 30)
|
||||||
|
{
|
||||||
|
var targetUserId = UserId;
|
||||||
|
|
||||||
|
// Doctors can query any patient
|
||||||
|
if (Role == "doctor" && Request.Query.ContainsKey("patientId"))
|
||||||
|
targetUserId = Guid.Parse(Request.Query["patientId"]!);
|
||||||
|
|
||||||
|
var records = await healthService.GetRecordsAsync(targetUserId, type, days);
|
||||||
|
return Ok(records.Select(r => new
|
||||||
|
{
|
||||||
|
r.Id, r.Type, Value = r.Value.RootElement.GetRawText(), r.Unit,
|
||||||
|
r.RecordedAt, r.Source, r.Notes, r.CreatedAt,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("stats")]
|
||||||
|
public async Task<IActionResult> GetStats()
|
||||||
|
{
|
||||||
|
var stats = await healthService.GetStatsAsync(UserId);
|
||||||
|
return Ok(stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("latest/{type}")]
|
||||||
|
public async Task<IActionResult> GetLatest(string type)
|
||||||
|
{
|
||||||
|
var record = await healthService.GetLatestAsync(UserId, type);
|
||||||
|
if (record == null) return Ok((object?)null);
|
||||||
|
return Ok(new { record.Id, record.Type, Value = record.Value.RootElement.GetRawText(), record.Unit, record.RecordedAt, record.Source });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> AddRecord([FromBody] HealthRecordCreateRequest request)
|
||||||
|
{
|
||||||
|
// Validate JSON
|
||||||
|
try { JsonDocument.Parse(request.ValueJson); }
|
||||||
|
catch (JsonException) { return BadRequest(new { message = "无效的数据格式" }); }
|
||||||
|
|
||||||
|
var record = await healthService.AddRecordAsync(UserId, request.Type, request.ValueJson, request.Unit, request.RecordedAt, request.Notes);
|
||||||
|
return Ok(new { record.Id, record.Type, Value = record.Value.RootElement.GetRawText(), record.Unit, record.RecordedAt, record.Source });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record HealthRecordCreateRequest(string Type, string ValueJson, string Unit, DateTime RecordedAt, string? Notes);
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HealthManager.WebApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/medications")]
|
||||||
|
[Authorize]
|
||||||
|
public class MedicationController(MedicationService medicationService) : ControllerBase
|
||||||
|
{
|
||||||
|
private Guid UserId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||||
|
private string Role => User.FindFirstValue(ClaimTypes.Role)!;
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetMedications()
|
||||||
|
{
|
||||||
|
var targetUserId = UserId;
|
||||||
|
if (Role == "doctor" && Request.Query.ContainsKey("patientId"))
|
||||||
|
targetUserId = Guid.Parse(Request.Query["patientId"]!);
|
||||||
|
|
||||||
|
var medications = await medicationService.GetUserMedicationsAsync(targetUserId);
|
||||||
|
return Ok(medications.Select(m => new
|
||||||
|
{
|
||||||
|
m.Id, m.UserId, m.DrugName, m.Dosage, m.Frequency, m.TimeSlots,
|
||||||
|
m.StartDate, m.EndDate, m.Notes, m.Status, m.CreatedAt,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> AddMedication([FromBody] MedicationCreateRequest request)
|
||||||
|
{
|
||||||
|
var med = await medicationService.AddAsync(UserId, request.DrugName, request.Dosage,
|
||||||
|
request.Frequency, request.TimeSlots, request.StartDate, request.EndDate, request.Notes);
|
||||||
|
return Ok(new { med.Id, med.DrugName, med.Dosage, med.Frequency, med.Status });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:guid}")]
|
||||||
|
public async Task<IActionResult> GetMedication(Guid id)
|
||||||
|
{
|
||||||
|
var med = await medicationService.GetByIdAsync(id);
|
||||||
|
if (med == null) return NotFound(new { message = "药品不存在" });
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
med.Id, med.UserId, med.DrugName, med.Dosage, med.Frequency, med.TimeSlots,
|
||||||
|
med.StartDate, med.EndDate, med.Notes, med.Status, med.CreatedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:guid}/records")]
|
||||||
|
public async Task<IActionResult> GetRecords(Guid id)
|
||||||
|
{
|
||||||
|
var records = await medicationService.GetRecordsAsync(id);
|
||||||
|
return Ok(records.Select(r => new
|
||||||
|
{
|
||||||
|
r.Id, r.MedicationId, r.TimeSlot, r.TakenAt, r.IsTaken, r.SkippedReason, r.CreatedAt,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("{id:guid}/take")]
|
||||||
|
public async Task<IActionResult> MarkTaken(Guid id, [FromBody] MarkTakenRequest request)
|
||||||
|
{
|
||||||
|
var record = await medicationService.MarkTakenAsync(id, UserId, request.TimeSlot);
|
||||||
|
return Ok(new { record.Id, record.TimeSlot, record.TakenAt, record.IsTaken });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:guid}/adherence")]
|
||||||
|
public async Task<IActionResult> GetAdherence(Guid id)
|
||||||
|
{
|
||||||
|
var rate = await medicationService.GetAdherenceRateAsync(id);
|
||||||
|
return Ok(new { medicationId = id, rate });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record MedicationCreateRequest(
|
||||||
|
string DrugName, string Dosage, string Frequency,
|
||||||
|
List<string> TimeSlots, DateOnly StartDate, DateOnly? EndDate, string? Notes);
|
||||||
|
|
||||||
|
public record MarkTakenRequest(string TimeSlot);
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HealthManager.WebApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/notifications")]
|
||||||
|
[Authorize]
|
||||||
|
public class NotificationController(NotificationService notificationService) : ControllerBase
|
||||||
|
{
|
||||||
|
private Guid UserId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetNotifications()
|
||||||
|
{
|
||||||
|
var notifications = await notificationService.GetUserNotificationsAsync(UserId);
|
||||||
|
return Ok(notifications.Select(n => new
|
||||||
|
{
|
||||||
|
n.Id, n.Type, n.Title, n.Content, n.RelatedId,
|
||||||
|
n.IsRead, n.ReadAt, n.CreatedAt,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("unread-count")]
|
||||||
|
public async Task<IActionResult> GetUnreadCount()
|
||||||
|
{
|
||||||
|
var count = await notificationService.GetUnreadCountAsync(UserId);
|
||||||
|
return Ok(new { count });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("{id:guid}/read")]
|
||||||
|
public async Task<IActionResult> MarkAsRead(Guid id)
|
||||||
|
{
|
||||||
|
await notificationService.MarkAsReadAsync(id);
|
||||||
|
return Ok(new { message = "已标记为已读" });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("read-all")]
|
||||||
|
public async Task<IActionResult> MarkAllAsRead()
|
||||||
|
{
|
||||||
|
await notificationService.MarkAllAsReadAsync(UserId);
|
||||||
|
return Ok(new { message = "全部已读" });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HealthManager.WebApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/patients")]
|
||||||
|
[Authorize(Roles = "doctor")]
|
||||||
|
public class PatientController(PatientService patientService) : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetPatients([FromQuery] string? search, [FromQuery] int page = 1, [FromQuery] int pageSize = 20)
|
||||||
|
{
|
||||||
|
var patients = await patientService.GetPatientsAsync(search, null, page, pageSize);
|
||||||
|
return Ok(patients);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:guid}")]
|
||||||
|
public async Task<IActionResult> GetPatientDetail(Guid id)
|
||||||
|
{
|
||||||
|
var patient = await patientService.GetPatientDetailAsync(id);
|
||||||
|
if (patient == null) return NotFound(new { message = "患者不存在" });
|
||||||
|
return Ok(patient);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HealthManager.WebApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/reports")]
|
||||||
|
[Authorize]
|
||||||
|
public class ReportController(ReportService reportService) : ControllerBase
|
||||||
|
{
|
||||||
|
private Guid UserId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||||
|
private string Role => User.FindFirstValue(ClaimTypes.Role)!;
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetReports()
|
||||||
|
{
|
||||||
|
var targetUserId = UserId;
|
||||||
|
if (Role == "doctor" && Request.Query.ContainsKey("patientId"))
|
||||||
|
targetUserId = Guid.Parse(Request.Query["patientId"]!);
|
||||||
|
|
||||||
|
var reports = await reportService.GetPatientReportsAsync(targetUserId);
|
||||||
|
return Ok(reports.Select(r => new
|
||||||
|
{
|
||||||
|
r.Id, r.PatientId, r.Title, r.Category, r.ImageUrls, r.Status,
|
||||||
|
r.RiskLevel, r.UploadedAt, r.CompletedAt,
|
||||||
|
DoctorName = r.Doctor?.Name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("pending")]
|
||||||
|
[Authorize(Roles = "doctor")]
|
||||||
|
public async Task<IActionResult> GetPending()
|
||||||
|
{
|
||||||
|
var reports = await reportService.GetPendingAsync();
|
||||||
|
return Ok(reports.Select(r => new
|
||||||
|
{
|
||||||
|
r.Id, r.PatientId, r.Title, r.Category, r.Status, r.UploadedAt,
|
||||||
|
PatientName = r.Patient?.Name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:guid}")]
|
||||||
|
public async Task<IActionResult> GetReport(Guid id)
|
||||||
|
{
|
||||||
|
var report = await reportService.GetByIdAsync(id);
|
||||||
|
if (report == null) return NotFound(new { message = "报告不存在" });
|
||||||
|
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
report.Id, report.PatientId, report.Title, report.Category, report.ImageUrls,
|
||||||
|
report.Status, report.RiskLevel, report.Summary, report.Suggestions,
|
||||||
|
report.UploadedAt, report.CompletedAt,
|
||||||
|
PatientName = report.Patient?.Name,
|
||||||
|
DoctorName = report.Doctor?.Name,
|
||||||
|
Items = report.Items.Select(i => new
|
||||||
|
{
|
||||||
|
i.Id, i.ItemName, i.ResultValue, i.Unit, i.ReferenceRange, i.IsAbnormal,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> UploadReport([FromBody] ReportUploadRequest request)
|
||||||
|
{
|
||||||
|
var report = await reportService.UploadAsync(UserId, request.Title, request.Category, request.ImageUrls);
|
||||||
|
return Ok(new { report.Id, report.Title, report.Status });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("{id:guid}/interpret")]
|
||||||
|
[Authorize(Roles = "doctor")]
|
||||||
|
public async Task<IActionResult> InterpretReport(Guid id, [FromBody] ReportInterpretRequest request)
|
||||||
|
{
|
||||||
|
var items = request.Items.Select(i => (i.ItemName, i.ResultValue, i.Unit, i.ReferenceRange, i.IsAbnormal)).ToList();
|
||||||
|
var report = await reportService.InterpretAsync(id, UserId, request.Summary, items, request.RiskLevel, request.Suggestions);
|
||||||
|
return Ok(new { report.Id, report.Status, report.RiskLevel });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record ReportUploadRequest(string Title, string Category, List<string> ImageUrls);
|
||||||
|
|
||||||
|
public record ReportInterpretRequest(
|
||||||
|
string Summary, List<ReportItemRequest> Items, string RiskLevel, string? Suggestions);
|
||||||
|
|
||||||
|
public record ReportItemRequest(
|
||||||
|
string ItemName, string ResultValue, string? Unit, string? ReferenceRange, bool IsAbnormal);
|
||||||
21
backend/src/HealthManager.WebApi/HealthManager.WebApi.csproj
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.8" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.8" />
|
||||||
|
<PackageReference Include="Microsoft.OpenApi" Version="2.4.1" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\HealthManager.Application\HealthManager.Application.csproj" />
|
||||||
|
<ProjectReference Include="..\HealthManager.Infrastructure\HealthManager.Infrastructure.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
@HealthManager.WebApi_HostAddress = http://localhost:5133
|
||||||
|
|
||||||
|
GET {{HealthManager.WebApi_HostAddress}}/weatherforecast/
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
||||||
40
backend/src/HealthManager.WebApi/Hubs/ChatHub.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
|
namespace HealthManager.WebApi.Hubs;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
public class ChatHub(ConsultationService consultationService) : Hub
|
||||||
|
{
|
||||||
|
public async Task JoinConsultation(Guid consultationId)
|
||||||
|
{
|
||||||
|
await Groups.AddToGroupAsync(Context.ConnectionId, $"consultation_{consultationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LeaveConsultation(Guid consultationId)
|
||||||
|
{
|
||||||
|
await Groups.RemoveFromGroupAsync(Context.ConnectionId, $"consultation_{consultationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SendMessage(Guid consultationId, string content)
|
||||||
|
{
|
||||||
|
var userId = Guid.Parse(Context.User!.FindFirstValue(ClaimTypes.NameIdentifier)!);
|
||||||
|
var role = Context.User!.FindFirstValue(ClaimTypes.Role)!;
|
||||||
|
|
||||||
|
var message = await consultationService.SendMessageAsync(consultationId, userId, role, content);
|
||||||
|
|
||||||
|
await Clients.Group($"consultation_{consultationId}").SendAsync("ReceiveMessage", new
|
||||||
|
{
|
||||||
|
message.Id,
|
||||||
|
message.SenderId,
|
||||||
|
message.SenderRole,
|
||||||
|
message.ContentType,
|
||||||
|
message.Content,
|
||||||
|
message.ImageUrl,
|
||||||
|
message.IsRead,
|
||||||
|
message.CreatedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
101
backend/src/HealthManager.WebApi/Program.cs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
using System.Text;
|
||||||
|
using HealthManager.Domain.Interfaces;
|
||||||
|
using HealthManager.Application.Services;
|
||||||
|
using HealthManager.Infrastructure.Data;
|
||||||
|
using HealthManager.Infrastructure.Services;
|
||||||
|
using HealthManager.WebApi.Hubs;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Database
|
||||||
|
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||||
|
options.UseNpgsql(builder.Configuration.GetConnectionString("Default")));
|
||||||
|
|
||||||
|
// JWT
|
||||||
|
var jwtSecret = builder.Configuration["Jwt:Secret"]!;
|
||||||
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidateLifetime = true,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidIssuer = builder.Configuration["Jwt:Issuer"],
|
||||||
|
ValidAudience = builder.Configuration["Jwt:Audience"],
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSecret)),
|
||||||
|
};
|
||||||
|
options.Events = new JwtBearerEvents
|
||||||
|
{
|
||||||
|
OnMessageReceived = context =>
|
||||||
|
{
|
||||||
|
var accessToken = context.Request.Query["access_token"];
|
||||||
|
var path = context.HttpContext.Request.Path;
|
||||||
|
if (!string.IsNullOrEmpty(accessToken) && path.StartsWithSegments("/hubs"))
|
||||||
|
context.Token = accessToken;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
builder.Services.AddAuthorization();
|
||||||
|
|
||||||
|
// Services
|
||||||
|
builder.Services.AddSingleton<IJwtProvider, JwtProvider>();
|
||||||
|
builder.Services.AddScoped<AuthService>();
|
||||||
|
builder.Services.AddScoped<HealthService>();
|
||||||
|
builder.Services.AddScoped<MedicationService>();
|
||||||
|
builder.Services.AddScoped<ConsultationService>();
|
||||||
|
builder.Services.AddScoped<ReportService>();
|
||||||
|
builder.Services.AddScoped<FollowUpService>();
|
||||||
|
builder.Services.AddScoped<PatientService>();
|
||||||
|
builder.Services.AddScoped<NotificationService>();
|
||||||
|
|
||||||
|
// SignalR
|
||||||
|
builder.Services.AddSignalR();
|
||||||
|
|
||||||
|
// Swagger
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
// CORS
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("Dev", policy =>
|
||||||
|
{
|
||||||
|
policy.WithOrigins("http://localhost:5173", "http://localhost:5174", "http://localhost:5175")
|
||||||
|
.AllowAnyHeader()
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowCredentials();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseCors("Dev");
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
app.MapControllers();
|
||||||
|
app.MapHub<ChatHub>("/hubs/chat");
|
||||||
|
|
||||||
|
// Auto-migrate and seed on startup
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||||
|
await db.Database.EnsureCreatedAsync();
|
||||||
|
await DataSeeder.SeedAsync(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run();
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "http://localhost:5133",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "https://localhost:7241;http://localhost:5133",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
backend/src/HealthManager.WebApi/appsettings.json
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"Default": "Host=localhost;Port=5432;Database=health_manager;Username=postgres;Password=postgres123"
|
||||||
|
},
|
||||||
|
"Jwt": {
|
||||||
|
"Secret": "health-manager-jwt-secret-key-2026-super-secure-long-enough!",
|
||||||
|
"Issuer": "HealthManager",
|
||||||
|
"Audience": "HealthManagerApp"
|
||||||
|
},
|
||||||
|
"Redis": {
|
||||||
|
"Connection": "localhost:6379"
|
||||||
|
},
|
||||||
|
"MinIO": {
|
||||||
|
"Endpoint": "localhost:9000",
|
||||||
|
"AccessKey": "minioadmin",
|
||||||
|
"SecretKey": "minioadmin"
|
||||||
|
}
|
||||||
|
}
|
||||||
24
frontend-doctor/.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
frontend-doctor/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
frontend-doctor/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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
12
frontend-doctor/index.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>健康管理平台 - 医生工作台</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
2979
frontend-doctor/package-lock.json
generated
Normal file
36
frontend-doctor/package.json
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend-doctor",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dayjs": "^1.11.20",
|
||||||
|
"echarts": "^6.0.0",
|
||||||
|
"echarts-for-react": "^3.0.6",
|
||||||
|
"framer-motion": "^12.39.0",
|
||||||
|
"react": "^19.2.6",
|
||||||
|
"react-dom": "^19.2.6",
|
||||||
|
"react-router-dom": "^7.15.1",
|
||||||
|
"zustand": "^5.0.13"
|
||||||
|
},
|
||||||
|
"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
frontend-doctor/public/favicon.svg
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
24
frontend-doctor/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 |
184
frontend-doctor/src/App.css
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
.counter {
|
||||||
|
font-size: 16px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
color: var(--accent);
|
||||||
|
background: var(--accent-bg);
|
||||||
|
border: 2px solid transparent;
|
||||||
|
transition: border-color 0.3s;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: var(--accent-border);
|
||||||
|
}
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 2px solid var(--accent);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.base,
|
||||||
|
.framework,
|
||||||
|
.vite {
|
||||||
|
inset-inline: 0;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.base {
|
||||||
|
width: 170px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.framework,
|
||||||
|
.vite {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.framework {
|
||||||
|
z-index: 1;
|
||||||
|
top: 34px;
|
||||||
|
height: 28px;
|
||||||
|
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
|
||||||
|
scale(1.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.vite {
|
||||||
|
z-index: 0;
|
||||||
|
top: 107px;
|
||||||
|
height: 26px;
|
||||||
|
width: auto;
|
||||||
|
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
|
||||||
|
scale(0.8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#center {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 25px;
|
||||||
|
place-content: center;
|
||||||
|
place-items: center;
|
||||||
|
flex-grow: 1;
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
padding: 32px 20px 24px;
|
||||||
|
gap: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#next-steps {
|
||||||
|
display: flex;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
& > div {
|
||||||
|
flex: 1 1 0;
|
||||||
|
padding: 32px;
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
padding: 24px 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#docs {
|
||||||
|
border-right: 1px solid var(--border);
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
border-right: none;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#next-steps ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin: 32px 0 0;
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--text-h);
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--social-bg);
|
||||||
|
display: flex;
|
||||||
|
padding: 6px 12px;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: box-shadow 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
}
|
||||||
|
.button-icon {
|
||||||
|
height: 18px;
|
||||||
|
width: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
margin-top: 20px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
li {
|
||||||
|
flex: 1 1 calc(50% - 8px);
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#spacer {
|
||||||
|
height: 88px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
height: 48px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ticks {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&::before,
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: -4.5px;
|
||||||
|
border: 5px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
left: 0;
|
||||||
|
border-left-color: var(--border);
|
||||||
|
}
|
||||||
|
&::after {
|
||||||
|
right: 0;
|
||||||
|
border-right-color: var(--border);
|
||||||
|
}
|
||||||
|
}
|
||||||
6
frontend-doctor/src/App.tsx
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { RouterProvider } from 'react-router-dom';
|
||||||
|
import { router } from './router';
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
return <RouterProvider router={router} />;
|
||||||
|
}
|
||||||
BIN
frontend-doctor/src/assets/hero.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
1
frontend-doctor/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 |
4
frontend-doctor/src/assets/styles/global.css
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||||
|
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
||||||
|
a { color: inherit; }
|
||||||
|
button { cursor: pointer; }
|
||||||
1
frontend-doctor/src/assets/vite.svg
Normal file
|
After Width: | Height: | Size: 8.5 KiB |
83
frontend-doctor/src/components/layout/DoctorLayout.tsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import { Outlet, NavLink, useNavigate } from 'react-router-dom';
|
||||||
|
import { useAuthStore } from '../../stores/auth.store';
|
||||||
|
|
||||||
|
const navItems = [
|
||||||
|
{ to: '/dashboard', label: '工作台', icon: '📊' },
|
||||||
|
{ to: '/patients', label: '患者管理', icon: '👥' },
|
||||||
|
{ to: '/consultations', label: '在线问诊', icon: '💬' },
|
||||||
|
{ to: '/reports', label: '报告审核', icon: '📋' },
|
||||||
|
{ to: '/follow-ups', label: '随访管理', icon: '📅' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const sidebarBg = '#0F1D3D';
|
||||||
|
const accentColor = '#4D8FFF';
|
||||||
|
const textMuted = '#8E9DB5';
|
||||||
|
|
||||||
|
export function DoctorLayout() {
|
||||||
|
const { user, logout } = useAuthStore();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
logout();
|
||||||
|
navigate('/login');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', minHeight: '100vh', fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif' }}>
|
||||||
|
{/* Sidebar */}
|
||||||
|
<aside style={{
|
||||||
|
width: 220, background: sidebarBg, color: '#fff',
|
||||||
|
display: 'flex', flexDirection: 'column', flexShrink: 0,
|
||||||
|
}}>
|
||||||
|
<div style={{ padding: '24px 20px 20px', borderBottom: '1px solid rgba(255,255,255,0.08)' }}>
|
||||||
|
<h1 style={{ fontSize: 17, margin: 0, fontWeight: 600, color: '#fff', letterSpacing: 1 }}>
|
||||||
|
<span style={{ color: accentColor }}>♥</span> 健康管家
|
||||||
|
</h1>
|
||||||
|
<p style={{ fontSize: 12, margin: '6px 0 0', color: textMuted }}>医生工作台</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<nav style={{ flex: 1, padding: '12px 0' }}>
|
||||||
|
{navItems.map((item) => (
|
||||||
|
<NavLink
|
||||||
|
key={item.to}
|
||||||
|
to={item.to}
|
||||||
|
style={({ isActive }) => ({
|
||||||
|
display: 'flex', alignItems: 'center', gap: 10,
|
||||||
|
padding: '11px 20px', margin: '2px 8px',
|
||||||
|
borderRadius: 8,
|
||||||
|
color: isActive ? '#fff' : textMuted,
|
||||||
|
background: isActive ? accentColor : 'transparent',
|
||||||
|
textDecoration: 'none', fontSize: 14,
|
||||||
|
fontWeight: isActive ? 500 : 400,
|
||||||
|
transition: 'all 0.15s',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<span style={{ fontSize: 16 }}>{item.icon}</span>
|
||||||
|
<span>{item.label}</span>
|
||||||
|
</NavLink>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div style={{ padding: '16px 20px', borderTop: '1px solid rgba(255,255,255,0.08)' }}>
|
||||||
|
<div style={{ fontSize: 13, color: '#fff', fontWeight: 500 }}>{user?.name}</div>
|
||||||
|
<div style={{ fontSize: 11, color: textMuted, marginTop: 2 }}>{user?.department} · {user?.title}</div>
|
||||||
|
<button onClick={handleLogout}
|
||||||
|
style={{
|
||||||
|
marginTop: 10, padding: '6px 14px', fontSize: 12,
|
||||||
|
background: 'transparent', color: textMuted, border: '1px solid rgba(255,255,255,0.15)',
|
||||||
|
borderRadius: 6, cursor: 'pointer', transition: 'all 0.15s',
|
||||||
|
}}
|
||||||
|
onMouseEnter={(e) => { e.currentTarget.style.color = '#fff'; e.currentTarget.style.borderColor = '#fff'; }}
|
||||||
|
onMouseLeave={(e) => { e.currentTarget.style.color = textMuted; e.currentTarget.style.borderColor = 'rgba(255,255,255,0.15)'; }}>
|
||||||
|
退出登录
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
{/* Main content */}
|
||||||
|
<main style={{ flex: 1, background: '#F2F5FA', overflow: 'auto' }}>
|
||||||
|
<Outlet />
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
111
frontend-doctor/src/index.css
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
:root {
|
||||||
|
--text: #6b6375;
|
||||||
|
--text-h: #08060d;
|
||||||
|
--bg: #fff;
|
||||||
|
--border: #e5e4e7;
|
||||||
|
--code-bg: #f4f3ec;
|
||||||
|
--accent: #aa3bff;
|
||||||
|
--accent-bg: rgba(170, 59, 255, 0.1);
|
||||||
|
--accent-border: rgba(170, 59, 255, 0.5);
|
||||||
|
--social-bg: rgba(244, 243, 236, 0.5);
|
||||||
|
--shadow:
|
||||||
|
rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px;
|
||||||
|
|
||||||
|
--sans: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
--heading: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
--mono: ui-monospace, Consolas, monospace;
|
||||||
|
|
||||||
|
font: 18px/145% var(--sans);
|
||||||
|
letter-spacing: 0.18px;
|
||||||
|
color-scheme: light dark;
|
||||||
|
color: var(--text);
|
||||||
|
background: var(--bg);
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--text: #9ca3af;
|
||||||
|
--text-h: #f3f4f6;
|
||||||
|
--bg: #16171d;
|
||||||
|
--border: #2e303a;
|
||||||
|
--code-bg: #1f2028;
|
||||||
|
--accent: #c084fc;
|
||||||
|
--accent-bg: rgba(192, 132, 252, 0.15);
|
||||||
|
--accent-border: rgba(192, 132, 252, 0.5);
|
||||||
|
--social-bg: rgba(47, 48, 58, 0.5);
|
||||||
|
--shadow:
|
||||||
|
rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#social .button-icon {
|
||||||
|
filter: invert(1) brightness(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#root {
|
||||||
|
width: 1126px;
|
||||||
|
max-width: 100%;
|
||||||
|
margin: 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
border-inline: 1px solid var(--border);
|
||||||
|
min-height: 100svh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2 {
|
||||||
|
font-family: var(--heading);
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-h);
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 56px;
|
||||||
|
letter-spacing: -1.68px;
|
||||||
|
margin: 32px 0;
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
font-size: 36px;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
font-size: 24px;
|
||||||
|
line-height: 118%;
|
||||||
|
letter-spacing: -0.24px;
|
||||||
|
margin: 0 0 8px;
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
code,
|
||||||
|
.counter {
|
||||||
|
font-family: var(--mono);
|
||||||
|
display: inline-flex;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: var(--text-h);
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 135%;
|
||||||
|
padding: 4px 8px;
|
||||||
|
background: var(--code-bg);
|
||||||
|
}
|
||||||
11
frontend-doctor/src/main.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { StrictMode } from 'react';
|
||||||
|
import { createRoot } from 'react-dom/client';
|
||||||
|
import { RouterProvider } from 'react-router-dom';
|
||||||
|
import { router } from './router';
|
||||||
|
import './assets/styles/global.css';
|
||||||
|
|
||||||
|
createRoot(document.getElementById('root')!).render(
|
||||||
|
<StrictMode>
|
||||||
|
<RouterProvider router={router} />
|
||||||
|
</StrictMode>,
|
||||||
|
);
|
||||||
66
frontend-doctor/src/pages/auth/LoginPage.tsx
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { useAuthStore } from '../../stores/auth.store';
|
||||||
|
|
||||||
|
export function LoginPage() {
|
||||||
|
const [phone, setPhone] = useState('13700137000');
|
||||||
|
const [code, setCode] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const login = useAuthStore((s) => s.login);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const handleLogin = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setError('');
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
await login(phone, code || '0000');
|
||||||
|
navigate('/dashboard');
|
||||||
|
} catch (err: unknown) {
|
||||||
|
setError(err instanceof Error ? err.message : '登录失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{
|
||||||
|
display: 'flex', justifyContent: 'center', alignItems: 'center',
|
||||||
|
minHeight: '100vh', background: '#f0f2f5',
|
||||||
|
}}>
|
||||||
|
<form onSubmit={handleLogin} style={{
|
||||||
|
width: 400, padding: 40, background: '#fff', borderRadius: 8,
|
||||||
|
boxShadow: '0 2px 12px rgba(0,0,0,0.1)',
|
||||||
|
}}>
|
||||||
|
<h2 style={{ textAlign: 'center', marginBottom: 24 }}>医生登录</h2>
|
||||||
|
|
||||||
|
{error && <div style={{ color: '#f44336', marginBottom: 12, fontSize: 13 }}>{error}</div>}
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 16 }}>
|
||||||
|
<label style={{ display: 'block', marginBottom: 4, fontSize: 13 }}>手机号</label>
|
||||||
|
<input value={phone} onChange={(e) => setPhone(e.target.value)}
|
||||||
|
style={{ width: '100%', padding: '10px 12px', border: '1px solid #ddd', borderRadius: 4, fontSize: 14 }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 20 }}>
|
||||||
|
<label style={{ display: 'block', marginBottom: 4, fontSize: 13 }}>验证码 (演示环境任意输入)</label>
|
||||||
|
<input value={code} onChange={(e) => setCode(e.target.value)}
|
||||||
|
placeholder="输入任意验证码"
|
||||||
|
style={{ width: '100%', padding: '10px 12px', border: '1px solid #ddd', borderRadius: 4, fontSize: 14 }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" disabled={loading} style={{
|
||||||
|
width: '100%', padding: '12px', background: '#1976d2', color: '#fff',
|
||||||
|
border: 'none', borderRadius: 4, fontSize: 15, opacity: loading ? 0.7 : 1,
|
||||||
|
}}>
|
||||||
|
{loading ? '登录中...' : '登录'}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<p style={{ marginTop: 16, fontSize: 12, color: '#999', textAlign: 'center' }}>
|
||||||
|
演示账号:13700137000 (王建国 主任医师)
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
81
frontend-doctor/src/pages/consultations/ChatPage.tsx
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import { useEffect, useState, useRef } from 'react';
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
|
||||||
|
interface Message {
|
||||||
|
id: string; senderId: string; senderRole: string;
|
||||||
|
content: string; contentType: string; createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ChatPage() {
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const [messages, setMessages] = useState<Message[]>([]);
|
||||||
|
const [input, setInput] = useState('');
|
||||||
|
const bottomRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!id) return;
|
||||||
|
api.get<Message[]>(`/api/consultations/${id}/messages`)
|
||||||
|
.then((r) => setMessages(r.data))
|
||||||
|
.catch(() => {});
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||||
|
}, [messages]);
|
||||||
|
|
||||||
|
const handleSend = async () => {
|
||||||
|
if (!input.trim() || !id) return;
|
||||||
|
try {
|
||||||
|
const res = await api.post<Message>(`/api/consultations/${id}/messages`, { content: input });
|
||||||
|
setMessages((prev) => [...prev, res.data]);
|
||||||
|
setInput('');
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', height: 'calc(100vh - 0px)' }}>
|
||||||
|
<div style={{ padding: '14px 20px', background: '#fff', borderBottom: '1px solid #eee', fontSize: 15, fontWeight: 500 }}>
|
||||||
|
在线问诊
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ flex: 1, overflow: 'auto', padding: 20, background: '#fafafa' }}>
|
||||||
|
{messages.map((msg) => (
|
||||||
|
<div key={msg.id} style={{
|
||||||
|
display: 'flex', justifyContent: msg.senderRole === 'doctor' ? 'flex-end' : 'flex-start',
|
||||||
|
marginBottom: 12,
|
||||||
|
}}>
|
||||||
|
<div style={{
|
||||||
|
maxWidth: '70%', padding: '10px 14px', borderRadius: 12, fontSize: 14,
|
||||||
|
background: msg.senderRole === 'doctor' ? '#1976d2' : '#fff',
|
||||||
|
color: msg.senderRole === 'doctor' ? '#fff' : '#333',
|
||||||
|
boxShadow: '0 1px 3px rgba(0,0,0,0.08)',
|
||||||
|
}}>
|
||||||
|
<div>{msg.content}</div>
|
||||||
|
<div style={{
|
||||||
|
fontSize: 10, marginTop: 4, textAlign: 'right',
|
||||||
|
opacity: 0.7,
|
||||||
|
}}>
|
||||||
|
{msg.createdAt?.split('T')[1]?.slice(0, 5)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<div ref={bottomRef} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ padding: '12px 20px', background: '#fff', borderTop: '1px solid #eee', display: 'flex', gap: 12 }}>
|
||||||
|
<input value={input} onChange={(e) => setInput(e.target.value)}
|
||||||
|
onKeyDown={(e) => e.key === 'Enter' && handleSend()}
|
||||||
|
placeholder="输入回复..."
|
||||||
|
style={{ flex: 1, padding: '10px 14px', border: '1px solid #ddd', borderRadius: 20, fontSize: 14 }} />
|
||||||
|
<button onClick={handleSend} style={{
|
||||||
|
padding: '10px 24px', background: '#1976d2', color: '#fff',
|
||||||
|
border: 'none', borderRadius: 20, fontSize: 14,
|
||||||
|
}}>
|
||||||
|
发送
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
|
||||||
|
interface ConsultationItem {
|
||||||
|
id: string; patientId: string; patientName: string; subject: string;
|
||||||
|
status: string; startedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RawConsultation {
|
||||||
|
id: string; patientId: string; patientName?: string; subject?: string;
|
||||||
|
status: string; startedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ConsultationListPage() {
|
||||||
|
const [consultations, setConsultations] = useState<ConsultationItem[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
api.get<RawConsultation[]>('/api/consultations').then((r) => {
|
||||||
|
const mapped = r.data.map((c) => ({
|
||||||
|
id: c.id,
|
||||||
|
patientId: c.patientId,
|
||||||
|
patientName: c.patientName || 'unknown',
|
||||||
|
subject: c.subject || 'online consult',
|
||||||
|
status: c.status,
|
||||||
|
startedAt: c.startedAt,
|
||||||
|
}));
|
||||||
|
setConsultations(mapped);
|
||||||
|
}).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<h2 style={{ marginBottom: 16 }}>在线问诊</h2>
|
||||||
|
|
||||||
|
<div style={{ background: '#fff', borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
|
||||||
|
{consultations.map((c) => (
|
||||||
|
<Link key={c.id} to={`/consultations/${c.id}`} style={{
|
||||||
|
display: 'flex', justifyContent: 'space-between', alignItems: 'center',
|
||||||
|
padding: '14px 20px', borderBottom: '1px solid #f5f5f5',
|
||||||
|
textDecoration: 'none', color: 'inherit',
|
||||||
|
}}>
|
||||||
|
<div>
|
||||||
|
<div style={{ fontSize: 14, fontWeight: 500 }}>{c.patientName}</div>
|
||||||
|
<div style={{ fontSize: 12, color: '#888', marginTop: 2 }}>{c.subject}</div>
|
||||||
|
</div>
|
||||||
|
<div style={{ textAlign: 'right' }}>
|
||||||
|
<span style={{
|
||||||
|
padding: '2px 8px', borderRadius: 10, fontSize: 11,
|
||||||
|
background: c.status === 'active' ? '#e8f5e9' : '#f5f5f5',
|
||||||
|
color: c.status === 'active' ? '#2e7d32' : '#999',
|
||||||
|
}}>
|
||||||
|
{c.status === 'active' ? '进行中' : '已结束'}
|
||||||
|
</span>
|
||||||
|
<div style={{ fontSize: 11, color: '#bbb', marginTop: 4 }}>
|
||||||
|
{c.startedAt?.split('T')[0]}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
{consultations.length === 0 && (
|
||||||
|
<div style={{ padding: 40, textAlign: 'center', color: '#999' }}>暂无问诊记录</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
102
frontend-doctor/src/pages/dashboard/DashboardPage.tsx
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
import { useAuthStore } from '../../stores/auth.store';
|
||||||
|
import type { DashboardStats } from '../../types';
|
||||||
|
|
||||||
|
interface RawPatient { id: string; name: string; phone: string; }
|
||||||
|
interface RawConsultation { id: string; status: string; patientName: string; subject: string; }
|
||||||
|
interface RawFollowUp { id: string; scheduledAt: string; title: string; status: string; }
|
||||||
|
interface RawReport { id: string; title: string; status: string; }
|
||||||
|
|
||||||
|
export function DashboardPage() {
|
||||||
|
const user = useAuthStore((s) => s.user);
|
||||||
|
const [stats, setStats] = useState<DashboardStats>({
|
||||||
|
totalPatients: 0, activeConsultations: 0, pendingReports: 0,
|
||||||
|
todayFollowUps: 0, weeklyNewPatients: 0, weeklyConsultations: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function loadStats() {
|
||||||
|
try {
|
||||||
|
const [patients, consultations, reports, followUps] = await Promise.all([
|
||||||
|
api.get<RawPatient[]>('/api/patients'),
|
||||||
|
api.get<RawConsultation[]>('/api/consultations'),
|
||||||
|
api.get<RawReport[]>('/api/reports?status=pending'),
|
||||||
|
api.get<RawFollowUp[]>('/api/follow-ups'),
|
||||||
|
]);
|
||||||
|
setStats({
|
||||||
|
totalPatients: patients.data.length,
|
||||||
|
activeConsultations: consultations.data.filter((c) => c.status === 'active').length,
|
||||||
|
pendingReports: reports.data.length,
|
||||||
|
todayFollowUps: followUps.data.filter((f) => {
|
||||||
|
const d = (f.scheduledAt as string)?.split('T')[0];
|
||||||
|
return d === new Date().toISOString().split('T')[0];
|
||||||
|
}).length,
|
||||||
|
weeklyNewPatients: 0,
|
||||||
|
weeklyConsultations: consultations.data.length,
|
||||||
|
});
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
}
|
||||||
|
loadStats();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<h2 style={{ marginBottom: 20 }}>欢迎回来,{user?.name}</h2>
|
||||||
|
|
||||||
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: 16, marginBottom: 32 }}>
|
||||||
|
{[
|
||||||
|
{ label: '患者总数', value: stats.totalPatients, color: '#1976d2' },
|
||||||
|
{ label: '进行中问诊', value: stats.activeConsultations, color: '#388e3c' },
|
||||||
|
{ label: '待审核报告', value: stats.pendingReports, color: '#f57c00' },
|
||||||
|
{ label: '今日随访', value: stats.todayFollowUps, color: '#7b1fa2' },
|
||||||
|
].map((item) => (
|
||||||
|
<div key={item.label} style={{
|
||||||
|
background: '#fff', padding: 20, borderRadius: 8,
|
||||||
|
borderLeft: `4px solid ${item.color}`, boxShadow: '0 1px 4px rgba(0,0,0,0.08)',
|
||||||
|
}}>
|
||||||
|
<div style={{ fontSize: 28, fontWeight: 700, color: item.color }}>{item.value}</div>
|
||||||
|
<div style={{ fontSize: 13, color: '#888', marginTop: 4 }}>{item.label}</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ display: 'grid', gridTemplateColumns: '2fr 1fr', gap: 16 }}>
|
||||||
|
<div style={{ background: '#fff', padding: 20, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
|
||||||
|
<h3 style={{ marginBottom: 12, fontSize: 15 }}>快捷操作</h3>
|
||||||
|
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
|
||||||
|
{[
|
||||||
|
{ label: '患者列表', href: '/patients' },
|
||||||
|
{ label: '在线问诊', href: '/consultations' },
|
||||||
|
{ label: '报告审核', href: '/reports' },
|
||||||
|
{ label: '随访管理', href: '/follow-ups' },
|
||||||
|
].map((action) => (
|
||||||
|
<Link key={action.label} to={action.href} style={{
|
||||||
|
padding: '8px 16px', background: '#f0f2f5', borderRadius: 4,
|
||||||
|
textDecoration: 'none', color: '#1976d2', fontSize: 13,
|
||||||
|
}}>
|
||||||
|
{action.label} →
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ background: '#fff', padding: 20, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
|
||||||
|
<h3 style={{ marginBottom: 12, fontSize: 15 }}>今日待办</h3>
|
||||||
|
<ul style={{ fontSize: 13, color: '#666', listStyle: 'none', padding: 0 }}>
|
||||||
|
<li style={{ padding: '6px 0', borderBottom: '1px solid #f0f0f0' }}>
|
||||||
|
📋 待审核报告: {stats.pendingReports} 份
|
||||||
|
</li>
|
||||||
|
<li style={{ padding: '6px 0', borderBottom: '1px solid #f0f0f0' }}>
|
||||||
|
💬 进行中问诊: {stats.activeConsultations} 个
|
||||||
|
</li>
|
||||||
|
<li style={{ padding: '6px 0' }}>
|
||||||
|
📅 今日随访: {stats.todayFollowUps} 项
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
84
frontend-doctor/src/pages/followups/FollowUpEditPage.tsx
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useParams, useNavigate } from 'react-router-dom';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
|
||||||
|
export function FollowUpEditPage() {
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const isNew = !id || id === 'new';
|
||||||
|
|
||||||
|
const [title, setTitle] = useState('');
|
||||||
|
const [patientId, setPatientId] = useState('');
|
||||||
|
const [scheduledAt, setScheduledAt] = useState('');
|
||||||
|
const [notes, setNotes] = useState('');
|
||||||
|
const [patients, setPatients] = useState<{ id: string; name: string }[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
api.get<{ id: string; name: string }[]>('/api/patients').then((r) => setPatients(r.data));
|
||||||
|
if (!isNew) {
|
||||||
|
api.get<Record<string, unknown>>(`/api/follow-ups/${id}`).then((r) => {
|
||||||
|
setTitle(r.data.title as string);
|
||||||
|
setPatientId(r.data.patientId as string);
|
||||||
|
setScheduledAt((r.data.scheduledAt as string)?.slice(0, 16) || '');
|
||||||
|
setNotes((r.data.notes as string) || '');
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
}, [id, isNew]);
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const body = { title, patientId, scheduledAt, notes };
|
||||||
|
try {
|
||||||
|
if (isNew) {
|
||||||
|
await api.post('/api/follow-ups', body);
|
||||||
|
} else {
|
||||||
|
await api.put(`/api/follow-ups/${id}`, body);
|
||||||
|
}
|
||||||
|
navigate('/follow-ups');
|
||||||
|
} catch { alert('操作失败'); }
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<h2 style={{ marginBottom: 16 }}>{isNew ? '新建随访' : '编辑随访'}</h2>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} style={{ background: '#fff', padding: 24, borderRadius: 8, maxWidth: 500 }}>
|
||||||
|
<div style={{ marginBottom: 14 }}>
|
||||||
|
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}>标题</label>
|
||||||
|
<input value={title} onChange={(e) => setTitle(e.target.value)} required
|
||||||
|
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 14 }}>
|
||||||
|
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}>患者</label>
|
||||||
|
<select value={patientId} onChange={(e) => setPatientId(e.target.value)} required
|
||||||
|
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }}>
|
||||||
|
<option value="">请选择</option>
|
||||||
|
{patients.map((p) => (
|
||||||
|
<option key={p.id} value={p.id}>{p.name}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 14 }}>
|
||||||
|
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}>计划时间</label>
|
||||||
|
<input type="datetime-local" value={scheduledAt} onChange={(e) => setScheduledAt(e.target.value)} required
|
||||||
|
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 18 }}>
|
||||||
|
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}>备注</label>
|
||||||
|
<textarea value={notes} onChange={(e) => setNotes(e.target.value)} rows={3}
|
||||||
|
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4, resize: 'vertical' }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" style={{
|
||||||
|
padding: '10px 24px', background: '#1976d2', color: '#fff',
|
||||||
|
border: 'none', borderRadius: 4, fontSize: 14,
|
||||||
|
}}>
|
||||||
|
{isNew ? '创建' : '保存'}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
82
frontend-doctor/src/pages/followups/FollowUpListPage.tsx
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
|
||||||
|
interface FollowUpItem {
|
||||||
|
id: string; patientId: string; patientName: string;
|
||||||
|
title: string; scheduledAt: string; status: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RawFollowUpItem {
|
||||||
|
id: string; patientId: string; patientName?: string;
|
||||||
|
title: string; scheduledAt: string; status: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FollowUpListPage() {
|
||||||
|
const [followUps, setFollowUps] = useState<FollowUpItem[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
api.get<RawFollowUpItem[]>('/api/follow-ups').then((r) => {
|
||||||
|
const mapped = r.data.map((f) => ({
|
||||||
|
id: f.id,
|
||||||
|
patientId: f.patientId,
|
||||||
|
patientName: f.patientName || 'unknown',
|
||||||
|
title: f.title,
|
||||||
|
scheduledAt: f.scheduledAt,
|
||||||
|
status: f.status,
|
||||||
|
}));
|
||||||
|
setFollowUps(mapped);
|
||||||
|
}).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const statusLabel = (s: string) => {
|
||||||
|
switch (s) {
|
||||||
|
case 'pending': return { text: '待随访', color: '#f57c00', bg: '#fff3e0' };
|
||||||
|
case 'completed': return { text: '已完成', color: '#2e7d32', bg: '#e8f5e9' };
|
||||||
|
case 'missed': return { text: '已错过', color: '#c62828', bg: '#ffebee' };
|
||||||
|
default: return { text: s, color: '#666', bg: '#f5f5f5' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||||
|
<h2>随访管理</h2>
|
||||||
|
<Link to="/follow-ups/new/edit" style={{
|
||||||
|
padding: '8px 16px', background: '#1976d2', color: '#fff',
|
||||||
|
borderRadius: 4, textDecoration: 'none', fontSize: 13,
|
||||||
|
}}>
|
||||||
|
+ 新建随访
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ background: '#fff', borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
|
||||||
|
{followUps.map((f) => {
|
||||||
|
const s = statusLabel(f.status);
|
||||||
|
return (
|
||||||
|
<div key={f.id} style={{
|
||||||
|
display: 'flex', justifyContent: 'space-between', alignItems: 'center',
|
||||||
|
padding: '14px 20px', borderBottom: '1px solid #f5f5f5',
|
||||||
|
}}>
|
||||||
|
<div>
|
||||||
|
<div style={{ fontSize: 14, fontWeight: 500 }}>{f.title}</div>
|
||||||
|
<div style={{ fontSize: 12, color: '#888', marginTop: 2 }}>
|
||||||
|
{f.patientName} · {f.scheduledAt?.split('T')[0]}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||||
|
<span style={{ padding: '2px 8px', borderRadius: 10, fontSize: 11, background: s.bg, color: s.color }}>
|
||||||
|
{s.text}
|
||||||
|
</span>
|
||||||
|
<Link to={`/follow-ups/${f.id}/edit`} style={{ color: '#1976d2', fontSize: 13 }}>编辑</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{followUps.length === 0 && (
|
||||||
|
<div style={{ padding: 40, textAlign: 'center', color: '#999' }}>暂无随访记录</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
81
frontend-doctor/src/pages/patients/PatientDetailPage.tsx
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useParams, Link } from 'react-router-dom';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
|
||||||
|
interface PatientDetail {
|
||||||
|
id: string; name: string; phone: string; gender: string; birthday: string;
|
||||||
|
heightCm: number; weightKg: number; medicalHistory: string[];
|
||||||
|
stentDate: string; stentType: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface HealthRecord {
|
||||||
|
id: string; type: string; value: string; unit: string; recordedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PatientDetailPage() {
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const [patient, setPatient] = useState<PatientDetail | null>(null);
|
||||||
|
const [records, setRecords] = useState<HealthRecord[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!id) return;
|
||||||
|
// Fetch patient detail directly by ID + health records
|
||||||
|
api.get<PatientDetail>(`/api/patients/${id}`).then((r) => {
|
||||||
|
if (r.data) setPatient(r.data);
|
||||||
|
}).catch(() => {});
|
||||||
|
api.get<HealthRecord[]>(`/api/health-records?patientId=${id}&days=30`).then((r) => setRecords(r.data));
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
if (!patient) return <div style={{ padding: 24 }}>加载中...</div>;
|
||||||
|
|
||||||
|
const latestByType: Record<string, HealthRecord> = {};
|
||||||
|
records.forEach((r) => {
|
||||||
|
if (!latestByType[r.type] || r.recordedAt > latestByType[r.type].recordedAt) {
|
||||||
|
latestByType[r.type] = r;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const parseValueDisplay = (r: HealthRecord) => {
|
||||||
|
try {
|
||||||
|
const v = JSON.parse(r.value);
|
||||||
|
if (typeof v === 'object') return `${v.systolic ?? v.value ?? '-'}/${v.diastolic ?? '-'}`;
|
||||||
|
return String(v.value ?? v);
|
||||||
|
} catch { return r.value; }
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<Link to="/patients" style={{ fontSize: 13, color: '#1976d2' }}>← 返回患者列表</Link>
|
||||||
|
|
||||||
|
<div style={{ background: '#fff', marginTop: 16, padding: 24, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
|
||||||
|
<h2>{patient.name}</h2>
|
||||||
|
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '8px 24px', marginTop: 12, fontSize: 14 }}>
|
||||||
|
<div>手机号:{patient.phone}</div>
|
||||||
|
<div>性别:{patient.gender || '-'}</div>
|
||||||
|
<div>出生日期:{patient.birthday || '-'}</div>
|
||||||
|
<div>身高:{patient.heightCm}cm / 体重:{patient.weightKg}kg</div>
|
||||||
|
<div>病史:{(patient.medicalHistory || []).join('、') || '-'}</div>
|
||||||
|
<div>支架日期:{patient.stentDate || '-'}</div>
|
||||||
|
<div>支架类型:{patient.stentType || '-'}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3 style={{ marginTop: 24, marginBottom: 12 }}>最近健康数据</h3>
|
||||||
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: 12 }}>
|
||||||
|
{Object.entries(latestByType).map(([type, record]) => (
|
||||||
|
<div key={type} style={{ background: '#fff', padding: 16, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
|
||||||
|
<div style={{ fontSize: 12, color: '#888' }}>
|
||||||
|
{type === 'blood_pressure' ? '血压' : type === 'heart_rate' ? '心率' : type}
|
||||||
|
</div>
|
||||||
|
<div style={{ fontSize: 20, fontWeight: 600, marginTop: 4 }}>
|
||||||
|
{parseValueDisplay(record)} {record.unit}
|
||||||
|
</div>
|
||||||
|
<div style={{ fontSize: 11, color: '#bbb', marginTop: 4 }}>
|
||||||
|
{record.recordedAt?.split('T')[0]}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
68
frontend-doctor/src/pages/patients/PatientListPage.tsx
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
|
||||||
|
interface Patient {
|
||||||
|
id: string; name: string; phone: string; gender: string;
|
||||||
|
medicalHistory: string[]; stentDate: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PatientListPage() {
|
||||||
|
const [patients, setPatients] = useState<Patient[]>([]);
|
||||||
|
const [search, setSearch] = useState('');
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
api.get<Patient[]>('/api/patients')
|
||||||
|
.then((r) => setPatients(r.data))
|
||||||
|
.catch(() => {})
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const filtered = patients.filter((p) =>
|
||||||
|
!search || p.name.includes(search) || p.phone.includes(search)
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<h2 style={{ marginBottom: 16 }}>患者管理</h2>
|
||||||
|
|
||||||
|
<input value={search} onChange={(e) => setSearch(e.target.value)} placeholder="搜索姓名或手机号..."
|
||||||
|
style={{ width: 300, padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4, marginBottom: 16 }} />
|
||||||
|
|
||||||
|
{loading ? <div>加载中...</div> : (
|
||||||
|
<div style={{ background: '#fff', borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
|
||||||
|
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
|
||||||
|
<thead>
|
||||||
|
<tr style={{ borderBottom: '2px solid #f0f0f0', textAlign: 'left' }}>
|
||||||
|
<th style={{ padding: '12px 16px' }}>姓名</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>手机号</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>性别</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>病史</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>支架日期</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{filtered.map((p) => (
|
||||||
|
<tr key={p.id} style={{ borderBottom: '1px solid #f5f5f5' }}>
|
||||||
|
<td style={{ padding: '10px 16px' }}>{p.name}</td>
|
||||||
|
<td style={{ padding: '10px 16px', color: '#888' }}>{p.phone}</td>
|
||||||
|
<td style={{ padding: '10px 16px' }}>{p.gender || '-'}</td>
|
||||||
|
<td style={{ padding: '10px 16px' }}>{(p.medicalHistory || []).slice(0, 3).join('、') || '-'}</td>
|
||||||
|
<td style={{ padding: '10px 16px' }}>{p.stentDate || '-'}</td>
|
||||||
|
<td style={{ padding: '10px 16px' }}>
|
||||||
|
<Link to={`/patients/${p.id}`} style={{ color: '#1976d2', fontSize: 13 }}>查看详情</Link>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{filtered.length === 0 && (
|
||||||
|
<tr><td colSpan={6} style={{ padding: 24, textAlign: 'center', color: '#999' }}>暂无患者数据</td></tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
114
frontend-doctor/src/pages/reports/ReportDetailPage.tsx
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useParams, Link } from 'react-router-dom';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
|
||||||
|
interface RawReport {
|
||||||
|
id: string; patientId: string; title: string; category: string;
|
||||||
|
imageUrls: string[]; status: string; riskLevel?: string;
|
||||||
|
summary?: string; suggestions?: string;
|
||||||
|
patientName?: string; doctorName?: string;
|
||||||
|
createdAt: string; completedAt?: string;
|
||||||
|
items?: { id: string; itemName: string; resultValue: string; unit?: string; referenceRange?: string; isAbnormal: boolean }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ReportDetailPage() {
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const [report, setReport] = useState<RawReport | null>(null);
|
||||||
|
const [interpretation, setInterpretation] = useState('');
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!id) return;
|
||||||
|
api.get<RawReport>(`/api/reports/${id}`).then((r) => setReport(r.data)).catch(() => {});
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
const handleInterpret = async () => {
|
||||||
|
if (!interpretation.trim() || !id) return;
|
||||||
|
setSubmitting(true);
|
||||||
|
try {
|
||||||
|
await api.post(`/api/reports/${id}/interpret`, {
|
||||||
|
summary: interpretation,
|
||||||
|
items: [],
|
||||||
|
riskLevel: 'normal',
|
||||||
|
suggestions: null,
|
||||||
|
});
|
||||||
|
// Refetch report to show updated status
|
||||||
|
const updated = await api.get<RawReport>(`/api/reports/${id}`);
|
||||||
|
setReport(updated.data);
|
||||||
|
setInterpretation('');
|
||||||
|
alert('interpretation submitted');
|
||||||
|
} catch { alert('submit failed'); }
|
||||||
|
finally { setSubmitting(false); }
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!report) return <div style={{ padding: 24 }}>loading...</div>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<Link to="/reports" style={{ fontSize: 13, color: '#1976d2' }}>← back to reports</Link>
|
||||||
|
|
||||||
|
<div style={{ background: '#fff', marginTop: 16, padding: 24, borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
|
||||||
|
<h2>{report.title}</h2>
|
||||||
|
<div style={{ marginTop: 12, fontSize: 14, color: '#666' }}>
|
||||||
|
<div>Patient: {report.patientName || 'unknown'}</div>
|
||||||
|
<div>Category: {report.category}</div>
|
||||||
|
<div>Status: {report.status}</div>
|
||||||
|
<div>Submitted: {report.createdAt?.split('T')[0]}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{report.imageUrls && report.imageUrls.length > 0 && (
|
||||||
|
<div style={{ marginTop: 16 }}>
|
||||||
|
<h4 style={{ fontSize: 14, marginBottom: 8 }}>Report Images</h4>
|
||||||
|
{report.imageUrls.map((url, i) => (
|
||||||
|
<div key={i} style={{ padding: '8px 12px', background: '#f5f5f5', borderRadius: 4, marginBottom: 4, fontSize: 12 }}>
|
||||||
|
{url}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{report.status === 'completed' && (
|
||||||
|
<div style={{ marginTop: 16, padding: 16, background: '#e8f5e9', borderRadius: 8 }}>
|
||||||
|
<h4 style={{ fontSize: 14, marginBottom: 4 }}>Interpretation Result</h4>
|
||||||
|
<p style={{ fontSize: 13, color: '#555' }}>{report.summary || 'No summary'}</p>
|
||||||
|
{report.riskLevel && <p style={{ fontSize: 12, color: '#888' }}>Risk: {report.riskLevel}</p>}
|
||||||
|
{report.suggestions && <p style={{ fontSize: 12, color: '#888' }}>Suggestions: {report.suggestions}</p>}
|
||||||
|
{report.items && report.items.length > 0 && (
|
||||||
|
<table style={{ width: '100%', marginTop: 8, borderCollapse: 'collapse', fontSize: 12 }}>
|
||||||
|
<thead><tr style={{ textAlign: 'left', borderBottom: '1px solid #ddd' }}>
|
||||||
|
<th style={{ padding: 4 }}>Item</th><th style={{ padding: 4 }}>Value</th><th style={{ padding: 4 }}>Range</th><th style={{ padding: 4 }}>Abnormal</th>
|
||||||
|
</tr></thead>
|
||||||
|
<tbody>
|
||||||
|
{report.items.map((item) => (
|
||||||
|
<tr key={item.id} style={{ borderBottom: '1px solid #f0f0f0' }}>
|
||||||
|
<td style={{ padding: 4 }}>{item.itemName}</td>
|
||||||
|
<td style={{ padding: 4 }}>{item.resultValue} {item.unit || ''}</td>
|
||||||
|
<td style={{ padding: 4 }}>{item.referenceRange || '-'}</td>
|
||||||
|
<td style={{ padding: 4, color: item.isAbnormal ? '#c62828' : '#2e7d32' }}>{item.isAbnormal ? 'Yes' : 'No'}</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{report.status !== 'completed' && (
|
||||||
|
<div style={{ marginTop: 20 }}>
|
||||||
|
<h4 style={{ fontSize: 14, marginBottom: 8 }}>Doctor Interpretation</h4>
|
||||||
|
<textarea value={interpretation} onChange={(e) => setInterpretation(e.target.value)}
|
||||||
|
placeholder="Enter your interpretation..."
|
||||||
|
rows={5}
|
||||||
|
style={{ width: '100%', padding: 12, border: '1px solid #ddd', borderRadius: 4, fontSize: 14, resize: 'vertical' }} />
|
||||||
|
<button onClick={handleInterpret} disabled={submitting} style={{
|
||||||
|
marginTop: 8, padding: '10px 24px', background: '#1976d2', color: '#fff',
|
||||||
|
border: 'none', borderRadius: 4, fontSize: 14, opacity: submitting ? 0.7 : 1,
|
||||||
|
}}>
|
||||||
|
{submitting ? 'Submitting...' : 'Submit Interpretation'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
85
frontend-doctor/src/pages/reports/ReportListPage.tsx
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
|
||||||
|
interface ReportItem {
|
||||||
|
id: string; patientId: string; patientName: string;
|
||||||
|
title: string; category: string; status: string; createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RawReportItem {
|
||||||
|
id: string; patientId: string; patientName?: string;
|
||||||
|
title: string; category: string; status: string; createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ReportListPage() {
|
||||||
|
const [reports, setReports] = useState<ReportItem[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
api.get<RawReportItem[]>('/api/reports').then((r) => {
|
||||||
|
const mapped = r.data.map((rp) => ({
|
||||||
|
id: rp.id,
|
||||||
|
patientId: rp.patientId,
|
||||||
|
patientName: rp.patientName || 'unknown',
|
||||||
|
title: rp.title,
|
||||||
|
category: rp.category,
|
||||||
|
status: rp.status,
|
||||||
|
createdAt: rp.createdAt,
|
||||||
|
}));
|
||||||
|
setReports(mapped);
|
||||||
|
}).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const statusLabel = (s: string) => {
|
||||||
|
switch (s) {
|
||||||
|
case 'pending': return { text: '待审核', color: '#f57c00', bg: '#fff3e0' };
|
||||||
|
case 'completed': return { text: '已完成', color: '#2e7d32', bg: '#e8f5e9' };
|
||||||
|
default: return { text: s, color: '#666', bg: '#f5f5f5' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<h2 style={{ marginBottom: 16 }}>报告审核</h2>
|
||||||
|
|
||||||
|
<div style={{ background: '#fff', borderRadius: 8, boxShadow: '0 1px 4px rgba(0,0,0,0.08)' }}>
|
||||||
|
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
|
||||||
|
<thead>
|
||||||
|
<tr style={{ borderBottom: '2px solid #f0f0f0', textAlign: 'left' }}>
|
||||||
|
<th style={{ padding: '12px 16px' }}>患者</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>标题</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>分类</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>状态</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>日期</th>
|
||||||
|
<th style={{ padding: '12px 16px' }}>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{reports.map((r) => {
|
||||||
|
const s = statusLabel(r.status);
|
||||||
|
return (
|
||||||
|
<tr key={r.id} style={{ borderBottom: '1px solid #f5f5f5' }}>
|
||||||
|
<td style={{ padding: '10px 16px' }}>{r.patientName}</td>
|
||||||
|
<td style={{ padding: '10px 16px' }}>{r.title}</td>
|
||||||
|
<td style={{ padding: '10px 16px', color: '#888' }}>{r.category}</td>
|
||||||
|
<td style={{ padding: '10px 16px' }}>
|
||||||
|
<span style={{ padding: '2px 8px', borderRadius: 10, fontSize: 11, background: s.bg, color: s.color }}>
|
||||||
|
{s.text}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td style={{ padding: '10px 16px', color: '#888' }}>{r.createdAt?.split('T')[0]}</td>
|
||||||
|
<td style={{ padding: '10px 16px' }}>
|
||||||
|
<Link to={`/reports/${r.id}`} style={{ color: '#1976d2', fontSize: 13 }}>查看</Link>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{reports.length === 0 && (
|
||||||
|
<tr><td colSpan={6} style={{ padding: 24, textAlign: 'center', color: '#999' }}>暂无报告</td></tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
83
frontend-doctor/src/pages/settings/ProfilePage.tsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { api } from '../../services/api-client';
|
||||||
|
import { useAuthStore } from '../../stores/auth.store';
|
||||||
|
|
||||||
|
export function ProfilePage() {
|
||||||
|
const user = useAuthStore((s) => s.user);
|
||||||
|
const updateProfile = useAuthStore((s) => s.updateProfile);
|
||||||
|
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
name: '', department: '', title: '', introduction: '', phone: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (user) setForm({
|
||||||
|
name: user.name || '',
|
||||||
|
department: user.department || '',
|
||||||
|
title: user.title || '',
|
||||||
|
introduction: user.introduction || '',
|
||||||
|
phone: user.phone || '',
|
||||||
|
});
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
await api.put('/api/auth/me', {
|
||||||
|
name: form.name,
|
||||||
|
department: form.department,
|
||||||
|
title: form.title,
|
||||||
|
introduction: form.introduction,
|
||||||
|
});
|
||||||
|
updateProfile(form);
|
||||||
|
alert('保存成功');
|
||||||
|
} catch { alert('保存失败'); }
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!user) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<h2 style={{ marginBottom: 16 }}>个人设置</h2>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} style={{ background: '#fff', padding: 24, borderRadius: 8, maxWidth: 500 }}>
|
||||||
|
<div style={{ marginBottom: 14 }}>
|
||||||
|
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}>姓名</label>
|
||||||
|
<input value={form.name} onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||||
|
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 14 }}>
|
||||||
|
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}>手机号</label>
|
||||||
|
<input value={form.phone} disabled
|
||||||
|
style={{ width: '100%', padding: '8px 12px', border: '1px solid #eee', borderRadius: 4, background: '#f9f9f9' }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 14 }}>
|
||||||
|
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}>科室</label>
|
||||||
|
<input value={form.department} onChange={(e) => setForm({ ...form, department: e.target.value })}
|
||||||
|
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 14 }}>
|
||||||
|
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}>职称</label>
|
||||||
|
<input value={form.title} onChange={(e) => setForm({ ...form, title: e.target.value })}
|
||||||
|
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4 }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: 18 }}>
|
||||||
|
<label style={{ display: 'block', fontSize: 13, marginBottom: 4 }}>个人简介</label>
|
||||||
|
<textarea value={form.introduction} onChange={(e) => setForm({ ...form, introduction: e.target.value })} rows={4}
|
||||||
|
style={{ width: '100%', padding: '8px 12px', border: '1px solid #ddd', borderRadius: 4, resize: 'vertical' }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" style={{
|
||||||
|
padding: '10px 24px', background: '#1976d2', color: '#fff',
|
||||||
|
border: 'none', borderRadius: 4, fontSize: 14,
|
||||||
|
}}>
|
||||||
|
保存
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
8
frontend-doctor/src/router/AuthGuard.tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Navigate } from 'react-router-dom';
|
||||||
|
import { useAuthStore } from '../stores/auth.store';
|
||||||
|
|
||||||
|
export function AuthGuard({ children }: { children: React.ReactNode }) {
|
||||||
|
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
||||||
|
if (!isAuthenticated) return <Navigate to="/login" replace />;
|
||||||
|
return <>{children}</>;
|
||||||
|
}
|
||||||
41
frontend-doctor/src/router/index.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { createBrowserRouter, Navigate } from 'react-router-dom';
|
||||||
|
import { DoctorLayout } from '../components/layout/DoctorLayout';
|
||||||
|
import { AuthGuard } from './AuthGuard';
|
||||||
|
import { LoginPage } from '../pages/auth/LoginPage';
|
||||||
|
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';
|
||||||
|
import { ProfilePage } from '../pages/settings/ProfilePage';
|
||||||
|
|
||||||
|
export const router = createBrowserRouter([
|
||||||
|
{
|
||||||
|
path: '/login',
|
||||||
|
element: <LoginPage />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
element: (
|
||||||
|
<AuthGuard>
|
||||||
|
<DoctorLayout />
|
||||||
|
</AuthGuard>
|
||||||
|
),
|
||||||
|
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/:id/edit', element: <FollowUpEditPage /> },
|
||||||
|
{ path: 'profile', element: <ProfilePage /> },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
74
frontend-doctor/src/services/api-client.ts
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/** Doctor frontend API client — calls same backend as patient frontend */
|
||||||
|
|
||||||
|
interface ApiResponse<T> {
|
||||||
|
code: number;
|
||||||
|
data: T;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BASE_URL = 'http://localhost:5000';
|
||||||
|
|
||||||
|
// Endpoints that should NEVER include auth token
|
||||||
|
const PUBLIC_ENDPOINTS = ['/api/auth/login', '/api/auth/register', '/api/auth/send-sms', '/api/auth/refresh'];
|
||||||
|
|
||||||
|
function getToken(): string | null {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem('doc_auth');
|
||||||
|
if (!raw) return null;
|
||||||
|
const state = JSON.parse(raw);
|
||||||
|
return state?.state?.token ?? null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearAuth() {
|
||||||
|
localStorage.removeItem('doc_auth');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function request<T>(method: string, path: string, body?: unknown): Promise<ApiResponse<T>> {
|
||||||
|
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
||||||
|
|
||||||
|
// Only attach token for non-public endpoints
|
||||||
|
if (!PUBLIC_ENDPOINTS.includes(path)) {
|
||||||
|
const token = getToken();
|
||||||
|
if (token) headers['Authorization'] = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${BASE_URL}${path}`, {
|
||||||
|
method, headers,
|
||||||
|
body: body ? JSON.stringify(body) : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status === 401) {
|
||||||
|
clearAuth();
|
||||||
|
if (!window.location.pathname.includes('/login')) {
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
|
throw new Error('登录已过期,请重新登录');
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = await response.text();
|
||||||
|
let data: T;
|
||||||
|
try {
|
||||||
|
data = JSON.parse(text);
|
||||||
|
} catch {
|
||||||
|
data = text as unknown as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const msg = (data as Record<string, unknown>)?.message || response.statusText;
|
||||||
|
throw new Error(String(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
return { code: response.status, data, message: 'success' };
|
||||||
|
}
|
||||||
|
|
||||||
|
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),
|
||||||
|
};
|
||||||
|
|
||||||
|
export type { ApiResponse };
|
||||||
66
frontend-doctor/src/stores/auth.store.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { create } from 'zustand';
|
||||||
|
import { persist } from 'zustand/middleware';
|
||||||
|
import { api } from '../services/api-client';
|
||||||
|
import type { User } from '../types';
|
||||||
|
|
||||||
|
interface AuthState {
|
||||||
|
user: User | null;
|
||||||
|
token: string | null;
|
||||||
|
isAuthenticated: boolean;
|
||||||
|
login: (phone: string, code: string) => Promise<void>;
|
||||||
|
logout: () => void;
|
||||||
|
updateProfile: (data: Partial<User>) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useAuthStore = create<AuthState>()(
|
||||||
|
persist(
|
||||||
|
(set) => ({
|
||||||
|
user: null,
|
||||||
|
token: null,
|
||||||
|
isAuthenticated: false,
|
||||||
|
|
||||||
|
login: async (phone: string, code: string) => {
|
||||||
|
const res = await api.post<{
|
||||||
|
userId: string; name: string; role: string;
|
||||||
|
accessToken: string; refreshToken: string;
|
||||||
|
}>('/api/auth/login', { phone, smsCode: code });
|
||||||
|
|
||||||
|
// Verify role is doctor
|
||||||
|
if (res.data.role !== 'doctor') {
|
||||||
|
throw new Error('仅限医生账号登录');
|
||||||
|
}
|
||||||
|
|
||||||
|
set({
|
||||||
|
token: res.data.accessToken,
|
||||||
|
isAuthenticated: true,
|
||||||
|
user: { id: res.data.userId, name: res.data.name, role: res.data.role } as User,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fetch full profile
|
||||||
|
try {
|
||||||
|
const profile = await api.get<User>('/api/auth/me');
|
||||||
|
set({ user: profile.data });
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
},
|
||||||
|
|
||||||
|
logout: () => {
|
||||||
|
localStorage.removeItem('doc_auth');
|
||||||
|
set({ user: null, token: null, isAuthenticated: false });
|
||||||
|
},
|
||||||
|
|
||||||
|
updateProfile: (data: Partial<User>) => {
|
||||||
|
set((state) => ({
|
||||||
|
user: state.user ? { ...state.user, ...data } : null,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
name: 'doc_auth',
|
||||||
|
partialize: (state) => ({
|
||||||
|
user: state.user,
|
||||||
|
token: state.token,
|
||||||
|
isAuthenticated: state.isAuthenticated,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
101
frontend-doctor/src/types/index.ts
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
export interface User {
|
||||||
|
id: string;
|
||||||
|
phone: string;
|
||||||
|
name: string;
|
||||||
|
role: string;
|
||||||
|
gender: string;
|
||||||
|
department: string;
|
||||||
|
title: string;
|
||||||
|
specialty: string[];
|
||||||
|
introduction: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Patient {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
phone: string;
|
||||||
|
gender: string;
|
||||||
|
age: number;
|
||||||
|
medicalHistory: string[];
|
||||||
|
stentDate: string;
|
||||||
|
stentType: string;
|
||||||
|
lastRecordAt?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HealthRecord {
|
||||||
|
id: string;
|
||||||
|
type: string;
|
||||||
|
value: string;
|
||||||
|
unit: string;
|
||||||
|
recordedAt: string;
|
||||||
|
source: string;
|
||||||
|
notes?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Medication {
|
||||||
|
id: string;
|
||||||
|
drugName: string;
|
||||||
|
dosage: string;
|
||||||
|
frequency: string;
|
||||||
|
timeSlots: string[];
|
||||||
|
startDate: string;
|
||||||
|
endDate?: string;
|
||||||
|
notes?: string;
|
||||||
|
status: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Consultation {
|
||||||
|
id: string;
|
||||||
|
patientId: string;
|
||||||
|
patientName: string;
|
||||||
|
doctorId: string;
|
||||||
|
subject?: string;
|
||||||
|
status: string;
|
||||||
|
startedAt: string;
|
||||||
|
lastMessage?: string;
|
||||||
|
lastMessageAt?: string;
|
||||||
|
unreadCount?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConsultationMessage {
|
||||||
|
id: string;
|
||||||
|
senderId: string;
|
||||||
|
senderRole: string;
|
||||||
|
content: string;
|
||||||
|
contentType: string;
|
||||||
|
isRead: boolean;
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Report {
|
||||||
|
id: string;
|
||||||
|
patientId: string;
|
||||||
|
patientName: string;
|
||||||
|
title: string;
|
||||||
|
category: string;
|
||||||
|
imageUrls: string[];
|
||||||
|
status: string;
|
||||||
|
result?: string;
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FollowUp {
|
||||||
|
id: string;
|
||||||
|
patientId: string;
|
||||||
|
patientName: string;
|
||||||
|
doctorId: string;
|
||||||
|
title: string;
|
||||||
|
scheduledAt: string;
|
||||||
|
status: string;
|
||||||
|
notes?: string;
|
||||||
|
completedAt?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DashboardStats {
|
||||||
|
totalPatients: number;
|
||||||
|
activeConsultations: number;
|
||||||
|
pendingReports: number;
|
||||||
|
todayFollowUps: number;
|
||||||
|
weeklyNewPatients: number;
|
||||||
|
weeklyConsultations: number;
|
||||||
|
}
|
||||||
25
frontend-doctor/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
frontend-doctor/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
24
frontend-doctor/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
frontend-doctor/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()],
|
||||||
|
})
|
||||||
11
frontend-patient/.claude/launch.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.0.1",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Patient Frontend",
|
||||||
|
"runtimeExecutable": "cmd.exe",
|
||||||
|
"runtimeArgs": ["/c", "cd /d D:\\APP\\frontend-patient && npm run dev"],
|
||||||
|
"port": 5173
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
24
frontend-patient/.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
frontend-patient/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
frontend-patient/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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
15
frontend-patient/index.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||||
|
<meta name="theme-color" content="#2563EB" />
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||||
|
<title>健康管家 · 心脏健康管理</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
2953
frontend-patient/package-lock.json
generated
Normal file
36
frontend-patient/package.json
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"name": "health-manager-demo",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dayjs": "^1.11.20",
|
||||||
|
"echarts": "^6.0.0",
|
||||||
|
"echarts-for-react": "^3.0.6",
|
||||||
|
"framer-motion": "^12.39.0",
|
||||||
|
"react": "^19.2.6",
|
||||||
|
"react-dom": "^19.2.6",
|
||||||
|
"react-router-dom": "^7.15.1",
|
||||||
|
"zustand": "^5.0.13"
|
||||||
|
},
|
||||||
|
"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
frontend-patient/public/favicon.svg
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
24
frontend-patient/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 |
6
frontend-patient/src/App.tsx
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { RouterProvider } from 'react-router-dom';
|
||||||
|
import { router } from './router';
|
||||||
|
|
||||||
|
export function App() {
|
||||||
|
return <RouterProvider router={router} />;
|
||||||
|
}
|
||||||