/// <summary>
        /// Adds the prescription to the AllPrescriptions property or refreshes it if it's a new group.
        /// </summary>
        /// <param name="item"></param>
        public async void AddPrescriptionToCollection(Prescription item)
        {
            bool isSessionPresent = AllPrescriptions.Any(p => p.TimeStamp == item.Schedule);

            if (isSessionPresent)
            {
                AllPrescriptions.Single(grp => grp.TimeStamp == item.Schedule).Prescriptions.Add(item);
            }
            else
            {
                await RefreshDataAsync();
            }
        }
        /// <summary>
        /// Removes the prescription group.
        /// </summary>
        /// <param name="selectedItems">The prescription group</param>
        public async void DeletePrescriptionGroup(object selectedItems)
        {
            try
            {
                PrescriptionGroup group = selectedItems as PrescriptionGroup;
                var count = group.Prescriptions.Count;

                await imsSvc.DeletePrescriptionGroupAsync(group.Prescriptions);

                AllPrescriptions.Remove(group);
                Prescriptions.Remove(group);
            }
            catch (Exception e)
            {
                MessengerInstance.Send(new ExceptionDialogMessage(e));
            }
        }
        /// <summary>
        /// Removes the prescription.
        /// </summary>
        /// <param name="selectedItem"></param>
        public async void DeletePrescription(object selectedItem)
        {
            try
            {
                Prescription item = selectedItem as Prescription;
                await imsSvc.DeletePrescriptionAsync(item);

                var group = AllPrescriptions.Single(grp => grp.TimeStamp == item.Schedule);
                if (group.Prescriptions.Count > 1)
                {
                    AllPrescriptions.Single(grp => grp.TimeStamp == item.Schedule).Prescriptions.Remove(item);
                    Prescriptions.Single(grp => grp.TimeStamp == item.Schedule).Prescriptions.Remove(item);
                }
                else
                {
                    AllPrescriptions.Remove(group);
                    Prescriptions.Remove(group);
                }
            }
            catch (Exception e)
            {
                MessengerInstance.Send(new ExceptionDialogMessage(e));
            }
        }
        /// <summary>
        /// Divides the prescriptions into their own respective classifications.
        /// </summary>
        private void DividePrescriptions()
        {
            if (ScheduledPrescriptions == null)
            {
                ScheduledPrescriptions = new ObservableCollection <PrescriptionGroup>();
            }
            if (AdministeredPrescriptions == null)
            {
                AdministeredPrescriptions = new ObservableCollection <PrescriptionGroup>();
            }
            if (UnadministeredPrescriptions == null)
            {
                UnadministeredPrescriptions = new ObservableCollection <PrescriptionGroup>();
            }
            if (SelectedPrescriptions == null)
            {
                SelectedPrescriptions = new ObservableCollection <PrescriptionGroup>();
            }

            // past v. future for scheduled
            List <PrescriptionGroup> recentPast;

            try
            {
                recentPast = AllPrescriptions.Where(grp => (((grp.TimeStamp - DateTime.Now).TotalMinutes > -30) && ((grp.TimeStamp - DateTime.Now).TotalMinutes < 0))).ToList();
            }
            catch (ArgumentNullException)
            {
                recentPast = new List <PrescriptionGroup>();
            }

            List <PrescriptionGroup> future;

            try
            {
                future = AllPrescriptions.Where(grp => (grp.TimeStamp - DateTime.Now).TotalMinutes > 0).ToList();
            }
            catch (ArgumentNullException)
            {
                future = new List <PrescriptionGroup>();
            }
            var oc = recentPast.Union(future);

            ScheduledPrescriptions = new ObservableCollection <PrescriptionGroup>(oc);

            // selected
            var selected = AllPrescriptions.Where(grp => grp.IsSelectedOnly).ToList();

            SelectedPrescriptions = new ObservableCollection <PrescriptionGroup>(selected);
            SelectedPrescriptions.CollectionChanged += SelectedPrescriptions_CollectionChanged;

            // administered v. unadministered
            try
            {
                foreach (PrescriptionGroup group in AllPrescriptions)
                {
                    bool isAdministered = false;
                    foreach (var med in group.Prescriptions)
                    {
                        if (med.AdministeredOn.HasValue)
                        {
                            isAdministered = true;
                            break;
                        }
                    }

                    if (isAdministered)
                    {
                        AdministeredPrescriptions.Add(group);
                    }
                    else
                    {
                        UnadministeredPrescriptions.Add(group);
                    }
                }
            }
            catch (Exception)
            {
            }
        }