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