001package org.hl7.fhir.r4.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 Thu, Sep 13, 2018 09:04-0400 for FHIR v3.5.0 033 034import java.util.*; 035 036import org.hl7.fhir.utilities.Utilities; 037import ca.uhn.fhir.model.api.annotation.Child; 038import ca.uhn.fhir.model.api.annotation.ChildOrder; 039import ca.uhn.fhir.model.api.annotation.Description; 040import ca.uhn.fhir.model.api.annotation.DatatypeDef; 041import ca.uhn.fhir.model.api.annotation.Block; 042import org.hl7.fhir.instance.model.api.*; 043import org.hl7.fhir.exceptions.FHIRException; 044/** 045 * A reference from one resource to another. 046 */ 047@DatatypeDef(name="Reference") 048public class Reference extends BaseReference implements IBaseReference, ICompositeType { 049 050 /** 051 * A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources. 052 */ 053 @Child(name = "reference", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true) 054 @Description(shortDefinition="Literal reference, Relative, internal or absolute URL", formalDefinition="A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources." ) 055 protected StringType reference; 056 057 /** 058 * The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent. 059 060The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources). 061 */ 062 @Child(name = "type", type = {UriType.class}, order=1, min=0, max=1, modifier=false, summary=true) 063 @Description(shortDefinition="Type the reference refers to (e.g. \"Patient\")", formalDefinition="The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.\n\nThe type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. \"Patient\" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources)." ) 064 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/resource-types") 065 protected UriType type; 066 067 /** 068 * An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference. 069 */ 070 @Child(name = "identifier", type = {Identifier.class}, order=2, min=0, max=1, modifier=false, summary=true) 071 @Description(shortDefinition="Logical reference, when literal reference is not known", formalDefinition="An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference." ) 072 protected Identifier identifier; 073 074 /** 075 * Plain text narrative that identifies the resource in addition to the resource reference. 076 */ 077 @Child(name = "display", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true) 078 @Description(shortDefinition="Text alternative for the resource", formalDefinition="Plain text narrative that identifies the resource in addition to the resource reference." ) 079 protected StringType display; 080 081 private static final long serialVersionUID = 784245805L; 082 083 /** 084 * Constructor 085 */ 086 public Reference() { 087 super(); 088 } 089 090 /** 091 * Constructor 092 * 093 * @param theReference The given reference string (e.g. "Patient/123" or "http://example.com/Patient/123") 094 */ 095 public Reference(String theReference) { 096 super(theReference); 097 } 098 099 /** 100 * Constructor 101 * 102 * @param theReference The given reference as an IdType (e.g. "Patient/123" or "http://example.com/Patient/123") 103 */ 104 public Reference(IIdType theReference) { 105 super(theReference); 106 } 107 108 /** 109 * Constructor 110 * 111 * @param theResource The resource represented by this reference 112 */ 113 public Reference(IAnyResource theResource) { 114 super(theResource); 115 } 116 117 /** 118 * @return {@link #reference} (A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources.). This is the underlying object with id, value and extensions. The accessor "getReference" gives direct access to the value 119 */ 120 public StringType getReferenceElement_() { 121 if (this.reference == null) 122 if (Configuration.errorOnAutoCreate()) 123 throw new Error("Attempt to auto-create Reference.reference"); 124 else if (Configuration.doAutoCreate()) 125 this.reference = new StringType(); // bb 126 return this.reference; 127 } 128 129 public boolean hasReferenceElement() { 130 return this.reference != null && !this.reference.isEmpty(); 131 } 132 133 public boolean hasReference() { 134 return this.reference != null && !this.reference.isEmpty(); 135 } 136 137 /** 138 * @param value {@link #reference} (A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources.). This is the underlying object with id, value and extensions. The accessor "getReference" gives direct access to the value 139 */ 140 public Reference setReferenceElement(StringType value) { 141 this.reference = value; 142 return this; 143 } 144 145 /** 146 * @return A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources. 147 */ 148 public String getReference() { 149 return this.reference == null ? null : this.reference.getValue(); 150 } 151 152 /** 153 * @param value A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources. 154 */ 155 public Reference setReference(String value) { 156 if (Utilities.noString(value)) 157 this.reference = null; 158 else { 159 if (this.reference == null) 160 this.reference = new StringType(); 161 this.reference.setValue(value); 162 } 163 return this; 164 } 165 166 /** 167 * @return {@link #type} (The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent. 168 169The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value 170 */ 171 public UriType getTypeElement() { 172 if (this.type == null) 173 if (Configuration.errorOnAutoCreate()) 174 throw new Error("Attempt to auto-create Reference.type"); 175 else if (Configuration.doAutoCreate()) 176 this.type = new UriType(); // bb 177 return this.type; 178 } 179 180 public boolean hasTypeElement() { 181 return this.type != null && !this.type.isEmpty(); 182 } 183 184 public boolean hasType() { 185 return this.type != null && !this.type.isEmpty(); 186 } 187 188 /** 189 * @param value {@link #type} (The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent. 190 191The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value 192 */ 193 public Reference setTypeElement(UriType value) { 194 this.type = value; 195 return this; 196 } 197 198 /** 199 * @return The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent. 200 201The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources). 202 */ 203 public String getType() { 204 return this.type == null ? null : this.type.getValue(); 205 } 206 207 /** 208 * @param value The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent. 209 210The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources). 211 */ 212 public Reference setType(String value) { 213 if (Utilities.noString(value)) 214 this.type = null; 215 else { 216 if (this.type == null) 217 this.type = new UriType(); 218 this.type.setValue(value); 219 } 220 return this; 221 } 222 223 /** 224 * @return {@link #identifier} (An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.) 225 */ 226 public Identifier getIdentifier() { 227 if (this.identifier == null) 228 if (Configuration.errorOnAutoCreate()) 229 throw new Error("Attempt to auto-create Reference.identifier"); 230 else if (Configuration.doAutoCreate()) 231 this.identifier = new Identifier(); // cc 232 return this.identifier; 233 } 234 235 public boolean hasIdentifier() { 236 return this.identifier != null && !this.identifier.isEmpty(); 237 } 238 239 /** 240 * @param value {@link #identifier} (An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.) 241 */ 242 public Reference setIdentifier(Identifier value) { 243 this.identifier = value; 244 return this; 245 } 246 247 /** 248 * @return {@link #display} (Plain text narrative that identifies the resource in addition to the resource reference.). This is the underlying object with id, value and extensions. The accessor "getDisplay" gives direct access to the value 249 */ 250 public StringType getDisplayElement() { 251 if (this.display == null) 252 if (Configuration.errorOnAutoCreate()) 253 throw new Error("Attempt to auto-create Reference.display"); 254 else if (Configuration.doAutoCreate()) 255 this.display = new StringType(); // bb 256 return this.display; 257 } 258 259 public boolean hasDisplayElement() { 260 return this.display != null && !this.display.isEmpty(); 261 } 262 263 public boolean hasDisplay() { 264 return this.display != null && !this.display.isEmpty(); 265 } 266 267 /** 268 * @param value {@link #display} (Plain text narrative that identifies the resource in addition to the resource reference.). This is the underlying object with id, value and extensions. The accessor "getDisplay" gives direct access to the value 269 */ 270 public Reference setDisplayElement(StringType value) { 271 this.display = value; 272 return this; 273 } 274 275 /** 276 * @return Plain text narrative that identifies the resource in addition to the resource reference. 277 */ 278 public String getDisplay() { 279 return this.display == null ? null : this.display.getValue(); 280 } 281 282 /** 283 * @param value Plain text narrative that identifies the resource in addition to the resource reference. 284 */ 285 public Reference setDisplay(String value) { 286 if (Utilities.noString(value)) 287 this.display = null; 288 else { 289 if (this.display == null) 290 this.display = new StringType(); 291 this.display.setValue(value); 292 } 293 return this; 294 } 295 296 /** 297 * Convenience setter which sets the reference to the complete {@link IIdType#getValue() value} of the given 298 * reference. 299 * 300 * @param theReference The reference, or <code>null</code> 301 * @return 302 * @return Returns a reference to this 303 */ 304 public Reference setReferenceElement(IIdType theReference) { 305 if (theReference != null) { 306 setReference(theReference.getValue()); 307 } else { 308 setReference(null); 309 } 310 return this; 311 } 312 protected void listChildren(List<Property> children) { 313 super.listChildren(children); 314 children.add(new Property("reference", "string", "A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources.", 0, 1, reference)); 315 children.add(new Property("type", "uri", "The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.\n\nThe type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. \"Patient\" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).", 0, 1, type)); 316 children.add(new Property("identifier", "Identifier", "An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.", 0, 1, identifier)); 317 children.add(new Property("display", "string", "Plain text narrative that identifies the resource in addition to the resource reference.", 0, 1, display)); 318 } 319 320 @Override 321 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 322 switch (_hash) { 323 case -925155509: /*reference*/ return new Property("reference", "string", "A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources.", 0, 1, reference); 324 case 3575610: /*type*/ return new Property("type", "uri", "The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.\n\nThe type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. \"Patient\" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).", 0, 1, type); 325 case -1618432855: /*identifier*/ return new Property("identifier", "Identifier", "An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.", 0, 1, identifier); 326 case 1671764162: /*display*/ return new Property("display", "string", "Plain text narrative that identifies the resource in addition to the resource reference.", 0, 1, display); 327 default: return super.getNamedProperty(_hash, _name, _checkValid); 328 } 329 330 } 331 332 @Override 333 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 334 switch (hash) { 335 case -925155509: /*reference*/ return this.reference == null ? new Base[0] : new Base[] {this.reference}; // StringType 336 case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // UriType 337 case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : new Base[] {this.identifier}; // Identifier 338 case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType 339 default: return super.getProperty(hash, name, checkValid); 340 } 341 342 } 343 344 @Override 345 public Base setProperty(int hash, String name, Base value) throws FHIRException { 346 switch (hash) { 347 case -925155509: // reference 348 this.reference = castToString(value); // StringType 349 return value; 350 case 3575610: // type 351 this.type = castToUri(value); // UriType 352 return value; 353 case -1618432855: // identifier 354 this.identifier = castToIdentifier(value); // Identifier 355 return value; 356 case 1671764162: // display 357 this.display = castToString(value); // StringType 358 return value; 359 default: return super.setProperty(hash, name, value); 360 } 361 362 } 363 364 @Override 365 public Base setProperty(String name, Base value) throws FHIRException { 366 if (name.equals("reference")) { 367 this.reference = castToString(value); // StringType 368 } else if (name.equals("type")) { 369 this.type = castToUri(value); // UriType 370 } else if (name.equals("identifier")) { 371 this.identifier = castToIdentifier(value); // Identifier 372 } else if (name.equals("display")) { 373 this.display = castToString(value); // StringType 374 } else 375 return super.setProperty(name, value); 376 return value; 377 } 378 379 @Override 380 public Base makeProperty(int hash, String name) throws FHIRException { 381 switch (hash) { 382 case -925155509: return (Base) getReferenceElement(); 383 case 3575610: return getTypeElement(); 384 case -1618432855: return getIdentifier(); 385 case 1671764162: return getDisplayElement(); 386 default: return super.makeProperty(hash, name); 387 } 388 389 } 390 391 @Override 392 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 393 switch (hash) { 394 case -925155509: /*reference*/ return new String[] {"string"}; 395 case 3575610: /*type*/ return new String[] {"uri"}; 396 case -1618432855: /*identifier*/ return new String[] {"Identifier"}; 397 case 1671764162: /*display*/ return new String[] {"string"}; 398 default: return super.getTypesForProperty(hash, name); 399 } 400 401 } 402 403 @Override 404 public Base addChild(String name) throws FHIRException { 405 if (name.equals("reference")) { 406 throw new FHIRException("Cannot call addChild on a primitive type Reference.reference"); 407 } 408 else if (name.equals("type")) { 409 throw new FHIRException("Cannot call addChild on a primitive type Reference.type"); 410 } 411 else if (name.equals("identifier")) { 412 this.identifier = new Identifier(); 413 return this.identifier; 414 } 415 else if (name.equals("display")) { 416 throw new FHIRException("Cannot call addChild on a primitive type Reference.display"); 417 } 418 else 419 return super.addChild(name); 420 } 421 422 public String fhirType() { 423 return "Reference"; 424 425 } 426 427 public Reference copy() { 428 Reference dst = new Reference(); 429 copyValues(dst); 430 dst.reference = reference == null ? null : reference.copy(); 431 dst.type = type == null ? null : type.copy(); 432 dst.identifier = identifier == null ? null : identifier.copy(); 433 dst.display = display == null ? null : display.copy(); 434 return dst; 435 } 436 437 protected Reference typedCopy() { 438 return copy(); 439 } 440 441 @Override 442 public boolean equalsDeep(Base other_) { 443 if (!super.equalsDeep(other_)) 444 return false; 445 if (!(other_ instanceof Reference)) 446 return false; 447 Reference o = (Reference) other_; 448 return compareDeep(reference, o.reference, true) && compareDeep(type, o.type, true) && compareDeep(identifier, o.identifier, true) 449 && compareDeep(display, o.display, true); 450 } 451 452 @Override 453 public boolean equalsShallow(Base other_) { 454 if (!super.equalsShallow(other_)) 455 return false; 456 if (!(other_ instanceof Reference)) 457 return false; 458 Reference o = (Reference) other_; 459 return compareValues(reference, o.reference, true) && compareValues(type, o.type, true) && compareValues(display, o.display, true) 460 ; 461 } 462 463 public boolean isEmpty() { 464 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(reference, type, identifier 465 , display); 466 } 467 468 469} 470