001package org.hl7.fhir.r4.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 Thu, Sep 13, 2018 09:04-0400 for FHIR v3.5.0
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;
044/**
045 * A resource that includes narrative, extensions, and contained resources.
046 */
047public abstract class DomainResource extends Resource implements IBaseHasExtensions, IBaseHasModifierExtensions, IDomainResource {
048
049    /**
050     * A human-readable narrative that contains a summary of the resource and can 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.
051     */
052    @Child(name = "text", type = {Narrative.class}, order=0, min=0, max=1, modifier=false, summary=false)
053    @Description(shortDefinition="Text summary of the resource, for human interpretation", formalDefinition="A human-readable narrative that contains a summary of the resource and can 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." )
054    protected Narrative text;
055
056    /**
057     * 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.
058     */
059    @Child(name = "contained", type = {Resource.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
060    @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." )
061    protected List<Resource> contained;
062
063    /**
064     * May be used to represent additional information that is not part of the basic definition of the resource. 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 can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.
065     */
066    @Child(name = "extension", type = {Extension.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
067    @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. 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 can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension." )
068    protected List<Extension> extension;
069
070    /**
071     * 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. 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.
072
073Modifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).
074     */
075    @Child(name = "modifierExtension", type = {Extension.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=true, summary=false)
076    @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. 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.\n\nModifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself)." )
077    protected List<Extension> modifierExtension;
078
079    private static final long serialVersionUID = -970285559L;
080
081  /**
082   * Constructor
083   */
084    public DomainResource() {
085      super();
086    }
087
088    /**
089     * @return {@link #text} (A human-readable narrative that contains a summary of the resource and can 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.)
090     */
091    public Narrative getText() { 
092      if (this.text == null)
093        if (Configuration.errorOnAutoCreate())
094          throw new Error("Attempt to auto-create DomainResource.text");
095        else if (Configuration.doAutoCreate())
096          this.text = new Narrative(); // cc
097      return this.text;
098    }
099
100    public boolean hasText() { 
101      return this.text != null && !this.text.isEmpty();
102    }
103
104    /**
105     * @param value {@link #text} (A human-readable narrative that contains a summary of the resource and can 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.)
106     */
107    public DomainResource setText(Narrative value) { 
108      this.text = value;
109      return this;
110    }
111
112    /**
113     * @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.)
114     */
115    public List<Resource> getContained() { 
116      if (this.contained == null)
117        this.contained = new ArrayList<Resource>();
118      return this.contained;
119    }
120
121    /**
122     * @return Returns a reference to <code>this</code> for easy method chaining
123     */
124    public DomainResource setContained(List<Resource> theContained) { 
125      this.contained = theContained;
126      return this;
127    }
128
129    public boolean hasContained() { 
130      if (this.contained == null)
131        return false;
132      for (Resource item : this.contained)
133        if (!item.isEmpty())
134          return true;
135      return false;
136    }
137
138    public DomainResource addContained(Resource t) { //3
139      if (t == null)
140        return this;
141      if (this.contained == null)
142        this.contained = new ArrayList<Resource>();
143      this.contained.add(t);
144      return this;
145    }
146
147    /**
148     * @return {@link #extension} (May be used to represent additional information that is not part of the basic definition of the resource. 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 can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.)
149     */
150    public List<Extension> getExtension() { 
151      if (this.extension == null)
152        this.extension = new ArrayList<Extension>();
153      return this.extension;
154    }
155
156    /**
157     * @return Returns a reference to <code>this</code> for easy method chaining
158     */
159    public DomainResource setExtension(List<Extension> theExtension) { 
160      this.extension = theExtension;
161      return this;
162    }
163
164    public boolean hasExtension() { 
165      if (this.extension == null)
166        return false;
167      for (Extension item : this.extension)
168        if (!item.isEmpty())
169          return true;
170      return false;
171    }
172
173    public Extension addExtension() { //3
174      Extension t = new Extension();
175      if (this.extension == null)
176        this.extension = new ArrayList<Extension>();
177      this.extension.add(t);
178      return t;
179    }
180
181    public DomainResource addExtension(Extension t) { //3
182      if (t == null)
183        return this;
184      if (this.extension == null)
185        this.extension = new ArrayList<Extension>();
186      this.extension.add(t);
187      return this;
188    }
189
190    /**
191     * @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. 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.
192
193Modifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).)
194     */
195    public List<Extension> getModifierExtension() { 
196      if (this.modifierExtension == null)
197        this.modifierExtension = new ArrayList<Extension>();
198      return this.modifierExtension;
199    }
200
201    /**
202     * @return Returns a reference to <code>this</code> for easy method chaining
203     */
204    public DomainResource setModifierExtension(List<Extension> theModifierExtension) { 
205      this.modifierExtension = theModifierExtension;
206      return this;
207    }
208
209    public boolean hasModifierExtension() { 
210      if (this.modifierExtension == null)
211        return false;
212      for (Extension item : this.modifierExtension)
213        if (!item.isEmpty())
214          return true;
215      return false;
216    }
217
218    public Extension addModifierExtension() { //3
219      Extension t = new Extension();
220      if (this.modifierExtension == null)
221        this.modifierExtension = new ArrayList<Extension>();
222      this.modifierExtension.add(t);
223      return t;
224    }
225
226    public DomainResource addModifierExtension(Extension t) { //3
227      if (t == null)
228        return this;
229      if (this.modifierExtension == null)
230        this.modifierExtension = new ArrayList<Extension>();
231      this.modifierExtension.add(t);
232      return this;
233    }
234
235    /**
236     * Returns a list of extensions from this element which have the given URL. Note that
237     * this list may not be modified (you can not add or remove elements from it)
238     */
239    public List<Extension> getExtensionsByUrl(String theUrl) {
240      org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value");
241      ArrayList<Extension> retVal = new ArrayList<Extension>();
242      for (Extension next : getExtension()) {
243        if (theUrl.equals(next.getUrl())) {
244          retVal.add(next);
245        }
246      }
247      return Collections.unmodifiableList(retVal);
248    }
249
250    /**
251     * Returns a list of modifier extensions from this element which have the given URL. Note that
252     * this list may not be modified (you can not add or remove elements from it)
253     */
254    public List<Extension> getModifierExtensionsByUrl(String theUrl) {
255      org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value");
256      ArrayList<Extension> retVal = new ArrayList<Extension>();
257      for (Extension next : getModifierExtension()) {
258        if (theUrl.equals(next.getUrl())) {
259          retVal.add(next);
260        }
261      }
262      return Collections.unmodifiableList(retVal);
263    }
264
265      protected void listChildren(List<Property> children) {
266        super.listChildren(children);
267        children.add(new Property("text", "Narrative", "A human-readable narrative that contains a summary of the resource and can 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));
268        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));
269        children.add(new Property("extension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource. 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 can 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));
270        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. 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.\n\nModifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).", 0, java.lang.Integer.MAX_VALUE, modifierExtension));
271      }
272
273      @Override
274      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
275        switch (_hash) {
276        case 3556653: /*text*/  return new Property("text", "Narrative", "A human-readable narrative that contains a summary of the resource and can 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);
277        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);
278        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. 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 can 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);
279        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. 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.\n\nModifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).", 0, java.lang.Integer.MAX_VALUE, modifierExtension);
280        default: return super.getNamedProperty(_hash, _name, _checkValid);
281        }
282
283      }
284
285      @Override
286      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
287        switch (hash) {
288        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // Narrative
289        case -410956685: /*contained*/ return this.contained == null ? new Base[0] : this.contained.toArray(new Base[this.contained.size()]); // Resource
290        case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension
291        case -298878168: /*modifierExtension*/ return this.modifierExtension == null ? new Base[0] : this.modifierExtension.toArray(new Base[this.modifierExtension.size()]); // Extension
292        default: return super.getProperty(hash, name, checkValid);
293        }
294
295      }
296
297      @Override
298      public Base setProperty(int hash, String name, Base value) throws FHIRException {
299        switch (hash) {
300        case 3556653: // text
301          this.text = castToNarrative(value); // Narrative
302          return value;
303        case -410956685: // contained
304          this.getContained().add(castToResource(value)); // Resource
305          return value;
306        case -612557761: // extension
307          this.getExtension().add(castToExtension(value)); // Extension
308          return value;
309        case -298878168: // modifierExtension
310          this.getModifierExtension().add(castToExtension(value)); // Extension
311          return value;
312        default: return super.setProperty(hash, name, value);
313        }
314
315      }
316
317      @Override
318      public Base setProperty(String name, Base value) throws FHIRException {
319        if (name.equals("text")) {
320          this.text = castToNarrative(value); // Narrative
321        } else if (name.equals("contained")) {
322          this.getContained().add(castToResource(value));
323        } else if (name.equals("extension")) {
324          this.getExtension().add(castToExtension(value));
325        } else if (name.equals("modifierExtension")) {
326          this.getModifierExtension().add(castToExtension(value));
327        } else
328          return super.setProperty(name, value);
329        return value;
330      }
331
332      @Override
333      public Base makeProperty(int hash, String name) throws FHIRException {
334        switch (hash) {
335        case 3556653:  return getText(); 
336        case -410956685: throw new FHIRException("Cannot make property contained as it is not a complex type"); // Resource
337        case -612557761:  return addExtension(); 
338        case -298878168:  return addModifierExtension(); 
339        default: return super.makeProperty(hash, name);
340        }
341
342      }
343
344      @Override
345      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
346        switch (hash) {
347        case 3556653: /*text*/ return new String[] {"Narrative"};
348        case -410956685: /*contained*/ return new String[] {"Resource"};
349        case -612557761: /*extension*/ return new String[] {"Extension"};
350        case -298878168: /*modifierExtension*/ return new String[] {"Extension"};
351        default: return super.getTypesForProperty(hash, name);
352        }
353
354      }
355
356      @Override
357      public Base addChild(String name) throws FHIRException {
358        if (name.equals("text")) {
359          this.text = new Narrative();
360          return this.text;
361        }
362        else if (name.equals("contained")) {
363          throw new FHIRException("Cannot call addChild on an abstract type DomainResource.contained");
364        }
365        else if (name.equals("extension")) {
366          return addExtension();
367        }
368        else if (name.equals("modifierExtension")) {
369          return addModifierExtension();
370        }
371        else
372          return super.addChild(name);
373      }
374
375  public String fhirType() {
376    return "DomainResource";
377
378  }
379
380      public abstract DomainResource copy();
381
382      public void copyValues(DomainResource dst) {
383        super.copyValues(dst);
384        dst.text = text == null ? null : text.copy();
385        if (contained != null) {
386          dst.contained = new ArrayList<Resource>();
387          for (Resource i : contained)
388            dst.contained.add(i.copy());
389        };
390        if (extension != null) {
391          dst.extension = new ArrayList<Extension>();
392          for (Extension i : extension)
393            dst.extension.add(i.copy());
394        };
395        if (modifierExtension != null) {
396          dst.modifierExtension = new ArrayList<Extension>();
397          for (Extension i : modifierExtension)
398            dst.modifierExtension.add(i.copy());
399        };
400      }
401
402      @Override
403      public boolean equalsDeep(Base other_) {
404        if (!super.equalsDeep(other_))
405          return false;
406        if (!(other_ instanceof DomainResource))
407          return false;
408        DomainResource o = (DomainResource) other_;
409        return compareDeep(text, o.text, true) && compareDeep(contained, o.contained, true) && compareDeep(extension, o.extension, true)
410           && compareDeep(modifierExtension, o.modifierExtension, true);
411      }
412
413      @Override
414      public boolean equalsShallow(Base other_) {
415        if (!super.equalsShallow(other_))
416          return false;
417        if (!(other_ instanceof DomainResource))
418          return false;
419        DomainResource o = (DomainResource) other_;
420        return true;
421      }
422
423      public boolean isEmpty() {
424        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(text, contained, extension
425          , modifierExtension);
426      }
427
428// added from java-adornments.txt:
429
430  public void checkNoModifiers(String noun, String verb) throws FHIRException {
431        if (hasModifierExtension()) {
432          throw new FHIRException("Found unknown Modifier Exceptions on "+noun+" doing "+verb);
433        }
434        
435  }
436
437  public void addExtension(String url, Type value) {
438    Extension ex = new Extension();
439    ex.setUrl(url);
440    ex.setValue(value);
441    getExtension().add(ex);    
442  }
443  
444
445
446
447  public boolean hasExtension(String url) {
448    for (Extension e : getExtension())
449      if (url.equals(e.getUrl()))
450        return true;
451    return false;
452    }
453    
454       public Extension getExtensionByUrl(String theUrl) {
455     org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null");
456     ArrayList<Extension> retVal = new ArrayList<Extension>();
457     for (Extension next : getExtension()) {
458       if (theUrl.equals(next.getUrl())) {
459         retVal.add(next);
460       }
461     }
462     if (retVal.size() == 0)
463       return null;
464     else {
465       org.apache.commons.lang3.Validate.isTrue(retVal.size() == 1, "Url "+theUrl+" must have only one match");
466       return retVal.get(0);
467     }
468   }
469  
470
471
472// end addition
473
474}
475