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.List; 034 035import org.hl7.fhir.exceptions.FHIRException; 036import org.hl7.fhir.instance.model.api.IAnyResource; 037import org.hl7.fhir.instance.model.api.IBaseReference; 038import org.hl7.fhir.instance.model.api.ICompositeType; 039import org.hl7.fhir.instance.model.api.IIdType; 040import org.hl7.fhir.utilities.Utilities; 041 042import ca.uhn.fhir.model.api.annotation.Child; 043import ca.uhn.fhir.model.api.annotation.DatatypeDef; 044import ca.uhn.fhir.model.api.annotation.Description; 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="Relative, internal or absolute URL reference", 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 * Plain text narrative that identifies the resource in addition to the resource reference. 060 */ 061 @Child(name = "display", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true) 062 @Description(shortDefinition="Text alternative for the resource", formalDefinition="Plain text narrative that identifies the resource in addition to the resource reference." ) 063 protected StringType display; 064 065 private static final long serialVersionUID = 22777321L; 066 067 /** 068 * Constructor 069 */ 070 public Reference() { 071 super(); 072 } 073 074 /** 075 * Constructor 076 * 077 * @param theReference The given reference string (e.g. "Patient/123" or "http://example.com/Patient/123") 078 */ 079 public Reference(String theReference) { 080 super(theReference); 081 } 082 083 /** 084 * Constructor 085 * 086 * @param theReference The given reference as an IdType (e.g. "Patient/123" or "http://example.com/Patient/123") 087 */ 088 public Reference(IIdType theReference) { 089 super(theReference); 090 } 091 092 /** 093 * Constructor 094 * 095 * @param theResource The resource represented by this reference 096 */ 097 public Reference(IAnyResource theResource) { 098 super(theResource); 099 } 100 101 /** 102 * @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 103 */ 104 public StringType getReferenceElement_() { 105 if (this.reference == null) 106 if (Configuration.errorOnAutoCreate()) 107 throw new Error("Attempt to auto-create Reference.reference"); 108 else if (Configuration.doAutoCreate()) 109 this.reference = new StringType(); // bb 110 return this.reference; 111 } 112 113 public boolean hasReferenceElement() { 114 return this.reference != null && !this.reference.isEmpty(); 115 } 116 117 public boolean hasReference() { 118 return this.reference != null && !this.reference.isEmpty(); 119 } 120 121 /** 122 * @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 123 */ 124 public Reference setReferenceElement(StringType value) { 125 this.reference = value; 126 return this; 127 } 128 129 /** 130 * @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. 131 */ 132 @Override 133 public String getReference() { 134 return this.reference == null ? null : this.reference.getValue(); 135 } 136 137 /** 138 * @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. 139 */ 140 public Reference setReference(String value) { 141 if (Utilities.noString(value)) 142 this.reference = null; 143 else { 144 if (this.reference == null) 145 this.reference = new StringType(); 146 this.reference.setValue(value); 147 } 148 return this; 149 } 150 151 /** 152 * @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 153 */ 154 public StringType getDisplayElement() { 155 if (this.display == null) 156 if (Configuration.errorOnAutoCreate()) 157 throw new Error("Attempt to auto-create Reference.display"); 158 else if (Configuration.doAutoCreate()) 159 this.display = new StringType(); // bb 160 return this.display; 161 } 162 163 public boolean hasDisplayElement() { 164 return this.display != null && !this.display.isEmpty(); 165 } 166 167 public boolean hasDisplay() { 168 return this.display != null && !this.display.isEmpty(); 169 } 170 171 /** 172 * @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 173 */ 174 public Reference setDisplayElement(StringType value) { 175 this.display = value; 176 return this; 177 } 178 179 /** 180 * @return Plain text narrative that identifies the resource in addition to the resource reference. 181 */ 182 public String getDisplay() { 183 return this.display == null ? null : this.display.getValue(); 184 } 185 186 /** 187 * @param value Plain text narrative that identifies the resource in addition to the resource reference. 188 */ 189 public Reference setDisplay(String value) { 190 if (Utilities.noString(value)) 191 this.display = null; 192 else { 193 if (this.display == null) 194 this.display = new StringType(); 195 this.display.setValue(value); 196 } 197 return this; 198 } 199 200 /** 201 * Convenience setter which sets the reference to the complete {@link IIdType#getValue() value} of the given 202 * reference. 203 * 204 * @param theReference The reference, or <code>null</code> 205 * @return 206 * @return Returns a reference to this 207 */ 208 public Reference setReferenceElement(IIdType theReference) { 209 if (theReference != null) { 210 setReference(theReference.getValue()); 211 } else { 212 setReference(null); 213 } 214 return this; 215 } 216 protected void listChildren(List<Property> childrenList) { 217 super.listChildren(childrenList); 218 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)); 219 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)); 220 } 221 222 @Override 223 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 224 switch (hash) { 225 case -925155509: /*reference*/ return this.reference == null ? new Base[0] : new Base[] {this.reference}; // StringType 226 case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType 227 default: return super.getProperty(hash, name, checkValid); 228 } 229 230 } 231 232 @Override 233 public void setProperty(int hash, String name, Base value) throws FHIRException { 234 switch (hash) { 235 case -925155509: // reference 236 this.reference = castToString(value); // StringType 237 break; 238 case 1671764162: // display 239 this.display = castToString(value); // StringType 240 break; 241 default: super.setProperty(hash, name, value); 242 } 243 244 } 245 246 @Override 247 public void setProperty(String name, Base value) throws FHIRException { 248 if (name.equals("reference")) 249 this.reference = castToString(value); // StringType 250 else if (name.equals("display")) 251 this.display = castToString(value); // StringType 252 else 253 super.setProperty(name, value); 254 } 255 256 @Override 257 public Base makeProperty(int hash, String name) throws FHIRException { 258 switch (hash) { 259 case -925155509: throw new FHIRException("Cannot make property reference as it is not a complex type"); // StringType 260 case 1671764162: throw new FHIRException("Cannot make property display as it is not a complex type"); // StringType 261 default: return super.makeProperty(hash, name); 262 } 263 264 } 265 266 @Override 267 public Base addChild(String name) throws FHIRException { 268 if (name.equals("reference")) { 269 throw new FHIRException("Cannot call addChild on a primitive type Reference.reference"); 270 } 271 else if (name.equals("display")) { 272 throw new FHIRException("Cannot call addChild on a primitive type Reference.display"); 273 } 274 else 275 return super.addChild(name); 276 } 277 278 public String fhirType() { 279 return "Reference"; 280 281 } 282 283 public Reference copy() { 284 Reference dst = new Reference(); 285 copyValues(dst); 286 dst.reference = reference == null ? null : reference.copy(); 287 dst.display = display == null ? null : display.copy(); 288 return dst; 289 } 290 291 protected Reference typedCopy() { 292 return copy(); 293 } 294 295 @Override 296 public boolean equalsDeep(Base other) { 297 if (!super.equalsDeep(other)) 298 return false; 299 if (!(other instanceof Reference)) 300 return false; 301 Reference o = (Reference) other; 302 return compareDeep(reference, o.reference, true) && compareDeep(display, o.display, true); 303 } 304 305 @Override 306 public boolean equalsShallow(Base other) { 307 if (!super.equalsShallow(other)) 308 return false; 309 if (!(other instanceof Reference)) 310 return false; 311 Reference o = (Reference) other; 312 return compareValues(reference, o.reference, true) && compareValues(display, o.display, true); 313 } 314 315 public boolean isEmpty() { 316 return super.isEmpty() && (reference == null || reference.isEmpty()) && (display == null || display.isEmpty()) 317 ; 318 } 319 320 321} 322