private void UpdateRecentPatientContexts()
        {
            var patientContext = new PatientContext();

            patientContext.PatientId       = _patientId;
            patientContext.ActivePlanSetup = MapPlanningItemViewModelToData(SelectedPlanSetup);

            foreach (var planningItemsInScope in PlanningItems.Where(p => p.IsChecked))
            {
                patientContext.PlanningItemsInScope
                .Add(MapPlanningItemViewModelToData(planningItemsInScope));
            }

            if (RecentPatientContexts.Contains(patientContext))
            {
                var index = RecentPatientContexts.IndexOf(patientContext);
                RecentPatientContexts.Move(index, 0);
            }
            else
            {
                RecentPatientContexts.Insert(0, patientContext);

                if (RecentPatientContexts.Count > MaximumNumberOfRecentPatientContexts)
                {
                    RecentPatientContexts.Remove(RecentPatientContexts.Last());
                }
            }
        }
 private IEnumerable <PlanSum> GetPlanSumsInScope()
 {
     return(PlanningItems
            .Where(p => p.PlanningItem is PlanSum && p.IsChecked)
            .Select(p => p.PlanningItem)
            .Cast <PlanSum>());
 }
 private void UpdatePlanSetupsInScopeWhenPlanSetupVmIsCheckedChanged()
 {
     // Each planSetupVm is a PlanningItemViewModel that contains a PlanSetup
     foreach (var planSetupVm in PlanningItems.Where(p => p.PlanningItem is PlanSetup))
     {
         planSetupVm.PropertyChanged += (o, e) =>
         {
             if (e.PropertyName == "IsChecked")
             {
                 UpdatePlanSetupsInScope((PlanningItemViewModel)o);
             }
         };
     }
 }
        private void OpenPatientContext()
        {
            PatientId = SelectedPatientContext.PatientId;

            OpenPatient();

            foreach (var planningItem in SelectedPatientContext.PlanningItemsInScope)
            {
                var pi = PlanningItems
                         .FirstOrDefault(p => p.Id == planningItem.Id && p.CourseId == planningItem.CourseId);

                if (pi != null)
                {
                    pi.IsChecked = true;  // Will add it to PlanSetupsInScope
                }
            }

            if (SelectedPatientContext.ActivePlanSetup != null)
            {
                SelectedPlanSetup = PlanSetupsInScope
                                    .SingleOrDefault(p => p.Id == SelectedPatientContext.ActivePlanSetup.Id &&
                                                     p.CourseId == SelectedPatientContext.ActivePlanSetup.CourseId);
            }
        }