Ejemplo n.º 1
0
        protected override void AddItem(T item)
        {
            Check.Require(this.parent != null || item.Parent != null,
                          "item of type Pathable must have Parent attribute set when list parent not set");

            Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");

            Locatable locatable = item as Locatable;

            Check.Assert(item != null, "item must not be null");

            if (item.Parent == null)
            {
                item.Parent = this.parent;
            }

            else if (this.parent == null)
            {
                this.parent = item.Parent;
            }

            else if (!Object.ReferenceEquals(item.Parent, this.parent))
            {
                throw new ApplicationException("item parent must have same parent as other items");
            }

            NamedLocatableList <T> namedLocatables;

            if (identifiedLocatables.ContainsKey(item.ArchetypeNodeId))
            {
                namedLocatables = identifiedLocatables[item.ArchetypeNodeId];
            }
            else
            {
                namedLocatables = new NamedLocatableList <T>();
                identifiedLocatables.Add(item.ArchetypeNodeId, namedLocatables);
            }

            DvCodedText codedName = item.Name as DvCodedText;

            if (codedName != null)
            {
                if (namedLocatables.Contains(codedName.DefiningCode.TerminologyId.Value, codedName.DefiningCode.CodeString))
                {
                    throw new ApplicationException(string.Format("locatable ({0}) name ({1}) already existing in the namedLocatable list.",
                                                                 item.ArchetypeNodeId, codedName.ToString()));
                }
            }
            else if (namedLocatables.Contains(item.Name.Value))
            {
                throw new ApplicationException(string.Format("locatable ({0}) name ({1}) already existing in this namedLocatable list",
                                                             item.ArchetypeNodeId, item.Name.Value));
            }

            namedLocatables.Add(item);

            base.AddItem(item);
        }
Ejemplo n.º 2
0
        internal LocatableList(OpenEhr.RM.Common.Archetyped.Pathable parent,
                               System.Collections.Generic.IEnumerable <T> items) : this()
        {
            Check.Require(parent != null, "parent must not be null");

            this.parent = parent;

            if (items != null)
            {
                foreach (T item in items)
                {
                    item.Parent = null;
                    AddItem(item);
                }
            }

            Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");
        }