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