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