001package org.hl7.fhir.dstu2.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.dstu2
006 * %%
007 * Copyright (C) 2014 - 2019 Health Level 7
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023
024import java.util.ArrayList;
025import java.util.List;
026
027/**
028 * A child element or property defined by the FHIR specification
029 * This class is defined as a helper class when iterating the 
030 * children of an element in a generic fashion
031 * 
032 * At present, iteration is only based on the specification, but 
033 * this may be changed to allow profile based expression at a
034 * later date
035 * 
036 * note: there's no point in creating one of these classes outside this package
037 */
038public class Property {
039
040        /**
041         * The name of the property as found in the FHIR specification
042         */
043        private String name;
044        
045        /**
046         * The type of the property as specified in the FHIR specification (e.g. type|type|Reference(Name|Name)
047         */
048        private String typeCode;
049        
050        /**
051         * The formal definition of the element given in the FHIR specification
052         */
053        private String definition;
054        
055        /**
056         * The minimum allowed cardinality - 0 or 1 when based on the specification
057         */
058        private int minCardinality;
059        
060        /** 
061         * The maximum allowed cardinality - 1 or MAX_INT when based on the specification
062         */
063        private int maxCardinality;
064        
065        /**
066         * The actual elements that exist on this instance
067         */
068        private List<Base> values = new ArrayList<Base>();
069
070        /**
071         * For run time, if/once a property is hooked up to it's definition
072         */
073        private StructureDefinition structure; 
074
075        /**
076         * Internal constructor
077         */
078        public Property(String name, String typeCode, String definition, int minCardinality, int maxCardinality, Base value) {
079          super();
080          this.name = name;
081          this.typeCode = typeCode;
082          this.definition = definition;
083          this.minCardinality = minCardinality;
084          this.maxCardinality = maxCardinality;
085          this.values.add(value);
086  }
087
088        /**
089         * Internal constructor
090         */
091        public Property(String name, String typeCode, String definition, int minCardinality, int maxCardinality, List<? extends Base> values) {
092          super();
093          this.name = name;
094          this.typeCode = typeCode;
095          this.definition = definition;
096          this.minCardinality = minCardinality;
097          this.maxCardinality = maxCardinality;
098          if (values != null)
099            this.values.addAll(values);
100  }
101
102        /**
103         * @return The name of this property in the FHIR Specification
104         */
105        public String getName() {
106                return name;
107        }
108
109        /**
110         * @return The stated type in the FHIR specification
111         */
112        public String getTypeCode() {
113                return typeCode;
114        }
115
116        /** 
117         * @return The definition of this element in the FHIR spec
118         */
119        public String getDefinition() {
120                return definition;
121        }
122
123        /**
124         * @return the minimum cardinality for this element 
125         */
126        public int getMinCardinality() {
127                return minCardinality;
128        }
129
130        /**
131         * @return the maximum cardinality for this element 
132         */
133        public int getMaxCardinality() {
134                return maxCardinality;
135        }
136
137        /**
138         * @return the actual values - will only be 1 unless maximum cardinality == MAX_INT
139         */
140        public List<Base> getValues() {
141                return values;
142        }
143
144  public boolean hasValues() {
145    for (Base e : getValues())
146      if (e != null)
147        return true;
148    return false;
149  }
150
151  public StructureDefinition getStructure() {
152    return structure;
153  }
154
155  public void setStructure(StructureDefinition structure) {
156    this.structure = structure;
157  }
158
159
160        
161}