Exemplo n.º 1
0
        /// <summary> Adds a new item to the Structure. </summary>
        /// <exception cref="HL7Exception">Thrown when the named Structure is not part of this group
        /// or if the structure is not repeatable and an item already exists. </exception>
        public virtual IStructure AddStructure(String name)
        {
            AbstractGroupItem item = GetGroupItem(name);

            if (item == null)
            {
                throw new HL7Exception(name + " does not exist in the group " + GetType().FullName,
                                       ErrorCode.APPLICATION_INTERNAL_ERROR);
            }

            // Verify that Structure is repeating ...
            bool repeats = item.IsRepeating;

            if (!repeats && item.Structures.Count > 0)
            {
                throw new HL7Exception(
                          "Can't create repetition of Structure " + name + " - this Structure is non-repeating and this Structure already has an item present.",
                          ErrorCode.APPLICATION_INTERNAL_ERROR);
            }

            // Create a new Structure, add it to the list, and return it
            Type classType = item.ClassType;
            var  ret       = tryToInstantiateStructure(classType, name);

            item.Structures.Add(ret);
            return(ret);
        }
Exemplo n.º 2
0
        /// <summary> Returns the number of existing repetitions of the named structure.</summary>
        public virtual int currentReps(System.String name)
        {
            AbstractGroupItem item = GetGroupItem(name);

            if (item == null)
            {
                throw new HL7Exception("The structure " + name + " does not exist in the group " + this.GetType().FullName, HL7Exception.APPLICATION_INTERNAL_ERROR);
            }
            return(item.Structures.Count);
        }
Exemplo n.º 3
0
        /// <summary> Returns true if the named structure is required. </summary>
        public virtual bool IsRepeating(String name)
        {
            AbstractGroupItem item = GetGroupItem(name);

            if (item == null)
            {
                throw new HL7Exception("The structure " + name + " does not exist in the group " + GetType().FullName,
                                       ErrorCode.APPLICATION_INTERNAL_ERROR);
            }
            return(item.IsRepeating);
        }
Exemplo n.º 4
0
        /// <summary> Returns true if the class name is already being used. </summary>
        private bool nameExists(String name)
        {
            bool exists            = false;
            AbstractGroupItem item = GetGroupItem(name);

            if (item != null)
            {
                exists = true;
            }
            return(exists);
        }
Exemplo n.º 5
0
        /// <summary> Removes the given structure from the named Structure. </summary>
        /// <exception cref="HL7Exception">Thrown when the named Structure is not part of this Group.</exception>
        public virtual void RemoveStructure(String name, IStructure toRemove)
        {
            AbstractGroupItem item = GetGroupItem(name);

            if (item == null)
            {
                throw new HL7Exception(name + " does not exist in the group " + GetType().FullName,
                                       ErrorCode.APPLICATION_INTERNAL_ERROR);
            }

            item.Structures.Remove(toRemove);
        }
Exemplo n.º 6
0
        /// <summary>   Returns true if the named structure is required. </summary>
        ///
        /// <exception cref="HL7Exception"> Thrown when a HL 7 error condition occurs. </exception>
        ///
        /// <param name="name"> The name of the group item. </param>
        ///
        /// <returns>   true if required, false if not. </returns>

        public virtual bool IsRequired(System.String name)
        {
            AbstractGroupItem item = this.GetGroupItem(name);

            if (item == null)
            {
                throw new HL7Exception(
                          "The structure " + name + " does not exist in the group " + this.GetType().FullName,
                          HL7Exception.APPLICATION_INTERNAL_ERROR);
            }
            return(item.IsRequired);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets a group item by name
        /// </summary>
        /// <param name="name">The name of the group item</param>
        /// <returns>Group item if found, null otherwise</returns>
        protected AbstractGroupItem GetGroupItem(string name)
        {
            AbstractGroupItem ret = null;

            foreach (AbstractGroupItem item in _items)
            {
                if (item.Name.Equals(name))
                {
                    ret = item;
                    break;
                }
            }
            return(ret);
        }
Exemplo n.º 8
0
        /// <summary> Returns an array of Structure objects by name.  For example, if the Group contains
        /// an MSH segment and "MSH" is supplied then this call would return a 1-element array
        /// containing the MSH segment.  Multiple elements are returned when the segment or
        /// group repeats.  The array may be empty if no repetitions have been accessed
        /// yet using the get(...) methods.
        /// </summary>
        /// <throws>  HL7Exception if the named Structure is not part of this Group.  </throws>
        public virtual IStructure[] GetAll(System.String name)
        {
            AbstractGroupItem item = GetGroupItem(name);

            if (item == null)
            {
                throw new HL7Exception("The structure " + name + " does not exist in the group " + this.GetType().FullName, HL7Exception.APPLICATION_INTERNAL_ERROR);
            }
            IStructure[] all = new IStructure[item.Structures.Count];
            for (int i = 0; i < item.Structures.Count; i++)
            {
                all[i] = item.Structures[i];
            }
            return(all);
        }
Exemplo n.º 9
0
        /// <summary>   Returns a particular repetition of the named Structure. If the given repetition
        ///             number is one greater than the existing number of repetitions then a new
        ///             Structure is created.  </summary>
        /// <summary>   if the structure is not repeatable and the given rep is > 0,
        ///             or if the given repetition number is more than one greater than the existing
        ///             number of repetitions.  </summary>
        ///
        /// <exception cref="HL7Exception"> Thrown when a HL 7 error condition occurs. </exception>
        ///
        /// <param name="name"> an optional name of the structure (used by Generic structures; may be
        ///                     null) </param>
        /// <param name="rep">  The rep. </param>
        ///
        /// <returns>   The structure. </returns>

        public virtual IStructure GetStructure(System.String name, int rep)
        {
            AbstractGroupItem item = this.GetGroupItem(name);

            if (item == null)
            {
                throw new HL7Exception(
                          name + " does not exist in the group " + this.GetType().FullName,
                          HL7Exception.APPLICATION_INTERNAL_ERROR);
            }

            IStructure ret;

            if (rep < item.Structures.Count)
            {
                // return existng Structure if it exists
                ret = item.Structures[rep];
            }
            else if (rep == item.Structures.Count)
            {
                //verify that Structure is repeating ...
                bool repeats = item.IsRepeating;
                if (!repeats && item.Structures.Count > 0)
                {
                    throw new HL7Exception(
                              "Can't create repetition #" + rep + " of Structure " + name
                              + " - this Structure is non-repeating",
                              HL7Exception.APPLICATION_INTERNAL_ERROR);
                }

                //create a new Structure, add it to the list, and return it
                System.Type classType = item.ClassType;
                ret = this.tryToInstantiateStructure(classType, name);
                item.Structures.Add(ret);
            }
            else
            {
                throw new HL7Exception(
                          "Can't return repetition #" + rep + " of " + name + " - there are only " + this._items.Count
                          + " repetitions.",
                          HL7Exception.APPLICATION_INTERNAL_ERROR);
            }
            return(ret);
        }
Exemplo n.º 10
0
        /// <summary> Inserts the given structure into this group, at the
        /// indicated index number.  This method is used to support handling
        /// of unexpected segments (e.g. Z-segments).  In contrast, specification
        /// of the group's normal children should be done at construction time, using the
        /// add(...) method.
        /// </summary>
        private String insert(Type classType, bool required, bool repeating, int index, String name)
        {
            //see if there is already something by this name and make a new name if necessary ...
            if (nameExists(name))
            {
                int    version = 2;
                String newName = name;
                while (nameExists(newName))
                {
                    newName = name + version++;
                }
                name = newName;
            }

            AbstractGroupItem item = new AbstractGroupItem(name, required, repeating, classType);

            _items.Insert(index, item);
            return(name);
        }
Exemplo n.º 11
0
        /// <summary> Removes the structure at the given index from the named Structure. </summary>
        /// <exception cref = "HL7Exception" > Thrown when the named Structure is not part of this Group
        /// or an index greater than the number of items in the structure is supplied.
        /// </exception>
        public virtual void RemoveRepetition(String name, int rep)
        {
            AbstractGroupItem item = GetGroupItem(name);

            if (item == null)
            {
                throw new HL7Exception("The structure " + name + " does not exist in the group " + GetType().FullName,
                                       ErrorCode.APPLICATION_INTERNAL_ERROR);
            }

            if (rep >= item.Structures.Count)
            {
                throw new HL7Exception(
                          "The structure " + name + " does not have " + rep + " repetitions. ",
                          ErrorCode.APPLICATION_INTERNAL_ERROR);
            }

            item.Structures.RemoveAt(rep);
        }
Exemplo n.º 12
0
        /// <summary> Inserts the given structure into this group, at the
        /// indicated index number.  This method is used to support handling
        /// of unexpected segments (e.g. Z-segments).  In contrast, specification
        /// of the group's normal children should be done at construction time, using the
        /// add(...) method.
        /// </summary>
        private string Insert(Type classType, bool required, bool repeating, bool choiceElement, int index, string name)
        {
            // see if there is already something by this name and make a new name if necessary ...
            if (NameExists(name))
            {
                var version = 2;
                var newName = name;
                while (NameExists(newName))
                {
                    newName = name + version++;
                }

                name = newName;
            }

            var item = new AbstractGroupItem(name, required, repeating, choiceElement, classType);

            items.Insert(index, item);
            return(name);
        }
Exemplo n.º 13
0
        /// <summary> Returns the Class of the Structure at the given name index.  </summary>
        public virtual Type GetClass(String name)
        {
            AbstractGroupItem item = GetGroupItem(name);

            return(item.ClassType);
        }
Exemplo n.º 14
0
        /// <summary>   Returns the Class of the Structure at the given name index. </summary>
        ///
        /// <param name="name"> an optional name of the structure (used by Generic structures; may be
        ///                     null) </param>
        ///
        /// <returns>   The class. </returns>

        public virtual System.Type GetClass(System.String name)
        {
            AbstractGroupItem item = this.GetGroupItem(name);

            return(item.ClassType);
        }
Exemplo n.º 15
0
        /// <summary> Inserts the given structure into this group, at the
        /// indicated index number.  This method is used to support handling 
        /// of unexpected segments (e.g. Z-segments).  In contrast, specification 
        /// of the group's normal children should be done at construction time, using the 
        /// add(...) method. 
        /// </summary>
        private System.String insert(System.Type classType, bool required, bool repeating, int index, System.String name)
        {
            //see if there is already something by this name and make a new name if necessary ...
            if (nameExists(name))
            {
                int version = 2;
                System.String newName = name;
                while (nameExists(newName))
                {
                    newName = name + version++;
                }
                name = newName;
            }

            AbstractGroupItem item = new AbstractGroupItem(name, required, repeating, classType);
            _items.Insert(index, item);
            return name;
        }