Ejemplo n.º 1
0
        /*
         * Adds a appointment. Returns null if adding succeeded.
         */
        public ResponseErrorEnum?AddAppointment(AddAppointmentRequest request)
        {
            try
            {
                var alreadyHasAppointment = _appointmentRepository.Exists(a => a.StaffId == request.StaffId && a.Date == request.Date);
                if (alreadyHasAppointment)
                {
                    return(ResponseErrorEnum.StaffAlreadyHasAppointmentOnDateTime);
                }

                var appointmentStatus = request.CreatorUserType == UserTypeEnum.PATIENT ? Status.WAIT : Status.ACCEPTED;

                var appointment = new Appointment
                {
                    PatientId   = request.PatientId,
                    StaffId     = request.StaffId,
                    CreatedAt   = DateTime.Now,
                    Date        = request.Date,
                    Description = request.Description,
                    Status      = appointmentStatus
                };

                _appointmentRepository.Insert(appointment);
                _appointmentRepository.Save();
            }
            catch
            {
                // TODO: Log the exception.
                return(ResponseErrorEnum.RepositoryError);
            }

            return(null);
        }
        public Guid AddNewAppointment(AddAppointmentRequest newAppointment)
        {
            var bookingId = new Guid();

            var validatedRquest = _addBookingValidator.ValidateRequest(newAppointment);

            if (!validatedRquest.PassedValidation)
            {
                throw new ArgumentException(validatedRquest.Errors.First());
            }

            var myBooking = new Order
            {
                Id          = bookingId,
                StartTime   = newAppointment.StartTime,
                EndTime     = newAppointment.EndTime,
                PatientId   = validatedRquest.AppointmentPatient.Id,
                DoctorId    = validatedRquest.AppointmentPatient.Id,
                Patient     = validatedRquest.AppointmentPatient,
                Doctor      = validatedRquest.AppointmentDoctor,
                SurgeryType = (int)validatedRquest.AppointmentPatient.Clinic.SurgeryType
            };

            _context.Order.AddRange(new List <Order> {
                myBooking
            });
            _context.SaveChanges();

            return(myBooking.Id);
        }
        private bool IsAppointmentSlotAvailable(AddAppointmentRequest newAppointment, AppointmentValidationResult result)
        {
            result.AppointmentPatient = _context.Patient.FirstOrDefault(x => x.Id == newAppointment.PatientId);

            if (result.AppointmentPatient == null)
            {
                result.PassedValidation = false;
                result.Errors.Add($"Patient {newAppointment.PatientId} does not exist");

                return(false);
            }

            result.AppointmentDoctor = _context.Doctor.FirstOrDefault(x => x.Id == newAppointment.DoctorId);

            if (result.AppointmentDoctor == null)
            {
                result.PassedValidation = false;
                result.Errors.Add($"Doctor {newAppointment.DoctorId} does not exist");

                return(false);
            }

            if (result.AppointmentDoctor.Orders.Any(a => a.StartTime <= newAppointment.EndTime && a.EndTime >= newAppointment.StartTime && !a.IsCancelled))
            {
                result.PassedValidation = false;
                result.Errors.Add("Appointment slot is taken");

                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public void Add(Appointment appointment)
        {
            var request = new AddAppointmentRequest();

            request.Appointment = appointment;
            var response = HttpPost <AddAppointmentRequest>("api/appointment/add", request, MediaType.Json);
        }
        public bool IsAppointmentTimeValid(AddAppointmentRequest request, AppointmentValidationResult result)
        {
            if (request.StartTime < DateTime.UtcNow)
            {
                result.PassedValidation = false;
                result.Errors.Add("Appointmnet cannot be in the past");

                return(false);
            }

            return(true);
        }
 public IActionResult AddBooking(AddAppointmentRequest newAppointment)
 {
     try
     {
         return(Ok(_appointmentService.AddNewAppointment(newAppointment)));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex));
     }
 }
        public AppointmentValidationResult ValidateRequest(AddAppointmentRequest request)
        {
            var result = new AppointmentValidationResult(true);

            if (!IsAppointmentTimeValid(request, result))
            {
                return(result);
            }

            if (!IsAppointmentSlotAvailable(request, result))
            {
                return(result);
            }

            return(result);
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> AddAppointment([FromBody] AddAppointmentRequest request)
        {
            _unityOfWork.BeginTransaction();
            try
            {
                var result = await _mediator.Send(request, CancellationToken.None);

                _unityOfWork.Commit();
                return(Created("", result));
            }
            catch (Exception e)
            {
                _unityOfWork.Rollback();
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 9
0
 public AddAppointmentResponse add(AddAppointmentRequest request)
 {
     try
     {
         var response = new AddAppointmentResponse();
         var bc       = new AppointmentComponent();
         response.Result = bc.Add(request.Appointment);
         return(response);
     }
     catch (Exception ex)
     {
         var httpError = new HttpResponseMessage()
         {
             StatusCode   = (HttpStatusCode)422,
             ReasonPhrase = ex.Message
         };
         throw new HttpResponseException(httpError);
     }
 }