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