/// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(GetClinicianScheduleByClinicianKeyAndDateRangeRequest request)
        {
            var clinicianKey      = request.ClinicianKey;
            var startDate         = request.StartDate;
            var endDate           = request.EndDate;
            var slotSizeInMinutes = request.SlotSizeInMinutes;
            var beginTime         = request.BeginTime;
            var endTime           = request.EndTime;

            var potentialTimeSlots = BuildFullScheduleForDate(startDate, slotSizeInMinutes, beginTime, endTime);
            var totalDays          = ( int )((endDate.Date - startDate.Date).TotalDays);
            var totalAppointments  = totalDays == 0 ? potentialTimeSlots.Count : totalDays * potentialTimeSlots.Count;

            var visits               = _visitRepository.GetVisitsByClinicianAndDateRange(clinicianKey, startDate, endDate);
            var clinician            = _staffRepository.GetByKey(clinicianKey);
            var clinicianScheduleDto = new ClinicianScheduleDto
            {
                ClinicianFirstName    = clinician.StaffProfile.StaffName.First,
                ClinicianLastName     = clinician.StaffProfile.StaffName.Last,
                ClinicianKey          = clinician.Key,
                TotalAppointments     = totalAppointments,
                AvailableAppointments = totalAppointments - visits.Count
            };

            var scheduledVisits = from scheduledVisit in visits
                                  select new ClinicianAppointmentDto
            {
                Key                    = scheduledVisit.Key,
                ClinicianKey           = clinician.Key,
                PatientKey             = scheduledVisit.ClinicalCase.Patient.Key,
                PatientFirstName       = scheduledVisit.ClinicalCase.Patient.Name.First,
                PatientLastName        = scheduledVisit.ClinicalCase.Patient.Name.Last,
                AppointmentEndDateTime =
                    scheduledVisit.AppointmentDateTimeRange.EndDateTime,
                AppointmentStartDateTime =
                    scheduledVisit.AppointmentDateTimeRange.StartDateTime,
                VisitStatus = new LookupValueDto
                {
                    WellKnownName = scheduledVisit.VisitStatus.WellKnownName,
                    Key           = scheduledVisit.VisitStatus.Key,
                    Name          = scheduledVisit.VisitStatus.Name
                },
                VisitTemplateName = scheduledVisit.Name,
                PatientAlerts     =
                    scheduledVisit.ClinicalCase.Patient.Alerts.Select(
                        Mapper.Map <PatientAlert, PatientAlertDto>).ToList()
            };

            clinicianScheduleDto.ClinicianAppointments =
                new ObservableCollection <ClinicianAppointmentDto> (scheduledVisits);

            var response = CreateTypedResponse();

            response.ClinicianScheduleDto = clinicianScheduleDto;

            return(response);
        }
        public ClinicianScheduleTileViewModel (
            IAsyncRequestDispatcherFactory asyncRequestDispatcherFactory,
            IUserDialogService userDialogService,
            IEventAggregator eventAggregator,
            IAccessControlManager accessControlManager,
            INotificationService notificationService,
            INavigationService navigationService,
            ICommandFactory commandFactory,
            IPopupService popupService)
            : base ( accessControlManager, commandFactory )
        {
            _asyncRequestDispatcherFactory = asyncRequestDispatcherFactory;
            _notificationService = notificationService;
            _navigationService = navigationService;
            _popupService = popupService;
            _userDialogService = userDialogService;
            _eventAggregator = eventAggregator;

            _eventAggregator.GetEvent<AppointmentCreatedEvent> ().Subscribe (
                AppointmentCreatedEventHandler,
                ThreadOption.BackgroundThread,
                false,
                FilterAppointmentCreatedEvents );

            _eventAggregator.GetEvent<VisitChangedEvent> ().Subscribe (
                VisitChangedEventHandler,
                ThreadOption.BackgroundThread,
                false,
                FilterVisitChangedEvents );

            _eventAggregator.GetEvent<AppointmentUpdatedEvent> ().Subscribe (
                AppointmentUpdatedEventHandler,
                ThreadOption.BackgroundThread,
                false,
                FilterAppointmentUpdatedEvents );

            _eventAggregator.GetEvent<PatientChangedEvent> ().Subscribe (
                FilterPatientChangedEventHandler,
                ThreadOption.BackgroundThread,
                false,
                FilterPatientChangedEvents );

            var commandFactoryHelper = CommandFactoryHelper.CreateHelper ( this, commandFactory );

            StatusUpdatedCommand = commandFactoryHelper.BuildDelegateCommand<ClinicianAppointmentDto> (
                () => StatusUpdatedCommand, ExecuteStatusUpdatedCommand );
            AppointmentUpdatedCommand = commandFactoryHelper.BuildDelegateCommand<ClinicianAppointmentDto> (
                () => AppointmentUpdatedCommand,
                ExecuteAppointmentUpdatedCommand,
                CanExecuteAppointmentUpdatedCommand );
            ShowAppointmentDetailsCommand =
                commandFactoryHelper.BuildDelegateCommand<ClinicianAppointmentDto> (
                    () => ShowAppointmentDetailsCommand, ExecuteDoubleClickAppointmentCommand, CanExecuteDoubleClickAppointmentCommand );
            RangeUpdatedCommand = commandFactoryHelper.BuildDelegateCommand<DateRange> (
                () => RangeUpdatedCommand,
                ExecuteRangeUpdatedCommand,
                CanExecuteRangeUpdatedCommand );
            AppointmentAddedCommand = commandFactoryHelper.BuildDelegateCommand<ClinicianAppointmentDto> (
                () => AppointmentAddedCommand, ExecuteAppointmentAddedCommand, CanExecuteAppointmentAddedCommand );
            AppointmentDeletedCommand = commandFactoryHelper.BuildDelegateCommand<ClinicianAppointmentDto> (
                () => AppointmentDeletedCommand, ExecuteAppointmentDeletedCommand, CanExecuteAppointmentDeletedCommand );
            ShowAlertDetailsCommand = commandFactoryHelper.BuildDelegateCommand<PatientAlertDto> (
                () => ShowAlertDetailsCommand, ExecuteShowAlertDetailsCommand );
            GoToPatientDashboardCommand = commandFactoryHelper.BuildDelegateCommand<ClinicianAppointmentDto> (
                () => GoToPatientDashboardCommand, ExecuteGoToPatientDashboardCommand );
            GoToPatientProfileCommand = commandFactoryHelper.BuildDelegateCommand<ClinicianAppointmentDto> (
                () => GoToPatientProfileCommand, ExecuteGoToPatientProfileCommand);
            GoToPaymentCommand = commandFactoryHelper.BuildDelegateCommand<ClinicianAppointmentDto> (
                () => GoToPaymentCommand, ExecuteGoToPaymentCommand );

            ClinicianSchedule = new ClinicianScheduleDto ();

            _eventAggregator.GetEvent<FrontDeskDashboardDateChangedEvent> ().Subscribe (
                OnFrontDeskDashboardDateChanged, ThreadOption.PublisherThread, false, FilterFrontDeskDashboardDateChanged );
        }