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 Thu, Mar 23, 2023 19:59+1100 for FHIR v5.0.0
033
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.List;
037import org.hl7.fhir.r5.model.Enumerations.*;
038import org.hl7.fhir.utilities.Utilities;
039import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
040import org.hl7.fhir.exceptions.FHIRException;
041import org.hl7.fhir.instance.model.api.ICompositeType;
042import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
043import ca.uhn.fhir.model.api.annotation.Child;
044import ca.uhn.fhir.model.api.annotation.ChildOrder;
045import ca.uhn.fhir.model.api.annotation.DatatypeDef;
046import ca.uhn.fhir.model.api.annotation.Description;
047import ca.uhn.fhir.model.api.annotation.Block;
048
049/**
050 * BackboneElement Type: Base definition for all elements that are defined inside a resource - but not those in a data type.
051 */
052@DatatypeDef(name="BackboneElement")
053public abstract class BackboneElement extends Element implements IBaseBackboneElement {
054
055    /**
056     * May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained 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 managable, 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. Applications processing a resource are required to check for modifier extensions.
057
058Modifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).
059     */
060    @Child(name = "modifierExtension", type = {Extension.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=true, summary=true)
061    @Description(shortDefinition="Extensions that cannot be ignored even if unrecognized", formalDefinition="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained 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 managable, 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. 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)." )
062    protected List<Extension> modifierExtension;
063
064    private static final long serialVersionUID = -1431673179L;
065
066  /**
067   * Constructor
068   */
069    public BackboneElement() {
070      super();
071    }
072
073    /**
074     * @return {@link #modifierExtension} (May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained 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 managable, 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. Applications processing a resource are required to check for modifier extensions.
075
076Modifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).)
077     */
078    public List<Extension> getModifierExtension() { 
079      if (this.modifierExtension == null)
080        this.modifierExtension = new ArrayList<Extension>();
081      return this.modifierExtension;
082    }
083
084    /**
085     * @return Returns a reference to <code>this</code> for easy method chaining
086     */
087    public BackboneElement setModifierExtension(List<Extension> theModifierExtension) { 
088      this.modifierExtension = theModifierExtension;
089      return this;
090    }
091
092    public boolean hasModifierExtension() { 
093      if (this.modifierExtension == null)
094        return false;
095      for (Extension item : this.modifierExtension)
096        if (!item.isEmpty())
097          return true;
098      return false;
099    }
100
101    public Extension addModifierExtension() { //3
102      Extension t = new Extension();
103      if (this.modifierExtension == null)
104        this.modifierExtension = new ArrayList<Extension>();
105      this.modifierExtension.add(t);
106      return t;
107    }
108
109    public BackboneElement addModifierExtension(Extension t) { //3
110      if (t == null)
111        return this;
112      if (this.modifierExtension == null)
113        this.modifierExtension = new ArrayList<Extension>();
114      this.modifierExtension.add(t);
115      return this;
116    }
117
118    /**
119     * @return The first repetition of repeating field {@link #modifierExtension}, creating it if it does not already exist {3}
120     */
121    public Extension getModifierExtensionFirstRep() { 
122      if (getModifierExtension().isEmpty()) {
123        addModifierExtension();
124      }
125      return getModifierExtension().get(0);
126    }
127
128      protected void listChildren(List<Property> children) {
129        super.listChildren(children);
130        children.add(new Property("modifierExtension", "Extension", "May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained 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 managable, 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. 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));
131      }
132
133      @Override
134      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
135        switch (_hash) {
136        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 element and that modifies the understanding of the element in which it is contained 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 managable, 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. 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);
137        default: return super.getNamedProperty(_hash, _name, _checkValid);
138        }
139
140      }
141
142      @Override
143      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
144        switch (hash) {
145        case -298878168: /*modifierExtension*/ return this.modifierExtension == null ? new Base[0] : this.modifierExtension.toArray(new Base[this.modifierExtension.size()]); // Extension
146        default: return super.getProperty(hash, name, checkValid);
147        }
148
149      }
150
151      @Override
152      public Base setProperty(int hash, String name, Base value) throws FHIRException {
153        switch (hash) {
154        case -298878168: // modifierExtension
155          this.getModifierExtension().add(TypeConvertor.castToExtension(value)); // Extension
156          return value;
157        default: return super.setProperty(hash, name, value);
158        }
159
160      }
161
162      @Override
163      public Base setProperty(String name, Base value) throws FHIRException {
164        if (name.equals("modifierExtension")) {
165          this.getModifierExtension().add(TypeConvertor.castToExtension(value));
166        } else
167          return super.setProperty(name, value);
168        return value;
169      }
170
171      @Override
172      public Base makeProperty(int hash, String name) throws FHIRException {
173        switch (hash) {
174        case -298878168:  return addModifierExtension(); 
175        default: return super.makeProperty(hash, name);
176        }
177
178      }
179
180      @Override
181      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
182        switch (hash) {
183        case -298878168: /*modifierExtension*/ return new String[] {"Extension"};
184        default: return super.getTypesForProperty(hash, name);
185        }
186
187      }
188
189      @Override
190      public Base addChild(String name) throws FHIRException {
191        if (name.equals("modifierExtension")) {
192          return addModifierExtension();
193        }
194        else
195          return super.addChild(name);
196      }
197
198  public String fhirType() {
199    return "BackboneElement";
200
201  }
202
203      public abstract BackboneElement copy();
204
205      public void copyValues(BackboneElement dst) {
206        super.copyValues(dst);
207        if (modifierExtension != null) {
208          dst.modifierExtension = new ArrayList<Extension>();
209          for (Extension i : modifierExtension)
210            dst.modifierExtension.add(i.copy());
211        };
212      }
213
214      @Override
215      public boolean equalsDeep(Base other_) {
216        if (!super.equalsDeep(other_))
217          return false;
218        if (!(other_ instanceof BackboneElement))
219          return false;
220        BackboneElement o = (BackboneElement) other_;
221        return compareDeep(modifierExtension, o.modifierExtension, true);
222      }
223
224      @Override
225      public boolean equalsShallow(Base other_) {
226        if (!super.equalsShallow(other_))
227          return false;
228        if (!(other_ instanceof BackboneElement))
229          return false;
230        BackboneElement o = (BackboneElement) other_;
231        return true;
232      }
233
234      public boolean isEmpty() {
235        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(modifierExtension);
236      }
237
238// Manual code (from Configuration.txt):
239  public void checkNoModifiers(String noun, String verb) throws FHIRException {
240        if (hasModifierExtension()) {
241          throw new FHIRException("Found unknown Modifier Exceptions on "+noun+" doing "+verb);
242        }
243        
244  }
245  
246  public void addModifierExtension(String url, DataType value) {
247    if (isDisallowExtensions())
248      throw new Error("Extensions are not allowed in this context");
249    Extension ex = new Extension();
250    ex.setUrl(url);
251    ex.setValue(value);
252    getModifierExtension().add(ex);    
253  }
254
255
256   @Override
257   public Extension getExtensionByUrl(String theUrl) {
258     org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null");
259     ArrayList<Extension> retVal = new ArrayList<Extension>();
260     Extension res = super.getExtensionByUrl(theUrl);
261     if (res != null) {
262       retVal.add(res);
263     }
264     for (Extension next : getModifierExtension()) {
265       if (theUrl.equals(next.getUrl())) {
266         retVal.add(next);
267       }
268     }
269     if (retVal.size() == 0)
270       return null;
271     else {
272       org.apache.commons.lang3.Validate.isTrue(retVal.size() == 1, "Url "+theUrl+" must have only one match");
273       return retVal.get(0);
274     }
275   }
276  
277   @Override
278   public void removeExtension(String theUrl) {
279     for (int i = getModifierExtension().size()-1; i >= 0; i--) {
280       if (theUrl.equals(getExtension().get(i).getUrl()))
281         getExtension().remove(i);
282     }
283     super.removeExtension(theUrl);
284   }
285   
286
287   /**
288    * Returns an unmodifiable list containing all extensions on this element which 
289    * match the given URL.
290    * 
291    * @param theUrl The URL. Must not be blank or null.
292    * @return an unmodifiable list containing all extensions on this element which 
293    * match the given URL
294    */
295   @Override
296   public List<Extension> getExtensionsByUrl(String theUrl) {
297     org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null");
298     ArrayList<Extension> retVal = new ArrayList<Extension>();
299     retVal.addAll(super.getExtensionsByUrl(theUrl));
300     for (Extension next : getModifierExtension()) {
301       if (theUrl.equals(next.getUrl())) {
302         retVal.add(next);
303       }
304     }
305     return java.util.Collections.unmodifiableList(retVal);
306   }
307   
308   public void copyExtensions(org.hl7.fhir.r5.model.BackboneElement src, String... urls) {
309     super.copyExtensions(src,urls);
310     for (Extension e : src.getModifierExtension()) {
311       if (Utilities.existsInList(e.getUrl(), urls)) {
312         addModifierExtension(e.copy());
313       }
314     }    
315   }
316
317
318   
319// end addition
320
321}
322