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 ca.uhn.fhir.model.api.annotation.ResourceDef;
037import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
038import ca.uhn.fhir.model.api.annotation.Child;
039import ca.uhn.fhir.model.api.annotation.ChildOrder;
040import ca.uhn.fhir.model.api.annotation.Description;
041import ca.uhn.fhir.model.api.annotation.Block;
042import org.hl7.fhir.instance.model.api.*;
043import org.hl7.fhir.exceptions.FHIRException;
044import org.hl7.fhir.exceptions.FHIRFormatError;
045/**
046 * A resource that includes narrative, extensions, and contained resources.
047 */
048public abstract class DomainResource extends Resource implements IBaseHasExtensions, IBaseHasModifierExtensions, IDomainResource {
049
050    /**
051     * A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it "clinically safe" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.
052     */
053    @Child(name = "text", type = {Narrative.class}, order=0, min=0, max=1, modifier=false, summary=false)
054    @Description(shortDefinition="Text summary of the resource, for human interpretation", formalDefinition="A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it \"clinically safe\" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety." )
055    protected Narrative text;
056
057    /**
058     * These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope.
059     */
060    @Child(name = "contained", type = {Resource.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
061    @Description(shortDefinition="Contained, inline Resources", formalDefinition="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope." )
062    protected List<Resource> contained;
063
064    /**
065     * May be used to represent additional information that is not part of the basic definition of the resource. 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.
066     */
067    @Child(name = "extension", type = {Extension.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
068    @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 resource. 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." )
069    protected List<Extension> extension;
070
071    /**
072     * May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions.
073     */
074    @Child(name = "modifierExtension", type = {Extension.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=true, summary=false)
075    @Description(shortDefinition="Extensions that cannot be ignored", formalDefinition="May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions." )
076    protected List<Extension> modifierExtension;
077
078    private static final long serialVersionUID = -970285559L;
079
080  /**
081   * Constructor
082   */
083    public DomainResource() {
084      super();
085    }
086
087    /**
088     * @return {@link #text} (A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it "clinically safe" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.)
089     */
090    public Narrative getText() { 
091      if (this.text == null)
092        if (Configuration.errorOnAutoCreate())
093          throw new Error("Attempt to auto-create DomainResource.text");
094        else if (Configuration.doAutoCreate())
095          this.text = new Narrative(); // cc
096      return this.text;
097    }
098
099    public boolean hasText() { 
100      return this.text != null && !this.text.isEmpty();
101    }
102
103    /**
104     * @param value {@link #text} (A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it "clinically safe" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.)
105     */
106    public DomainResource setText(Narrative value)  { 
107      this.text = value;
108      return this;
109    }
110
111    /**
112     * @return {@link #contained} (These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope.)
113     */
114    public List<Resource> getContained() { 
115      if (this.contained == null)
116        this.contained = new ArrayList<Resource>();
117      return this.contained;
118    }
119
120    /**
121     * @return Returns a reference to <code>this</code> for easy method chaining
122     */
123    public DomainResource setContained(List<Resource> theContained) { 
124      this.contained = theContained;
125      return this;
126    }
127
128    public boolean hasContained() { 
129      if (this.contained == null)
130        return false;
131      for (Resource item : this.contained)
132        if (!item.isEmpty())
133          return true;
134      return false;
135    }
136
137    public DomainResource addContained(Resource t) { //3
138      if (t == null)
139        return this;
140      if (this.contained == null)
141        this.contained = new ArrayList<Resource>();
142      this.contained.add(t);
143      return this;
144    }
145
146    /**
147     * @return {@link #extension} (May be used to represent additional information that is not part of the basic definition of the resource. 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.)
148     */
149    public List<Extension> getExtension() { 
150      if (this.extension == null)
151        this.extension = new ArrayList<Extension>();
152      return this.extension;
153    }
154
155    /**
156     * @return Returns a reference to <code>this</code> for easy method chaining
157     */
158    public DomainResource setExtension(List<Extension> theExtension) { 
159      this.extension = theExtension;
160      return this;
161    }
162
163    public boolean hasExtension() { 
164      if (this.extension == null)
165        return false;
166      for (Extension item : this.extension)
167        if (!item.isEmpty())
168          return true;
169      return false;
170    }
171
172    public Extension addExtension() { //3
173      Extension t = new Extension();
174      if (this.extension == null)
175        this.extension = new ArrayList<Extension>();
176      this.extension.add(t);
177      return t;
178    }
179
180    public DomainResource addExtension(Extension t) { //3
181      if (t == null)
182        return this;
183      if (this.extension == null)
184        this.extension = new ArrayList<Extension>();
185      this.extension.add(t);
186      return this;
187    }
188
189    /**
190     * @return {@link #modifierExtension} (May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions.)
191     */
192    public List<Extension> getModifierExtension() { 
193      if (this.modifierExtension == null)
194        this.modifierExtension = new ArrayList<Extension>();
195      return this.modifierExtension;
196    }
197
198    /**
199     * @return Returns a reference to <code>this</code> for easy method chaining
200     */
201    public DomainResource setModifierExtension(List<Extension> theModifierExtension) { 
202      this.modifierExtension = theModifierExtension;
203      return this;
204    }
205
206    public boolean hasModifierExtension() { 
207      if (this.modifierExtension == null)
208        return false;
209      for (Extension item : this.modifierExtension)
210        if (!item.isEmpty())
211          return true;
212      return false;
213    }
214
215    public Extension addModifierExtension() { //3
216      Extension t = new Extension();
217      if (this.modifierExtension == null)
218        this.modifierExtension = new ArrayList<Extension>();
219      this.modifierExtension.add(t);
220      return t;
221    }
222
223    public DomainResource addModifierExtension(Extension t) { //3
224      if (t == null)
225        return this;
226      if (this.modifierExtension == null)
227        this.modifierExtension = new ArrayList<Extension>();
228      this.modifierExtension.add(t);
229      return this;
230    }
231
232    /**
233     * Returns a list of extensions from this element which have the given URL. Note that
234     * this list may not be modified (you can not add or remove elements from it)
235     */
236    public List<Extension> getExtensionsByUrl(String theUrl) {
237      org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value");
238      ArrayList<Extension> retVal = new ArrayList<Extension>();
239      for (Extension next : getExtension()) {
240        if (theUrl.equals(next.getUrl())) {
241          retVal.add(next);
242        }
243      }
244      return Collections.unmodifiableList(retVal);
245    }
246
247    /**
248     * Returns a list of modifier extensions from this element which have the given URL. Note that
249     * this list may not be modified (you can not add or remove elements from it)
250     */
251    public List<Extension> getModifierExtensionsByUrl(String theUrl) {
252      org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value");
253      ArrayList<Extension> retVal = new ArrayList<Extension>();
254      for (Extension next : getModifierExtension()) {
255        if (theUrl.equals(next.getUrl())) {
256          retVal.add(next);
257        }
258      }
259      return Collections.unmodifiableList(retVal);
260    }
261
262      protected void listChildren(List<Property> children) {
263        children.add(new Property("text", "Narrative", "A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it \"clinically safe\" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", 0, 1, text));
264        children.add(new Property("contained", "Resource", "These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope.", 0, java.lang.Integer.MAX_VALUE, contained));
265        children.add(new Property("extension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource. 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));
266        children.add(new Property("modifierExtension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions.", 0, java.lang.Integer.MAX_VALUE, modifierExtension));
267      }
268
269      @Override
270      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
271        switch (_hash) {
272        case 3556653: /*text*/  return new Property("text", "Narrative", "A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it \"clinically safe\" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", 0, 1, text);
273        case -410956685: /*contained*/  return new Property("contained", "Resource", "These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope.", 0, java.lang.Integer.MAX_VALUE, contained);
274        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 resource. 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);
275        case -298878168: /*modifierExtension*/  return new Property("modifierExtension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions.", 0, java.lang.Integer.MAX_VALUE, modifierExtension);
276        default: return super.getNamedProperty(_hash, _name, _checkValid);
277        }
278
279      }
280
281      @Override
282      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
283        switch (hash) {
284        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // Narrative
285        case -410956685: /*contained*/ return this.contained == null ? new Base[0] : this.contained.toArray(new Base[this.contained.size()]); // Resource
286        case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension
287        case -298878168: /*modifierExtension*/ return this.modifierExtension == null ? new Base[0] : this.modifierExtension.toArray(new Base[this.modifierExtension.size()]); // Extension
288        default: return super.getProperty(hash, name, checkValid);
289        }
290
291      }
292
293      @Override
294      public Base setProperty(int hash, String name, Base value) throws FHIRException {
295        switch (hash) {
296        case 3556653: // text
297          this.text = castToNarrative(value); // Narrative
298          return value;
299        case -410956685: // contained
300          this.getContained().add(castToResource(value)); // Resource
301          return value;
302        case -612557761: // extension
303          this.getExtension().add(castToExtension(value)); // Extension
304          return value;
305        case -298878168: // modifierExtension
306          this.getModifierExtension().add(castToExtension(value)); // Extension
307          return value;
308        default: return super.setProperty(hash, name, value);
309        }
310
311      }
312
313      @Override
314      public Base setProperty(String name, Base value) throws FHIRException {
315        if (name.equals("text")) {
316          this.text = castToNarrative(value); // Narrative
317        } else if (name.equals("contained")) {
318          this.getContained().add(castToResource(value));
319        } else if (name.equals("extension")) {
320          this.getExtension().add(castToExtension(value));
321        } else if (name.equals("modifierExtension")) {
322          this.getModifierExtension().add(castToExtension(value));
323        } else
324          return super.setProperty(name, value);
325        return value;
326      }
327
328      @Override
329      public Base makeProperty(int hash, String name) throws FHIRException {
330        switch (hash) {
331        case 3556653:  return getText(); 
332        case -410956685: throw new FHIRException("Cannot make property contained as it is not a complex type"); // Resource
333        case -612557761:  return addExtension(); 
334        case -298878168:  return addModifierExtension(); 
335        default: return super.makeProperty(hash, name);
336        }
337
338      }
339
340      @Override
341      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
342        switch (hash) {
343        case 3556653: /*text*/ return new String[] {"Narrative"};
344        case -410956685: /*contained*/ return new String[] {"Resource"};
345        case -612557761: /*extension*/ return new String[] {"Extension"};
346        case -298878168: /*modifierExtension*/ return new String[] {"Extension"};
347        default: return super.getTypesForProperty(hash, name);
348        }
349
350      }
351
352      @Override
353      public Base addChild(String name) throws FHIRException {
354        if (name.equals("text")) {
355          this.text = new Narrative();
356          return this.text;
357        }
358        else if (name.equals("contained")) {
359          throw new FHIRException("Cannot call addChild on an abstract type DomainResource.contained");
360        }
361        else if (name.equals("extension")) {
362          return addExtension();
363        }
364        else if (name.equals("modifierExtension")) {
365          return addModifierExtension();
366        }
367        else
368          return super.addChild(name);
369      }
370
371  public String fhirType() {
372    return "DomainResource";
373
374  }
375
376      public abstract DomainResource copy();
377
378      public void copyValues(DomainResource dst) {
379        super.copyValues(dst);
380        dst.text = text == null ? null : text.copy();
381        if (contained != null) {
382          dst.contained = new ArrayList<Resource>();
383          for (Resource i : contained)
384            dst.contained.add(i.copy());
385        };
386        if (extension != null) {
387          dst.extension = new ArrayList<Extension>();
388          for (Extension i : extension)
389            dst.extension.add(i.copy());
390        };
391        if (modifierExtension != null) {
392          dst.modifierExtension = new ArrayList<Extension>();
393          for (Extension i : modifierExtension)
394            dst.modifierExtension.add(i.copy());
395        };
396      }
397
398      @Override
399      public boolean equalsDeep(Base other_) {
400        if (!super.equalsDeep(other_))
401          return false;
402        if (!(other_ instanceof DomainResource))
403          return false;
404        DomainResource o = (DomainResource) other_;
405        return compareDeep(text, o.text, true) && compareDeep(contained, o.contained, true) && compareDeep(extension, o.extension, true)
406           && compareDeep(modifierExtension, o.modifierExtension, true);
407      }
408
409      @Override
410      public boolean equalsShallow(Base other_) {
411        if (!super.equalsShallow(other_))
412          return false;
413        if (!(other_ instanceof DomainResource))
414          return false;
415        DomainResource o = (DomainResource) other_;
416        return true;
417      }
418
419      public boolean isEmpty() {
420        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(text, contained, extension
421          , modifierExtension);
422      }
423
424
425}
426