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,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);
|
||||
Reference in New Issue
Block a user