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