示例#1
0
 /// <summary>
 /// Maps the domain object to the data contract
 /// </summary>
 /// <param name="domainObject">
 /// The domain object.
 /// </param>
 /// <returns>
 /// The <see cref="AppointmentDurationDataContract"/>
 /// </returns>
 private AppointmentDurationDataContract MapToDataContract(AppointmentDuration domainObject)
 {
     return(new AppointmentDurationDataContract
     {
         DurationId = domainObject.DurationId,
         AppointmentLength = domainObject.AppointmentLength.ToString()
     });
 }
示例#2
0
 private void ResetComponentValues()
 {
     DoctorComboBox.SelectedIndex  = -1;
     DatePicker.SelectedDate       = null;
     AppointmentTime.SelectedIndex = -1;
     AppointmentDuration.Clear();
     AppointmentTypeComboBox.SelectedItem = null;
     RoomComboBox.SelectedIndex           = -1;
 }
 private void ClearAddAppointment(object sender, DialogClosingEventArgs eventArgs)
 {
     AppointmentTimePicker.SelectedTime = null;
     PatientNameComboBox.SelectedItem   = null;
     DoctorNameComboBox.SelectedItem    = null;
     AppointmentDuration.Clear();
     AppointmentDatePicker.SelectedDate = DateTime.Today;
     validation.Text = "";
 }
 public void addSubmit(object sender, RoutedEventArgs e)
 {
     if (ViewModel.Validate())
     {
         ViewModel.addAppointment();
         AppointmentDuration.Clear();
         AppointmentTimePicker.SelectedTime = null;
         PatientNameComboBox.SelectedItem   = null;
         DoctorNameComboBox.SelectedItem    = null;
         AppointmentDatePicker.SelectedDate = DateTime.Today;
     }
 }
示例#5
0
        public bool Validate()
        {
            AppointmentDuration = (AppointmentDuration != null) ? AppointmentDuration.Trim() : "";

            if (AppointmentDuration == "")
            {
                textValidation = "Can't Have empty Values";
                return(false);
            }
            if (PatientNameComboBox == null)
            {
                textValidation = "Can't Have empty Values";

                return(false);
            }
            if (DoctorNameComboBox == null)
            {
                textValidation = "Can't Have empty Values";

                return(false);
            }
            for (int i = 0; i < AppointmentDuration.Length; i++)
            {
                if (AppointmentDuration[i] >= 'a' && AppointmentDuration[i] <= 'z')
                {
                    textValidation = "Can't Have empty Values";
                    return(false);
                }
            }
            bool foundPatient = false, foundDoctor = false;

            foreach (Patient patient in Hospital.Patients.Values)
            {
                if (patient.GetType() == typeof(AppointmentPatient) && PatientNameComboBox.Value == patient.Name)
                {
                    foundPatient = true;
                }
            }
            foreach (Employee employee in Hospital.Employees.Values)
            {
                if (employee.GetType() == typeof(Doctor) && DoctorNameComboBox.Value == employee.Name)
                {
                    foundDoctor = true;
                }
            }
            if (!foundPatient || !foundDoctor)
            {
                return(false);
            }
            return(true);
        }
        public async Task HandleAsync(ScheduleAppointmentCommand command, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var unitOfWork = await _unitOfWorkFactory.CreateAsync())
            {
                // Convert from external representations to domain representations
                var appointmentId       = new AppointmentId(command.AppointmentId);
                var doctorId            = new DoctorId(command.DoctorId);
                var patientId           = new PatientId(command.PatientId);
                var appointmentDuration = new AppointmentDuration(command.AppointmentDurationInMinutes);

                // Invoke domain logic
                await _scheduleAppointmentService.ScheduleAsync(appointmentId, doctorId, patientId, command.AppointmentAt,
                                                                appointmentDuration, cancellationToken);

                await unitOfWork.CommitAsync();
            }
        }
        public async Task ScheduleAsync(AppointmentId appointmentId, DoctorId doctorId, PatientId patientId, DateTime requestedAppointmentAt, AppointmentDuration requestedAppointmentDuration,
                                        CancellationToken cancellationToken = default)
        {
            if (requestedAppointmentAt < _systemClockService.UtcNow.DateTime)
            {
                throw new DomainValidationException("The appointment could not be scheduled because it occurs in the past.");
            }

            var doctor = await _doctorRepository.GetByIdAsync(doctorId, cancellationToken);

            if (doctor == null)
            {
                throw new EntityNotFoundException("The requested doctor was not found.");
            }

            var patient = await _patientRepository.GetByIdAsync(patientId, cancellationToken);

            if (patient == null)
            {
                throw new EntityNotFoundException("The requested patient was not found.");
            }

            // Does the requested appointment occur during the doctor's availability?

            var doctorAvailabilities = await _doctorAvailabilityRepository.GetAllForDoctorAsync(doctorId, cancellationToken);

            var doctorIsAvailable = doctorAvailabilities.Any(a =>
                                                             a.DayOfWeek == requestedAppointmentAt.DayOfWeek &&                            // Occurs on an available day of the week
                                                             a.StartsAt <= requestedAppointmentAt.TimeOfDay && // After that day of the week's start time
                                                             a.EndsAt >= requestedAppointmentAt.TimeOfDay + requestedAppointmentDuration); // And ends before that day of the week's end time

            if (!doctorIsAvailable)
            {
                throw new DomainValidationException("The appointment could not be scheduled because it is outside of the doctor's availability.");
            }

            // Determine if there are any scheduling conflicts.
            // Algorithm description: Two time periods overlap if each one starts before the other one ends.

            var doctorAppointments = await _appointmentRepository.GetAllUpcomingForDoctorAsync(doctorId, cancellationToken);

            var doctorHasConflictingAppointment = doctorAppointments.Any(existingAppointment =>
                                                                         requestedAppointmentAt < existingAppointment.AppointmentAt.Add(existingAppointment.AppointmentDuration) &&
                                                                         existingAppointment.AppointmentAt < requestedAppointmentAt.Add(requestedAppointmentDuration));

            if (doctorHasConflictingAppointment)
            {
                throw new DomainValidationException("The appointment could not be scheduled because the doctor has a conflicting appointment.");
            }

            var patientAppointments = await _appointmentRepository.GetAllUpcomingForPatientAsync(patientId, cancellationToken);

            var patientHasConflictingAppointment = patientAppointments.Any(existingAppointment =>
                                                                           requestedAppointmentAt < existingAppointment.AppointmentAt.Add(existingAppointment.AppointmentDuration) &&
                                                                           existingAppointment.AppointmentAt < requestedAppointmentAt.Add(requestedAppointmentDuration));

            if (patientHasConflictingAppointment)
            {
                throw new DomainValidationException("The appointment could not be scheduled because the patient has a conflicting appointment.");
            }

            var appointment = new Appointment(appointmentId, doctorId, patientId, requestedAppointmentAt, requestedAppointmentDuration);

            await _appointmentRepository.CreateAsync(appointment, cancellationToken);
        }