From 94da24572e5679ce1b1251aac08830f27d3345b1 Mon Sep 17 00:00:00 2001 From: MingNian <1281442923@qq.com> Date: Fri, 22 May 2026 15:38:08 +0800 Subject: [PATCH] fix: doctor can see patient-created follow-ups, camelCase JSON support - FollowUpService: doctor query includes unassigned (DoctorId=null) follow-ups - FollowUpController: doctor creates follow-up with correct patientId and sets DoctorId - FollowUpCreateRequest/UpdateRequest: changed from positional record to class for System.Text.Json compat - Program.cs: added PropertyNameCaseInsensitive for camelCase JSON deserialization --- .../Services/FollowUpService.cs | 2 +- .../Controllers/FollowUpController.cs | 32 ++++++++++++++++--- backend/src/HealthManager.WebApi/Program.cs | 6 +++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/backend/src/HealthManager.Application/Services/FollowUpService.cs b/backend/src/HealthManager.Application/Services/FollowUpService.cs index 5376a95..96d96bd 100644 --- a/backend/src/HealthManager.Application/Services/FollowUpService.cs +++ b/backend/src/HealthManager.Application/Services/FollowUpService.cs @@ -16,7 +16,7 @@ public class FollowUpService(AppDbContext db) public async Task> GetDoctorFollowUpsAsync(Guid doctorId) => await db.FollowUps .Include(f => f.Patient) - .Where(f => f.DoctorId == doctorId) + .Where(f => f.DoctorId == doctorId || f.DoctorId == null) .OrderBy(f => f.ScheduledAt) .ToListAsync(); diff --git a/backend/src/HealthManager.WebApi/Controllers/FollowUpController.cs b/backend/src/HealthManager.WebApi/Controllers/FollowUpController.cs index f7065db..f19d42a 100644 --- a/backend/src/HealthManager.WebApi/Controllers/FollowUpController.cs +++ b/backend/src/HealthManager.WebApi/Controllers/FollowUpController.cs @@ -45,8 +45,17 @@ public class FollowUpController(FollowUpService followUpService) : ControllerBas [HttpPost] public async Task AddFollowUp([FromBody] FollowUpCreateRequest request) { - var followUp = await followUpService.AddAsync(UserId, request.Title, request.Description, - request.ScheduledAt, request.ReminderEnabled); + var patientId = UserId; + Guid? doctorId = null; + + if (Role == "doctor" && request.PatientId.HasValue) + { + patientId = request.PatientId.Value; + doctorId = UserId; + } + + var followUp = await followUpService.AddAsync(patientId, request.Title, request.Description, + request.ScheduledAt, request.ReminderEnabled, doctorId); return Ok(new { followUp.Id, followUp.Title, followUp.Status }); } @@ -61,7 +70,20 @@ public class FollowUpController(FollowUpService followUpService) : ControllerBas } } -public record FollowUpCreateRequest(string Title, string? Description, DateTime ScheduledAt, bool ReminderEnabled = true); +public class FollowUpCreateRequest +{ + public string Title { get; set; } = string.Empty; + public string? Description { get; set; } + public DateTime ScheduledAt { get; set; } + public bool ReminderEnabled { get; set; } = true; + public Guid? PatientId { get; set; } +} -public record FollowUpUpdateRequest( - string? Title, string? Description, DateTime? ScheduledAt, string? Status, string? Notes); +public class FollowUpUpdateRequest +{ + public string? Title { get; set; } + public string? Description { get; set; } + public DateTime? ScheduledAt { get; set; } + public string? Status { get; set; } + public string? Notes { get; set; } +} diff --git a/backend/src/HealthManager.WebApi/Program.cs b/backend/src/HealthManager.WebApi/Program.cs index 29bba0e..809c627 100644 --- a/backend/src/HealthManager.WebApi/Program.cs +++ b/backend/src/HealthManager.WebApi/Program.cs @@ -74,7 +74,11 @@ builder.Services.AddCors(options => }); }); -builder.Services.AddControllers(); +builder.Services.AddControllers() + .AddJsonOptions(options => + { + options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; + }); var app = builder.Build();