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