001package org.hl7.fhir.dstu3.model; 002 003/* 004 Copyright (c) 2011+, HL7, Inc. 005 All rights reserved. 006 007 Redistribution and use in source and binary forms, with or without modification, 008 are permitted provided that the following conditions are met: 009 010 * Redistributions of source code must retain the above copyright notice, this 011 list of conditions and the following disclaimer. 012 * Redistributions in binary form must reproduce the above copyright notice, 013 this list of conditions and the following disclaimer in the documentation 014 and/or other materials provided with the distribution. 015 * Neither the name of HL7 nor the names of its contributors may be used to 016 endorse or promote products derived from this software without specific 017 prior written permission. 018 019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 022 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 023 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 024 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 025 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 026 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028 POSSIBILITY OF SUCH DAMAGE. 029 030*/ 031 032// Generated on Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1 033 034import java.util.*; 035 036import org.hl7.fhir.utilities.Utilities; 037import ca.uhn.fhir.model.api.annotation.Child; 038import ca.uhn.fhir.model.api.annotation.ChildOrder; 039import ca.uhn.fhir.model.api.annotation.Description; 040import ca.uhn.fhir.model.api.annotation.DatatypeDef; 041import ca.uhn.fhir.model.api.annotation.Block; 042import org.hl7.fhir.instance.model.api.*; 043import org.hl7.fhir.exceptions.FHIRException; 044/** 045 * Base definition for all elements in a resource. 046 */ 047public abstract class Element extends Base implements IBaseHasExtensions, IBaseElement { 048 049 /** 050 * unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces. 051 */ 052 @Child(name = "id", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=false) 053 @Description(shortDefinition="xml:id (or equivalent in JSON)", formalDefinition="unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces." ) 054 protected StringType id; 055 056 /** 057 * May be used to represent additional information that is not part of the basic definition of the element. 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. 058 */ 059 @Child(name = "extension", type = {Extension.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false) 060 @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 element. 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." ) 061 protected List<Extension> extension; 062 063 private static final long serialVersionUID = -1452745816L; 064 065 /** 066 * Constructor 067 */ 068 public Element() { 069 super(); 070 } 071 072 /** 073 * @return {@link #id} (unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.). This is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value 074 */ 075 public StringType getIdElement() { 076 if (this.id == null) 077 if (Configuration.errorOnAutoCreate()) 078 throw new Error("Attempt to auto-create Element.id"); 079 else if (Configuration.doAutoCreate()) 080 this.id = new StringType(); // bb 081 return this.id; 082 } 083 084 public boolean hasIdElement() { 085 return this.id != null && !this.id.isEmpty(); 086 } 087 088 public boolean hasId() { 089 return this.id != null && !this.id.isEmpty(); 090 } 091 092 /** 093 * @param value {@link #id} (unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.). This is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value 094 */ 095 public Element setIdElement(StringType value) { 096 this.id = value; 097 return this; 098 } 099 100 /** 101 * @return unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces. 102 */ 103 public String getId() { 104 return this.id == null ? null : this.id.getValue(); 105 } 106 107 /** 108 * @param value unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces. 109 */ 110 public Element setId(String value) { 111 if (Utilities.noString(value)) 112 this.id = null; 113 else { 114 if (this.id == null) 115 this.id = new StringType(); 116 this.id.setValue(value); 117 } 118 return this; 119 } 120 121 /** 122 * @return {@link #extension} (May be used to represent additional information that is not part of the basic definition of the element. 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.) 123 */ 124 public List<Extension> getExtension() { 125 if (this.extension == null) 126 this.extension = new ArrayList<Extension>(); 127 return this.extension; 128 } 129 130 /** 131 * @return Returns a reference to <code>this</code> for easy method chaining 132 */ 133 public Element setExtension(List<Extension> theExtension) { 134 this.extension = theExtension; 135 return this; 136 } 137 138 public boolean hasExtension() { 139 if (this.extension == null) 140 return false; 141 for (Extension item : this.extension) 142 if (!item.isEmpty()) 143 return true; 144 return false; 145 } 146 147 public Extension addExtension() { //3 148 Extension t = new Extension(); 149 if (this.extension == null) 150 this.extension = new ArrayList<Extension>(); 151 this.extension.add(t); 152 return t; 153 } 154 155 public Element addExtension(Extension t) { //3 156 if (t == null) 157 return this; 158 if (this.extension == null) 159 this.extension = new ArrayList<Extension>(); 160 this.extension.add(t); 161 return this; 162 } 163 164 /** 165 * @return The first repetition of repeating field {@link #extension}, creating it if it does not already exist 166 */ 167 public Extension getExtensionFirstRep() { 168 if (getExtension().isEmpty()) { 169 addExtension(); 170 } 171 return getExtension().get(0); 172 } 173 174 /** 175 * Returns an unmodifiable list containing all extensions on this element which 176 * match the given URL. 177 * 178 * @param theUrl The URL. Must not be blank or null. 179 * @return an unmodifiable list containing all extensions on this element which 180 * match the given URL 181 */ 182 public List<Extension> getExtensionsByUrl(String theUrl) { 183 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null"); 184 ArrayList<Extension> retVal = new ArrayList<Extension>(); 185 for (Extension next : getExtension()) { 186 if (theUrl.equals(next.getUrl())) { 187 retVal.add(next); 188 } 189 } 190 return java.util.Collections.unmodifiableList(retVal); 191 } 192 public boolean hasExtension(String theUrl) { 193 return !getExtensionsByUrl(theUrl).isEmpty(); 194 } 195 196 public String getExtensionString(String theUrl) throws FHIRException { 197 List<Extension> ext = getExtensionsByUrl(theUrl); 198 if (ext.isEmpty()) 199 return null; 200 if (ext.size() > 1) 201 throw new FHIRException("Multiple matching extensions found"); 202 if (!ext.get(0).getValue().isPrimitive()) 203 throw new FHIRException("Extension could not be converted to a string"); 204 return ext.get(0).getValue().primitiveValue(); 205 } 206 207 protected void listChildren(List<Property> childrenList) { 208 childrenList.add(new Property("id", "string", "unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", 0, java.lang.Integer.MAX_VALUE, id)); 209 childrenList.add(new Property("extension", "Extension", "May be used to represent additional information that is not part of the basic definition of the element. 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)); 210 } 211 212 @Override 213 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 214 switch (hash) { 215 case 3355: /*id*/ return this.id == null ? new Base[0] : new Base[] {this.id}; // StringType 216 case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension 217 default: return super.getProperty(hash, name, checkValid); 218 } 219 220 } 221 222 @Override 223 public Base setProperty(int hash, String name, Base value) throws FHIRException { 224 switch (hash) { 225 case 3355: // id 226 this.id = castToString(value); // StringType 227 return value; 228 case -612557761: // extension 229 this.getExtension().add(castToExtension(value)); // Extension 230 return value; 231 default: return super.setProperty(hash, name, value); 232 } 233 234 } 235 236 @Override 237 public Base setProperty(String name, Base value) throws FHIRException { 238 if (name.equals("id")) { 239 this.id = castToString(value); // StringType 240 } else if (name.equals("extension")) { 241 this.getExtension().add(castToExtension(value)); 242 } else 243 return super.setProperty(name, value); 244 return value; 245 } 246 247 @Override 248 public Base makeProperty(int hash, String name) throws FHIRException { 249 switch (hash) { 250 case 3355: return getIdElement(); 251 case -612557761: return addExtension(); 252 default: return super.makeProperty(hash, name); 253 } 254 255 } 256 257 @Override 258 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 259 switch (hash) { 260 case 3355: /*id*/ return new String[] {"string"}; 261 case -612557761: /*extension*/ return new String[] {"Extension"}; 262 default: return super.getTypesForProperty(hash, name); 263 } 264 265 } 266 267 @Override 268 public Base addChild(String name) throws FHIRException { 269 if (name.equals("id")) { 270 throw new FHIRException("Cannot call addChild on a primitive type Element.id"); 271 } 272 else if (name.equals("extension")) { 273 return addExtension(); 274 } 275 else 276 return super.addChild(name); 277 } 278 279 public String fhirType() { 280 return "Element"; 281 282 } 283 284 public abstract Element copy(); 285 286 public void copyValues(Element dst) { 287 dst.id = id == null ? null : id.copy(); 288 if (extension != null) { 289 dst.extension = new ArrayList<Extension>(); 290 for (Extension i : extension) 291 dst.extension.add(i.copy()); 292 }; 293 } 294 295 @Override 296 public boolean equalsDeep(Base other) { 297 if (!super.equalsDeep(other)) 298 return false; 299 if (!(other instanceof Element)) 300 return false; 301 Element o = (Element) other; 302 return compareDeep(id, o.id, true) && compareDeep(extension, o.extension, true); 303 } 304 305 @Override 306 public boolean equalsShallow(Base other) { 307 if (!super.equalsShallow(other)) 308 return false; 309 if (!(other instanceof Element)) 310 return false; 311 Element o = (Element) other; 312 return compareValues(id, o.id, true); 313 } 314 315 public boolean isEmpty() { 316 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(id, extension); 317 } 318 319 @Override 320 public String getIdBase() { 321 return getId(); 322 } 323 324 @Override 325 public void setIdBase(String value) { 326 setId(value); 327 } 328// added from java-adornments.txt: 329 public void addExtension(String url, Type value) { 330 Extension ex = new Extension(); 331 ex.setUrl(url); 332 ex.setValue(value); 333 getExtension().add(ex); 334 } 335 336 337// end addition 338 339} 340