Backend: .NET 10 + PostgreSQL + EF Core + JWT + SignalR Frontend patient: React 19 + TypeScript + Vite (mobile H5) Frontend doctor: React 19 + TypeScript + Vite (desktop web)
68 lines
2.6 KiB
C#
68 lines
2.6 KiB
C#
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);
|