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