fix: Missing input validators + No patient update endpoint + Pagination inconsistencies + Missing list/get endpoints

This commit is contained in:
voltsrage
2026-06-21 19:13:13 +08:00
parent 33895122d1
commit a37fad0e57
26 changed files with 932 additions and 22 deletions
@@ -90,6 +90,44 @@ public class PatientService : IPatientService
return new PagedResult<Patient>(patients, page, pageSize, total);
}
public async Task<Patient> UpdateAsync(Guid id, UpdatePatientRequest req)
{
var patient = await _db.Patients.FindAsync(id)
?? throw new NotFoundException("Patient not found.", "PATIENT_NOT_FOUND");
var before = new
{
patient.FirstName, patient.LastName, patient.DateOfBirth,
patient.Gender, patient.BloodType, patient.Allergies,
patient.EmergencyContactName, patient.EmergencyContactPhone
};
if (req.FirstName is not null) patient.FirstName = req.FirstName;
if (req.LastName is not null) patient.LastName = req.LastName;
if (req.DateOfBirth is not null) patient.DateOfBirth = req.DateOfBirth.Value;
if (req.Gender is not null) patient.Gender = req.Gender;
if (req.BloodType is not null) patient.BloodType = req.BloodType;
if (req.Allergies is not null) patient.Allergies = req.Allergies;
if (req.EmergencyContactName is not null) patient.EmergencyContactName = req.EmergencyContactName;
if (req.EmergencyContactPhone is not null) patient.EmergencyContactPhone = req.EmergencyContactPhone;
await _db.SaveChangesAsync();
await _audit.WriteAsync(
AuditAction.PatientUpdated,
"Patient",
patient.Id,
previousValue: before,
newValue: new
{
patient.FirstName, patient.LastName, patient.DateOfBirth,
patient.Gender, patient.BloodType, patient.Allergies,
patient.EmergencyContactName, patient.EmergencyContactPhone
});
return patient;
}
public async Task<Patient> GetByIdAsync(Guid id)
{
var patient = await _db.Patients