fix: Missing input validators + No patient update endpoint + Pagination inconsistencies + Missing list/get endpoints
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user