001package org.hl7.fhir.r4.model; 002 003/*- 004 * #%L 005 * org.hl7.fhir.r4 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 Copyright (c) 2011+, HL7, Inc. 025 All rights reserved. 026 027 Redistribution and use in source and binary forms, with or without modification, 028 are permitted provided that the following conditions are met: 029 030 * Redistributions of source code must retain the above copyright notice, this 031 list of conditions and the following disclaimer. 032 * Redistributions in binary form must reproduce the above copyright notice, 033 this list of conditions and the following disclaimer in the documentation 034 and/or other materials provided with the distribution. 035 * Neither the name of HL7 nor the names of its contributors may be used to 036 endorse or promote products derived from this software without specific 037 prior written permission. 038 039 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 040 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 041 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 042 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 043 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 044 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 045 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 046 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 047 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 048 POSSIBILITY OF SUCH DAMAGE. 049 050*/ 051 052// Generated on Thu, Dec 13, 2018 14:07+1100 for FHIR v4.0.0 053import java.util.ArrayList; 054import java.util.Collections; 055import java.util.List; 056 057import org.hl7.fhir.exceptions.FHIRException; 058import org.hl7.fhir.instance.model.api.IBaseHasExtensions; 059import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions; 060import org.hl7.fhir.instance.model.api.IDomainResource; 061 062import ca.uhn.fhir.model.api.annotation.Child; 063import ca.uhn.fhir.model.api.annotation.Description; 064/** 065 * A resource that includes narrative, extensions, and contained resources. 066 */ 067public abstract class DomainResource extends Resource implements IBaseHasExtensions, IBaseHasModifierExtensions, IDomainResource { 068 069 /** 070 * A human-readable narrative that contains a summary of the resource and can 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. 071 */ 072 @Child(name = "text", type = {Narrative.class}, order=0, min=0, max=1, modifier=false, summary=false) 073 @Description(shortDefinition="Text summary of the resource, for human interpretation", formalDefinition="A human-readable narrative that contains a summary of the resource and can 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." ) 074 protected Narrative text; 075 076 /** 077 * 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. 078 */ 079 @Child(name = "contained", type = {Resource.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false) 080 @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." ) 081 protected List<Resource> contained; 082 083 /** 084 * May be used to represent additional information that is not part of the basic definition of the resource. 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 can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. 085 */ 086 @Child(name = "extension", type = {Extension.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false) 087 @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. 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 can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension." ) 088 protected List<Extension> extension; 089 090 /** 091 * 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 and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. 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. 092 093Modifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself). 094 */ 095 @Child(name = "modifierExtension", type = {Extension.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=true, summary=false) 096 @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 and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. 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.\n\nModifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself)." ) 097 protected List<Extension> modifierExtension; 098 099 private static final long serialVersionUID = -970285559L; 100 101 /** 102 * Constructor 103 */ 104 public DomainResource() { 105 super(); 106 } 107 108 /** 109 * @return {@link #text} (A human-readable narrative that contains a summary of the resource and can 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.) 110 */ 111 public Narrative getText() { 112 if (this.text == null) 113 if (Configuration.errorOnAutoCreate()) 114 throw new Error("Attempt to auto-create DomainResource.text"); 115 else if (Configuration.doAutoCreate()) 116 this.text = new Narrative(); // cc 117 return this.text; 118 } 119 120 public boolean hasText() { 121 return this.text != null && !this.text.isEmpty(); 122 } 123 124 /** 125 * @param value {@link #text} (A human-readable narrative that contains a summary of the resource and can 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.) 126 */ 127 public DomainResource setText(Narrative value) { 128 this.text = value; 129 return this; 130 } 131 132 /** 133 * @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.) 134 */ 135 public List<Resource> getContained() { 136 if (this.contained == null) 137 this.contained = new ArrayList<Resource>(); 138 return this.contained; 139 } 140 141 /** 142 * @return Returns a reference to <code>this</code> for easy method chaining 143 */ 144 public DomainResource setContained(List<Resource> theContained) { 145 this.contained = theContained; 146 return this; 147 } 148 149 public boolean hasContained() { 150 if (this.contained == null) 151 return false; 152 for (Resource item : this.contained) 153 if (!item.isEmpty()) 154 return true; 155 return false; 156 } 157 158 public DomainResource addContained(Resource t) { //3 159 if (t == null) 160 return this; 161 if (this.contained == null) 162 this.contained = new ArrayList<Resource>(); 163 this.contained.add(t); 164 return this; 165 } 166 167 /** 168 * @return {@link #extension} (May be used to represent additional information that is not part of the basic definition of the resource. 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 can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.) 169 */ 170 public List<Extension> getExtension() { 171 if (this.extension == null) 172 this.extension = new ArrayList<Extension>(); 173 return this.extension; 174 } 175 176 /** 177 * @return Returns a reference to <code>this</code> for easy method chaining 178 */ 179 public DomainResource setExtension(List<Extension> theExtension) { 180 this.extension = theExtension; 181 return this; 182 } 183 184 public boolean hasExtension() { 185 if (this.extension == null) 186 return false; 187 for (Extension item : this.extension) 188 if (!item.isEmpty()) 189 return true; 190 return false; 191 } 192 193 public Extension addExtension() { //3 194 Extension t = new Extension(); 195 if (this.extension == null) 196 this.extension = new ArrayList<Extension>(); 197 this.extension.add(t); 198 return t; 199 } 200 201 public DomainResource addExtension(Extension t) { //3 202 if (t == null) 203 return this; 204 if (this.extension == null) 205 this.extension = new ArrayList<Extension>(); 206 this.extension.add(t); 207 return this; 208 } 209 210 /** 211 * @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 and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. 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. 212 213Modifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).) 214 */ 215 public List<Extension> getModifierExtension() { 216 if (this.modifierExtension == null) 217 this.modifierExtension = new ArrayList<Extension>(); 218 return this.modifierExtension; 219 } 220 221 /** 222 * @return Returns a reference to <code>this</code> for easy method chaining 223 */ 224 public DomainResource setModifierExtension(List<Extension> theModifierExtension) { 225 this.modifierExtension = theModifierExtension; 226 return this; 227 } 228 229 public boolean hasModifierExtension() { 230 if (this.modifierExtension == null) 231 return false; 232 for (Extension item : this.modifierExtension) 233 if (!item.isEmpty()) 234 return true; 235 return false; 236 } 237 238 public Extension addModifierExtension() { //3 239 Extension t = new Extension(); 240 if (this.modifierExtension == null) 241 this.modifierExtension = new ArrayList<Extension>(); 242 this.modifierExtension.add(t); 243 return t; 244 } 245 246 public DomainResource addModifierExtension(Extension t) { //3 247 if (t == null) 248 return this; 249 if (this.modifierExtension == null) 250 this.modifierExtension = new ArrayList<Extension>(); 251 this.modifierExtension.add(t); 252 return this; 253 } 254 255 /** 256 * Returns a list of extensions from this element which have the given URL. Note that 257 * this list may not be modified (you can not add or remove elements from it) 258 */ 259 public List<Extension> getExtensionsByUrl(String theUrl) { 260 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value"); 261 ArrayList<Extension> retVal = new ArrayList<Extension>(); 262 for (Extension next : getExtension()) { 263 if (theUrl.equals(next.getUrl())) { 264 retVal.add(next); 265 } 266 } 267 return Collections.unmodifiableList(retVal); 268 } 269 270 /** 271 * Returns a list of modifier extensions from this element which have the given URL. Note that 272 * this list may not be modified (you can not add or remove elements from it) 273 */ 274 public List<Extension> getModifierExtensionsByUrl(String theUrl) { 275 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value"); 276 ArrayList<Extension> retVal = new ArrayList<Extension>(); 277 for (Extension next : getModifierExtension()) { 278 if (theUrl.equals(next.getUrl())) { 279 retVal.add(next); 280 } 281 } 282 return Collections.unmodifiableList(retVal); 283 } 284 285 protected void listChildren(List<Property> children) { 286 super.listChildren(children); 287 children.add(new Property("text", "Narrative", "A human-readable narrative that contains a summary of the resource and can 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)); 288 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)); 289 children.add(new Property("extension", "Extension", "May be used to represent additional information that is not part of the basic definition of the resource. 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 can 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)); 290 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 and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. 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.\n\nModifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).", 0, java.lang.Integer.MAX_VALUE, modifierExtension)); 291 } 292 293 @Override 294 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 295 switch (_hash) { 296 case 3556653: /*text*/ return new Property("text", "Narrative", "A human-readable narrative that contains a summary of the resource and can 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); 297 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); 298 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. 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 can 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); 299 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 and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. 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.\n\nModifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).", 0, java.lang.Integer.MAX_VALUE, modifierExtension); 300 default: return super.getNamedProperty(_hash, _name, _checkValid); 301 } 302 303 } 304 305 @Override 306 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 307 switch (hash) { 308 case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // Narrative 309 case -410956685: /*contained*/ return this.contained == null ? new Base[0] : this.contained.toArray(new Base[this.contained.size()]); // Resource 310 case -612557761: /*extension*/ return this.extension == null ? new Base[0] : this.extension.toArray(new Base[this.extension.size()]); // Extension 311 case -298878168: /*modifierExtension*/ return this.modifierExtension == null ? new Base[0] : this.modifierExtension.toArray(new Base[this.modifierExtension.size()]); // Extension 312 default: return super.getProperty(hash, name, checkValid); 313 } 314 315 } 316 317 @Override 318 public Base setProperty(int hash, String name, Base value) throws FHIRException { 319 switch (hash) { 320 case 3556653: // text 321 this.text = castToNarrative(value); // Narrative 322 return value; 323 case -410956685: // contained 324 this.getContained().add(castToResource(value)); // Resource 325 return value; 326 case -612557761: // extension 327 this.getExtension().add(castToExtension(value)); // Extension 328 return value; 329 case -298878168: // modifierExtension 330 this.getModifierExtension().add(castToExtension(value)); // Extension 331 return value; 332 default: return super.setProperty(hash, name, value); 333 } 334 335 } 336 337 @Override 338 public Base setProperty(String name, Base value) throws FHIRException { 339 if (name.equals("text")) { 340 this.text = castToNarrative(value); // Narrative 341 } else if (name.equals("contained")) { 342 this.getContained().add(castToResource(value)); 343 } else if (name.equals("extension")) { 344 this.getExtension().add(castToExtension(value)); 345 } else if (name.equals("modifierExtension")) { 346 this.getModifierExtension().add(castToExtension(value)); 347 } else 348 return super.setProperty(name, value); 349 return value; 350 } 351 352 @Override 353 public Base makeProperty(int hash, String name) throws FHIRException { 354 switch (hash) { 355 case 3556653: return getText(); 356 case -410956685: throw new FHIRException("Cannot make property contained as it is not a complex type"); // Resource 357 case -612557761: return addExtension(); 358 case -298878168: return addModifierExtension(); 359 default: return super.makeProperty(hash, name); 360 } 361 362 } 363 364 @Override 365 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 366 switch (hash) { 367 case 3556653: /*text*/ return new String[] {"Narrative"}; 368 case -410956685: /*contained*/ return new String[] {"Resource"}; 369 case -612557761: /*extension*/ return new String[] {"Extension"}; 370 case -298878168: /*modifierExtension*/ return new String[] {"Extension"}; 371 default: return super.getTypesForProperty(hash, name); 372 } 373 374 } 375 376 @Override 377 public Base addChild(String name) throws FHIRException { 378 if (name.equals("text")) { 379 this.text = new Narrative(); 380 return this.text; 381 } 382 else if (name.equals("contained")) { 383 throw new FHIRException("Cannot call addChild on an abstract type DomainResource.contained"); 384 } 385 else if (name.equals("extension")) { 386 return addExtension(); 387 } 388 else if (name.equals("modifierExtension")) { 389 return addModifierExtension(); 390 } 391 else 392 return super.addChild(name); 393 } 394 395 public String fhirType() { 396 return "DomainResource"; 397 398 } 399 400 public abstract DomainResource copy(); 401 402 public void copyValues(DomainResource dst) { 403 super.copyValues(dst); 404 dst.text = text == null ? null : text.copy(); 405 if (contained != null) { 406 dst.contained = new ArrayList<Resource>(); 407 for (Resource i : contained) 408 dst.contained.add(i.copy()); 409 }; 410 if (extension != null) { 411 dst.extension = new ArrayList<Extension>(); 412 for (Extension i : extension) 413 dst.extension.add(i.copy()); 414 }; 415 if (modifierExtension != null) { 416 dst.modifierExtension = new ArrayList<Extension>(); 417 for (Extension i : modifierExtension) 418 dst.modifierExtension.add(i.copy()); 419 }; 420 } 421 422 @Override 423 public boolean equalsDeep(Base other_) { 424 if (!super.equalsDeep(other_)) 425 return false; 426 if (!(other_ instanceof DomainResource)) 427 return false; 428 DomainResource o = (DomainResource) other_; 429 return compareDeep(text, o.text, true) && compareDeep(contained, o.contained, true) && compareDeep(extension, o.extension, true) 430 && compareDeep(modifierExtension, o.modifierExtension, true); 431 } 432 433 @Override 434 public boolean equalsShallow(Base other_) { 435 if (!super.equalsShallow(other_)) 436 return false; 437 if (!(other_ instanceof DomainResource)) 438 return false; 439 DomainResource o = (DomainResource) other_; 440 return true; 441 } 442 443 public boolean isEmpty() { 444 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(text, contained, extension 445 , modifierExtension); 446 } 447 448// added from java-adornments.txt: 449 450 public void checkNoModifiers(String noun, String verb) throws FHIRException { 451 if (hasModifierExtension()) { 452 throw new FHIRException("Found unknown Modifier Exceptions on "+noun+" doing "+verb); 453 } 454 455 } 456 457 public void addExtension(String url, Type value) { 458 Extension ex = new Extension(); 459 ex.setUrl(url); 460 ex.setValue(value); 461 getExtension().add(ex); 462 } 463 464 465 466 467 public boolean hasExtension(String url) { 468 for (Extension e : getExtension()) 469 if (url.equals(e.getUrl())) 470 return true; 471 return false; 472 } 473 474 public Extension getExtensionByUrl(String theUrl) { 475 org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null"); 476 ArrayList<Extension> retVal = new ArrayList<Extension>(); 477 for (Extension next : getExtension()) { 478 if (theUrl.equals(next.getUrl())) { 479 retVal.add(next); 480 } 481 } 482 if (retVal.size() == 0) 483 return null; 484 else { 485 org.apache.commons.lang3.Validate.isTrue(retVal.size() == 1, "Url "+theUrl+" must have only one match"); 486 return retVal.get(0); 487 } 488 } 489 490 491 public Resource getContained(String ref) { 492 if (ref == null) 493 return null; 494 495 if (ref.startsWith("#")) 496 ref = ref.substring(1); 497 for (Resource r : getContained()) { 498 if (r.getId().equals(ref)) 499 return r; 500 } 501 return null; 502 } 503 504// end addition 505 506} 507