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