Пример #1
0
        public void TryAddNewAppointment(Action <bool> operationResultCallback,
                                         AggregateIdentifier aggregateId,
                                         Guid patientId, string description,
                                         Time startTime, Time endTime,
                                         Guid therapyPlaceId, Guid labelId,
                                         Guid appointmentId,
                                         ActionTag actionTag,
                                         Action <string> errorCallback)
        {
            RequestLock(
                successfulLocked =>
            {
                if (!successfulLocked)
                {
                    operationResultCallback(false);
                    return;
                }

                readModelRepository.RequestAppointmentSetOfADay(
                    appointmentSet =>
                {
                    if (!AddingIsPossible(therapyPlaceId, appointmentId, startTime, endTime, appointmentSet))
                    {
                        ReleaseAllLocks(errorCallback);
                        operationResultCallback(false);
                        return;
                    }

                    commandBus.SendCommand(new AddAppointment(appointmentSet.Identifier,
                                                              appointmentSet.AggregateVersion,
                                                              session.LoggedInUser.Id,
                                                              actionTag,
                                                              patientId,
                                                              description,
                                                              startTime,
                                                              endTime,
                                                              therapyPlaceId,
                                                              labelId,
                                                              appointmentId));



                    ReleaseAllLocks(errorCallback);
                    operationResultCallback(true);
                },
                    aggregateId,
                    errorCallback
                    );
            },
                aggregateId.MedicalPracticeId,
                aggregateId.Date,
                errorCallback
                );
        }
Пример #2
0
        public PrintDialogViewModel(AggregateIdentifier identifier,
                                    IClientMedicalPracticeRepository medicalPracticeRepository,
                                    IClientReadModelRepository readModelRepository,
                                    Action <string> errorCallback)
        {
            Cancel = new Command(CloseWindow);
            Print  = new ParameterrizedCommand <FrameworkElement>(DoPrint);

            medicalPracticeRepository.RequestMedicalPractice(
                practice =>
            {
                readModelRepository.RequestAppointmentSetOfADay(
                    appointmentSet =>
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        var initialGridSize = CurrentGridSize ?? new Size(new Width(850), new Height(600));

                        AppointmentGrid = new PrintAppointmentGridViewModel(identifier, practice, appointmentSet.Appointments, initialGridSize);
                    });
                },
                    identifier,
                    errorCallback
                    );
            },
                identifier.MedicalPracticeId,
                identifier.Date,
                errorCallback
                );
        }
        private void ComputeTimeSlots(IClientMedicalPracticeRepository medicalPracticeRepository, Guid medicalPracticeId)
        {
            medicalPracticeRepository.RequestMedicalPractice(
                loadedPractice =>
            {
                readModelRepository.RequestAppointmentSetOfADay(
                    fixAppointmentSet =>
                {
                    medicalPractice = loadedPractice;

                    IDictionary <TherapyPlaceRowIdentifier, IEnumerable <TimeSlot> > allSlots =
                        new Dictionary <TherapyPlaceRowIdentifier, IEnumerable <TimeSlot> >();

                    IDictionary <TherapyPlace, IList <Appointment> > sortedAppointments =
                        new Dictionary <TherapyPlace, IList <Appointment> >();

                    foreach (var therapyPlace in medicalPractice.GetAllTherapyPlaces())
                    {
                        sortedAppointments.Add(therapyPlace, new List <Appointment>());
                    }

                    fixAppointmentSet.Appointments.Do(appointment => sortedAppointments[appointment.TherapyPlace].Add(appointment));

                    var openingTime = medicalPractice.HoursOfOpening.GetOpeningTime(creationDate);
                    var closingTime = medicalPractice.HoursOfOpening.GetClosingTime(creationDate);

                    foreach (var therapyRowData in sortedAppointments)
                    {
                        var slots = ComputeSlots(openingTime, closingTime, therapyRowData.Value);

                        allSlots.Add(
                            new TherapyPlaceRowIdentifier(new AggregateIdentifier(creationDate, medicalPractice.Id), therapyRowData.Key.Id),
                            slots);
                    }

                    allAvailableTimeSlots = allSlots;
                },
                    new AggregateIdentifier(creationDate, loadedPractice.Id, loadedPractice.Version),
                    errorCallback
                    );
            },
                medicalPracticeId,
                creationDate,
                errorCallback
                );
        }
Пример #4
0
        private void OnSelectedDateVariableChanged(Date date)
        {
            if (date != CurrentLocation.PlaceAndDate.Date)
            {
                medicalPracticeRepository.RequestMedicalPractice(
                    newMedicalPractice =>
                {
                    if (newMedicalPractice.HoursOfOpening.IsOpen(date))
                    {
                        readModelRepository.RequestAppointmentSetOfADay(
                            fixedAppointmentSet =>
                        {
                            IDictionary <TherapyPlace, IList <Appointment> > sortedAppointments = new Dictionary <TherapyPlace, IList <Appointment> >();

                            foreach (var therapyPlace in newMedicalPractice.GetAllTherapyPlaces())
                            {
                                sortedAppointments.Add(therapyPlace, new List <Appointment>());
                            }

                            foreach (var appointment in fixedAppointmentSet.Appointments)
                            {
                                if (appointment != OriginalAppointment)
                                {
                                    sortedAppointments[appointment.TherapyPlace].Add(appointment);
                                }
                            }

                            var openingTime = newMedicalPractice.HoursOfOpening.GetOpeningTime(date);
                            var closingTime = newMedicalPractice.HoursOfOpening.GetClosingTime(date);

                            var appointmentDuration = new Duration(BeginTime, EndTime);

                            foreach (var therapyRowData in sortedAppointments)
                            {
                                var slots        = ComputeAllSlotsWithinARow(openingTime, closingTime, therapyRowData.Value);
                                var suitableSlot = GetSlotForAppointment(slots, appointmentDuration);

                                if (suitableSlot != null)
                                {
                                    Application.Current.Dispatcher.Invoke(() =>
                                    {
                                        SetNewLocation(
                                            new TherapyPlaceRowIdentifier(new AggregateIdentifier(date,
                                                                                                  CurrentLocation.PlaceAndDate.MedicalPracticeId),
                                                                          therapyRowData.Key.Id),
                                            suitableSlot.Begin,
                                            suitableSlot.Begin + appointmentDuration
                                            );
                                    });

                                    return;
                                }
                            }

                            viewModelCommunication.Send(
                                new ShowNotification("cannot move the OriginalAppointment to that day. No timeslot is big enough!", 5)
                                );

                            selectedDateVariable.Value = CurrentLocation.PlaceAndDate.Date;
                        },
                            new AggregateIdentifier(date, currentMedicalPracticeVersion.Id),
                            errorCallback
                            );
                    }
                    else
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            viewModelCommunication.Send(
                                new ShowNotification("cannot move an OriginalAppointment to a day where the practice is closed!", 5)
                                );
                        });

                        selectedDateVariable.Value = CurrentLocation.PlaceAndDate.Date;
                    }
                },
                    currentMedicalPracticeVersion.Id,
                    date,
                    errorCallback
                    );
            }
        }