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