private void RecomputeGrid() { if (gridSize.Width < 200) { return; } var newGridViewDivision = GetDevisionForWidth(gridSize.Width); var slotLengthInSeconds = GetSlotLengthInSeconds(newGridViewDivision); var timeSlotDuration = new Duration(timeSlotEnd, timeSlotStart); var excactTimeSlotCount = (double)timeSlotDuration.Seconds / slotLengthInSeconds; int roundedTimeSlotCount = (int)Math.Floor(excactTimeSlotCount); var timeSlotWidth = gridSize.Width / excactTimeSlotCount; if (newGridViewDivision != gridViewDivisionState || TimeSlotLabels.Count == 0) { gridViewDivisionState = newGridViewDivision; CreateGridDrawing(roundedTimeSlotCount, excactTimeSlotCount, slotLengthInSeconds, timeSlotWidth); } else { UpdateGridDrawing(roundedTimeSlotCount, excactTimeSlotCount, timeSlotWidth); } }
private void CalculateCorrectAppointmentPosition(DragEventArgs dragEventArgs, out Time newBeginTime, out Time newEndTime) { var timeAtDropPosition = GetTimeForPosition(dragEventArgs.GetPosition(AssociatedObject).X); var appointmentDuration = new Duration(AppointmentModifications.BeginTime, AppointmentModifications.EndTime); var halfappointmentDuration = appointmentDuration / 2u; var slotAtDropPosition = GetSlot(timeAtDropPosition); if (timeAtDropPosition + halfappointmentDuration > slotAtDropPosition.End) { newEndTime = slotAtDropPosition.End; newBeginTime = slotAtDropPosition.End - appointmentDuration; } else if (timeAtDropPosition - halfappointmentDuration < slotAtDropPosition.Begin) { newBeginTime = slotAtDropPosition.Begin; newEndTime = slotAtDropPosition.Begin + appointmentDuration; } else { newBeginTime = timeAtDropPosition - halfappointmentDuration; newEndTime = timeAtDropPosition + halfappointmentDuration; } }
public void SetNewBeginTimeDelta(double deltaInPixel) { var lengthOfOneHour = currentGridWidth / (new Duration(currentDayClosingTime, currentDayOpeningTime).Seconds / 3600.0); var secondsDelta = (uint)Math.Floor(Math.Abs(deltaInPixel) / (lengthOfOneHour / 3600)); var durationDelta = new Duration(secondsDelta); BeginTime = CheckBeginTime(deltaInPixel > 0 ? lastSetBeginTime + durationDelta : lastSetBeginTime - durationDelta); }
private Time GetTimeForPosition(double xPosition) { var durationOfWholeDay = new Duration(TimeSlotBegin, TimeSlotEnd); double relativePosition = xPosition / GridWidth; var resultTime = TimeSlotBegin + new Duration((uint)Math.Floor((durationOfWholeDay.Seconds * relativePosition))); return(resultTime); }
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); }
private Duration GetAppointmentDuration(Time startTime, Time closingTime) { int tryCount = 0; var currentIntervalTry = RandomTimeInterval(4); while (startTime + currentIntervalTry > closingTime) { if (tryCount++ > 100) { currentIntervalTry = new Duration(60 * 30); break; } currentIntervalTry = RandomTimeInterval(4); } return(currentIntervalTry); }
private Tuple <TherapyPlaceRowIdentifier, TimeSlot> ComputeFirstFittingSlot() { if (allAvailableTimeSlots == null) { return(null); } var duration = new Duration((uint)(DurationHours * 3600 + DurationMinutes * 60)); return((from timeSlotsOfARow in allAvailableTimeSlots from timeSlot in timeSlotsOfARow.Value let slotDuration = new Duration(timeSlot.Begin, timeSlot.End) where slotDuration >= duration select new Tuple <TherapyPlaceRowIdentifier, TimeSlot>(new TherapyPlaceRowIdentifier(new AggregateIdentifier(creationDate, medicalPractice.Id), timeSlotsOfARow.Key.TherapyPlaceId), timeSlot) ).FirstOrDefault()); }
private void DoCreateAppointment() { var therapyPlace = medicalPractice.GetTherapyPlaceById(firstFittingTimeSlot.Item1.TherapyPlaceId); var duration = new Duration((uint)(DurationHours * 3600 + DurationMinutes * 60)); var newAppointmentViewModel = appointmentViewModelBuilder.Build(new Appointment(SelectedPatient, Description, therapyPlace, creationDate, firstFittingTimeSlot.Item2.Begin, firstFittingTimeSlot.Item2.Begin + duration, Guid.NewGuid(), selectedLabel), new AggregateIdentifier(creationDate, medicalPractice.Id, medicalPractice.Version), errorCallback); newAppointmentViewModel.SwitchToEditMode.Execute(true); CloseWindow(); }
public void FixTimeShiftDelta() { var duration = new Duration(BeginTime, EndTime); var finalBeginTime = GetTimeToSnap(BeginTime); var finalEndTime = GetTimeToSnap(finalBeginTime + duration); if (finalBeginTime != lastSetBeginTime || finalEndTime != lastSetEndTime) { versions.AddnewVersion(new ModificationDataSet(finalBeginTime, finalEndTime, versions.CurrentVersion.Description, versions.CurrentVersion.Label, versions.CurrentVersion.Location, false)); } else { BeginTime = finalBeginTime; EndTime = finalEndTime; } }
public void SetNewLocation(TherapyPlaceRowIdentifier newLocation, Time newBeginTime, Time newEndTime) { var finalBeginTime = GetTimeToSnap(newBeginTime); var appointmentDuration = new Duration(newBeginTime, newEndTime); var finalEndTime = GetTimeToSnap(finalBeginTime + appointmentDuration); if (newLocation != CurrentLocation || finalBeginTime != lastSetBeginTime || finalEndTime != lastSetEndTime) { versions.AddnewVersion(new ModificationDataSet(finalBeginTime, finalEndTime, versions.CurrentVersion.Description, versions.CurrentVersion.Label, newLocation, true)); } else { BeginTime = finalBeginTime; EndTime = finalEndTime; } }
public void SetNewTimeShiftDelta(double deltaInPixel) { var lengthOfOneHour = currentGridWidth / (new Duration(currentDayClosingTime, currentDayOpeningTime).Seconds / 3600.0); var secondsDelta = (uint)Math.Floor(Math.Abs(deltaInPixel) / (lengthOfOneHour / 3600)); var durationDelta = new Duration(secondsDelta); if (deltaInPixel > 0) { var tempEndTime = CheckEndTime(deltaInPixel > 0 ? lastSetEndTime + durationDelta : lastSetEndTime - durationDelta); var actualTimeDelta = new Duration(lastSetEndTime, tempEndTime); BeginTime = lastSetBeginTime + actualTimeDelta; EndTime = lastSetEndTime + actualTimeDelta; } else { var tmpBeginTime = CheckBeginTime(deltaInPixel > 0 ? lastSetBeginTime + durationDelta : lastSetBeginTime - durationDelta); var actualTimeDelta = new Duration(lastSetBeginTime, tmpBeginTime); BeginTime = lastSetBeginTime - actualTimeDelta; EndTime = lastSetEndTime - actualTimeDelta; } }
private void OnDragOver(object sender, DragEventArgs dragEventArgs) { if (dragEventArgs.Data.GetDataPresent(typeof(Appointment))) { if (Appointments != null && AdornerControl != null) { if (slots == null) { ComputeSlots(currentDraggedAppointment.Id); } AdornerControl.NewMousePositionForAdorner(dragEventArgs.GetPosition(AdornerControl.ReferenceElement)); var mousePositionTime = GetTimeForPosition(dragEventArgs.GetPosition(AssociatedObject).X); var currentPointedSlot = GetSlot(mousePositionTime); if (currentPointedSlot != null) { var slotLength = new Duration(currentPointedSlot.Begin, currentPointedSlot.End); var appointmentLength = new Duration(AppointmentModifications.BeginTime, AppointmentModifications.EndTime); if (slotLength >= appointmentLength) { AdornerControl.ShowAdornerLikeDropIsPossible(); dropIsPossible = true; return; } } AdornerControl.ShowAdornerLikeDropIsNotPossible(); dropIsPossible = false; } } }
private static TimeSlot GetSlotForAppointment(IEnumerable <TimeSlot> timeSlots, Duration appointmentDuration) { return(timeSlots.FirstOrDefault(slot => new Duration(slot.Begin, slot.End) >= appointmentDuration)); }
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 ); } }