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