001package org.hl7.fhir.dstu3.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// Generated on Fri, Mar 16, 2018 15:21+1100 for FHIR v3.0.x
035import java.util.ArrayList;
036import java.util.Collections;
037import java.util.List;
038
039import org.hl7.fhir.exceptions.FHIRException;
040import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
041import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions;
042import org.hl7.fhir.instance.model.api.IDomainResource;
043
044import ca.uhn.fhir.model.api.annotation.Child;
045import ca.uhn.fhir.model.api.annotation.Description;
046/**
047 * A resource that includes narrative, extensions, and contained resources.
048 */
049public abstract class DomainResource extends Resource implements IBaseHasExtensions, IBaseHasModifierExtensions, IDomainResource {
050
051    /**
052     * A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it "clinically safe" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.
053     */
054    @Child(name = "text", type = {Narrative.class}, order=0, min=0, max=1, modifier=false, summary=false)
055    @Description(shortDefinition="Text summary of the resource, for human interpretation", formalDefinition="A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it \"clinically safe\" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety." )
056    protected Narrative text;
057
058    /**
059     * 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.
060     */
061    @Child(name = "contained", type = {Resource.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
062    @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." )
063    protected List<Resource> contained;
064
065    /**
066     * May be used to represent additional information that is not part of the basic definition of the resource. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.
067     */
068    @Child(name = "extension", type = {Extension.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
069    @Description(shortDefinition="Additional Content defined by implementations", formalDefinition="May be used to represent additional information that is not part of the basic definition of the resource. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension." )
070    protected List<Extension> extension;
071
072    /**
073     * May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.
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. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions." )
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 may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it "clinically safe" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.)
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 may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it "clinically safe" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.)
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. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.)
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. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.)
192     */
193    public List<Extension> getModifierExtension() { 
194      if (this.modifierExtension == null)
195        this.modifierExtension = new ArrayList<Extension>();
196      return this.modifierExtension;
197    }
198
199    /**
200     * @return Returns a reference to <code>this</code> for easy method chaining
201     */
202    public DomainResource setModifierExtension(List<Extension> theModifierExtension) { 
203      this.modifierExtension = theModifierExtension;
204      return this;
205    }
206
207    public boolean hasModifierExtension() { 
208      if (this.modifierExtension == null)
209        return false;
210      for (Extension item : this.modifierExtension)
211        if (!item.isEmpty())
212          return true;
213      return false;
214    }
215
216    public Extension addModifierExtension() { //3
217      Extension t = new Extension();
218      if (this.modifierExtension == null)
219        this.modifierExtension = new ArrayList<Extension>();
220      this.modifierExtension.add(t);
221      return t;
222    }
223
224    public DomainResource addModifierExtension(Extension t) { //3
225      if (t == null)
226        return this;
227      if (this.modifierExtension == null)
228        this.modifierExtension = new ArrayList<Extension>();
229      this.modifierExtension.add(t);
230      return this;
231    }
232
233    /**
234     * Returns a list of extensions from this element which have the given URL. Note that
235     * this list may not be modified (you can not add or remove elements from it)
236     */
237    public List<Extension> getExtensionsByUrl(String theUrl) {
238      org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value");
239      ArrayList<Extension> retVal = new ArrayList<Extension>();
240      for (Extension next : getExtension()) {
241        if (theUrl.equals(next.getUrl())) {
242          retVal.add(next);
243        }
244      }
245      for (Extension next : getModifierExtension()) {
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        children.add(new Property("text", "Narrative", "A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it \"clinically safe\" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", 0, 1, text));
270        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));
271        children.add(new Property("extension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", 0, java.lang.Integer.MAX_VALUE, extension));
272        children.add(new Property("modifierExtension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", 0, java.lang.Integer.MAX_VALUE, modifierExtension));
273      }
274
275      @Override
276      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
277        switch (_hash) {
278        case 3556653: /*text*/  return new Property("text", "Narrative", "A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it \"clinically safe\" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", 0, 1, text);
279        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);
280        case -612557761: /*extension*/  return new Property("extension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", 0, java.lang.Integer.MAX_VALUE, extension);
281        case -298878168: /*modifierExtension*/  return new Property("modifierExtension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", 0, java.lang.Integer.MAX_VALUE, modifierExtension);
282        default: return super.getNamedProperty(_hash, _name, _checkValid);
283        }
284
285      }
286
287      @Override
288      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
289        switch (hash) {
290        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // Narrative
291        case -410956685: /*contained*/ return this.contained == null ? new Base[0] : this.contained.toArray(new Base[this.contained.size()]); // Resource
292        case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension
293        case -298878168: /*modifierExtension*/ return this.modifierExtension == null ? new Base[0] : this.modifierExtension.toArray(new Base[this.modifierExtension.size()]); // Extension
294        default: return super.getProperty(hash, name, checkValid);
295        }
296
297      }
298
299      @Override
300      public Base setProperty(int hash, String name, Base value) throws FHIRException {
301        switch (hash) {
302        case 3556653: // text
303          this.text = castToNarrative(value); // Narrative
304          return value;
305        case -410956685: // contained
306          this.getContained().add(castToResource(value)); // Resource
307          return value;
308        case -612557761: // extension
309          this.getExtension().add(castToExtension(value)); // Extension
310          return value;
311        case -298878168: // modifierExtension
312          this.getModifierExtension().add(castToExtension(value)); // Extension
313          return value;
314        default: return super.setProperty(hash, name, value);
315        }
316
317      }
318
319      @Override
320      public Base setProperty(String name, Base value) throws FHIRException {
321        if (name.equals("text")) {
322          this.text = castToNarrative(value); // Narrative
323        } else if (name.equals("contained")) {
324          this.getContained().add(castToResource(value));
325        } else if (name.equals("extension")) {
326          this.getExtension().add(castToExtension(value));
327        } else if (name.equals("modifierExtension")) {
328          this.getModifierExtension().add(castToExtension(value));
329        } else
330          return super.setProperty(name, value);
331        return value;
332      }
333
334      @Override
335      public Base makeProperty(int hash, String name) throws FHIRException {
336        switch (hash) {
337        case 3556653:  return getText(); 
338        case -410956685: throw new FHIRException("Cannot make property contained as it is not a complex type"); // Resource
339        case -612557761:  return addExtension(); 
340        case -298878168:  return addModifierExtension(); 
341        default: return super.makeProperty(hash, name);
342        }
343
344      }
345
346      @Override
347      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
348        switch (hash) {
349        case 3556653: /*text*/ return new String[] {"Narrative"};
350        case -410956685: /*contained*/ return new String[] {"Resource"};
351        case -612557761: /*extension*/ return new String[] {"Extension"};
352        case -298878168: /*modifierExtension*/ return new String[] {"Extension"};
353        default: return super.getTypesForProperty(hash, name);
354        }
355
356      }
357
358      @Override
359      public Base addChild(String name) throws FHIRException {
360        if (name.equals("text")) {
361          this.text = new Narrative();
362          return this.text;
363        }
364        else if (name.equals("contained")) {
365          throw new FHIRException("Cannot call addChild on an abstract type DomainResource.contained");
366        }
367        else if (name.equals("extension")) {
368          return addExtension();
369        }
370        else if (name.equals("modifierExtension")) {
371          return addModifierExtension();
372        }
373        else
374          return super.addChild(name);
375      }
376
377  public String fhirType() {
378    return "DomainResource";
379
380  }
381
382      public abstract DomainResource copy();
383
384      public void copyValues(DomainResource dst) {
385        super.copyValues(dst);
386        dst.text = text == null ? null : text.copy();
387        if (contained != null) {
388          dst.contained = new ArrayList<Resource>();
389          for (Resource i : contained)
390            dst.contained.add(i.copy());
391        };
392        if (extension != null) {
393          dst.extension = new ArrayList<Extension>();
394          for (Extension i : extension)
395            dst.extension.add(i.copy());
396        };
397        if (modifierExtension != null) {
398          dst.modifierExtension = new ArrayList<Extension>();
399          for (Extension i : modifierExtension)
400            dst.modifierExtension.add(i.copy());
401        };
402      }
403
404      @Override
405      public boolean equalsDeep(Base other_) {
406        if (!super.equalsDeep(other_))
407          return false;
408        if (!(other_ instanceof DomainResource))
409          return false;
410        DomainResource o = (DomainResource) other_;
411        return compareDeep(text, o.text, true) && compareDeep(contained, o.contained, true) && compareDeep(extension, o.extension, true)
412           && compareDeep(modifierExtension, o.modifierExtension, true);
413      }
414
415      @Override
416      public boolean equalsShallow(Base other_) {
417        if (!super.equalsShallow(other_))
418          return false;
419        if (!(other_ instanceof DomainResource))
420          return false;
421        DomainResource o = (DomainResource) other_;
422        return true;
423      }
424
425      public boolean isEmpty() {
426        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(text, contained, extension
427          , modifierExtension);
428      }
429
430
431      public void addExtension(String url, Type value) {
432        Extension ex = new Extension();
433        ex.setUrl(url);
434        ex.setValue(value);
435        getExtension().add(ex);    
436      }
437
438
439      public boolean hasExtension(String url) {
440        for (Extension next : getModifierExtension()) {
441          if (url.equals(next.getUrl())) {
442            return true;
443          }
444        }
445        for (Extension e : getExtension())
446          if (url.equals(e.getUrl()))
447            return true;
448        return false;
449      }
450
451      public Extension getExtensionByUrl(String theUrl) {
452        org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null");
453        ArrayList<Extension> retVal = new ArrayList<Extension>();
454        for (Extension next : getExtension()) {
455          if (theUrl.equals(next.getUrl())) {
456            retVal.add(next);
457          }
458        }
459        for (Extension next : getModifierExtension()) {
460          if (theUrl.equals(next.getUrl())) {
461            retVal.add(next);
462          }
463        }
464        if (retVal.size() == 0)
465          return null;
466        else {
467          org.apache.commons.lang3.Validate.isTrue(retVal.size() == 1, "Url "+theUrl+" must have only one match");
468          return retVal.get(0);
469        }
470      }
471
472
473}