private void OnRoomFilterVariableChanged(Guid?guid)
        {
            if (guid == null)
            {
                SelectedRoomFilter = allRoomFilter;
            }
            else
            {
                medicalPracticeRepository.RequestMedicalPractice(
                    medicalPractice =>
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        var room = medicalPractice.GetRoomById(guid.Value);

                        selectedRoomFilter = new RoomSelectorData(room.Name, room.Id, room.DisplayedColor);
                        PropertyChanged.Notify(this, nameof(SelectedRoomFilter));
                    });
                },
                    displayedMedicalPracticeVariable.Value,
                    selectedDateVariable.Value,
                    errorCallback
                    );
            }
        }
Exemple #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
                );
        }
        public void RequestBuild(Action <IEnumerable <ITherapyPlaceRowViewModel> > viewModelsAvailable,
                                 AggregateIdentifier identifier, IEnumerable <Room> rooms,
                                 Action <string> errorCallback)
        {
            medicalPracticeRepository.RequestMedicalPractice(
                practice =>
            {
                viewModelsAvailable(
                    (
                        from room in rooms
                        from therapyPlace in room.TherapyPlaces

                        let location = new TherapyPlaceRowIdentifier(identifier, therapyPlace.Id)
                                       let hoursOfOpeing = practice.HoursOfOpening

                                                           select new ViewModels.TherapyPlaceRowView.TherapyPlaceRowViewModel(
                            viewModelCommunication,
                            therapyPlaceTypeRepository,
                            therapyPlace,
                            room.DisplayedColor,
                            location,
                            adornerControl,
                            hoursOfOpeing.GetOpeningTime(location.PlaceAndDate.Date),
                            hoursOfOpeing.GetClosingTime(location.PlaceAndDate.Date),
                            appointmentModificationsVariable,
                            appointmentGridSizeVariable.Value.Width,
                            errorCallback)
                    ).ToList()
                    );
            },
                identifier.MedicalPracticeId,
                identifier.PracticeVersion,
                errorCallback
                );
        }
Exemple #4
0
        public MedicalPracticeSelectorViewModel(ISession session,
                                                IClientMedicalPracticeRepository medicalPracticeRepository,
                                                ILocalSettingsRepository localSettingsRepository,
                                                ISharedState <Guid> selectedMedicalPracticeIdVariable,
                                                ISharedStateReadOnly <AppointmentModifications> appointmentModificationsVariable,
                                                Action <string> errorCallback)
        {
            this.localSettingsRepository           = localSettingsRepository;
            this.selectedMedicalPracticeIdVariable = selectedMedicalPracticeIdVariable;
            this.appointmentModificationsVariable  = appointmentModificationsVariable;

            selectedMedicalPracticeIdVariable.StateChanged += OnSelectedMedicalPracticeIdVariableChanged;
            appointmentModificationsVariable.StateChanged  += OnAppointmentModificationVariableChanged;

            AvailableMedicalPractices = session.LoggedInUser
                                        .ListOfAccessablePractices
                                        .Select(practiceId => new MedicalPracticeDisplayData(practiceId, practiceId.ToString()))
                                        .ToObservableCollection();

            foreach (var medicalPracticeDisplayData in AvailableMedicalPractices)
            {
                medicalPracticeRepository.RequestMedicalPractice(
                    practice =>
                {
                    medicalPracticeDisplayData.PracticeName = practice.Name;
                },
                    medicalPracticeDisplayData.MedicalPracticeId,
                    errorCallback
                    );
            }

            SelectedMedicalPractice = AvailableMedicalPractices.First(practice => practice.MedicalPracticeId == selectedMedicalPracticeIdVariable.Value);

            PracticeIsSelectable = true;
        }
        public void RequestBuild(Action <IAppointmentGridViewModel> viewModelAvailableCallback, AggregateIdentifier identifier, Action <string> errorCallback)
        {
            medicalPracticeRepository.RequestMedicalPractice(
                medicalPractice =>
            {
                if (medicalPractice.HoursOfOpening.IsOpen(identifier.Date))
                {
                    therapyPlaceRowViewModelBuilder.RequestBuild(
                        therapyPlaceRowViewModels =>
                    {
                        readModelRepository.RequestAppointmentsOfADayReadModel(
                            readModel =>
                        {
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                foreach (var appointment in readModel.Appointments)
                                {
                                    appointmentViewModelBuilder.Build(appointment, identifier, errorCallback);
                                }

                                viewModelAvailableCallback(new ViewModels.AppointmentGrid.AppointmentGridViewModel(identifier,
                                                                                                                   medicalPractice,
                                                                                                                   viewModelCommunication,
                                                                                                                   gridSizeVariable,
                                                                                                                   roomFilterVariable,
                                                                                                                   displayedMedicalPracticeVariable,
                                                                                                                   appointmentModificationsVariable,
                                                                                                                   appointmentViewModelBuilder,
                                                                                                                   readModel,
                                                                                                                   therapyPlaceRowViewModels,
                                                                                                                   errorCallback));
                            });
                        },
                            identifier,
                            errorCallback
                            );
                    },
                        identifier,
                        medicalPractice.Rooms,
                        errorCallback
                        );
                }
                else
                {
                    viewModelAvailableCallback(new ClosedDayGridViewModel(identifier,
                                                                          medicalPractice,
                                                                          viewModelCommunication,
                                                                          gridSizeVariable));
                }
            },
                identifier.MedicalPracticeId,
                identifier.Date,
                errorCallback
                );
        }
        public void RequestAppointmentsOfADayReadModel(Action <AppointmentsOfADayReadModel> readModelAvailable,
                                                       AggregateIdentifier id, Action <string> errorCallback)
        {
            if (cachedDayReadmodels.ContainsKey(id))
            {
                readModelAvailable(cachedDayReadmodels[id]);
                return;
            }

            connectionService.RequestAppointmentsOfADay(
                (appointments, aggregateId, aggregateVersion) =>
            {
                medicalPracticeRepository.RequestMedicalPractice(
                    practice =>
                {
                    var newReadModel = new AppointmentsOfADayReadModel(eventBus,
                                                                       patientsRepository,
                                                                       labelRepository,
                                                                       practice,
                                                                       appointments,
                                                                       aggregateId,
                                                                       aggregateVersion,
                                                                       errorCallback);
                    if (!cachedDayReadmodels.ContainsKey(aggregateId))
                    {
                        cachedDayReadmodels.Add(aggregateId, newReadModel);
                    }

                    readModelAvailable(cachedDayReadmodels[id]);
                },
                    aggregateId.MedicalPracticeId,
                    aggregateId.PracticeVersion,
                    errorCallback
                    );
            },
                id.Date,
                id.MedicalPracticeId,
                errorCallback
                );
        }
Exemple #7
0
        public AppointmentModifications(Appointment originalAppointment,
                                        Guid medicalPracticeId,
                                        IClientMedicalPracticeRepository medicalPracticeRepository,
                                        IClientReadModelRepository readModelRepository,
                                        IViewModelCommunication viewModelCommunication,
                                        ISharedState <Date> selectedDateVariable,
                                        ISharedStateReadOnly <Size> gridSizeVariable,
                                        bool isInitialAdjustment,
                                        Action <string> errorCallback)
        {
            OriginalAppointment            = originalAppointment;
            IsInitialAdjustment            = isInitialAdjustment;
            this.medicalPracticeRepository = medicalPracticeRepository;
            this.selectedDateVariable      = selectedDateVariable;
            this.gridSizeVariable          = gridSizeVariable;
            this.errorCallback             = errorCallback;
            this.readModelRepository       = readModelRepository;
            this.viewModelCommunication    = viewModelCommunication;

            versions = new VersionManager <ModificationDataSet>(100);

            versions.CurrentVersionChanged    += OnCurrentVersionChanged;
            versions.PropertyChanged          += OnVersionsManagerPropertyChanged;
            selectedDateVariable.StateChanged += OnSelectedDateVariableChanged;
            gridSizeVariable.StateChanged     += OnGridSizeVariableChanged;

            OnGridSizeVariableChanged(gridSizeVariable.Value);

            var aggregateIdentifier = new AggregateIdentifier(originalAppointment.Day, medicalPracticeId);

            InitialLocation = new TherapyPlaceRowIdentifier(aggregateIdentifier, originalAppointment.TherapyPlace.Id);

            medicalPracticeRepository.RequestMedicalPractice(
                practice =>
            {
                Application.Current.Dispatcher.Invoke(() => currentMedicalPracticeVersion = practice);
            },
                InitialLocation.PlaceAndDate.MedicalPracticeId,
                InitialLocation.PlaceAndDate.Date,
                errorCallback
                );

            var initialDataSet = new ModificationDataSet(originalAppointment.StartTime,
                                                         originalAppointment.EndTime,
                                                         originalAppointment.Description,
                                                         originalAppointment.Label,
                                                         InitialLocation,
                                                         true);

            versions.AddnewVersion(initialDataSet);
        }
        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
                );
        }
Exemple #9
0
        private void AddAppointment(AppointmentTransferData newAppointmentData)
        {
            medicalPracticeRepository.RequestMedicalPractice(
                practice =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    DisplayedAppointments.Add(new DisplayAppointmentData(newAppointmentData, practice.Name));
                    DisplayedAppointments.Sort(new AppointmentSorter());

                    CheckDisplayedAppointmentCount();
                });
            },
                newAppointmentData.MedicalPracticeId,
                newAppointmentData.Day,
                errorCallBack
                );
        }
Exemple #10
0
        private void UpdateAddAppointmentPossible()
        {
            if (appointmentModificationsVariable.Value != null)
            {
                AddAppointmentPossible = false;
                return;
            }

            var day = selectedDayVariable.Value;

            medicalPracticeRepository.RequestMedicalPractice(
                practice =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    AddAppointmentPossible = practice.HoursOfOpening.IsOpen(day);
                });
            },
                selectedMedicalPracticeIdVariable.Value,
                day,
                errorCallback
                );
        }
Exemple #11
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
                    );
            }
        }
        public void Process(ReplaceAppointment command)
        {
            if (session.LoggedInUser == null)
            {
                errorCallback("commands can only be processed when a user is logged in");
                return;
            }

            var eventList = new List <DomainEvent>();

            if (command.NewDate == command.OriginalDate)
            {
                eventList.Add(new AppointmentReplaced(command.SourceAggregateId,
                                                      command.SourceAggregateVersion,
                                                      session.LoggedInUser.Id,
                                                      command.PatientId,
                                                      TimeTools.GetCurrentTimeStamp(),
                                                      command.ActionTag,
                                                      command.NewDescription,
                                                      command.NewDate,
                                                      command.NewStartTime,
                                                      command.NewEndTime,
                                                      command.NewTherapyPlaceId,
                                                      command.NewLabelId,
                                                      command.OriginalAppointmendId));
            }
            else
            {
                eventList.Add(new AppointmentDeleted(command.SourceAggregateId,
                                                     command.SourceAggregateVersion,
                                                     session.LoggedInUser.Id,
                                                     command.PatientId,
                                                     TimeTools.GetCurrentTimeStamp(),
                                                     GetDividedActionTag(command.ActionTag),
                                                     command.OriginalAppointmendId));

                eventList.Add(new AppointmentAdded(command.DestinationAggregateId,
                                                   command.DestinationAggregateVersion,
                                                   session.LoggedInUser.Id,
                                                   TimeTools.GetCurrentTimeStamp(),
                                                   GetDividedActionTag(command.ActionTag),
                                                   command.PatientId,
                                                   command.NewDescription,
                                                   command.NewStartTime,
                                                   command.NewEndTime,
                                                   command.NewTherapyPlaceId,
                                                   command.NewLabelId,
                                                   command.OriginalAppointmendId));
            }

            connectionService.TryAddEvents(
                addingWasSuccesscful =>
            {
                if (!addingWasSuccesscful)
                {
                    errorCallback("adding events failed");
                }
                else
                {
                    if (command.ActionTag == ActionTag.RegularAction)
                    {
                        practiceRepository.RequestMedicalPractice(
                            sourcePractice =>
                        {
                            practiceRepository.RequestMedicalPractice(
                                destinationPractice =>
                            {
                                patientRepository.RequestPatient(
                                    patient =>
                                {
                                    Application.Current.Dispatcher.Invoke(() =>
                                    {
                                        session.ReportUserAction(userActionBuilder.BuildReplacedAction(command,
                                                                                                       patient,
                                                                                                       sourcePractice.GetTherapyPlaceById(command.OriginalTherapyPlaceId),
                                                                                                       destinationPractice.GetTherapyPlaceById(command.NewTherapyPlaceId)));
                                    });
                                },
                                    command.PatientId,
                                    errorCallback
                                    );
                            },
                                command.DestinationAggregateId.MedicalPracticeId,
                                command.DestinationAggregateId.PracticeVersion,
                                errorCallback
                                );
                        },
                            command.SourceAggregateId.MedicalPracticeId,
                            command.SourceAggregateId.PracticeVersion,
                            errorCallback
                            );
                    }
                }
            },
                eventList,
                errorCallback
                );
        }