Exemplo n.º 1
0
        public EventStream <AggregateIdentifier> GetEventStream(AggregateIdentifier identifier)
        {
            if (cachedEventStreams.ContainsKey(identifier))
            {
                var eventStreamToDeliver = cachedEventStreams[identifier];

                if (eventStreamToDeliver.EventCount == 0)
                {
                    CreateNewEventStream(identifier);
                }

                return(cachedEventStreams[identifier]);
            }

            if (cachedEventStreams.Keys.Any(aggregateId => aggregateId.MedicalPracticeId == identifier.MedicalPracticeId &&
                                            aggregateId.Date.Month == identifier.Date.Month))
            {
                CreateNewEventStream(identifier);
                return(cachedEventStreams[identifier]);
            }

            LoadMonth(identifier);

            if (!cachedEventStreams.ContainsKey(identifier))
            {
                CreateNewEventStream(identifier);
            }

            return(cachedEventStreams[identifier]);
        }
Exemplo n.º 2
0
        public ReplaceAppointment(AggregateIdentifier sourceAggregateId,
                                  AggregateIdentifier destinationAggregateId,
                                  uint sourceAggregateVersion,
                                  uint destinationAggregateVersion,
                                  Guid userId, Guid patientId, ActionTag actionTag,

                                  string originalDescription, string newDescription,
                                  Date originalDate, Date newDate,
                                  Time originalStartTime, Time newStartTime,
                                  Time originalEndTime, Time newEndTime,
                                  Guid originalTherapyPlaceId, Guid newTherapyPlaceId,
                                  Guid originalLabelId, Guid newLabelId,
                                  Guid originalAppointmendId)

            : base(userId, patientId, actionTag)
        {
            SourceAggregateId           = sourceAggregateId;
            DestinationAggregateId      = destinationAggregateId;
            SourceAggregateVersion      = sourceAggregateVersion;
            DestinationAggregateVersion = destinationAggregateVersion;
            NewDescription         = newDescription;
            NewDate                = newDate;
            NewStartTime           = newStartTime;
            NewEndTime             = newEndTime;
            NewTherapyPlaceId      = newTherapyPlaceId;
            NewLabelId             = newLabelId;
            OriginalAppointmendId  = originalAppointmendId;
            OriginalDate           = originalDate;
            OriginalDescription    = originalDescription;
            OriginalStartTime      = originalStartTime;
            OriginalEndTime        = originalEndTime;
            OriginalTherapyPlaceId = originalTherapyPlaceId;
            OriginalLabelId        = originalLabelId;
        }
        public ClosedDayGridViewModel(AggregateIdentifier identifier,
                                      ClientMedicalPracticeData medicalPractice,
                                      IViewModelCommunication viewModelCommunication,
                                      ISharedStateReadOnly <Size> appointmentGridSizeVariable)
        {
            this.viewModelCommunication      = viewModelCommunication;
            this.appointmentGridSizeVariable = appointmentGridSizeVariable;

            Identifier = identifier;
            IsActive   = false;

            viewModelCommunication.RegisterViewModelAtCollection <IAppointmentGridViewModel, AggregateIdentifier>(
                Constants.ViewModelCollections.AppointmentGridViewModelCollection,
                this
                );

            appointmentGridSizeVariable.StateChanged += OnGridSizeChanged;

            TimeGridViewModel = new TimeGridViewModel(Identifier, viewModelCommunication,
                                                      medicalPractice, appointmentGridSizeVariable.Value);

            TherapyPlaceRowViewModels = new ObservableCollection <ITherapyPlaceRowViewModel>();

            PracticeIsClosedAtThisDay = true;
        }
Exemplo n.º 4
0
        private void DisplayCachedViewModel(AggregateIdentifier identifier)
        {
            CurrentDisplayedAppointmentGridIndex      = GetGridIndex(identifier);
            currentDisplayedAppointmentGridIdentifier = identifier;

            ActivateGridViewModel(identifier);
        }
Exemplo n.º 5
0
 public AppointmentDeleted(AggregateIdentifier aggregateId, uint aggregateVersion,
                           Guid userId, Guid patientId, Tuple <Date, Time> timeStamp,
                           ActionTag actionTag, Guid removedAppointmentId)
     : base(aggregateId, aggregateVersion, userId, patientId, timeStamp, actionTag)
 {
     RemovedAppointmentId = removedAppointmentId;
 }
Exemplo n.º 6
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
                );
        }
Exemplo n.º 8
0
        private void AddGridViewModel(AggregateIdentifier identifier)
        {
            if (!cachedAppointmentGridViewModels.ContainsKey(identifier))
            {
                cachedAppointmentGridViewModels.Add(identifier, null);

                appointmentGridViewModelBuilder.RequestBuild(
                    buildedViewModel =>
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        cachedAppointmentGridViewModels[identifier] = buildedViewModel;
                        LoadedAppointmentGrids.Add(buildedViewModel);

                        if (identifier.Date == selectedDateVariable.Value &&
                            identifier.MedicalPracticeId == selectedMedicalPracticeIdVariable.Value)
                        {
                            DisplayCachedViewModel(identifier);
                        }
                    });
                },
                    identifier,
                    errorCallback
                    );
            }
        }
        public TimeGridViewModelSampleData()
        {
            TimeSlotLabels = new ObservableCollection <TimeSlotLabel>
            {
                new TimeSlotLabel("8:00")
                {
                    XCoord = 200, YCoord = 10
                },
                new TimeSlotLabel("7:00")
                {
                    XCoord = 100, YCoord = 10
                }
            };

            TimeSlotLines = new ObservableCollection <TimeSlotLine>
            {
                new TimeSlotLine {
                    XCoord = 100, YCoordTop = 40, YCoordBottom = 400
                },
                new TimeSlotLine {
                    XCoord = 200, YCoordTop = 40, YCoordBottom = 400
                }
            };

            Identifier = new AggregateIdentifier(Date.Dummy, new Guid());
        }
Exemplo n.º 10
0
        private static AppointmentDeleted DeserializeAppointmentDeleted(string s)
        {
            var eventParts = s.Split('|');

            var aggregateIdDate            = Date.Parse(eventParts[1]);
            var aggregateIdMedPracticeId   = Guid.Parse(eventParts[2]);
            var aggregateIdPracticeVersion = uint.Parse(eventParts[3]);

            var aggregateId = new AggregateIdentifier(aggregateIdDate, aggregateIdMedPracticeId, aggregateIdPracticeVersion);

            var removedAppointemtnId = Guid.Parse(eventParts[4]);

            var patientId        = Guid.Parse(eventParts[5]);
            var aggregateVersion = uint.Parse(eventParts[6]);
            var userId           = Guid.Parse(eventParts[7]);
            var timeStampDate    = Date.Parse(eventParts[8]);
            var timeStampTime    = Time.Parse(eventParts[9]);

            var timeStamp = new Tuple <Date, Time>(timeStampDate, timeStampTime);

            var actionTag = (ActionTag)Enum.Parse(typeof(ActionTag), eventParts[10]);

            return(new AppointmentDeleted(aggregateId, aggregateVersion, userId, patientId,
                                          timeStamp, actionTag, removedAppointemtnId));
        }
Exemplo n.º 11
0
        private static AppointmentReplaced DeserializeAppointmentReplaced(string s)
        {
            var eventParts = s.Split('|');

            var aggregateIdDate            = Date.Parse(eventParts[1]);
            var aggregateIdMedPracticeId   = Guid.Parse(eventParts[2]);
            var aggregateIdPracticeVersion = uint.Parse(eventParts[3]);

            var aggregateId = new AggregateIdentifier(aggregateIdDate, aggregateIdMedPracticeId, aggregateIdPracticeVersion);

            var newDescription        = eventParts[4];
            var newDate               = Date.Parse(eventParts[5]);
            var newStartTime          = Time.Parse(eventParts[6]);
            var newEndTime            = Time.Parse(eventParts[7]);
            var newTherpyPlaceId      = Guid.Parse(eventParts[8]);
            var newLabelId            = Guid.Parse(eventParts[9]);
            var originalAppointmentId = Guid.Parse(eventParts[10]);

            var patientId        = Guid.Parse(eventParts[11]);
            var aggregateVersion = uint.Parse(eventParts[12]);
            var userId           = Guid.Parse(eventParts[13]);
            var timeStampDate    = Date.Parse(eventParts[14]);
            var timeStampTime    = Time.Parse(eventParts[15]);

            var timeStamp = new Tuple <Date, Time>(timeStampDate, timeStampTime);

            var actionTag = (ActionTag)Enum.Parse(typeof(ActionTag), eventParts[16]);

            return(new AppointmentReplaced(aggregateId, aggregateVersion, userId, patientId,
                                           timeStamp, actionTag,
                                           newDescription, newDate, newStartTime, newEndTime,
                                           newTherpyPlaceId, newLabelId, originalAppointmentId));
        }
Exemplo n.º 12
0
 public EventStream <AggregateIdentifier> GetEventStreamForADay(AggregateIdentifier id)
 {
     lock (eventStore)
     {
         return(eventStore.GetEventStreamForADay(id));
     }
 }
 public PrintDialog BuildWindow(AggregateIdentifier identifier)
 {
     return(new PrintDialog
     {
         Owner = Application.Current.MainWindow,
         DataContext = new PrintDialogViewModel(identifier, medicalPracticeRepository, readModelRepository, errorCallback)
     });
 }
Exemplo n.º 14
0
 public FixedAppointmentSet(AggregateIdentifier identifier,
                            uint aggregateVersion,
                            IEnumerable <Appointment> appointments)
 {
     Identifier       = identifier;
     AggregateVersion = aggregateVersion;
     Appointments     = appointments;
 }
Exemplo n.º 15
0
 private void DeactivateGridViewModel(AggregateIdentifier identifier)
 {
     viewModelCommunication.SendTo(
         Constants.ViewModelCollections.AppointmentGridViewModelCollection,
         identifier,
         new Deactivate()
         );
 }
Exemplo n.º 16
0
        private void LoadMonth(AggregateIdentifier identifier)
        {
            var newStreams = eventStreamPersistenceService.Load(GetFilePath(identifier));

            foreach (var eventStream in newStreams)
            {
                cachedEventStreams.Add(eventStream.Id, eventStream);
            }
        }
Exemplo n.º 17
0
        private int GetGridIndex(AggregateIdentifier identifier)
        {
            if (GridViewModelIsCached(identifier))
            {
                var gridViewModel = cachedAppointmentGridViewModels[identifier];
                return(LoadedAppointmentGrids.IndexOf(gridViewModel));
            }

            throw new ArgumentException("viewModel is not cached");
        }
Exemplo n.º 18
0
        private void RemoveGridViewModel(AggregateIdentifier identifier)
        {
            if (GridViewModelIsCached(identifier))
            {
                var gridViewModel = cachedAppointmentGridViewModels[identifier];
                cachedAppointmentGridViewModels.Remove(identifier);
                LoadedAppointmentGrids.Remove(gridViewModel);

                gridViewModel.Dispose();
            }
        }
Exemplo n.º 19
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
                );
        }
Exemplo n.º 20
0
        private string GetFilePath(AggregateIdentifier identifier)
        {
            var folderPath = $@"{basePath}\{identifier.MedicalPracticeId}\{identifier.Date.Year}";

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            return($@"{folderPath}\{identifier.Date.Month}.xml");
        }
Exemplo n.º 21
0
 private void OnDisplayedPracticeStateChanged(Guid medicalPracticeId)
 {
     medicalPracticeRepository.RequestPraticeVersion(
         practiceVersion =>
     {
         var newIdentifier = new AggregateIdentifier(selectedDateVariable.Value, medicalPracticeId, practiceVersion);
         TryToShowGridViewModel(newIdentifier);
     },
         medicalPracticeId,
         selectedDateVariable.Value,
         errorCallback
         );
 }
Exemplo n.º 22
0
 private void OnSelectedDateStateChanged(Date date)
 {
     medicalPracticeRepository.RequestPraticeVersion(
         practiceVersion =>
     {
         var newIdentifier = new AggregateIdentifier(date, selectedMedicalPracticeIdVariable.Value, practiceVersion);
         TryToShowGridViewModel(newIdentifier);
     },
         selectedMedicalPracticeIdVariable.Value,
         date,
         errorCallback
         );
 }
Exemplo n.º 23
0
        private void CreateNewEventStream(AggregateIdentifier identifier)
        {
            var newEventStream = new EventStream <AggregateIdentifier>(new AggregateIdentifier(identifier.Date,
                                                                                               identifier.MedicalPracticeId,
                                                                                               config.GetLatestVersionFor(identifier.MedicalPracticeId)));

            if (cachedEventStreams.ContainsKey(identifier))
            {
                cachedEventStreams.Remove(identifier);
            }

            cachedEventStreams.Add(identifier, newEventStream);
        }
Exemplo n.º 24
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);
        }
        public PrintTimeGridViewModel(AggregateIdentifier identifier,
                                      ClientMedicalPracticeData medicalPractice,
                                      Size initalSize)
        {
            Identifier = identifier;

            timeSlotStart = medicalPractice.HoursOfOpening.GetOpeningTime(identifier.Date);
            timeSlotEnd   = medicalPractice.HoursOfOpening.GetClosingTime(identifier.Date);

            TimeSlotLines  = new ObservableCollection <TimeSlotLine>();
            TimeSlotLabels = new ObservableCollection <TimeSlotLabel>();

            SetnewSize(initalSize);
        }
Exemplo n.º 26
0
        public AppointmentGridViewModelSampleData()
        {
            TherapyPlaceRowViewModels = new ObservableCollection <ITherapyPlaceRowViewModel>
            {
                new TherapyPlaceRowViewModelSampleData(),
                new TherapyPlaceRowViewModelSampleData(),
                new TherapyPlaceRowViewModelSampleData(),
            };

            TimeGridViewModel         = new TimeGridViewModelSampleData();
            Identifier                = new AggregateIdentifier(Date.Dummy, new Guid());
            PracticeIsClosedAtThisDay = true;
            IsActive = true;
        }
Exemplo n.º 27
0
 protected DomainEvent(AggregateIdentifier aggregateId,
                       uint aggregateVersion,
                       Guid userId,
                       Guid patientId,
                       Tuple <Date, Time> timeStamp,
                       ActionTag actionTag)
 {
     AggregateId      = aggregateId;
     AggregateVersion = aggregateVersion;
     UserId           = userId;
     TimeStamp        = timeStamp;
     PatientId        = patientId;
     ActionTag        = actionTag;
 }
Exemplo n.º 28
0
        public void NewAppointments(Guid medicalPracticeId, Date day)
        {
            var patients    = patientRepository.GetAllPatients().ToList();
            var user        = configurationRepository.GetAllUsers().First();
            var eventstream = eventStore.GetEventStreamForADay(new AggregateIdentifier(day, medicalPracticeId));

            if (eventstream.EventCount > 0)
            {
                MessageBox.Show("cannot create appointments - there are already appointments");
                return;
            }

            var medicalPractice = configurationRepository.GetMedicalPracticeByIdAndVersion(medicalPracticeId,
                                                                                           eventstream.Id.PracticeVersion);

            if (!medicalPractice.HoursOfOpening.IsOpen(day))
            {
                MessageBox.Show("cannot create appointments - practice is not open");
                return;
            }

            var identifier = new AggregateIdentifier(day, medicalPractice.Id, medicalPractice.Version);

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

            var eventList = new List <DomainEvent>();

            uint aggregateVersion = 0;

            foreach (var therapyPlace in medicalPractice.GetAllTherapyPlaces())
            {
                var currrentTime = openingTime;
                currrentTime += RandomTimeInterval(0);

                while (currrentTime + new Duration(60 * 60) < closingTime)
                {
                    var newEvent = CreateAppointmentData(patients, user, identifier, aggregateVersion++,
                                                         currrentTime, closingTime, therapyPlace.Id);

                    eventList.Add(newEvent);

                    currrentTime += new Duration(newEvent.StartTime, newEvent.EndTime);
                    currrentTime += RandomTimeInterval(0);
                }
            }

            eventStore.AddEvents(eventList);
        }
Exemplo n.º 29
0
 public AppointmentAdded(AggregateIdentifier aggregateId, uint aggregateVersion,
                         Guid userId, Tuple <Date, Time> timeStamp, ActionTag actionTag,
                         Guid patientId, string description,
                         Time startTime, Time endTime,
                         Guid therapyPlaceId, Guid labelId,
                         Guid appointmentId)
     : base(aggregateId, aggregateVersion, userId, patientId, timeStamp, actionTag)
 {
     Description    = description;
     StartTime      = startTime;
     EndTime        = endTime;
     TherapyPlaceId = therapyPlaceId;
     AppointmentId  = appointmentId;
     LabelId        = labelId;
 }
Exemplo n.º 30
0
        public void TryDeleteAppointment(Action <bool> operationResultCallback,
                                         AggregateIdentifier location, Guid patientId, Guid removedAppointmentId,
                                         string removedAppointmentDescription, Time removedAppointmentStartTime, Time removedAppointmentEndTime,
                                         Guid removedAppointmentTherapyPlaceId, Guid removedAppointmentLabelId, ActionTag actionTag, Action <string> errorCallback)
        {
            RequestLock(
                successfulLocked =>
            {
                if (!successfulLocked)
                {
                    operationResultCallback(false);
                    return;
                }

                readModelRepository.RequestAppointmentSetOfADay(
                    appointmentSet =>
                {
                    if (!DeletionPossible(removedAppointmentId, appointmentSet))
                    {
                        errorCallback("termin kann nicht gelöscht werden, da nicht vorhanden");
                        ReleaseAllLocks(errorCallback);
                        operationResultCallback(false);
                        return;
                    }

                    commandBus.SendCommand(new DeleteAppointment(appointmentSet.Identifier,
                                                                 appointmentSet.AggregateVersion,
                                                                 session.LoggedInUser.Id,
                                                                 patientId,
                                                                 actionTag,
                                                                 removedAppointmentId,
                                                                 removedAppointmentDescription,
                                                                 removedAppointmentStartTime,
                                                                 removedAppointmentEndTime,
                                                                 removedAppointmentTherapyPlaceId,
                                                                 removedAppointmentLabelId));
                    ReleaseAllLocks(errorCallback);
                    operationResultCallback(true);
                },
                    location,
                    errorCallback
                    );
            },
                location.MedicalPracticeId,
                location.Date,
                errorCallback
                );
        }