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