001package org.hl7.fhir.dstu2.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 Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2 036import java.util.ArrayList; 037import java.util.List; 038 039import ca.uhn.fhir.model.api.annotation.Child; 040import ca.uhn.fhir.model.api.annotation.Description; 041import org.hl7.fhir.instance.model.api.IBaseElement; 042import org.hl7.fhir.instance.model.api.IBaseHasExtensions; 043import org.hl7.fhir.exceptions.FHIRException; 044import org.hl7.fhir.utilities.Utilities; 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). 052 */ 053 @Child(name = "id", type = {IdType.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)." ) 055 protected IdType 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 = -158027598L; 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 is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value 075 */ 076 public IdType 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 IdType(); // 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 is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value 095 */ 096 public Element setIdElement(IdType value) { 097 this.id = value; 098 return this; 099 } 100 101 /** 102 * @return unique id for the element within a resource (for internal references). 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). 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 IdType(); 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 public boolean hasExtension() { 132 if (this.extension == null) 133 return false; 134 for (Extension item : this.extension) 135 if (!item.isEmpty()) 136 return true; 137 return false; 138 } 139 140 /** 141 * @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.) 142 */ 143 // syntactic sugar 144 public Extension addExtension() { //3 145 Extension t = new Extension(); 146 if (this.extension == null) 147 this.extension = new ArrayList<Extension>(); 148 this.extension.add(t); 149 return t; 150 } 151 152 // syntactic sugar 153 public Element addExtension(Extension t) { //3 154 if (t == null) 155 return this; 156 if (this.extension == null) 157 this.extension = new ArrayList<Extension>(); 158 this.extension.add(t); 159 return this; 160 } 161 162 /** 163 * Returns an unmodifiable list containing all extensions on this element which 164 * match the given URL. 165 * 166 * @param theUrl The URL. Must not be blank or null. 167 * @return an unmodifiable list containing all extensions on this element which 168 * match the given URL 169 */ 170 public List<Extension> getExtensionsByUrl(String theUrl) { 171 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null"); 172 ArrayList<Extension> retVal = new ArrayList<Extension>(); 173 for (Extension next : getExtension()) { 174 if (theUrl.equals(next.getUrl())) { 175 retVal.add(next); 176 } 177 } 178 return java.util.Collections.unmodifiableList(retVal); 179 } 180 public boolean hasExtension(String theUrl) { 181 return !getExtensionsByUrl(theUrl).isEmpty(); 182 } 183 184 public String getExtensionString(String theUrl) throws FHIRException { 185 List<Extension> ext = getExtensionsByUrl(theUrl); 186 if (ext.isEmpty()) 187 return null; 188 if (ext.size() > 1) 189 throw new FHIRException("Multiple matching extensions found"); 190 if (!ext.get(0).getValue().isPrimitive()) 191 throw new FHIRException("Extension could not be converted to a string"); 192 return ext.get(0).getValue().primitiveValue(); 193 } 194 195 protected void listChildren(List<Property> childrenList) { 196 childrenList.add(new Property("id", "id", "unique id for the element within a resource (for internal references).", 0, java.lang.Integer.MAX_VALUE, id)); 197 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)); 198 } 199 200 @Override 201 public void setProperty(String name, Base value) throws FHIRException { 202 if (name.equals("id")) 203 this.id = castToId(value); // IdType 204 else if (name.equals("extension")) 205 this.getExtension().add(castToExtension(value)); 206 else 207 super.setProperty(name, value); 208 } 209 210 @Override 211 public Base addChild(String name) throws FHIRException { 212 if (name.equals("id")) { 213 throw new FHIRException("Cannot call addChild on a primitive type Element.id"); 214 } 215 else if (name.equals("extension")) { 216 return addExtension(); 217 } 218 else 219 return super.addChild(name); 220 } 221 222 public String fhirType() { 223 return "Element"; 224 225 } 226 227 public abstract Element copy(); 228 229 public void copyValues(Element dst) { 230 dst.id = id == null ? null : id.copy(); 231 if (extension != null) { 232 dst.extension = new ArrayList<Extension>(); 233 for (Extension i : extension) 234 dst.extension.add(i.copy()); 235 }; 236 } 237 238 @Override 239 public boolean equalsDeep(Base other) { 240 if (!super.equalsDeep(other)) 241 return false; 242 if (!(other instanceof Element)) 243 return false; 244 Element o = (Element) other; 245 return compareDeep(id, o.id, true) && compareDeep(extension, o.extension, true); 246 } 247 248 @Override 249 public boolean equalsShallow(Base other) { 250 if (!super.equalsShallow(other)) 251 return false; 252 if (!(other instanceof Element)) 253 return false; 254 Element o = (Element) other; 255 return compareValues(id, o.id, true); 256 } 257 258 public boolean isEmpty() { 259 return super.isEmpty() && (id == null || id.isEmpty()) && (extension == null || extension.isEmpty()) 260 ; 261 } 262 263 264}