public UnassignedWindow(AppointmentPriority appointment, List <TechnicianDBInfo> techniciansList)
        {
            InitializeComponent();

            EventBus.EventBus.Instance.Register(this);

            this.appointment     = appointment;
            this.techniciansList = techniciansList;

            txtCost.Text      = string.Format("R {0}", appointment.Cost);
            txtOperation.Text = appointment.Operation;
            switch (appointment.Priority)
            {
            case 0:
                txtPriority.Text = string.Format("{0}  - Very Urgent", appointment.Priority);
                break;

            case 1:
                txtPriority.Text = string.Format("{0}  - Very Urgent", appointment.Priority);
                break;

            case 2:
                txtPriority.Text = string.Format("{0}  - Moderate Urgent", appointment.Priority);
                break;

            case 3:
                txtPriority.Text = string.Format("{0}  - Medium Urgent", appointment.Priority);
                break;

            case 4:
                txtPriority.Text = string.Format("{0}  - Least Urgent", appointment.Priority);
                break;

            case 5:
                txtPriority.Text = string.Format("{0}  - Least Urgent", appointment.Priority);
                break;

            default:
                break;
            }
            txtDate.Text       = appointment.Time.ToString("d MMMM, yyyy hh:mm tt");
            tbExtraDtails.Text = appointment.ExtraDetails;

            lvAllTechnicians.ItemsSource = techniciansList;
        }
        private void lvUnassignedAppointments_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            var item = (sender as ListView).SelectedItem;

            if (item != null)
            {
                try
                {
                    //dynamic selectedClient = (ExpandoObject)item;

                    AppointmentPriority selectedDictionaryItem = (AppointmentPriority)item;

                    NavigationService.NavigateToWithoutHide(new UnassignedWindow(selectedDictionaryItem, serviceDelivery.TechniciansList));
                }
                catch (Exception exception)
                {
                    ErrorHandler.ErrorHandle error = ErrorHandler.ErrorHandle.getInstance();
                    error.handle(exception, true);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <Appointment> CreateOnPatientRequest(TimeSpan preferredStartTime, TimeSpan preferredEndTime, DateTime latestAcceptableDate,
                                                               Patient requestingPatient, Doctor requestedDoctor, AppointmentPriority appointmentPriority)
        {
            Room   room   = null;
            Doctor doctor = null;
            var    start  = DateTime.Now;
            var    end    = DateTime.Now;


            if (preferredStartTime < requestedDoctor.WorkingHoursStart)
            {
                preferredStartTime = requestedDoctor.WorkingHoursStart;
            }

            if (preferredEndTime > requestedDoctor.WorkingHoursEnd)
            {
                preferredEndTime = requestedDoctor.WorkingHoursEnd;
            }

            switch (appointmentPriority)
            {
            case AppointmentPriority.Doctor:
                var(freeRoom, timeSlotStart) = await _roomService.GetFirstFreeByTimeSlotAndDoctor(preferredStartTime, preferredEndTime, latestAcceptableDate, requestedDoctor);

                if (freeRoom != null && timeSlotStart != null)
                {
                    room   = freeRoom;
                    start  = timeSlotStart.Value;
                    end    = start + TimeSpan.FromMinutes(29);
                    doctor = requestedDoctor;
                }
                else
                {
                    goto case AppointmentPriority.Time;
                }
                break;

            case AppointmentPriority.Time:
                var allDoctors = await _doctorService.GetAll();

                foreach (var doc in allDoctors.ToList())
                {
                    (freeRoom, timeSlotStart) = await _roomService.GetFirstFreeByTimeSlotAndDoctor(preferredStartTime, preferredEndTime, latestAcceptableDate, requestedDoctor);

                    if (freeRoom == null || timeSlotStart == null)
                    {
                        continue;
                    }
                    room   = freeRoom;
                    start  = timeSlotStart.Value;
                    end    = start + TimeSpan.FromMinutes(29);
                    doctor = doc;
                    break;
                }
                if (room == null || doctor == null)
                {
                    return(null);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(appointmentPriority), appointmentPriority, null);
            }

            var patientsAppointments = await GetAllByPatient(requestingPatient);

            if (patientsAppointments.Any(a => (a.StartDateTime >= start && a.StartDateTime <= end) ||
                                         (a.EndDateTime >= start && a.EndDateTime <= end) ||
                                         (a.StartDateTime >= start && a.EndDateTime <= end)))
            {
                return(null);
            }

            var appointment = new Appointment();

            appointment = await Create(appointment);

            appointment.IsActive      = true;
            appointment.StartDateTime = start;
            appointment.EndDateTime   = end;
            appointment.Doctor        = doctor;
            appointment.Patient       = requestingPatient;
            appointment.Room          = room;
            appointment.Status        = AppointmentStatus.Scheduled;
            appointment.Type          = doctor?.Specializations.FirstOrDefault();

            return(await Update(appointment));
        }