001package org.hl7.fhir.instance.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 Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2 033import java.util.ArrayList; 034import java.util.List; 035 036import org.hl7.fhir.exceptions.FHIRException; 037import org.hl7.fhir.instance.model.api.IBaseHasExtensions; 038import org.hl7.fhir.utilities.Utilities; 039 040import ca.uhn.fhir.model.api.annotation.Child; 041import ca.uhn.fhir.model.api.annotation.Description; 042/** 043 * Base definition for all elements in a resource. 044 */ 045public abstract class Element extends Base implements IBaseHasExtensions { 046 047 /** 048 * unique id for the element within a resource (for internal references). 049 */ 050 @Child(name = "id", type = {IdType.class}, order=0, min=0, max=1, modifier=false, summary=false) 051 @Description(shortDefinition="xml:id (or equivalent in JSON)", formalDefinition="unique id for the element within a resource (for internal references)." ) 052 protected IdType id; 053 054 /** 055 * 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. 056 */ 057 @Child(name = "extension", type = {Extension.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false) 058 @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." ) 059 protected List<Extension> extension; 060 061 private static final long serialVersionUID = -158027598L; 062 063 /* 064 * Constructor 065 */ 066 public Element() { 067 super(); 068 } 069 070 /** 071 * @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 072 */ 073 public IdType getIdElement() { 074 if (this.id == null) 075 if (Configuration.errorOnAutoCreate()) 076 throw new Error("Attempt to auto-create Element.id"); 077 else if (Configuration.doAutoCreate()) 078 this.id = new IdType(); // bb 079 return this.id; 080 } 081 082 public boolean hasIdElement() { 083 return this.id != null && !this.id.isEmpty(); 084 } 085 086 public boolean hasId() { 087 return this.id != null && !this.id.isEmpty(); 088 } 089 090 /** 091 * @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 092 */ 093 public Element setIdElement(IdType value) { 094 this.id = value; 095 return this; 096 } 097 098 /** 099 * @return unique id for the element within a resource (for internal references). 100 */ 101 public String getId() { 102 return this.id == null ? null : this.id.getValue(); 103 } 104 105 /** 106 * @param value unique id for the element within a resource (for internal references). 107 */ 108 public Element setId(String value) { 109 if (Utilities.noString(value)) 110 this.id = null; 111 else { 112 if (this.id == null) 113 this.id = new IdType(); 114 this.id.setValue(value); 115 } 116 return this; 117 } 118 119 /** 120 * @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.) 121 */ 122 public List<Extension> getExtension() { 123 if (this.extension == null) 124 this.extension = new ArrayList<Extension>(); 125 return this.extension; 126 } 127 128 public boolean hasExtension() { 129 if (this.extension == null) 130 return false; 131 for (Extension item : this.extension) 132 if (!item.isEmpty()) 133 return true; 134 return false; 135 } 136 137 /** 138 * @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.) 139 */ 140 // syntactic sugar 141 public Extension addExtension() { //3 142 Extension t = new Extension(); 143 if (this.extension == null) 144 this.extension = new ArrayList<Extension>(); 145 this.extension.add(t); 146 return t; 147 } 148 149 // syntactic sugar 150 public Element addExtension(Extension t) { //3 151 if (t == null) 152 return this; 153 if (this.extension == null) 154 this.extension = new ArrayList<Extension>(); 155 this.extension.add(t); 156 return this; 157 } 158 159 /** 160 * Returns an unmodifiable list containing all extensions on this element which 161 * match the given URL. 162 * 163 * @param theUrl The URL. Must not be blank or null. 164 * @return an unmodifiable list containing all extensions on this element which 165 * match the given URL 166 */ 167 public List<Extension> getExtensionsByUrl(String theUrl) { 168 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null"); 169 ArrayList<Extension> retVal = new ArrayList<Extension>(); 170 for (Extension next : getExtension()) { 171 if (theUrl.equals(next.getUrl())) { 172 retVal.add(next); 173 } 174 } 175 return java.util.Collections.unmodifiableList(retVal); 176 } 177 public boolean hasExtension(String theUrl) { 178 return !getExtensionsByUrl(theUrl).isEmpty(); 179 } 180 181 public String getExtensionString(String theUrl) throws FHIRException { 182 List<Extension> ext = getExtensionsByUrl(theUrl); 183 if (ext.isEmpty()) 184 return null; 185 if (ext.size() > 1) 186 throw new FHIRException("Multiple matching extensions found"); 187 if (!ext.get(0).getValue().isPrimitive()) 188 throw new FHIRException("Extension could not be converted to a string"); 189 return ext.get(0).getValue().primitiveValue(); 190 } 191 192 protected void listChildren(List<Property> childrenList) { 193 childrenList.add(new Property("id", "id", "unique id for the element within a resource (for internal references).", 0, java.lang.Integer.MAX_VALUE, id)); 194 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)); 195 } 196 197 @Override 198 public void setProperty(String name, Base value) throws FHIRException { 199 if (name.equals("id")) 200 this.id = castToId(value); // IdType 201 else if (name.equals("extension")) 202 this.getExtension().add(castToExtension(value)); 203 else 204 super.setProperty(name, value); 205 } 206 207 @Override 208 public Base addChild(String name) throws FHIRException { 209 if (name.equals("id")) { 210 throw new FHIRException("Cannot call addChild on a primitive type Element.id"); 211 } 212 else if (name.equals("extension")) { 213 return addExtension(); 214 } 215 else 216 return super.addChild(name); 217 } 218 219 public String fhirType() { 220 return "Element"; 221 222 } 223 224 public abstract Element copy(); 225 226 public void copyValues(Element dst) { 227 dst.id = id == null ? null : id.copy(); 228 if (extension != null) { 229 dst.extension = new ArrayList<Extension>(); 230 for (Extension i : extension) 231 dst.extension.add(i.copy()); 232 }; 233 } 234 235 @Override 236 public boolean equalsDeep(Base other) { 237 if (!super.equalsDeep(other)) 238 return false; 239 if (!(other instanceof Element)) 240 return false; 241 Element o = (Element) other; 242 return compareDeep(id, o.id, true) && compareDeep(extension, o.extension, true); 243 } 244 245 @Override 246 public boolean equalsShallow(Base other) { 247 if (!super.equalsShallow(other)) 248 return false; 249 if (!(other instanceof Element)) 250 return false; 251 Element o = (Element) other; 252 return compareValues(id, o.id, true); 253 } 254 255 public boolean isEmpty() { 256 return super.isEmpty() && (id == null || id.isEmpty()) && (extension == null || extension.isEmpty()) 257 ; 258 } 259 260 261} 262