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