Ejemplo n.º 1
0
        public HeaderViewModel(IHrsHolder holder)
        {
            Contract.Requires(holder != null);
            this.holder = holder;
            HolderVm    = new HolderViewModel(holder);

            if (holder is Patient)
            {
            }
            else if (holder is Course)
            {
                var course = holder as Course;
                course.Patient.CoursesChanged += Patient_CoursesChanged;
                ShowCourses();
            }
            else if (holder is Appointment)
            {
                var app = holder as Appointment;
                app.Course.AppointmentsChanged += Course_AppointmentsChanged;

                ShowApps();
            }

            ((INotifyPropertyChanged)holder).PropertyChanged += Holder_PropertyChanged;
        }
Ejemplo n.º 2
0
        public HolderViewModel(IHrsHolder holder, bool showOpen = false)
        {
            Contract.Requires(holder != null);
            this.holder = holder;
            if (holder is Patient)
            {
                var pat = holder as Patient;
                pat.CoursesChanged       += holder_CollectionChanged;
                pat.HealthRecordsChanged += holder_CollectionChanged;
            }
            else if (holder is Course)
            {
                var course = holder as Course;
                course.AppointmentsChanged  += holder_CollectionChanged;
                course.HealthRecordsChanged += holder_CollectionChanged;
            }
            else if (holder is Appointment)
            {
                var app = holder as Appointment;
                app.HealthRecordsChanged += holder_CollectionChanged;
            }

            StartCourseCommand.IsVisible    = holder is Patient;
            AddAppointmentCommand.IsVisible = holder is Course;
            OpenCommand.IsVisible           = showOpen;
        }
Ejemplo n.º 3
0
        private HrsResultItemViewModel(IHrsHolder holder, IEnumerable <HealthRecord> foundHrs = null)
        {
            this.holder = holder;
            // автообновление результатов поиска - сейчас только удаляется запись/холдер, но не статистика
            Holder.HealthRecordsChanged += Holder_HealthRecordsChanged;

            HealthRecords = new ObservableCollection <HealthRecord>(holder.HealthRecords);
            if (foundHrs != null)
            {
                FoundHealthRecords = new ObservableCollection <HealthRecord>(foundHrs);
            }
            else
            {
                FoundHealthRecords = new ObservableCollection <HealthRecord>();
            }

            FoundHealthRecords.CollectionChanged += (s, e) =>
            {
                if (FoundHealthRecords.Count == 0 && this.IsTerminal)
                {
                    // когда удалены все записи, по которым был найден холдер
                    this.Remove();
                }
            };
        }
Ejemplo n.º 4
0
        void IHrsHolder.RemoveHealthRecord(HealthRecord hr)
        {
            IHrsHolder test = this;

            Contract.Ensures(test.HealthRecords.Count() <= Contract.OldValue(test.HealthRecords.Count()));
            Contract.Ensures(!test.HealthRecords.Contains(hr));
            Contract.Ensures(hr.Words.All(x => !x.HealthRecords.Contains(hr)));
        }
Ejemplo n.º 5
0
        public virtual int CompareTo(IHrsHolder h)
        {
            var app = h as Appointment;

            if (app != null)
            {
                return(this.CompareTo(app));
            }
            return(new HrsHolderComparer().Compare(this, h));
        }
Ejemplo n.º 6
0
        internal void Select(HealthRecord hr, IHrsHolder holder)
        {
            var @switch = new Dictionary <Type, Action> {
                { typeof(Patient), () => OnHrOpened <Patient>(patMap, holder as Patient, hr) },
                { typeof(Course), () => OnHrOpened <Course>(courseMap, holder as Course, hr) },
                { typeof(Appointment), () => OnHrOpened <Appointment>(appMap, holder as Appointment, hr) }
            };

            @switch[holder.GetType()]();
        }
Ejemplo n.º 7
0
        public virtual int CompareTo(IHrsHolder h)
        {
            var course = h as Course;

            if (course != null)
            {
                return(this.CompareTo(course));
            }
            return(new HrsHolderComparer().Compare(this, h));
        }
Ejemplo n.º 8
0
        private static IEnumerable <HealthRecord> RemoveEmptyHrs(IHrsHolder holder)
        {
            Contract.Requires(holder != null);
            Contract.Ensures(holder.HealthRecords.All(x => !x.IsEmpty()));

            var emptyHrs = holder.HealthRecords.Where(hr => hr.IsEmpty()).ToList();

            emptyHrs.ForEach(hr => holder.RemoveHealthRecord(hr));
            return(emptyHrs);
        }
Ejemplo n.º 9
0
        HealthRecord IHrsHolder.AddHealthRecord(Doctor author)
        {
            IHrsHolder test = this;

            Contract.Requires(author != null);
            Contract.Ensures(test.HealthRecords.Count() == Contract.OldValue(test.HealthRecords.Count()) + 1);
            Contract.Ensures(test.HealthRecords.Contains(Contract.Result <HealthRecord>()));
            Contract.Ensures(Contract.Result <HealthRecord>().Words.All(x => x.HealthRecords.Contains(Contract.Result <HealthRecord>())));
            Contract.Ensures(author.HealthRecords.Contains(Contract.Result <HealthRecord>()));

            return(null);
        }
Ejemplo n.º 10
0
        public HealthRecordManager(IHrsHolder holder, PropertyChangedEventHandler onHrVmPropChanged)
        {
            this.holder                  = holder;
            this.onHrVmPropChanged       = onHrVmPropChanged;
            holder.HealthRecordsChanged += holder_HealthRecordsChanged;

            var hrs = holder.HealthRecords
                      .OrderBy(hr => hr.Ord)
                      .ToList();

            for (int i = 0; i < hrs.Count; i++)
            {
                hrs[i].Ord = i;
            }
            // all hrs with different order now

            var hrVMs = hrs
                        .Select(hr => CreateViewModel(hr))
                        .ToList();

            inner = new ObservableCollection <ShortHealthRecordViewModel>(hrVMs);

            healthRecords = new ObservableCollection <ShortHealthRecordViewModel>(hrVMs
                                                                                  .Where(hr => !hr.IsDeleted));
            deletedHealthRecords = new ObservableCollection <ShortHealthRecordViewModel>(hrVMs
                                                                                         .Where(hr => hr.IsDeleted));

            HealthRecords        = new INCCReadOnlyObservableCollection <ShortHealthRecordViewModel>(healthRecords);
            DeletedHealthRecords = new INCCReadOnlyObservableCollection <ShortHealthRecordViewModel>(deletedHealthRecords);

            inner.CollectionChanged += (s, e) =>
            {
                if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                {
                    foreach (ShortHealthRecordViewModel vm in e.NewItems)
                    {
                        healthRecords.Add(vm);
                    }
                }
                else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
                {
                    foreach (ShortHealthRecordViewModel vm in e.OldItems)
                    {
                        healthRecords.Remove(vm);
                        deletedHealthRecords.Remove(vm);
                    }
                }
            };
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Дата последнего обновления записей внутри.
        /// Дата обновления, если запсией нет.
        /// </summary>
        public static DateTime GetLastHrUpdatedAt(this IHrsHolder holder)
        {
            Contract.Requires(holder != null);

            if (holder.GetAllHrs().Any())
            {
                return(holder.GetAllHrs()
                       .OrderByDescending(x => x.UpdatedAt)
                       .First().UpdatedAt);
            }
            else
            {
                return((holder as IHaveAuditInformation).UpdatedAt);
            }
        }
Ejemplo n.º 12
0
        protected override void RemoveDeleted(IHrsHolder h)
        {
            var hrsResultItem = Patients.Cast <HrsResultItemViewModel>().FindHolderKeeperOf(h);

            if (hrsResultItem != null)
            {
                if (hrsResultItem.IsRoot)
                {
                    Patients.Remove(hrsResultItem);
                }
                else
                {
                    hrsResultItem.Remove();
                }
            }
        }
Ejemplo n.º 13
0
 // cannot use GetType because Nhibernate proxy
 DataTemplate Switch(IHrsHolder holder)
 {
     if (holder is Patient)
     {
         return(PatientTemplate);
     }
     if (holder is Course)
     {
         return(CourseTemplate);
     }
     if (holder is Appointment)
     {
         return(AppointmentTemplate);
     }
     throw new ArgumentOutOfRangeException();
 }
Ejemplo n.º 14
0
        private void OpenHolder(IHrsHolder holder, bool lastAppOrCourse)
        {
            Contract.Ensures(HrList.holder == holder.Actual || lastAppOrCourse);

            holder = holder.Actual as IHrsHolder;
            var was = viewer.AutoOpenChild;

            if (lastAppOrCourse)
            {
                viewer.AutoOpenChild = true;
            }

            Navigator.NavigateTo(holder);

            viewer.AutoOpenChild = was;
        }
Ejemplo n.º 15
0
        public static IEnumerable <Word> GetAllWords(this IHrsHolder holder)
        {
            if (holder is Patient)
            {
                return((holder as Patient).GetAllWords());
            }
            if (holder is Course)
            {
                return((holder as Course).GetAllWords());
            }
            if (holder is Appointment)
            {
                return((holder as Appointment).GetAllWords());
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 16
0
        private void ShowHeader(IHrsHolder holder)
        {
            if (Header != null)
            {
                if (Header.Holder == holder)
                {
                    return;
                }

                CloseHeader();
            }

            if (holder != null)
            {
                Header = new HeaderViewModel(holder);
            }
        }
Ejemplo n.º 17
0
        public HrListViewModel(IHrsHolder holder, ISession session, HrViewColumn sorting = HrViewColumn.Ord, HrViewColumn grouping = HrViewColumn.Category)
        {
            Contract.Requires(holder != null);
            Contract.Requires(session != null);
            this.session = session;
            this.holder  = holder;

            HolderVm = new HolderViewModel(holder);

            doNotNotifyLastSelectedChanged = new FlagActionWrapper(() =>
            {
                OnPropertyChanged(() => LastSelected);
                logger.DebugFormat("(bulk) selected in order\n{0}", string.Join("\n", selectedOrder));
            });

            preserveSelected = new FlagActionWrapper <IList <ShortHealthRecordViewModel> >((hrs) =>
            {
                hrs.ForEach(vm => vm.IsSelected = true);
                // fix new selected item appears in listbox after movement hrs from diff categories in grouped by category
                // TODO fix when diff createdAt
                HealthRecords.Except(hrs).ForEach(x => x.IsSelected = false);
            });

            handler = this.Subscribe(Event.NewSession, (e) =>
            {
                var s = e.GetValue <ISession>(MessageKeys.Session);
                ReplaceSession(s);
            });

            hrManager = new HealthRecordManager(holder, OnHrVmPropChanged);
            hrManager.DeletedHealthRecords.CollectionChangedWrapper += DeletedHrsCollectionChanged;
            hrManager.HealthRecords.CollectionChangedWrapper        += HrsCollectionChanged;

            view = (ListCollectionView)CollectionViewSource.GetDefaultView(HealthRecords);

            DropHandler = new DropTargetHandler(this);
            DragHandler = new DragSourceHandler();

            IsDragSourceEnabled = true;
            IsDropTargetEnabled = true;
            IsRectSelectEnabled = true;

            Grouping = grouping;
            Sorting  = sorting;
            SetHrExtra(HealthRecords);
        }
Ejemplo n.º 18
0
        private void AddHr(IHrsHolder holder, bool startEdit)
        {
            Contract.Requires(holder != null);
            Contract.Ensures(HrList.holder == holder);

            // open holder list first
            if (HrList.holder != holder)
            {
                Open(holder);
            }

            var hr = HrList.AddHr();

            if (startEdit)
            {
                StartEditHr(hr, false);
            }
        }
Ejemplo n.º 19
0
        internal void Delete(IHrsHolder holder)
        {
            using (var t = session.BeginTransaction())
            {
                try
                {
                    session.Delete(holder);
                    t.Commit();
                }
                catch (System.Exception e)
                {
                    t.Rollback();
                    logger.Error(e);
#if DEBUG
                    throw;
#endif
                }
            }
        }
Ejemplo n.º 20
0
        public static IEnumerable <HealthRecord> GetAllHrs(this IHrsHolder holder)
        {
            Contract.Requires(holder != null);

            if (holder is Patient)
            {
                return((holder as Patient).GetAllHrs());
            }
            if (holder is Course)
            {
                return((holder as Course).GetAllHrs());
            }
            if (holder is Appointment)
            {
                return((holder as Appointment).HealthRecords);
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 21
0
        public HealthRecord GetLastSelectedFor(IHrsHolder holder)
        {
            HealthRecord hr;

            if (holder is Patient && patMap.TryGetValue(holder as Patient, out hr))
            {
                return(hr);
            }
            if (holder is Course && courseMap.TryGetValue(holder as Course, out hr))
            {
                return(hr);
            }
            if (holder is Appointment && appMap.TryGetValue(holder as Appointment, out hr))
            {
                return(hr);
            }

            return(null);
        }
Ejemplo n.º 22
0
        public static T FindHolderKeeperOf <T>(this IEnumerable <T> root, IHrsHolder holder)
            where T : HierarchicalBase <T>, IHrsHolderKeeper
        {
            holder = holder.Actual as IHrsHolder;
            T vm;

            foreach (var item in root)
            {
                if (item.Holder.Actual == holder)
                {
                    return(item);
                }
                vm = item.AllChildren.Where(x => x.Holder.Actual == holder).FirstOrDefault();
                if (vm != null)
                {
                    return(vm);
                }
            }
            return(null);
        }
Ejemplo n.º 23
0
        internal void DeleteHolder(IHrsHolder holder)
        {
            Contract.Assume(deletingHolder == null);

            deletingHolder = holder;

            if (holder is Course)
            {
                var course = holder as Course;
                course.Patient.RemoveCourse(course);
            }
            else if (holder is Appointment)
            {
                var app = holder as Appointment;
                app.Course.RemoveAppointment(app);
            }
            Session.DoDelete(holder);

            ExecutePendingActions();
        }
Ejemplo n.º 24
0
        private void OnHolderDeleted(IHrsHolder holder)
        {
            Contract.Assume(deletingHolder != null);

            viewer.RemoveFromHistory(holder);

            if (holder is Patient)
            {
                Navigator.RemoveRoot(holder as Patient);
                if (Navigator.TopItems.Count == 0)
                {
                    OnLastItemRemoved();
                }
            }

            // holder may be child of deleting
            if (deletingHolder == holder)
            {
                deletingHolder = null;
            }
        }
Ejemplo n.º 25
0
        public CardItemViewModel(IHrsHolder holder)
        {
            this.holder = holder;

            HolderVm = new HolderViewModel(holder, true);
            if (holder is Patient)
            {
                var patient   = holder as Patient;
                var courseVMs = patient.GetOrderedCourses()
                                .Reverse()
                                .Select(i => new CardItemViewModel(i.Actual as Course))
                                .ToList();
                foreach (var item in courseVMs)
                {
                    Children.Add(item);
                }
                patient.CoursesChanged += nested_IHrsHolders_Changed;
            }
            else if (holder is Course)
            {
                var course = holder as Course;

                var appVMs = course.GetOrderedAppointments()
                             .Select(app => new CardItemViewModel(app.Actual as Appointment))
                             .ToList();

                foreach (var item in appVMs)
                {
                    Children.Add(item);
                }

                CorrectAppTimeVisibilty();

                course.AppointmentsChanged += nested_IHrsHolders_Changed;
            }

            holder.PropertyChanged += holder_PropertyChanged;
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Показвает записи активной сущности.
        /// Закрывает список записей, если передан null.
        /// </summary>
        private void ShowHrsList(IHrsHolder holder)
        {
            if (HrList != null)
            {
                if (HrList.holder == holder)
                {
                    return; // список может быть уже создан
                }
                CloseHrList();
            }

            if (holder != null)
            {
                HrList = new HrListViewModel(holder, Session);
                var          doctor = AuthorityController.CurrentDoctor;
                HrViewColumn gr;
                if (Enum.TryParse <HrViewColumn>(doctor.Settings.HrListGrouping, true, out gr))
                {
                    HrList.Grouping = gr;
                }
                HrViewColumn sort;
                if (Enum.TryParse <HrViewColumn>(doctor.Settings.HrListSorting, true, out sort))
                {
                    HrList.Sorting = sort;
                }

                HrList.SelectLastSelectedForHolder();

                HrList.PropertyChanged += HrList_PropertyChanged;
                HrList.HrsSaved        += (s, e) =>
                {
                    if (!HrEditor.HasHealthRecord)
                    {
                        HrList.IsFocused = true;
                    }
                };
            }
        }
Ejemplo n.º 27
0
        public void DeleteEmptyAppCoursePatient_NavigateUpper()
        {
            card.Open(a[5]);
            IHrsHolder holder = null;

            var NavigatingEh = (EventHandler <DomainEntityEventArgs>)((s, e) =>
            {
                holder = e.entity as IHrsHolder;
            });

            card.Navigator.Navigating += NavigatingEh;

            card.Navigator.Current.HolderVm.DeleteCommand.Execute(null);
            Assert.AreEqual(c[4], holder);

            card.Navigator.Current.HolderVm.DeleteCommand.Execute(null);
            Assert.AreEqual(p[3], holder);

            card.Navigator.Current.HolderVm.DeleteCommand.Execute(null);
            Assert.IsNull(holder);
            Assert.IsNull(card.Navigator.Current);

            card.Navigator.Navigating -= NavigatingEh;
        }