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 }; } }
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(); }); }); }
private void InitializeFilterCommands() { SearchCommand = new ActionCommand(async() => { await Task.Run(() => { Busy(); RangeObservableCollection <PatientModel> patients = null; if (String.IsNullOrWhiteSpace(SearchText)) { patients = new RangeObservableCollection <PatientModel>( Context.Patients.Local.Select(PatientSelector)); } else if (StepNameFilter != null) { patients = new RangeObservableCollection <PatientModel>( Context.Patients.Local.Where( e => (e.FirstName.ToLower() + " " + e.LastName.ToLower()) .Contains(SearchText.ToLower()) && e.CurrentStep.StepName == StepNameFilter) .Select(PatientSelector)); } else { patients = new RangeObservableCollection <PatientModel>( Context.Patients.Local.Where( e => (e.FirstName.ToLower() + " " + e.LastName.ToLower()) .Contains(SearchText.ToLower())) .Select(PatientSelector)); } ShowCanceled = true; ShowCompleted = true; ShowOngoing = true; ShowOverDue = true; Patients = patients; Free(); }); }); ReverseSortCommand = new ActionCommand(async() => { await Task.Run(() => { Busy(); Patients = new RangeObservableCollection <PatientModel>(Patients.Reverse()); Free(); }); }); FilterStepCommand = new ActionCommand(async() => { await Task.Run(() => { RangeObservableCollection <PatientModel> patients = null; Busy(); if (StepNameFilter != null) { patients = new RangeObservableCollection <PatientModel>( Context.Patients.OrderByDescending(e => e.Id) .Where(e => e.CurrentStep.StepName == StepNameFilter).Select(PatientSelector)); } else { patients = new RangeObservableCollection <PatientModel>( Context.Patients.OrderByDescending(e => e.Id).Select(PatientSelector)); } Patients = patients; ShowCanceled = true; ShowCompleted = true; ShowOngoing = true; ShowOverDue = true; Free(); }); }); FilterPatientsCommand = new ActionCommand(async obj => { ShowWindowCommand.Execute(null); await Task.Run(() => { var patients = new RangeObservableCollection <PatientModel>(); Busy(); if (obj is int) { BusyMessage = "Loading Patient"; Locator.SinglePatientViewModel.Patient = Patients.First(e => e.Id == (int)obj); } else { BusyMessage = "Loading Patients"; ShowOngoing = false; ShowCanceled = false; ShowCompleted = false; patients.AddRange(OverDuePatients.OrderBy(e => e.Id)); Patients = patients; } Free(); }); }); FilterCnacled = new ActionCommand(async() => { var patients = new RangeObservableCollection <PatientModel>(); await Task.Run(() => { Busy(); BusyMessage = "Applying Filter"; if (ShowCanceled) { patients.AddRange(Patients); patients.AddRange( Context.Patients.Local.Where(e => e.CurrentStep.IsCancled).Select(PatientSelector)); patients = new RangeObservableCollection <PatientModel>( patients.OrderByDescending(e => e.Id)); } else { for (int i = 0; i < Patients.Count; i++) { PatientModel patient = Patients[i]; if (!patient.CurrentStep.IsCancled) { patients.Add(patient); } } } Patients = patients; Free(); }); }); FilterCompleted = new ActionCommand(async() => { var patients = new RangeObservableCollection <PatientModel>(); await Task.Run(() => { Busy(); BusyMessage = "Applying Filter"; if (ShowCompleted) { patients.AddRange(Patients); patients.AddRange( Context.Patients.Local.Where(e => e.CurrentStep.IsCompleted).Select(PatientSelector)); patients = new RangeObservableCollection <PatientModel>( patients.OrderByDescending(e => e.Id)); } else { for (int i = 0; i < Patients.Count; i++) { PatientModel patient = Patients[i]; if (!patient.CurrentStep.IsCompleted) { patients.Add(patient); } } } Patients = patients; Free(); }); }); FilterOngoing = new ActionCommand(async() => { var patients = new RangeObservableCollection <PatientModel>(); await Task.Run(() => { Busy(); BusyMessage = "Applying Filter"; if (ShowOngoing) { patients.AddRange(Patients); patients.AddRange( Context.Patients.Local.Where(e => e.CurrentStep.Status == Status.Ongoing) .Select(PatientSelector)); patients = new RangeObservableCollection <PatientModel>( patients.OrderByDescending(e => e.Id)); } else { for (int i = 0; i < Patients.Count; i++) { PatientModel patient = Patients[i]; if (patient.CurrentStep.Status != Status.Ongoing) { patients.Add(patient); } } } Patients = patients; Free(); }); }); FilterOverdue = new ActionCommand(async() => { var patients = new RangeObservableCollection <PatientModel>(); await Task.Run(() => { Busy(); BusyMessage = "Applying Filter"; if (ShowOverDue) { patients.AddRange(Patients); patients.AddRange( Context.Patients.Local.Where(e => e.CurrentStep.Status == Status.Overdue) .Select(PatientSelector)); patients = new RangeObservableCollection <PatientModel>( patients.OrderByDescending(e => e.Id)); } else { for (int i = 0; i < Patients.Count; i++) { PatientModel patient = Patients[i]; if (patient.CurrentStep.Status != Status.Overdue) { patients.Add(patient); } } } Patients = patients; Free(); }); }); }
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; }); }