
001package org.hl7.fhir.dstu3.model; 002 003 004 005/* 006 Copyright (c) 2011+, HL7, Inc. 007 All rights reserved. 008 009 Redistribution and use in source and binary forms, with or without modification, 010 are permitted provided that the following conditions are met: 011 012 * Redistributions of source code must retain the above copyright notice, this 013 list of conditions and the following disclaimer. 014 * Redistributions in binary form must reproduce the above copyright notice, 015 this list of conditions and the following disclaimer in the documentation 016 and/or other materials provided with the distribution. 017 * Neither the name of HL7 nor the names of its contributors may be used to 018 endorse or promote products derived from this software without specific 019 prior written permission. 020 021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 024 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 025 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 026 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 027 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 028 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 029 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 030 POSSIBILITY OF SUCH DAMAGE. 031 032*/ 033 034// Generated on Fri, Mar 16, 2018 15:21+1100 for FHIR v3.0.x 035import java.util.ArrayList; 036import java.util.Collections; 037import java.util.List; 038 039import org.hl7.fhir.exceptions.FHIRException; 040import org.hl7.fhir.instance.model.api.IBaseHasExtensions; 041import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions; 042import org.hl7.fhir.instance.model.api.IDomainResource; 043 044import ca.uhn.fhir.model.api.annotation.Child; 045import ca.uhn.fhir.model.api.annotation.Description; 046 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 /** 123 * @return Returns a reference to <code>this</code> for easy method chaining 124 */ 125 public DomainResource setContained(List<Resource> theContained) { 126 this.contained = theContained; 127 return this; 128 } 129 130 public boolean hasContained() { 131 if (this.contained == null) 132 return false; 133 for (Resource item : this.contained) 134 if (!item.isEmpty()) 135 return true; 136 return false; 137 } 138 139 public DomainResource addContained(Resource t) { //3 140 if (t == null) 141 return this; 142 if (this.contained == null) 143 this.contained = new ArrayList<Resource>(); 144 this.contained.add(t); 145 return this; 146 } 147 148 /** 149 * @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.) 150 */ 151 public List<Extension> getExtension() { 152 if (this.extension == null) 153 this.extension = new ArrayList<Extension>(); 154 return this.extension; 155 } 156 157 /** 158 * @return Returns a reference to <code>this</code> for easy method chaining 159 */ 160 public DomainResource setExtension(List<Extension> theExtension) { 161 this.extension = theExtension; 162 return this; 163 } 164 165 public boolean hasExtension() { 166 if (this.extension == null) 167 return false; 168 for (Extension item : this.extension) 169 if (!item.isEmpty()) 170 return true; 171 return false; 172 } 173 174 public Extension addExtension() { //3 175 Extension t = new Extension(); 176 if (this.extension == null) 177 this.extension = new ArrayList<Extension>(); 178 this.extension.add(t); 179 return t; 180 } 181 182 public DomainResource addExtension(Extension t) { //3 183 if (t == null) 184 return this; 185 if (this.extension == null) 186 this.extension = new ArrayList<Extension>(); 187 this.extension.add(t); 188 return this; 189 } 190 191 /** 192 * @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.) 193 */ 194 public List<Extension> getModifierExtension() { 195 if (this.modifierExtension == null) 196 this.modifierExtension = new ArrayList<Extension>(); 197 return this.modifierExtension; 198 } 199 200 /** 201 * @return Returns a reference to <code>this</code> for easy method chaining 202 */ 203 public DomainResource setModifierExtension(List<Extension> theModifierExtension) { 204 this.modifierExtension = theModifierExtension; 205 return this; 206 } 207 208 public boolean hasModifierExtension() { 209 if (this.modifierExtension == null) 210 return false; 211 for (Extension item : this.modifierExtension) 212 if (!item.isEmpty()) 213 return true; 214 return false; 215 } 216 217 public Extension addModifierExtension() { //3 218 Extension t = new Extension(); 219 if (this.modifierExtension == null) 220 this.modifierExtension = new ArrayList<Extension>(); 221 this.modifierExtension.add(t); 222 return t; 223 } 224 225 public DomainResource addModifierExtension(Extension t) { //3 226 if (t == null) 227 return this; 228 if (this.modifierExtension == null) 229 this.modifierExtension = new ArrayList<Extension>(); 230 this.modifierExtension.add(t); 231 return this; 232 } 233 234 /** 235 * Returns a list of extensions from this element which have the given URL. Note that 236 * this list may not be modified (you can not add or remove elements from it) 237 */ 238 public List<Extension> getExtensionsByUrl(String theUrl) { 239 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value"); 240 ArrayList<Extension> retVal = new ArrayList<Extension>(); 241 for (Extension next : getExtension()) { 242 if (theUrl.equals(next.getUrl())) { 243 retVal.add(next); 244 } 245 } 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 /** 255 * Returns a list of modifier extensions from this element which have the given URL. Note that 256 * this list may not be modified (you can not add or remove elements from it) 257 */ 258 public List<Extension> getModifierExtensionsByUrl(String theUrl) { 259 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value"); 260 ArrayList<Extension> retVal = new ArrayList<Extension>(); 261 for (Extension next : getModifierExtension()) { 262 if (theUrl.equals(next.getUrl())) { 263 retVal.add(next); 264 } 265 } 266 return Collections.unmodifiableList(retVal); 267 } 268 269 protected void listChildren(List<Property> children) { 270 children.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, 1, text)); 271 children.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)); 272 children.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)); 273 children.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)); 274 } 275 276 @Override 277 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 278 switch (_hash) { 279 case 3556653: /*text*/ return 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, 1, text); 280 case -410956685: /*contained*/ return 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); 281 case -612557761: /*extension*/ return 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); 282 case -298878168: /*modifierExtension*/ return 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); 283 default: return super.getNamedProperty(_hash, _name, _checkValid); 284 } 285 286 } 287 288 @Override 289 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 290 switch (hash) { 291 case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // Narrative 292 case -410956685: /*contained*/ return this.contained == null ? new Base[0] : this.contained.toArray(new Base[this.contained.size()]); // Resource 293 case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension 294 case -298878168: /*modifierExtension*/ return this.modifierExtension == null ? new Base[0] : this.modifierExtension.toArray(new Base[this.modifierExtension.size()]); // Extension 295 default: return super.getProperty(hash, name, checkValid); 296 } 297 298 } 299 300 @Override 301 public Base setProperty(int hash, String name, Base value) throws FHIRException { 302 switch (hash) { 303 case 3556653: // text 304 this.text = castToNarrative(value); // Narrative 305 return value; 306 case -410956685: // contained 307 this.getContained().add(castToResource(value)); // Resource 308 return value; 309 case -612557761: // extension 310 this.getExtension().add(castToExtension(value)); // Extension 311 return value; 312 case -298878168: // modifierExtension 313 this.getModifierExtension().add(castToExtension(value)); // Extension 314 return value; 315 default: return super.setProperty(hash, name, value); 316 } 317 318 } 319 320 @Override 321 public Base setProperty(String name, Base value) throws FHIRException { 322 if (name.equals("text")) { 323 this.text = castToNarrative(value); // Narrative 324 } else if (name.equals("contained")) { 325 this.getContained().add(castToResource(value)); 326 } else if (name.equals("extension")) { 327 this.getExtension().add(castToExtension(value)); 328 } else if (name.equals("modifierExtension")) { 329 this.getModifierExtension().add(castToExtension(value)); 330 } else 331 return super.setProperty(name, value); 332 return value; 333 } 334 335 @Override 336 public Base makeProperty(int hash, String name) throws FHIRException { 337 switch (hash) { 338 case 3556653: return getText(); 339 case -410956685: throw new FHIRException("Cannot make property contained as it is not a complex type"); // Resource 340 case -612557761: return addExtension(); 341 case -298878168: return addModifierExtension(); 342 default: return super.makeProperty(hash, name); 343 } 344 345 } 346 347 @Override 348 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 349 switch (hash) { 350 case 3556653: /*text*/ return new String[] {"Narrative"}; 351 case -410956685: /*contained*/ return new String[] {"Resource"}; 352 case -612557761: /*extension*/ return new String[] {"Extension"}; 353 case -298878168: /*modifierExtension*/ return new String[] {"Extension"}; 354 default: return super.getTypesForProperty(hash, name); 355 } 356 357 } 358 359 @Override 360 public Base addChild(String name) throws FHIRException { 361 if (name.equals("text")) { 362 this.text = new Narrative(); 363 return this.text; 364 } 365 else if (name.equals("contained")) { 366 throw new FHIRException("Cannot call addChild on an abstract type DomainResource.contained"); 367 } 368 else if (name.equals("extension")) { 369 return addExtension(); 370 } 371 else if (name.equals("modifierExtension")) { 372 return addModifierExtension(); 373 } 374 else 375 return super.addChild(name); 376 } 377 378 public String fhirType() { 379 return "DomainResource"; 380 381 } 382 383 public abstract DomainResource copy(); 384 385 public void copyValues(DomainResource dst) { 386 super.copyValues(dst); 387 dst.text = text == null ? null : text.copy(); 388 if (contained != null) { 389 dst.contained = new ArrayList<Resource>(); 390 for (Resource i : contained) 391 dst.contained.add(i.copy()); 392 }; 393 if (extension != null) { 394 dst.extension = new ArrayList<Extension>(); 395 for (Extension i : extension) 396 dst.extension.add(i.copy()); 397 }; 398 if (modifierExtension != null) { 399 dst.modifierExtension = new ArrayList<Extension>(); 400 for (Extension i : modifierExtension) 401 dst.modifierExtension.add(i.copy()); 402 }; 403 } 404 405 @Override 406 public boolean equalsDeep(Base other_) { 407 if (!super.equalsDeep(other_)) 408 return false; 409 if (!(other_ instanceof DomainResource)) 410 return false; 411 DomainResource o = (DomainResource) other_; 412 return compareDeep(text, o.text, true) && compareDeep(contained, o.contained, true) && compareDeep(extension, o.extension, true) 413 && compareDeep(modifierExtension, o.modifierExtension, true); 414 } 415 416 @Override 417 public boolean equalsShallow(Base other_) { 418 if (!super.equalsShallow(other_)) 419 return false; 420 if (!(other_ instanceof DomainResource)) 421 return false; 422 DomainResource o = (DomainResource) other_; 423 return true; 424 } 425 426 public boolean isEmpty() { 427 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(text, contained, extension 428 , modifierExtension); 429 } 430 431 432 public void addExtension(String url, Type value) { 433 Extension ex = new Extension(); 434 ex.setUrl(url); 435 ex.setValue(value); 436 getExtension().add(ex); 437 } 438 439 440 public boolean hasExtension(String url) { 441 for (Extension next : getModifierExtension()) { 442 if (url.equals(next.getUrl())) { 443 return true; 444 } 445 } 446 for (Extension e : getExtension()) 447 if (url.equals(e.getUrl())) 448 return true; 449 return false; 450 } 451 452 public Extension getExtensionByUrl(String theUrl) { 453 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null"); 454 ArrayList<Extension> retVal = new ArrayList<Extension>(); 455 for (Extension next : getExtension()) { 456 if (theUrl.equals(next.getUrl())) { 457 retVal.add(next); 458 } 459 } 460 for (Extension next : getModifierExtension()) { 461 if (theUrl.equals(next.getUrl())) { 462 retVal.add(next); 463 } 464 } 465 if (retVal.size() == 0) 466 return null; 467 else { 468 boolean allValuesIdentical = true; 469 if (retVal.size() > 1) { 470 for (Extension next : retVal) { 471 allValuesIdentical = allValuesIdentical && next.value.equalsDeep(retVal.get(0).value); 472 } 473 } 474 org.apache.commons.lang3.Validate.isTrue(retVal.size() == 1 || allValuesIdentical, "Url "+theUrl+" must have only one match"); 475 return retVal.get(0); 476 } 477 } 478 479 480}