001package org.hl7.fhir.dstu3.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 Fri, Mar 16, 2018 15:21+1100 for FHIR v3.0.1 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; 044import org.hl7.fhir.exceptions.FHIRFormatError; 045/** 046 * A reference from one resource to another. 047 */ 048@DatatypeDef(name="Reference") 049public class Reference extends BaseReference implements IBaseReference, ICompositeType { 050 051 /** 052 * 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. 053 */ 054 @Child(name = "reference", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true) 055 @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." ) 056 protected StringType reference; 057 058 /** 059 * An identifier for the other resource. This is used when there is no way to reference the other resource directly, either because the entity 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. 060 */ 061 @Child(name = "identifier", type = {Identifier.class}, order=1, min=0, max=1, modifier=false, summary=true) 062 @Description(shortDefinition="Logical reference, when literal reference is not known", formalDefinition="An identifier for the other resource. This is used when there is no way to reference the other resource directly, either because the entity 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." ) 063 protected Identifier identifier; 064 065 /** 066 * Plain text narrative that identifies the resource in addition to the resource reference. 067 */ 068 @Child(name = "display", type = {StringType.class}, order=2, min=0, max=1, modifier=false, summary=true) 069 @Description(shortDefinition="Text alternative for the resource", formalDefinition="Plain text narrative that identifies the resource in addition to the resource reference." ) 070 protected StringType display; 071 072 private static final long serialVersionUID = -909353281L; 073 074 /** 075 * Constructor 076 */ 077 public Reference() { 078 super(); 079 } 080 081 /** 082 * Constructor 083 * 084 * @param theReference The given reference string (e.g. "Patient/123" or "http://example.com/Patient/123") 085 */ 086 public Reference(String theReference) { 087 super(theReference); 088 } 089 090 /** 091 * Constructor 092 * 093 * @param theReference The given reference as an IdType (e.g. "Patient/123" or "http://example.com/Patient/123") 094 */ 095 public Reference(IIdType theReference) { 096 super(theReference); 097 } 098 099 /** 100 * Constructor 101 * 102 * @param theResource The resource represented by this reference 103 */ 104 public Reference(IAnyResource theResource) { 105 super(theResource); 106 } 107 108 /** 109 * @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 110 */ 111 public StringType getReferenceElement_() { 112 if (this.reference == null) 113 if (Configuration.errorOnAutoCreate()) 114 throw new Error("Attempt to auto-create Reference.reference"); 115 else if (Configuration.doAutoCreate()) 116 this.reference = new StringType(); // bb 117 return this.reference; 118 } 119 120 public boolean hasReferenceElement() { 121 return this.reference != null && !this.reference.isEmpty(); 122 } 123 124 public boolean hasReference() { 125 return this.reference != null && !this.reference.isEmpty(); 126 } 127 128 /** 129 * @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 130 */ 131 public Reference setReferenceElement(StringType value) { 132 this.reference = value; 133 return this; 134 } 135 136 /** 137 * @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. 138 */ 139 @Override 140 public String getReference() { 141 return this.reference == null ? null : this.reference.getValue(); 142 } 143 144 /** 145 * @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. 146 */ 147 public Reference setReference(String value) { 148 if (Utilities.noString(value)) 149 this.reference = null; 150 else { 151 if (this.reference == null) 152 this.reference = new StringType(); 153 this.reference.setValue(value); 154 } 155 return this; 156 } 157 158 /** 159 * @return {@link #identifier} (An identifier for the other resource. This is used when there is no way to reference the other resource directly, either because the entity 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.) 160 */ 161 public Identifier getIdentifier() { 162 if (this.identifier == null) 163 if (Configuration.errorOnAutoCreate()) 164 throw new Error("Attempt to auto-create Reference.identifier"); 165 else if (Configuration.doAutoCreate()) 166 this.identifier = new Identifier(); // cc 167 return this.identifier; 168 } 169 170 public boolean hasIdentifier() { 171 return this.identifier != null && !this.identifier.isEmpty(); 172 } 173 174 /** 175 * @param value {@link #identifier} (An identifier for the other resource. This is used when there is no way to reference the other resource directly, either because the entity 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.) 176 */ 177 public Reference setIdentifier(Identifier value) { 178 this.identifier = value; 179 return this; 180 } 181 182 /** 183 * @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 184 */ 185 public StringType getDisplayElement() { 186 if (this.display == null) 187 if (Configuration.errorOnAutoCreate()) 188 throw new Error("Attempt to auto-create Reference.display"); 189 else if (Configuration.doAutoCreate()) 190 this.display = new StringType(); // bb 191 return this.display; 192 } 193 194 public boolean hasDisplayElement() { 195 return this.display != null && !this.display.isEmpty(); 196 } 197 198 public boolean hasDisplay() { 199 return this.display != null && !this.display.isEmpty(); 200 } 201 202 /** 203 * @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 204 */ 205 public Reference setDisplayElement(StringType value) { 206 this.display = value; 207 return this; 208 } 209 210 /** 211 * @return Plain text narrative that identifies the resource in addition to the resource reference. 212 */ 213 public String getDisplay() { 214 return this.display == null ? null : this.display.getValue(); 215 } 216 217 /** 218 * @param value Plain text narrative that identifies the resource in addition to the resource reference. 219 */ 220 public Reference setDisplay(String value) { 221 if (Utilities.noString(value)) 222 this.display = null; 223 else { 224 if (this.display == null) 225 this.display = new StringType(); 226 this.display.setValue(value); 227 } 228 return this; 229 } 230 231 /** 232 * Convenience setter which sets the reference to the complete {@link IIdType#getValue() value} of the given 233 * reference. 234 * 235 * @param theReference The reference, or <code>null</code> 236 * @return 237 * @return Returns a reference to this 238 */ 239 public Reference setReferenceElement(IIdType theReference) { 240 if (theReference != null) { 241 setReference(theReference.getValue()); 242 } else { 243 setReference(null); 244 } 245 return this; 246 } 247 protected void listChildren(List<Property> children) { 248 super.listChildren(children); 249 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)); 250 children.add(new Property("identifier", "Identifier", "An identifier for the other resource. This is used when there is no way to reference the other resource directly, either because the entity 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)); 251 children.add(new Property("display", "string", "Plain text narrative that identifies the resource in addition to the resource reference.", 0, 1, display)); 252 } 253 254 @Override 255 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 256 switch (_hash) { 257 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); 258 case -1618432855: /*identifier*/ return new Property("identifier", "Identifier", "An identifier for the other resource. This is used when there is no way to reference the other resource directly, either because the entity 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); 259 case 1671764162: /*display*/ return new Property("display", "string", "Plain text narrative that identifies the resource in addition to the resource reference.", 0, 1, display); 260 default: return super.getNamedProperty(_hash, _name, _checkValid); 261 } 262 263 } 264 265 @Override 266 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 267 switch (hash) { 268 case -925155509: /*reference*/ return this.reference == null ? new Base[0] : new Base[] {this.reference}; // StringType 269 case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : new Base[] {this.identifier}; // Identifier 270 case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType 271 default: return super.getProperty(hash, name, checkValid); 272 } 273 274 } 275 276 @Override 277 public Base setProperty(int hash, String name, Base value) throws FHIRException { 278 switch (hash) { 279 case -925155509: // reference 280 this.reference = castToString(value); // StringType 281 return value; 282 case -1618432855: // identifier 283 this.identifier = castToIdentifier(value); // Identifier 284 return value; 285 case 1671764162: // display 286 this.display = castToString(value); // StringType 287 return value; 288 default: return super.setProperty(hash, name, value); 289 } 290 291 } 292 293 @Override 294 public Base setProperty(String name, Base value) throws FHIRException { 295 if (name.equals("reference")) { 296 this.reference = castToString(value); // StringType 297 } else if (name.equals("identifier")) { 298 this.identifier = castToIdentifier(value); // Identifier 299 } else if (name.equals("display")) { 300 this.display = castToString(value); // StringType 301 } else 302 return super.setProperty(name, value); 303 return value; 304 } 305 306 @Override 307 public Base makeProperty(int hash, String name) throws FHIRException { 308 switch (hash) { 309 case -925155509: return getReferenceElement_(); 310 case -1618432855: return getIdentifier(); 311 case 1671764162: return getDisplayElement(); 312 default: return super.makeProperty(hash, name); 313 } 314 315 } 316 317 @Override 318 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 319 switch (hash) { 320 case -925155509: /*reference*/ return new String[] {"string"}; 321 case -1618432855: /*identifier*/ return new String[] {"Identifier"}; 322 case 1671764162: /*display*/ return new String[] {"string"}; 323 default: return super.getTypesForProperty(hash, name); 324 } 325 326 } 327 328 @Override 329 public Base addChild(String name) throws FHIRException { 330 if (name.equals("reference")) { 331 throw new FHIRException("Cannot call addChild on a primitive type Reference.reference"); 332 } 333 else if (name.equals("identifier")) { 334 this.identifier = new Identifier(); 335 return this.identifier; 336 } 337 else if (name.equals("display")) { 338 throw new FHIRException("Cannot call addChild on a primitive type Reference.display"); 339 } 340 else 341 return super.addChild(name); 342 } 343 344 public String fhirType() { 345 return "Reference"; 346 347 } 348 349 public Reference copy() { 350 Reference dst = new Reference(); 351 copyValues(dst); 352 dst.reference = reference == null ? null : reference.copy(); 353 dst.identifier = identifier == null ? null : identifier.copy(); 354 dst.display = display == null ? null : display.copy(); 355 return dst; 356 } 357 358 protected Reference typedCopy() { 359 return copy(); 360 } 361 362 @Override 363 public boolean equalsDeep(Base other_) { 364 if (!super.equalsDeep(other_)) 365 return false; 366 if (!(other_ instanceof Reference)) 367 return false; 368 Reference o = (Reference) other_; 369 return compareDeep(reference, o.reference, true) && compareDeep(identifier, o.identifier, true) 370 && compareDeep(display, o.display, true); 371 } 372 373 @Override 374 public boolean equalsShallow(Base other_) { 375 if (!super.equalsShallow(other_)) 376 return false; 377 if (!(other_ instanceof Reference)) 378 return false; 379 Reference o = (Reference) other_; 380 return compareValues(reference, o.reference, true) && compareValues(display, o.display, true); 381 } 382 383 public boolean isEmpty() { 384 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(reference, identifier, display 385 ); 386 } 387 388 389} 390