Beispiel #1
0
        private void InitializeGetCommands()
        {
            GetAllPatients =
                new ActionCommand(
                    async() =>
            {
                await Task.Run(async() =>
                {
                    Busy();
                    BusyMessage = "Loading Patients";

                    Patients =
                        new RangeObservableCollection <PatientModel>(
                            (await
                             Context.Patients.OrderByDescending(e => e.Id)
                             .Include(e => e.Steps)
                             .ToListAsync()).Select(PatientSelector));
                    Free();
                });
            });

            //getting patients from database to populate listbox


            GetOverDuePatientsCommand = new ActionCommand(async() =>
            {
                await Task.Run(async() =>
                {
                    Busy();
                    BusyMessage = "Applying Filter";
                    OverDuePatients.Clear();
                    List <Patient> patients = await Context.Patients.ToListAsync();
                    OverDuePatients.Clear();
                    OverDuePatients.AddRange(
                        patients.Where(
                            e =>
                            e.CurrentStep.AlarmTime < DateTime.Now + new TimeSpan(1, 0, 0, 0) &&
                            !e.CurrentStep.IsCompleted &&
                            !e.CurrentStep.IsCancled).Select(PatientSelector));
                    Free();
                });
            });
        }
Beispiel #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;
            });
        }