public GetPatientNextAppointmentResponse GetPatientNextAppointment(GetPatientNextAppointmentRequest request) { var validationResult = _getPatientNextAppointmentRequestValidator.ValidateRequest(request); if (!validationResult.PassedValidation) { throw new ObjectNotFoundException(validationResult.Errors.First()); } var booking = _context.Order .Where(x => x.PatientId == request.PatientId && x.StartTime > DateTime.UtcNow && !x.Cancelled) .OrderBy(x => x.StartTime) .FirstOrDefault(); if (booking == null) { return new GetPatientNextAppointmentResponse(); } return new GetPatientNextAppointmentResponse { Id = booking.Id, DoctorId = booking.DoctorId, StartTime = booking.StartTime, EndTime = booking.EndTime }; }
public PdrValidationResult ValidateRequest(GetPatientNextAppointmentRequest request) { var result = new PdrValidationResult(true); if (BookingNotFound(request, ref result)) { return(result); } return(result); }
private bool BookingNotFound(GetPatientNextAppointmentRequest request, ref PdrValidationResult result) { var errors = new List <string>(); var isBookingsExist = _context.Order .Where(x => x.PatientId == request.PatientId && !x.Cancelled) .Any(); if (!isBookingsExist) { errors.Add($"Active Bookings for Patient ID {request.PatientId} not found"); } if (errors.Any()) { result.PassedValidation = false; result.Errors.AddRange(errors); return(true); } return(false); }