001package org.hl7.fhir.dstu3.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 Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import org.hl7.fhir.dstu3.model.Enumerations.*;
038import ca.uhn.fhir.model.api.annotation.ResourceDef;
039import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.ChildOrder;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.Block;
044import org.hl7.fhir.instance.model.api.*;
045import org.hl7.fhir.exceptions.FHIRException;
046/**
047 * This is the base resource type for everything.
048 */
049public abstract class Resource extends BaseResource implements IAnyResource {
050
051    /**
052     * The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
053     */
054    @Child(name = "id", type = {IdType.class}, order=0, min=0, max=1, modifier=false, summary=true)
055    @Description(shortDefinition="Logical id of this artifact", formalDefinition="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes." )
056    protected IdType id;
057
058    /**
059     * The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource.
060     */
061    @Child(name = "meta", type = {Meta.class}, order=1, min=0, max=1, modifier=false, summary=true)
062    @Description(shortDefinition="Metadata about the resource", formalDefinition="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource." )
063    protected Meta meta;
064
065    /**
066     * A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.
067     */
068    @Child(name = "implicitRules", type = {UriType.class}, order=2, min=0, max=1, modifier=true, summary=true)
069    @Description(shortDefinition="A set of rules under which this content was created", formalDefinition="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content." )
070    protected UriType implicitRules;
071
072    /**
073     * The base language in which the resource is written.
074     */
075    @Child(name = "language", type = {CodeType.class}, order=3, min=0, max=1, modifier=false, summary=false)
076    @Description(shortDefinition="Language of the resource content", formalDefinition="The base language in which the resource is written." )
077    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/languages")
078    protected CodeType language;
079
080    private static final long serialVersionUID = -559462759L;
081
082  /**
083   * Constructor
084   */
085    public Resource() {
086      super();
087    }
088
089    /**
090     * @return {@link #id} (The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.). This is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value
091     */
092    public IdType getIdElement() { 
093      if (this.id == null)
094        if (Configuration.errorOnAutoCreate())
095          throw new Error("Attempt to auto-create Resource.id");
096        else if (Configuration.doAutoCreate())
097          this.id = new IdType(); // bb
098      return this.id;
099    }
100
101    public boolean hasIdElement() { 
102      return this.id != null && !this.id.isEmpty();
103    }
104
105    public boolean hasId() { 
106      return this.id != null && !this.id.isEmpty();
107    }
108
109    /**
110     * @param value {@link #id} (The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.). This is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value
111     */
112    public Resource setIdElement(IdType value) { 
113      this.id = value;
114      return this;
115    }
116
117    /**
118     * @return The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
119     */
120    public String getId() { 
121      return this.id == null ? null : this.id.getValue();
122    }
123
124    /**
125     * @param value The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
126     */
127    public Resource setId(String value) { 
128      if (Utilities.noString(value))
129        this.id = null;
130      else {
131        if (this.id == null)
132          this.id = new IdType();
133        this.id.setValue(value);
134      }
135      return this;
136    }
137
138    /**
139     * @return {@link #meta} (The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource.)
140     */
141    public Meta getMeta() { 
142      if (this.meta == null)
143        if (Configuration.errorOnAutoCreate())
144          throw new Error("Attempt to auto-create Resource.meta");
145        else if (Configuration.doAutoCreate())
146          this.meta = new Meta(); // cc
147      return this.meta;
148    }
149
150    public boolean hasMeta() { 
151      return this.meta != null && !this.meta.isEmpty();
152    }
153
154    /**
155     * @param value {@link #meta} (The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource.)
156     */
157    public Resource setMeta(Meta value) { 
158      this.meta = value;
159      return this;
160    }
161
162    /**
163     * @return {@link #implicitRules} (A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.). This is the underlying object with id, value and extensions. The accessor "getImplicitRules" gives direct access to the value
164     */
165    public UriType getImplicitRulesElement() { 
166      if (this.implicitRules == null)
167        if (Configuration.errorOnAutoCreate())
168          throw new Error("Attempt to auto-create Resource.implicitRules");
169        else if (Configuration.doAutoCreate())
170          this.implicitRules = new UriType(); // bb
171      return this.implicitRules;
172    }
173
174    public boolean hasImplicitRulesElement() { 
175      return this.implicitRules != null && !this.implicitRules.isEmpty();
176    }
177
178    public boolean hasImplicitRules() { 
179      return this.implicitRules != null && !this.implicitRules.isEmpty();
180    }
181
182    /**
183     * @param value {@link #implicitRules} (A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.). This is the underlying object with id, value and extensions. The accessor "getImplicitRules" gives direct access to the value
184     */
185    public Resource setImplicitRulesElement(UriType value) { 
186      this.implicitRules = value;
187      return this;
188    }
189
190    /**
191     * @return A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.
192     */
193    public String getImplicitRules() { 
194      return this.implicitRules == null ? null : this.implicitRules.getValue();
195    }
196
197    /**
198     * @param value A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.
199     */
200    public Resource setImplicitRules(String value) { 
201      if (Utilities.noString(value))
202        this.implicitRules = null;
203      else {
204        if (this.implicitRules == null)
205          this.implicitRules = new UriType();
206        this.implicitRules.setValue(value);
207      }
208      return this;
209    }
210
211    /**
212     * @return {@link #language} (The base language in which the resource is written.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value
213     */
214    public CodeType getLanguageElement() { 
215      if (this.language == null)
216        if (Configuration.errorOnAutoCreate())
217          throw new Error("Attempt to auto-create Resource.language");
218        else if (Configuration.doAutoCreate())
219          this.language = new CodeType(); // bb
220      return this.language;
221    }
222
223    public boolean hasLanguageElement() { 
224      return this.language != null && !this.language.isEmpty();
225    }
226
227    public boolean hasLanguage() { 
228      return this.language != null && !this.language.isEmpty();
229    }
230
231    /**
232     * @param value {@link #language} (The base language in which the resource is written.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value
233     */
234    public Resource setLanguageElement(CodeType value) { 
235      this.language = value;
236      return this;
237    }
238
239    /**
240     * @return The base language in which the resource is written.
241     */
242    public String getLanguage() { 
243      return this.language == null ? null : this.language.getValue();
244    }
245
246    /**
247     * @param value The base language in which the resource is written.
248     */
249    public Resource setLanguage(String value) { 
250      if (Utilities.noString(value))
251        this.language = null;
252      else {
253        if (this.language == null)
254          this.language = new CodeType();
255        this.language.setValue(value);
256      }
257      return this;
258    }
259
260      protected void listChildren(List<Property> childrenList) {
261        childrenList.add(new Property("id", "id", "The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", 0, java.lang.Integer.MAX_VALUE, id));
262        childrenList.add(new Property("meta", "Meta", "The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource.", 0, java.lang.Integer.MAX_VALUE, meta));
263        childrenList.add(new Property("implicitRules", "uri", "A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.", 0, java.lang.Integer.MAX_VALUE, implicitRules));
264        childrenList.add(new Property("language", "code", "The base language in which the resource is written.", 0, java.lang.Integer.MAX_VALUE, language));
265      }
266
267      @Override
268      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
269        switch (hash) {
270        case 3355: /*id*/ return this.id == null ? new Base[0] : new Base[] {this.id}; // IdType
271        case 3347973: /*meta*/ return this.meta == null ? new Base[0] : new Base[] {this.meta}; // Meta
272        case -961826286: /*implicitRules*/ return this.implicitRules == null ? new Base[0] : new Base[] {this.implicitRules}; // UriType
273        case -1613589672: /*language*/ return this.language == null ? new Base[0] : new Base[] {this.language}; // CodeType
274        default: return super.getProperty(hash, name, checkValid);
275        }
276
277      }
278
279      @Override
280      public Base setProperty(int hash, String name, Base value) throws FHIRException {
281        switch (hash) {
282        case 3355: // id
283          this.id = castToId(value); // IdType
284          return value;
285        case 3347973: // meta
286          this.meta = castToMeta(value); // Meta
287          return value;
288        case -961826286: // implicitRules
289          this.implicitRules = castToUri(value); // UriType
290          return value;
291        case -1613589672: // language
292          this.language = castToCode(value); // CodeType
293          return value;
294        default: return super.setProperty(hash, name, value);
295        }
296
297      }
298
299      @Override
300      public Base setProperty(String name, Base value) throws FHIRException {
301        if (name.equals("id")) {
302          this.id = castToId(value); // IdType
303        } else if (name.equals("meta")) {
304          this.meta = castToMeta(value); // Meta
305        } else if (name.equals("implicitRules")) {
306          this.implicitRules = castToUri(value); // UriType
307        } else if (name.equals("language")) {
308          this.language = castToCode(value); // CodeType
309        } else
310          return super.setProperty(name, value);
311        return value;
312      }
313
314      @Override
315      public Base makeProperty(int hash, String name) throws FHIRException {
316        switch (hash) {
317        case 3355:  return getIdElement();
318        case 3347973:  return getMeta(); 
319        case -961826286:  return getImplicitRulesElement();
320        case -1613589672:  return getLanguageElement();
321        default: return super.makeProperty(hash, name);
322        }
323
324      }
325
326      @Override
327      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
328        switch (hash) {
329        case 3355: /*id*/ return new String[] {"id"};
330        case 3347973: /*meta*/ return new String[] {"Meta"};
331        case -961826286: /*implicitRules*/ return new String[] {"uri"};
332        case -1613589672: /*language*/ return new String[] {"code"};
333        default: return super.getTypesForProperty(hash, name);
334        }
335
336      }
337
338      @Override
339      public Base addChild(String name) throws FHIRException {
340        if (name.equals("id")) {
341          throw new FHIRException("Cannot call addChild on a primitive type Resource.id");
342        }
343        else if (name.equals("meta")) {
344          this.meta = new Meta();
345          return this.meta;
346        }
347        else if (name.equals("implicitRules")) {
348          throw new FHIRException("Cannot call addChild on a primitive type Resource.implicitRules");
349        }
350        else if (name.equals("language")) {
351          throw new FHIRException("Cannot call addChild on a primitive type Resource.language");
352        }
353        else
354          return super.addChild(name);
355      }
356
357  public String fhirType() {
358    return "Resource";
359
360  }
361
362      public abstract Resource copy();
363
364      public void copyValues(Resource dst) {
365        dst.id = id == null ? null : id.copy();
366        dst.meta = meta == null ? null : meta.copy();
367        dst.implicitRules = implicitRules == null ? null : implicitRules.copy();
368        dst.language = language == null ? null : language.copy();
369      }
370
371      @Override
372      public boolean equalsDeep(Base other) {
373        if (!super.equalsDeep(other))
374          return false;
375        if (!(other instanceof Resource))
376          return false;
377        Resource o = (Resource) other;
378        return compareDeep(id, o.id, true) && compareDeep(meta, o.meta, true) && compareDeep(implicitRules, o.implicitRules, true)
379           && compareDeep(language, o.language, true);
380      }
381
382      @Override
383      public boolean equalsShallow(Base other) {
384        if (!super.equalsShallow(other))
385          return false;
386        if (!(other instanceof Resource))
387          return false;
388        Resource o = (Resource) other;
389        return compareValues(id, o.id, true) && compareValues(implicitRules, o.implicitRules, true) && compareValues(language, o.language, true)
390          ;
391      }
392
393      public boolean isEmpty() {
394        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(id, meta, implicitRules
395          , language);
396      }
397
398
399  @Override
400  public String getIdBase() {
401    return getId();
402  }
403  
404  @Override
405  public void setIdBase(String value) {
406    setId(value);
407  }
408  public abstract ResourceType getResourceType();
409
410}
411