001package org.hl7.fhir.dstu3.model;
002
003import java.util.ArrayList;
004import java.util.List;
005
006/**
007 * A child element or property defined by the FHIR specification
008 * This class is defined as a helper class when iterating the 
009 * children of an element in a generic fashion
010 * 
011 * At present, iteration is only based on the specification, but 
012 * this may be changed to allow profile based expression at a
013 * later date
014 * 
015 * note: there's no point in creating one of these classes outside this package
016 */
017public class Property {
018
019        /**
020         * The name of the property as found in the FHIR specification
021         */
022        private String name;
023        
024        /**
025         * The type of the property as specified in the FHIR specification (e.g. type|type|Reference(Name|Name)
026         */
027        private String typeCode;
028        
029        /**
030         * The formal definition of the element given in the FHIR specification
031         */
032        private String definition;
033        
034        /**
035         * The minimum allowed cardinality - 0 or 1 when based on the specification
036         */
037        private int minCardinality;
038        
039        /** 
040         * The maximum allowed cardinality - 1 or MAX_INT when based on the specification
041         */
042        private int maxCardinality;
043        
044        /**
045         * The actual elements that exist on this instance
046         */
047        private List<Base> values = new ArrayList<Base>();
048
049        /**
050         * For run time, if/once a property is hooked up to it's definition
051         */
052        private StructureDefinition structure; 
053
054        /**
055         * Internal constructor
056         */
057        public Property(String name, String typeCode, String definition, int minCardinality, int maxCardinality, Base value) {
058          super();
059          this.name = name;
060          this.typeCode = typeCode;
061          this.definition = definition;
062          this.minCardinality = minCardinality;
063          this.maxCardinality = maxCardinality;
064          this.values.add(value);
065  }
066
067        /**
068         * Internal constructor
069         */
070        public Property(String name, String typeCode, String definition, int minCardinality, int maxCardinality, List<? extends Base> values) {
071          super();
072          this.name = name;
073          this.typeCode = typeCode;
074          this.definition = definition;
075          this.minCardinality = minCardinality;
076          this.maxCardinality = maxCardinality;
077          if (values != null)
078            this.values.addAll(values);
079  }
080
081        /**
082         * @return The name of this property in the FHIR Specification
083         */
084        public String getName() {
085                return name;
086        }
087
088        /**
089         * @return The stated type in the FHIR specification
090         */
091        public String getTypeCode() {
092                return typeCode;
093        }
094
095        /** 
096         * @return The definition of this element in the FHIR spec
097         */
098        public String getDefinition() {
099                return definition;
100        }
101
102        /**
103         * @return the minimum cardinality for this element 
104         */
105        public int getMinCardinality() {
106                return minCardinality;
107        }
108
109        /**
110         * @return the maximum cardinality for this element 
111         */
112        public int getMaxCardinality() {
113                return maxCardinality;
114        }
115
116        /**
117         * @return the actual values - will only be 1 unless maximum cardinality == MAX_INT
118         */
119        public List<Base> getValues() {
120                return values;
121        }
122
123  public boolean hasValues() {
124    for (Base e : getValues())
125      if (e != null)
126        return true;
127    return false;
128  }
129
130  public StructureDefinition getStructure() {
131    return structure;
132  }
133
134  public void setStructure(StructureDefinition structure) {
135    this.structure = structure;
136  }
137
138
139        
140}