001package org.hl7.fhir.r5.model;
002
003
004/*
005  Copyright (c) 2011+, HL7, Inc.
006  All rights reserved.
007  
008  Redistribution and use in source and binary forms, with or without modification, \
009  are permitted provided that the following conditions are met:
010  
011   * Redistributions of source code must retain the above copyright notice, this \
012     list of conditions and the following disclaimer.
013   * Redistributions in binary form must reproduce the above copyright notice, \
014     this list of conditions and the following disclaimer in the documentation \
015     and/or other materials provided with the distribution.
016   * Neither the name of HL7 nor the names of its contributors may be used to 
017     endorse or promote products derived from this software without specific 
018     prior written permission.
019  
020  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \
021  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \
022  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \
023  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \
024  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \
025  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \
026  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \
027  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \
028  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \
029  POSSIBILITY OF SUCH DAMAGE.
030  */
031
032// Generated on Tue, Dec 28, 2021 07:16+1100 for FHIR v5.0.0-snapshot1
033
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.List;
037import org.hl7.fhir.utilities.Utilities;
038import org.hl7.fhir.r5.model.Enumerations.*;
039import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
040import org.hl7.fhir.exceptions.FHIRException;
041import org.hl7.fhir.instance.model.api.ICompositeType;
042import ca.uhn.fhir.model.api.annotation.ResourceDef;
043import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
044import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
045import ca.uhn.fhir.model.api.annotation.Child;
046import ca.uhn.fhir.model.api.annotation.ChildOrder;
047import ca.uhn.fhir.model.api.annotation.Description;
048import ca.uhn.fhir.model.api.annotation.Block;
049
050import org.hl7.fhir.instance.model.api.IAnyResource;
051/**
052 * This is the base resource type for everything.
053 */
054public abstract class Resource extends BaseResource implements IAnyResource {
055
056    /**
057     * The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
058     */
059    @Child(name = "id", type = {IdType.class}, order=0, min=0, max=1, modifier=false, summary=true)
060    @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." )
061    protected IdType id;
062
063    /**
064     * The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.
065     */
066    @Child(name = "meta", type = {Meta.class}, order=1, min=0, max=1, modifier=false, summary=true)
067    @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 might not always be associated with version changes to the resource." )
068    protected Meta meta;
069
070    /**
071     * A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.
072     */
073    @Child(name = "implicitRules", type = {UriType.class}, order=2, min=0, max=1, modifier=true, summary=true)
074    @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. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc." )
075    protected UriType implicitRules;
076
077    /**
078     * The base language in which the resource is written.
079     */
080    @Child(name = "language", type = {CodeType.class}, order=3, min=0, max=1, modifier=false, summary=false)
081    @Description(shortDefinition="Language of the resource content", formalDefinition="The base language in which the resource is written." )
082    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/languages")
083    protected CodeType language;
084
085    private static final long serialVersionUID = -559462759L;
086
087  /**
088   * Constructor
089   */
090    public Resource() {
091      super();
092    }
093
094    /**
095     * @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
096     */
097    public IdType getIdElement() { 
098      if (this.id == null)
099        if (Configuration.errorOnAutoCreate())
100          throw new Error("Attempt to auto-create Resource.id");
101        else if (Configuration.doAutoCreate())
102          this.id = new IdType(); // bb
103      return this.id;
104    }
105
106    public boolean hasIdElement() { 
107      return this.id != null && !this.id.isEmpty();
108    }
109
110    public boolean hasId() { 
111      return this.id != null && !this.id.isEmpty();
112    }
113
114    /**
115     * @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
116     */
117    public Resource setIdElement(IdType value) { 
118      this.id = value;
119      return this;
120    }
121
122  /**
123   * @return The most complete id value of the resource, containing all
124   * available context and history. Once assigned this value never changes.
125   * NOTE: this value is NOT limited to just the logical id property of a
126   * resource id.
127   * @see IdType
128   * @see IdType#getValue()
129   */
130    public String getId() { 
131      return this.id == null ? null : this.id.getValue();
132    }
133
134  /**
135   * @param value The id value of the resource. Once assigned, this value
136   *              never changes.
137   *
138   * @see IdType
139   * @see IdType#setValue(String)
140   */
141    public Resource setId(String value) { 
142      if (Utilities.noString(value))
143        this.id = null;
144      else {
145        if (this.id == null)
146          this.id = new IdType();
147        this.id.setValue(value);
148      }
149      return this;
150    }
151
152  /**
153   * @return  the logical ID part of this resource's id
154   * @see IdType#getIdPart()
155   */
156  public String getIdPart() {
157    return getIdElement().getIdPart();
158  }
159
160    /**
161     * @return {@link #meta} (The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.)
162     */
163    public Meta getMeta() { 
164      if (this.meta == null)
165        if (Configuration.errorOnAutoCreate())
166          throw new Error("Attempt to auto-create Resource.meta");
167        else if (Configuration.doAutoCreate())
168          this.meta = new Meta(); // cc
169      return this.meta;
170    }
171
172    public boolean hasMeta() { 
173      return this.meta != null && !this.meta.isEmpty();
174    }
175
176    /**
177     * @param value {@link #meta} (The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.)
178     */
179    public Resource setMeta(Meta value) { 
180      this.meta = value;
181      return this;
182    }
183
184    /**
185     * @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. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.). This is the underlying object with id, value and extensions. The accessor "getImplicitRules" gives direct access to the value
186     */
187    public UriType getImplicitRulesElement() { 
188      if (this.implicitRules == null)
189        if (Configuration.errorOnAutoCreate())
190          throw new Error("Attempt to auto-create Resource.implicitRules");
191        else if (Configuration.doAutoCreate())
192          this.implicitRules = new UriType(); // bb
193      return this.implicitRules;
194    }
195
196    public boolean hasImplicitRulesElement() { 
197      return this.implicitRules != null && !this.implicitRules.isEmpty();
198    }
199
200    public boolean hasImplicitRules() { 
201      return this.implicitRules != null && !this.implicitRules.isEmpty();
202    }
203
204    /**
205     * @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. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.). This is the underlying object with id, value and extensions. The accessor "getImplicitRules" gives direct access to the value
206     */
207    public Resource setImplicitRulesElement(UriType value) { 
208      this.implicitRules = value;
209      return this;
210    }
211
212    /**
213     * @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. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.
214     */
215    public String getImplicitRules() { 
216      return this.implicitRules == null ? null : this.implicitRules.getValue();
217    }
218
219    /**
220     * @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. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.
221     */
222    public Resource setImplicitRules(String value) { 
223      if (Utilities.noString(value))
224        this.implicitRules = null;
225      else {
226        if (this.implicitRules == null)
227          this.implicitRules = new UriType();
228        this.implicitRules.setValue(value);
229      }
230      return this;
231    }
232
233    /**
234     * @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
235     */
236    public CodeType getLanguageElement() { 
237      if (this.language == null)
238        if (Configuration.errorOnAutoCreate())
239          throw new Error("Attempt to auto-create Resource.language");
240        else if (Configuration.doAutoCreate())
241          this.language = new CodeType(); // bb
242      return this.language;
243    }
244
245    public boolean hasLanguageElement() { 
246      return this.language != null && !this.language.isEmpty();
247    }
248
249    public boolean hasLanguage() { 
250      return this.language != null && !this.language.isEmpty();
251    }
252
253    /**
254     * @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
255     */
256    public Resource setLanguageElement(CodeType value) { 
257      this.language = value;
258      return this;
259    }
260
261    /**
262     * @return The base language in which the resource is written.
263     */
264    public String getLanguage() { 
265      return this.language == null ? null : this.language.getValue();
266    }
267
268    /**
269     * @param value The base language in which the resource is written.
270     */
271    public Resource setLanguage(String value) { 
272      if (Utilities.noString(value))
273        this.language = null;
274      else {
275        if (this.language == null)
276          this.language = new CodeType();
277        this.language.setValue(value);
278      }
279      return this;
280    }
281
282      protected void listChildren(List<Property> children) {
283        super.listChildren(children);
284        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));
285        children.add(new Property("meta", "Meta", "The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.", 0, 1, meta));
286        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. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", 0, 1, implicitRules));
287        children.add(new Property("language", "code", "The base language in which the resource is written.", 0, 1, language));
288      }
289
290      @Override
291      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
292        switch (_hash) {
293        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);
294        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 might not always be associated with version changes to the resource.", 0, 1, meta);
295        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. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", 0, 1, implicitRules);
296        case -1613589672: /*language*/  return new Property("language", "code", "The base language in which the resource is written.", 0, 1, language);
297        default: return super.getNamedProperty(_hash, _name, _checkValid);
298        }
299
300      }
301
302      @Override
303      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
304        switch (hash) {
305        case 3355: /*id*/ return this.id == null ? new Base[0] : new Base[] {this.id}; // IdType
306        case 3347973: /*meta*/ return this.meta == null ? new Base[0] : new Base[] {this.meta}; // Meta
307        case -961826286: /*implicitRules*/ return this.implicitRules == null ? new Base[0] : new Base[] {this.implicitRules}; // UriType
308        case -1613589672: /*language*/ return this.language == null ? new Base[0] : new Base[] {this.language}; // CodeType
309        default: return super.getProperty(hash, name, checkValid);
310        }
311
312      }
313
314      @Override
315      public Base setProperty(int hash, String name, Base value) throws FHIRException {
316        switch (hash) {
317        case 3355: // id
318          this.id = TypeConvertor.castToId(value); // IdType
319          return value;
320        case 3347973: // meta
321          this.meta = TypeConvertor.castToMeta(value); // Meta
322          return value;
323        case -961826286: // implicitRules
324          this.implicitRules = TypeConvertor.castToUri(value); // UriType
325          return value;
326        case -1613589672: // language
327          this.language = TypeConvertor.castToCode(value); // CodeType
328          return value;
329        default: return super.setProperty(hash, name, value);
330        }
331
332      }
333
334      @Override
335      public Base setProperty(String name, Base value) throws FHIRException {
336        if (name.equals("id")) {
337          this.id = TypeConvertor.castToId(value); // IdType
338        } else if (name.equals("meta")) {
339          this.meta = TypeConvertor.castToMeta(value); // Meta
340        } else if (name.equals("implicitRules")) {
341          this.implicitRules = TypeConvertor.castToUri(value); // UriType
342        } else if (name.equals("language")) {
343          this.language = TypeConvertor.castToCode(value); // CodeType
344        } else
345          return super.setProperty(name, value);
346        return value;
347      }
348
349      @Override
350      public Base makeProperty(int hash, String name) throws FHIRException {
351        switch (hash) {
352        case 3355:  return getIdElement();
353        case 3347973:  return getMeta();
354        case -961826286:  return getImplicitRulesElement();
355        case -1613589672:  return getLanguageElement();
356        default: return super.makeProperty(hash, name);
357        }
358
359      }
360
361      @Override
362      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
363        switch (hash) {
364        case 3355: /*id*/ return new String[] {"id"};
365        case 3347973: /*meta*/ return new String[] {"Meta"};
366        case -961826286: /*implicitRules*/ return new String[] {"uri"};
367        case -1613589672: /*language*/ return new String[] {"code"};
368        default: return super.getTypesForProperty(hash, name);
369        }
370
371      }
372
373      @Override
374      public Base addChild(String name) throws FHIRException {
375        if (name.equals("id")) {
376          throw new FHIRException("Cannot call addChild on a primitive type Resource.id");
377        }
378        else if (name.equals("meta")) {
379          this.meta = new Meta();
380          return this.meta;
381        }
382        else if (name.equals("implicitRules")) {
383          throw new FHIRException("Cannot call addChild on a primitive type Resource.implicitRules");
384        }
385        else if (name.equals("language")) {
386          throw new FHIRException("Cannot call addChild on a primitive type Resource.language");
387        }
388        else
389          return super.addChild(name);
390      }
391
392  public String fhirType() {
393    return "Resource";
394
395  }
396
397      public abstract Resource copy();
398
399      public void copyValues(Resource dst) {
400        super.copyValues(dst);
401        dst.id = id == null ? null : id.copy();
402        dst.meta = meta == null ? null : meta.copy();
403        dst.implicitRules = implicitRules == null ? null : implicitRules.copy();
404        dst.language = language == null ? null : language.copy();
405      }
406
407      @Override
408      public boolean equalsDeep(Base other_) {
409        if (!super.equalsDeep(other_))
410          return false;
411        if (!(other_ instanceof Resource))
412          return false;
413        Resource o = (Resource) other_;
414        return compareDeep(id, o.id, true) && compareDeep(meta, o.meta, true) && compareDeep(implicitRules, o.implicitRules, true)
415           && compareDeep(language, o.language, true);
416      }
417
418      @Override
419      public boolean equalsShallow(Base other_) {
420        if (!super.equalsShallow(other_))
421          return false;
422        if (!(other_ instanceof Resource))
423          return false;
424        Resource o = (Resource) other_;
425        return compareValues(id, o.id, true) && compareValues(implicitRules, o.implicitRules, true) && compareValues(language, o.language, true)
426          ;
427      }
428
429      public boolean isEmpty() {
430        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(id, meta, implicitRules
431          , language);
432      }
433
434  // Manual code (from Configuration.txt):
435  @Override
436  public String getIdBase() {
437    return getId();
438  }
439  
440  @Override
441  public void setIdBase(String value) {
442    setId(value);
443  }
444  public abstract ResourceType getResourceType();
445  
446  public String getLanguage(String defValue) {
447    return hasLanguage() ? getLanguage() : defValue;
448  }
449  
450  // when possible, the source package is considered when performing reference resolution. 
451  
452  private PackageInformation sourcePackage;
453
454  public boolean hasSourcePackage() {
455    return sourcePackage != null;
456  }
457
458  public PackageInformation getSourcePackage() {
459    return sourcePackage;
460  }
461
462  public void setSourcePackage(PackageInformation sourcePackage) {
463    this.sourcePackage = sourcePackage;
464  }
465  
466  
467// end addition
468
469}
470