Exemple #1
0
        private async Task Notify()
        {
            int overDuePatientCount =
                OverDuePatients.Count();

            if (overDuePatientCount > 1)
            {
                await Alarm();

                NotificationModel =
                    new NotificationModel
                {
                    Message = overDuePatientCount + " patients have a step overdue"
                };
            }
            else if (overDuePatientCount == 1)
            {
                await Alarm();

                NotificationModel = new PatientNotificaitonModel
                {
                    PatientId = OverDuePatients[0].Id,
                    Name      = OverDuePatients[0].FullName
                };
            }
        }
Exemple #2
0
        private void InitializeCommands()
        {
            InitializeFilterCommands();
            //initiate switch to add pateint view model command
            SwitchToAddPatientViewCommmand = new ActionCommand(() => { CurrentViewModel = Locator.AddPatientViewModel; });
            //initiate get all patients command
            InitializeGetCommands();
            StopAlarmCommand = new ActionCommand(() =>
            {
                IsAlarming = false;
                Player.Stop();
            });
            ShowWindowCommand = new ActionCommand(() =>
            {
                Application.Current.MainWindow.Show();
                Application.Current.MainWindow.Activate();
            });
            ExitCommand = new ActionCommand(() => Application.Current.Shutdown());
            SubscribeNotificationsCommand = new ActionCommand(async() =>
            {
                await Task.Run(async() =>
                {
                    await Task.Delay(500);
                    Busy();
                    BusyMessage = "Loading Patients";
                    Patients    =
                        new RangeObservableCollection <PatientModel>(
                            (await
                             Context.Patients.OrderByDescending(e => e.Id)
                             .Include(e => e.CurrentStep)
                             .ToListAsync()).Select(PatientSelector));

                    BusyMessage = "Checking for overdue Steps";
                    OverDuePatients.Clear();
                    OverDuePatients.AddRange(
                        Patients.Where(
                            e =>
                            e.CurrentStep.AlarmTime < DateTime.Now + new TimeSpan(1, 0, 0, 0) &&
                            !e.CurrentStep.IsCompleted && !e.CurrentStep.IsCancled));
                });
                foreach (PatientModel item in OverDuePatients.Where(e => e.CurrentStep.AlarmTime > DateTime.Now))
                {
                    IObservable <long> singlePatientTimer =
                        Observable.Timer(new DateTimeOffset(item.CurrentStep.AlarmTime))
                        .ObserveOn(DispatcherScheduler.Current);
                    PatientModel patientModel = item;
                    singlePatientTimer.Subscribe(
                        async k =>
                    {
                        await Alarm();
                        NotificationModel = new PatientNotificaitonModel
                        {
                            PatientId = patientModel.Id,
                            Name      = patientModel.FullName
                        };
                    });
                }
                IObservable <long> interval = Observable.Interval(new TimeSpan(0, 10, 0), DispatcherScheduler.Current);

                interval.Subscribe(
                    async e => { await Notify(); });
                Free();
                await Notify();
                await interval;
            });
        }