001package org.hl7.fhir.r5.model;
002
003
004/*
005  Copyright (c) 2011+, HL7, Inc.
006  All rights reserved.
007  
008  Redistribution and use in source and binary forms, with or without modification, \
009  are permitted provided that the following conditions are met:
010  
011   * Redistributions of source code must retain the above copyright notice, this \
012     list of conditions and the following disclaimer.
013   * Redistributions in binary form must reproduce the above copyright notice, \
014     this list of conditions and the following disclaimer in the documentation \
015     and/or other materials provided with the distribution.
016   * Neither the name of HL7 nor the names of its contributors may be used to 
017     endorse or promote products derived from this software without specific 
018     prior written permission.
019  
020  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \
021  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \
022  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \
023  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \
024  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \
025  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \
026  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \
027  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \
028  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \
029  POSSIBILITY OF SUCH DAMAGE.
030  */
031
032// Generated on Tue, Dec 28, 2021 07:16+1100 for FHIR v5.0.0-snapshot1
033
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.List;
037import org.hl7.fhir.r5.model.Enumerations.*;
038import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
039import org.hl7.fhir.exceptions.FHIRException;
040import org.hl7.fhir.instance.model.api.ICompositeType;
041import ca.uhn.fhir.model.api.annotation.ResourceDef;
042import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
043import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
044import ca.uhn.fhir.model.api.annotation.Child;
045import ca.uhn.fhir.model.api.annotation.ChildOrder;
046import ca.uhn.fhir.model.api.annotation.Description;
047import ca.uhn.fhir.model.api.annotation.Block;
048
049import java.util.Collections;
050import  org.hl7.fhir.instance.model.api.IDomainResource;
051import  org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
052import  org.hl7.fhir.instance.model.api.IBaseHasExtensions;
053import  org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions;
054import  org.hl7.fhir.instance.model.api.IBaseBackboneElement;
055/**
056 * A resource that includes narrative, extensions, and contained resources.
057 */
058public abstract class DomainResource extends Resource implements IBaseHasExtensions, IBaseHasModifierExtensions, IDomainResource {
059
060    /**
061     * 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.
062     */
063    @Child(name = "text", type = {Narrative.class}, order=0, min=0, max=1, modifier=false, summary=false)
064    @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." )
065    protected Narrative text;
066
067    /**
068     * These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope.
069     */
070    @Child(name = "contained", type = {Resource.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
071    @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, nor can they have their own independent transaction scope." )
072    protected List<Resource> contained;
073
074    /**
075     * 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.
076     */
077    @Child(name = "extension", type = {Extension.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
078    @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." )
079    protected List<Extension> extension;
080
081    /**
082     * 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.
083
084Modifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).
085     */
086    @Child(name = "modifierExtension", type = {Extension.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=true, summary=false)
087    @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)." )
088    protected List<Extension> modifierExtension;
089
090    private static final long serialVersionUID = -970285559L;
091
092  /**
093   * Constructor
094   */
095    public DomainResource() {
096      super();
097    }
098
099    /**
100     * @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.)
101     */
102    public Narrative getText() { 
103      if (this.text == null)
104        if (Configuration.errorOnAutoCreate())
105          throw new Error("Attempt to auto-create DomainResource.text");
106        else if (Configuration.doAutoCreate())
107          this.text = new Narrative(); // cc
108      return this.text;
109    }
110
111    public boolean hasText() { 
112      return this.text != null && !this.text.isEmpty();
113    }
114
115    /**
116     * @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.)
117     */
118    public DomainResource setText(Narrative value) { 
119      this.text = value;
120      return this;
121    }
122
123    /**
124     * @return {@link #contained} (These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope.)
125     */
126    public List<Resource> getContained() { 
127      if (this.contained == null)
128        this.contained = new ArrayList<Resource>();
129      return this.contained;
130    }
131
132    /**
133     * @return Returns a reference to <code>this</code> for easy method chaining
134     */
135    public DomainResource setContained(List<Resource> theContained) { 
136      this.contained = theContained;
137      return this;
138    }
139
140    public boolean hasContained() { 
141      if (this.contained == null)
142        return false;
143      for (Resource item : this.contained)
144        if (!item.isEmpty())
145          return true;
146      return false;
147    }
148
149    public DomainResource addContained(Resource t) { //3
150      if (t == null)
151        return this;
152      if (this.contained == null)
153        this.contained = new ArrayList<Resource>();
154      this.contained.add(t);
155      return this;
156    }
157
158    /**
159     * @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.)
160     */
161    public List<Extension> getExtension() { 
162      if (this.extension == null)
163        this.extension = new ArrayList<Extension>();
164      return this.extension;
165    }
166
167    /**
168     * @return Returns a reference to <code>this</code> for easy method chaining
169     */
170    public DomainResource setExtension(List<Extension> theExtension) { 
171      this.extension = theExtension;
172      return this;
173    }
174
175    public boolean hasExtension() { 
176      if (this.extension == null)
177        return false;
178      for (Extension item : this.extension)
179        if (!item.isEmpty())
180          return true;
181      return false;
182    }
183
184    public Extension addExtension() { //3
185      Extension t = new Extension();
186      if (this.extension == null)
187        this.extension = new ArrayList<Extension>();
188      this.extension.add(t);
189      return t;
190    }
191
192    public DomainResource addExtension(Extension t) { //3
193      if (t == null)
194        return this;
195      if (this.extension == null)
196        this.extension = new ArrayList<Extension>();
197      this.extension.add(t);
198      return this;
199    }
200
201    /**
202     * @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.
203
204Modifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).)
205     */
206    public List<Extension> getModifierExtension() { 
207      if (this.modifierExtension == null)
208        this.modifierExtension = new ArrayList<Extension>();
209      return this.modifierExtension;
210    }
211
212    /**
213     * @return Returns a reference to <code>this</code> for easy method chaining
214     */
215    public DomainResource setModifierExtension(List<Extension> theModifierExtension) { 
216      this.modifierExtension = theModifierExtension;
217      return this;
218    }
219
220    public boolean hasModifierExtension() { 
221      if (this.modifierExtension == null)
222        return false;
223      for (Extension item : this.modifierExtension)
224        if (!item.isEmpty())
225          return true;
226      return false;
227    }
228
229    public Extension addModifierExtension() { //3
230      Extension t = new Extension();
231      if (this.modifierExtension == null)
232        this.modifierExtension = new ArrayList<Extension>();
233      this.modifierExtension.add(t);
234      return t;
235    }
236
237    public DomainResource addModifierExtension(Extension t) { //3
238      if (t == null)
239        return this;
240      if (this.modifierExtension == null)
241        this.modifierExtension = new ArrayList<Extension>();
242      this.modifierExtension.add(t);
243      return this;
244    }
245
246      protected void listChildren(List<Property> children) {
247        super.listChildren(children);
248        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));
249        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, nor can they have their own independent transaction scope.", 0, java.lang.Integer.MAX_VALUE, contained));
250        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));
251        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));
252      }
253
254      @Override
255      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
256        switch (_hash) {
257        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);
258        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, nor can they have their own independent transaction scope.", 0, java.lang.Integer.MAX_VALUE, contained);
259        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);
260        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);
261        default: return super.getNamedProperty(_hash, _name, _checkValid);
262        }
263
264      }
265
266      @Override
267      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
268        switch (hash) {
269        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // Narrative
270        case -410956685: /*contained*/ return this.contained == null ? new Base[0] : this.contained.toArray(new Base[this.contained.size()]); // Resource
271        case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension
272        case -298878168: /*modifierExtension*/ return this.modifierExtension == null ? new Base[0] : this.modifierExtension.toArray(new Base[this.modifierExtension.size()]); // Extension
273        default: return super.getProperty(hash, name, checkValid);
274        }
275
276      }
277
278      @Override
279      public Base setProperty(int hash, String name, Base value) throws FHIRException {
280        switch (hash) {
281        case 3556653: // text
282          this.text = TypeConvertor.castToNarrative(value); // Narrative
283          return value;
284        case -410956685: // contained
285          this.getContained().add(TypeConvertor.castToResource(value)); // Resource
286          return value;
287        case -612557761: // extension
288          this.getExtension().add(TypeConvertor.castToExtension(value)); // Extension
289          return value;
290        case -298878168: // modifierExtension
291          this.getModifierExtension().add(TypeConvertor.castToExtension(value)); // Extension
292          return value;
293        default: return super.setProperty(hash, name, value);
294        }
295
296      }
297
298      @Override
299      public Base setProperty(String name, Base value) throws FHIRException {
300        if (name.equals("text")) {
301          this.text = TypeConvertor.castToNarrative(value); // Narrative
302        } else if (name.equals("contained")) {
303          this.getContained().add(TypeConvertor.castToResource(value));
304        } else if (name.equals("extension")) {
305          this.getExtension().add(TypeConvertor.castToExtension(value));
306        } else if (name.equals("modifierExtension")) {
307          this.getModifierExtension().add(TypeConvertor.castToExtension(value));
308        } else
309          return super.setProperty(name, value);
310        return value;
311      }
312
313      @Override
314      public Base makeProperty(int hash, String name) throws FHIRException {
315        switch (hash) {
316        case 3556653:  return getText();
317        case -410956685: throw new FHIRException("Cannot make property contained as it is not a complex type"); // Resource
318        case -612557761:  return addExtension(); 
319        case -298878168:  return addModifierExtension(); 
320        default: return super.makeProperty(hash, name);
321        }
322
323      }
324
325      @Override
326      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
327        switch (hash) {
328        case 3556653: /*text*/ return new String[] {"Narrative"};
329        case -410956685: /*contained*/ return new String[] {"Resource"};
330        case -612557761: /*extension*/ return new String[] {"Extension"};
331        case -298878168: /*modifierExtension*/ return new String[] {"Extension"};
332        default: return super.getTypesForProperty(hash, name);
333        }
334
335      }
336
337      @Override
338      public Base addChild(String name) throws FHIRException {
339        if (name.equals("text")) {
340          this.text = new Narrative();
341          return this.text;
342        }
343        else if (name.equals("contained")) {
344          throw new FHIRException("Cannot call addChild on an abstract type DomainResource.contained");
345        }
346        else if (name.equals("extension")) {
347          return addExtension();
348        }
349        else if (name.equals("modifierExtension")) {
350          return addModifierExtension();
351        }
352        else
353          return super.addChild(name);
354      }
355
356  public String fhirType() {
357    return "DomainResource";
358
359  }
360
361      public abstract DomainResource copy();
362
363      public void copyValues(DomainResource dst) {
364        super.copyValues(dst);
365        dst.text = text == null ? null : text.copy();
366        if (contained != null) {
367          dst.contained = new ArrayList<Resource>();
368          for (Resource i : contained)
369            dst.contained.add(i.copy());
370        };
371        if (extension != null) {
372          dst.extension = new ArrayList<Extension>();
373          for (Extension i : extension)
374            dst.extension.add(i.copy());
375        };
376        if (modifierExtension != null) {
377          dst.modifierExtension = new ArrayList<Extension>();
378          for (Extension i : modifierExtension)
379            dst.modifierExtension.add(i.copy());
380        };
381      }
382
383      @Override
384      public boolean equalsDeep(Base other_) {
385        if (!super.equalsDeep(other_))
386          return false;
387        if (!(other_ instanceof DomainResource))
388          return false;
389        DomainResource o = (DomainResource) other_;
390        return compareDeep(text, o.text, true) && compareDeep(contained, o.contained, true) && compareDeep(extension, o.extension, true)
391           && compareDeep(modifierExtension, o.modifierExtension, true);
392      }
393
394      @Override
395      public boolean equalsShallow(Base other_) {
396        if (!super.equalsShallow(other_))
397          return false;
398        if (!(other_ instanceof DomainResource))
399          return false;
400        DomainResource o = (DomainResource) other_;
401        return true;
402      }
403
404      public boolean isEmpty() {
405        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(text, contained, extension
406          , modifierExtension);
407      }
408
409 /**
410   * Search parameter: <b>_text</b>
411   * <p>
412   * Description: <b>Search on the narrative of the resource</b><br>
413   * Type: <b>special</b><br>
414   * Path: <b>null</b><br>
415   * </p>
416   */
417  @SearchParamDefinition(name="_text", path="", description="Search on the narrative of the resource", type="special" )
418  public static final String SP_TEXT = "_text";
419 /**
420   * <b>Fluent Client</b> search parameter constant for <b>_text</b>
421   * <p>
422   * Description: <b>Search on the narrative of the resource</b><br>
423   * Type: <b>special</b><br>
424   * Path: <b>null</b><br>
425   * </p>
426   */
427  public static final ca.uhn.fhir.rest.gclient.SpecialClientParam TEXT = new ca.uhn.fhir.rest.gclient.SpecialClientParam(SP_TEXT);
428
429// Manual code (from Configuration.txt):
430public 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, DataType 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      public Resource getContained(String ref) {
471        if (ref == null)
472          return null;
473        
474        if (ref.startsWith("#"))
475          ref = ref.substring(1);
476        for (Resource r : getContained()) {
477          if (r.getId().equals(ref)) 
478            return r;
479        }
480        return null;
481      }
482
483    /**
484     * Returns a list of extensions from this element which have the given URL. Note that
485     * this list may not be modified (you can not add or remove elements from it)
486     */
487    public List<Extension> getExtensionsByUrl(String theUrl) {
488      org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value");
489      ArrayList<Extension> retVal = new ArrayList<Extension>();
490      for (Extension next : getExtension()) {
491        if (theUrl.equals(next.getUrl())) {
492          retVal.add(next);
493        }
494      }
495      return Collections.unmodifiableList(retVal);
496    }
497
498    /**
499     * Returns a list of modifier extensions from this element which have the given URL. Note that
500     * this list may not be modified (you can not add or remove elements from it)
501     */
502    public List<Extension> getModifierExtensionsByUrl(String theUrl) {
503      org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value");
504      ArrayList<Extension> retVal = new ArrayList<Extension>();
505      for (Extension next : getModifierExtension()) {
506        if (theUrl.equals(next.getUrl())) {
507          retVal.add(next);
508        }
509      }
510      return Collections.unmodifiableList(retVal);
511    }
512// end addition
513
514}
515