001package org.hl7.fhir.dstu2016may.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Sun, May 8, 2016 03:05+1000 for FHIR v1.4.0
033import java.util.ArrayList;
034import java.util.List;
035
036import org.hl7.fhir.exceptions.FHIRException;
037import org.hl7.fhir.instance.model.api.IBaseElement;
038import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
039import org.hl7.fhir.utilities.Utilities;
040
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.Description;
043/**
044 * Base definition for all elements in a resource.
045 */
046public abstract class Element extends Base implements IBaseHasExtensions, IBaseElement {
047
048    /**
049     * unique id for the element within a resource (for internal references).
050     */
051    @Child(name = "id", type = {IdType.class}, order=0, min=0, max=1, modifier=false, summary=false)
052    @Description(shortDefinition="xml:id (or equivalent in JSON)", formalDefinition="unique id for the element within a resource (for internal references)." )
053    protected IdType id;
054
055    /**
056     * May be used to represent additional information that is not part of the basic definition of the element. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.
057     */
058    @Child(name = "extension", type = {Extension.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
059    @Description(shortDefinition="Additional Content defined by implementations", formalDefinition="May be used to represent additional information that is not part of the basic definition of the element. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension." )
060    protected List<Extension> extension;
061
062    private static final long serialVersionUID = -158027598L;
063
064  /**
065   * Constructor
066   */
067    public Element() {
068      super();
069    }
070
071    /**
072     * @return {@link #id} (unique id for the element within a resource (for internal references).). This is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value
073     */
074    public IdType getIdElement() { 
075      if (this.id == null)
076        if (Configuration.errorOnAutoCreate())
077          throw new Error("Attempt to auto-create Element.id");
078        else if (Configuration.doAutoCreate())
079          this.id = new IdType(); // bb
080      return this.id;
081    }
082
083    public boolean hasIdElement() { 
084      return this.id != null && !this.id.isEmpty();
085    }
086
087    public boolean hasId() { 
088      return this.id != null && !this.id.isEmpty();
089    }
090
091    /**
092     * @param value {@link #id} (unique id for the element within a resource (for internal references).). This is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value
093     */
094    public Element setIdElement(IdType value) { 
095      this.id = value;
096      return this;
097    }
098
099    /**
100     * @return unique id for the element within a resource (for internal references).
101     */
102    public String getId() { 
103      return this.id == null ? null : this.id.getValue();
104    }
105
106    /**
107     * @param value unique id for the element within a resource (for internal references).
108     */
109    public Element setId(String value) { 
110      if (Utilities.noString(value))
111        this.id = null;
112      else {
113        if (this.id == null)
114          this.id = new IdType();
115        this.id.setValue(value);
116      }
117      return this;
118    }
119
120    /**
121     * @return {@link #extension} (May be used to represent additional information that is not part of the basic definition of the element. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.)
122     */
123    public List<Extension> getExtension() { 
124      if (this.extension == null)
125        this.extension = new ArrayList<Extension>();
126      return this.extension;
127    }
128
129    public boolean hasExtension() { 
130      if (this.extension == null)
131        return false;
132      for (Extension item : this.extension)
133        if (!item.isEmpty())
134          return true;
135      return false;
136    }
137
138    /**
139     * @return {@link #extension} (May be used to represent additional information that is not part of the basic definition of the element. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.)
140     */
141    // syntactic sugar
142    public Extension addExtension() { //3
143      Extension t = new Extension();
144      if (this.extension == null)
145        this.extension = new ArrayList<Extension>();
146      this.extension.add(t);
147      return t;
148    }
149
150    // syntactic sugar
151    public Element addExtension(Extension t) { //3
152      if (t == null)
153        return this;
154      if (this.extension == null)
155        this.extension = new ArrayList<Extension>();
156      this.extension.add(t);
157      return this;
158    }
159
160   /**
161    * Returns an unmodifiable list containing all extensions on this element which 
162    * match the given URL.
163    * 
164    * @param theUrl The URL. Must not be blank or null.
165    * @return an unmodifiable list containing all extensions on this element which 
166    * match the given URL
167    */
168   public List<Extension> getExtensionsByUrl(String theUrl) {
169     org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null");
170     ArrayList<Extension> retVal = new ArrayList<Extension>();
171     for (Extension next : getExtension()) {
172       if (theUrl.equals(next.getUrl())) {
173         retVal.add(next);
174       }
175     }
176     return java.util.Collections.unmodifiableList(retVal);
177   }
178  public boolean hasExtension(String theUrl) {
179    return !getExtensionsByUrl(theUrl).isEmpty(); 
180  }
181
182  public String getExtensionString(String theUrl) throws FHIRException {
183    List<Extension> ext = getExtensionsByUrl(theUrl); 
184    if (ext.isEmpty()) 
185      return null; 
186    if (ext.size() > 1) 
187      throw new FHIRException("Multiple matching extensions found");
188    if (!ext.get(0).getValue().isPrimitive())
189      throw new FHIRException("Extension could not be converted to a string");
190    return ext.get(0).getValue().primitiveValue();
191  }
192
193      protected void listChildren(List<Property> childrenList) {
194        childrenList.add(new Property("id", "id", "unique id for the element within a resource (for internal references).", 0, java.lang.Integer.MAX_VALUE, id));
195        childrenList.add(new Property("extension", "Extension", "May be used to represent additional information that is not part of the basic definition of the element. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", 0, java.lang.Integer.MAX_VALUE, extension));
196      }
197
198      @Override
199      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
200        switch (hash) {
201        case 3355: /*id*/ return this.id == null ? new Base[0] : new Base[] {this.id}; // IdType
202        case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension
203        default: return super.getProperty(hash, name, checkValid);
204        }
205
206      }
207
208      @Override
209      public void setProperty(int hash, String name, Base value) throws FHIRException {
210        switch (hash) {
211        case 3355: // id
212          this.id = castToId(value); // IdType
213          break;
214        case -612557761: // extension
215          this.getExtension().add(castToExtension(value)); // Extension
216          break;
217        default: super.setProperty(hash, name, value);
218        }
219
220      }
221
222      @Override
223      public void setProperty(String name, Base value) throws FHIRException {
224        if (name.equals("id"))
225          this.id = castToId(value); // IdType
226        else if (name.equals("extension"))
227          this.getExtension().add(castToExtension(value));
228        else
229          super.setProperty(name, value);
230      }
231
232      @Override
233      public Base makeProperty(int hash, String name) throws FHIRException {
234        switch (hash) {
235        case 3355: throw new FHIRException("Cannot make property id as it is not a complex type"); // IdType
236        case -612557761:  return addExtension(); // Extension
237        default: return super.makeProperty(hash, name);
238        }
239
240      }
241
242      @Override
243      public Base addChild(String name) throws FHIRException {
244        if (name.equals("id")) {
245          throw new FHIRException("Cannot call addChild on a primitive type Element.id");
246        }
247        else if (name.equals("extension")) {
248          return addExtension();
249        }
250        else
251          return super.addChild(name);
252      }
253
254  public String fhirType() {
255    return "Element";
256
257  }
258
259      public abstract Element copy();
260
261      public void copyValues(Element dst) {
262        dst.id = id == null ? null : id.copy();
263        if (extension != null) {
264          dst.extension = new ArrayList<Extension>();
265          for (Extension i : extension)
266            dst.extension.add(i.copy());
267        };
268      }
269
270      @Override
271      public boolean equalsDeep(Base other) {
272        if (!super.equalsDeep(other))
273          return false;
274        if (!(other instanceof Element))
275          return false;
276        Element o = (Element) other;
277        return compareDeep(id, o.id, true) && compareDeep(extension, o.extension, true);
278      }
279
280      @Override
281      public boolean equalsShallow(Base other) {
282        if (!super.equalsShallow(other))
283          return false;
284        if (!(other instanceof Element))
285          return false;
286        Element o = (Element) other;
287        return compareValues(id, o.id, true);
288      }
289
290      public boolean isEmpty() {
291        boolean retVal = super.isEmpty() && (id == null || id.isEmpty()) && (extension == null || extension.isEmpty());
292                return retVal
293          ;
294      }
295
296
297}
298