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)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user