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.Collections; 038import java.util.List; 039 040import org.hl7.fhir.exceptions.FHIRException; 041import org.hl7.fhir.instance.model.api.IBaseHasExtensions; 042import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions; 043import org.hl7.fhir.instance.model.api.IDomainResource; 044 045import ca.uhn.fhir.model.api.annotation.Child; 046import ca.uhn.fhir.model.api.annotation.Description; 047/** 048 * A resource that includes narrative, extensions, and contained resources. 049 */ 050public abstract class DomainResource extends Resource implements IBaseHasExtensions, IBaseHasModifierExtensions, IDomainResource { 051 052 /** 053 * A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it "clinically safe" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety. 054 */ 055 @Child(name = "text", type = {Narrative.class}, order=0, min=0, max=1, modifier=false, summary=false) 056 @Description(shortDefinition="Text summary of the resource, for human interpretation", formalDefinition="A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it \"clinically safe\" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety." ) 057 protected Narrative text; 058 059 /** 060 * These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope. 061 */ 062 @Child(name = "contained", type = {Resource.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false) 063 @Description(shortDefinition="Contained, inline Resources", formalDefinition="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope." ) 064 protected List<Resource> contained; 065 066 /** 067 * May be used to represent additional information that is not part of the basic definition of the resource. 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. 068 */ 069 @Child(name = "extension", type = {Extension.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false) 070 @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 resource. 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." ) 071 protected List<Extension> extension; 072 073 /** 074 * May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions. 075 */ 076 @Child(name = "modifierExtension", type = {Extension.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=true, summary=false) 077 @Description(shortDefinition="Extensions that cannot be ignored", formalDefinition="May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions." ) 078 protected List<Extension> modifierExtension; 079 080 private static final long serialVersionUID = -970285559L; 081 082 /** 083 * Constructor 084 */ 085 public DomainResource() { 086 super(); 087 } 088 089 /** 090 * @return {@link #text} (A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it "clinically safe" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.) 091 */ 092 public Narrative getText() { 093 if (this.text == null) 094 if (Configuration.errorOnAutoCreate()) 095 throw new Error("Attempt to auto-create DomainResource.text"); 096 else if (Configuration.doAutoCreate()) 097 this.text = new Narrative(); // cc 098 return this.text; 099 } 100 101 public boolean hasText() { 102 return this.text != null && !this.text.isEmpty(); 103 } 104 105 /** 106 * @param value {@link #text} (A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it "clinically safe" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.) 107 */ 108 public DomainResource setText(Narrative value) { 109 this.text = value; 110 return this; 111 } 112 113 /** 114 * @return {@link #contained} (These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope.) 115 */ 116 public List<Resource> getContained() { 117 if (this.contained == null) 118 this.contained = new ArrayList<Resource>(); 119 return this.contained; 120 } 121 122 public boolean hasContained() { 123 if (this.contained == null) 124 return false; 125 for (Resource item : this.contained) 126 if (!item.isEmpty()) 127 return true; 128 return false; 129 } 130 131 /** 132 * @return {@link #contained} (These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope.) 133 */ 134 // syntactic sugar 135 public DomainResource addContained(Resource t) { //3 136 if (t == null) 137 return this; 138 if (this.contained == null) 139 this.contained = new ArrayList<Resource>(); 140 this.contained.add(t); 141 return this; 142 } 143 144 /** 145 * @return {@link #extension} (May be used to represent additional information that is not part of the basic definition of the resource. 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.) 146 */ 147 public List<Extension> getExtension() { 148 if (this.extension == null) 149 this.extension = new ArrayList<Extension>(); 150 return this.extension; 151 } 152 153 public boolean hasExtension() { 154 if (this.extension == null) 155 return false; 156 for (Extension item : this.extension) 157 if (!item.isEmpty()) 158 return true; 159 return false; 160 } 161 162 /** 163 * @return {@link #extension} (May be used to represent additional information that is not part of the basic definition of the resource. 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.) 164 */ 165 // syntactic sugar 166 public Extension addExtension() { //3 167 Extension t = new Extension(); 168 if (this.extension == null) 169 this.extension = new ArrayList<Extension>(); 170 this.extension.add(t); 171 return t; 172 } 173 174 // syntactic sugar 175 public DomainResource addExtension(Extension t) { //3 176 if (t == null) 177 return this; 178 if (this.extension == null) 179 this.extension = new ArrayList<Extension>(); 180 this.extension.add(t); 181 return this; 182 } 183 184 /** 185 * @return {@link #modifierExtension} (May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions.) 186 */ 187 public List<Extension> getModifierExtension() { 188 if (this.modifierExtension == null) 189 this.modifierExtension = new ArrayList<Extension>(); 190 return this.modifierExtension; 191 } 192 193 public boolean hasModifierExtension() { 194 if (this.modifierExtension == null) 195 return false; 196 for (Extension item : this.modifierExtension) 197 if (!item.isEmpty()) 198 return true; 199 return false; 200 } 201 202 /** 203 * @return {@link #modifierExtension} (May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions.) 204 */ 205 // syntactic sugar 206 public Extension addModifierExtension() { //3 207 Extension t = new Extension(); 208 if (this.modifierExtension == null) 209 this.modifierExtension = new ArrayList<Extension>(); 210 this.modifierExtension.add(t); 211 return t; 212 } 213 214 // syntactic sugar 215 public DomainResource addModifierExtension(Extension t) { //3 216 if (t == null) 217 return this; 218 if (this.modifierExtension == null) 219 this.modifierExtension = new ArrayList<Extension>(); 220 this.modifierExtension.add(t); 221 return this; 222 } 223 224 /** 225 * Returns a list of extensions from this element which have the given URL. Note that 226 * this list may not be modified (you can not add or remove elements from it) 227 */ 228 public List<Extension> getExtensionsByUrl(String theUrl) { 229 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value"); 230 ArrayList<Extension> retVal = new ArrayList<Extension>(); 231 for (Extension next : getExtension()) { 232 if (theUrl.equals(next.getUrl())) { 233 retVal.add(next); 234 } 235 } 236 return Collections.unmodifiableList(retVal); 237 } 238 239 /** 240 * Returns a list of modifier extensions from this element which have the given URL. Note that 241 * this list may not be modified (you can not add or remove elements from it) 242 */ 243 public List<Extension> getModifierExtensionsByUrl(String theUrl) { 244 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value"); 245 ArrayList<Extension> retVal = new ArrayList<Extension>(); 246 for (Extension next : getModifierExtension()) { 247 if (theUrl.equals(next.getUrl())) { 248 retVal.add(next); 249 } 250 } 251 return Collections.unmodifiableList(retVal); 252 } 253 254 protected void listChildren(List<Property> childrenList) { 255 childrenList.add(new Property("text", "Narrative", "A human-readable narrative that contains a summary of the resource, and may be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it \"clinically safe\" for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", 0, java.lang.Integer.MAX_VALUE, text)); 256 childrenList.add(new Property("contained", "Resource", "These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, and nor can they have their own independent transaction scope.", 0, java.lang.Integer.MAX_VALUE, contained)); 257 childrenList.add(new Property("extension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource. 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)); 258 childrenList.add(new Property("modifierExtension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. 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. Applications processing a resource are required to check for modifier extensions.", 0, java.lang.Integer.MAX_VALUE, modifierExtension)); 259 } 260 261 @Override 262 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 263 switch (hash) { 264 case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // Narrative 265 case -410956685: /*contained*/ return this.contained == null ? new Base[0] : this.contained.toArray(new Base[this.contained.size()]); // Resource 266 case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension 267 case -298878168: /*modifierExtension*/ return this.modifierExtension == null ? new Base[0] : this.modifierExtension.toArray(new Base[this.modifierExtension.size()]); // Extension 268 default: return super.getProperty(hash, name, checkValid); 269 } 270 271 } 272 273 @Override 274 public void setProperty(int hash, String name, Base value) throws FHIRException { 275 switch (hash) { 276 case 3556653: // text 277 this.text = castToNarrative(value); // Narrative 278 break; 279 case -410956685: // contained 280 this.getContained().add(castToResource(value)); // Resource 281 break; 282 case -612557761: // extension 283 this.getExtension().add(castToExtension(value)); // Extension 284 break; 285 case -298878168: // modifierExtension 286 this.getModifierExtension().add(castToExtension(value)); // Extension 287 break; 288 default: super.setProperty(hash, name, value); 289 } 290 291 } 292 293 @Override 294 public void setProperty(String name, Base value) throws FHIRException { 295 if (name.equals("text")) 296 this.text = castToNarrative(value); // Narrative 297 else if (name.equals("contained")) 298 this.getContained().add(castToResource(value)); 299 else if (name.equals("extension")) 300 this.getExtension().add(castToExtension(value)); 301 else if (name.equals("modifierExtension")) 302 this.getModifierExtension().add(castToExtension(value)); 303 else 304 super.setProperty(name, value); 305 } 306 307 @Override 308 public Base makeProperty(int hash, String name) throws FHIRException { 309 switch (hash) { 310 case 3556653: return getText(); // Narrative 311 case -410956685: throw new FHIRException("Cannot make property contained as it is not a complex type"); // Resource 312 case -612557761: return addExtension(); // Extension 313 case -298878168: return addModifierExtension(); // Extension 314 default: return super.makeProperty(hash, name); 315 } 316 317 } 318 319 @Override 320 public Base addChild(String name) throws FHIRException { 321 if (name.equals("text")) { 322 this.text = new Narrative(); 323 return this.text; 324 } 325 else if (name.equals("contained")) { 326 throw new FHIRException("Cannot call addChild on an abstract type DomainResource.contained"); 327 } 328 else if (name.equals("extension")) { 329 return addExtension(); 330 } 331 else if (name.equals("modifierExtension")) { 332 return addModifierExtension(); 333 } 334 else 335 return super.addChild(name); 336 } 337 338 public String fhirType() { 339 return "DomainResource"; 340 341 } 342 343 public abstract DomainResource copy(); 344 345 public void copyValues(DomainResource dst) { 346 super.copyValues(dst); 347 dst.text = text == null ? null : text.copy(); 348 if (contained != null) { 349 dst.contained = new ArrayList<Resource>(); 350 for (Resource i : contained) 351 dst.contained.add(i.copy()); 352 }; 353 if (extension != null) { 354 dst.extension = new ArrayList<Extension>(); 355 for (Extension i : extension) 356 dst.extension.add(i.copy()); 357 }; 358 if (modifierExtension != null) { 359 dst.modifierExtension = new ArrayList<Extension>(); 360 for (Extension i : modifierExtension) 361 dst.modifierExtension.add(i.copy()); 362 }; 363 } 364 365 @Override 366 public boolean equalsDeep(Base other) { 367 if (!super.equalsDeep(other)) 368 return false; 369 if (!(other instanceof DomainResource)) 370 return false; 371 DomainResource o = (DomainResource) other; 372 return compareDeep(text, o.text, true) && compareDeep(contained, o.contained, true) && compareDeep(extension, o.extension, true) 373 && compareDeep(modifierExtension, o.modifierExtension, true); 374 } 375 376 @Override 377 public boolean equalsShallow(Base other) { 378 if (!super.equalsShallow(other)) 379 return false; 380 if (!(other instanceof DomainResource)) 381 return false; 382 DomainResource o = (DomainResource) other; 383 return true; 384 } 385 386 public boolean isEmpty() { 387 return super.isEmpty() && (text == null || text.isEmpty()) && (contained == null || contained.isEmpty()) 388 && (extension == null || extension.isEmpty()) && (modifierExtension == null || modifierExtension.isEmpty()) 389 ; 390 } 391 392 393}