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 Fri, Mar 16, 2018 15:21+1100 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; 044import org.hl7.fhir.exceptions.FHIRFormatError; 045/** 046 * Base definition for all elements in a resource. 047 */ 048public abstract class Element extends Base implements IBaseHasExtensions, IBaseElement { 049 050 /** 051 * unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces. 052 */ 053 @Child(name = "id", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=false) 054 @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." ) 055 protected StringType id; 056 057 /** 058 * 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. 059 */ 060 @Child(name = "extension", type = {Extension.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false) 061 @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." ) 062 protected List<Extension> extension; 063 064 private static final long serialVersionUID = -1452745816L; 065 066 /** 067 * Constructor 068 */ 069 public Element() { 070 super(); 071 } 072 073 /** 074 * @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 075 */ 076 public StringType getIdElement() { 077 if (this.id == null) 078 if (Configuration.errorOnAutoCreate()) 079 throw new Error("Attempt to auto-create Element.id"); 080 else if (Configuration.doAutoCreate()) 081 this.id = new StringType(); // bb 082 return this.id; 083 } 084 085 public boolean hasIdElement() { 086 return this.id != null && !this.id.isEmpty(); 087 } 088 089 public boolean hasId() { 090 return this.id != null && !this.id.isEmpty(); 091 } 092 093 /** 094 * @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 095 */ 096 public Element setIdElement(StringType value) { 097 this.id = value; 098 return this; 099 } 100 101 /** 102 * @return unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces. 103 */ 104 public String getId() { 105 return this.id == null ? null : this.id.getValue(); 106 } 107 108 /** 109 * @param value unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces. 110 */ 111 public Element setId(String value) { 112 if (Utilities.noString(value)) 113 this.id = null; 114 else { 115 if (this.id == null) 116 this.id = new StringType(); 117 this.id.setValue(value); 118 } 119 return this; 120 } 121 122 /** 123 * @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.) 124 */ 125 public List<Extension> getExtension() { 126 if (this.extension == null) 127 this.extension = new ArrayList<Extension>(); 128 return this.extension; 129 } 130 131 /** 132 * @return Returns a reference to <code>this</code> for easy method chaining 133 */ 134 public Element setExtension(List<Extension> theExtension) { 135 this.extension = theExtension; 136 return this; 137 } 138 139 public boolean hasExtension() { 140 if (this.extension == null) 141 return false; 142 for (Extension item : this.extension) 143 if (!item.isEmpty()) 144 return true; 145 return false; 146 } 147 148 public Extension addExtension() { //3 149 Extension t = new Extension(); 150 if (this.extension == null) 151 this.extension = new ArrayList<Extension>(); 152 this.extension.add(t); 153 return t; 154 } 155 156 public Element addExtension(Extension t) { //3 157 if (t == null) 158 return this; 159 if (this.extension == null) 160 this.extension = new ArrayList<Extension>(); 161 this.extension.add(t); 162 return this; 163 } 164 165 /** 166 * @return The first repetition of repeating field {@link #extension}, creating it if it does not already exist 167 */ 168 public Extension getExtensionFirstRep() { 169 if (getExtension().isEmpty()) { 170 addExtension(); 171 } 172 return getExtension().get(0); 173 } 174 175 /** 176 * Returns an unmodifiable list containing all extensions on this element which 177 * match the given URL. 178 * 179 * @param theUrl The URL. Must not be blank or null. 180 * @return an unmodifiable list containing all extensions on this element which 181 * match the given URL 182 */ 183 public List<Extension> getExtensionsByUrl(String theUrl) { 184 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null"); 185 ArrayList<Extension> retVal = new ArrayList<Extension>(); 186 for (Extension next : getExtension()) { 187 if (theUrl.equals(next.getUrl())) { 188 retVal.add(next); 189 } 190 } 191 return java.util.Collections.unmodifiableList(retVal); 192 } 193 public boolean hasExtension(String theUrl) { 194 return !getExtensionsByUrl(theUrl).isEmpty(); 195 } 196 197 public String getExtensionString(String theUrl) throws FHIRException { 198 List<Extension> ext = getExtensionsByUrl(theUrl); 199 if (ext.isEmpty()) 200 return null; 201 if (ext.size() > 1) 202 throw new FHIRException("Multiple matching extensions found"); 203 if (!ext.get(0).getValue().isPrimitive()) 204 throw new FHIRException("Extension could not be converted to a string"); 205 return ext.get(0).getValue().primitiveValue(); 206 } 207 208 protected void listChildren(List<Property> children) { 209 children.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, 1, id)); 210 children.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)); 211 } 212 213 @Override 214 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 215 switch (_hash) { 216 case 3355: /*id*/ return 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, 1, id); 217 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 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); 218 default: return super.getNamedProperty(_hash, _name, _checkValid); 219 } 220 221 } 222 223 @Override 224 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 225 switch (hash) { 226 case 3355: /*id*/ return this.id == null ? new Base[0] : new Base[] {this.id}; // StringType 227 case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension 228 default: return super.getProperty(hash, name, checkValid); 229 } 230 231 } 232 233 @Override 234 public Base setProperty(int hash, String name, Base value) throws FHIRException { 235 switch (hash) { 236 case 3355: // id 237 this.id = castToString(value); // StringType 238 return value; 239 case -612557761: // extension 240 this.getExtension().add(castToExtension(value)); // Extension 241 return value; 242 default: return super.setProperty(hash, name, value); 243 } 244 245 } 246 247 @Override 248 public Base setProperty(String name, Base value) throws FHIRException { 249 if (name.equals("id")) { 250 this.id = castToString(value); // StringType 251 } else if (name.equals("extension")) { 252 this.getExtension().add(castToExtension(value)); 253 } else 254 return super.setProperty(name, value); 255 return value; 256 } 257 258 @Override 259 public Base makeProperty(int hash, String name) throws FHIRException { 260 switch (hash) { 261 case 3355: return getIdElement(); 262 case -612557761: return addExtension(); 263 default: return super.makeProperty(hash, name); 264 } 265 266 } 267 268 @Override 269 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 270 switch (hash) { 271 case 3355: /*id*/ return new String[] {"string"}; 272 case -612557761: /*extension*/ return new String[] {"Extension"}; 273 default: return super.getTypesForProperty(hash, name); 274 } 275 276 } 277 278 @Override 279 public Base addChild(String name) throws FHIRException { 280 if (name.equals("id")) { 281 throw new FHIRException("Cannot call addChild on a primitive type Element.id"); 282 } 283 else if (name.equals("extension")) { 284 return addExtension(); 285 } 286 else 287 return super.addChild(name); 288 } 289 290 public String fhirType() { 291 return "Element"; 292 293 } 294 295 public abstract Element copy(); 296 297 public void copyValues(Element dst) { 298 dst.id = id == null ? null : id.copy(); 299 if (extension != null) { 300 dst.extension = new ArrayList<Extension>(); 301 for (Extension i : extension) 302 dst.extension.add(i.copy()); 303 }; 304 } 305 306 @Override 307 public boolean equalsDeep(Base other_) { 308 if (!super.equalsDeep(other_)) 309 return false; 310 if (!(other_ instanceof Element)) 311 return false; 312 Element o = (Element) other_; 313 return compareDeep(id, o.id, true) && compareDeep(extension, o.extension, true); 314 } 315 316 @Override 317 public boolean equalsShallow(Base other_) { 318 if (!super.equalsShallow(other_)) 319 return false; 320 if (!(other_ instanceof Element)) 321 return false; 322 Element o = (Element) other_; 323 return compareValues(id, o.id, true); 324 } 325 326 public boolean isEmpty() { 327 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(id, extension); 328 } 329 330 @Override 331 public String getIdBase() { 332 return getId(); 333 } 334 335 @Override 336 public void setIdBase(String value) { 337 setId(value); 338 } 339// added from java-adornments.txt: 340 public void addExtension(String url, Type value) { 341 Extension ex = new Extension(); 342 ex.setUrl(url); 343 ex.setValue(value); 344 getExtension().add(ex); 345 } 346 347 348// end addition 349 350} 351