001package org.hl7.fhir.instance.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 Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2 033import java.util.List; 034 035import org.hl7.fhir.exceptions.FHIRException; 036import org.hl7.fhir.instance.model.api.*; 037import org.hl7.fhir.utilities.Utilities; 038 039import ca.uhn.fhir.model.api.annotation.*; 040/** 041 * A reference from one resource to another. 042 */ 043@DatatypeDef(name="Reference") 044public class Reference extends BaseReference implements IBaseReference, ICompositeType { 045 046 /** 047 * 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. 048 */ 049 @Child(name = "reference", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true) 050 @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." ) 051 protected StringType reference; 052 053 /** 054 * Plain text narrative that identifies the resource in addition to the resource reference. 055 */ 056 @Child(name = "display", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true) 057 @Description(shortDefinition="Text alternative for the resource", formalDefinition="Plain text narrative that identifies the resource in addition to the resource reference." ) 058 protected StringType display; 059 060 private static final long serialVersionUID = 22777321L; 061 062 /* 063 * Constructor 064 */ 065 public Reference() { 066 super(); 067 } 068 069 /** 070 * Constructor 071 * 072 * @param theReference The given reference string (e.g. "Patient/123" or "http://example.com/Patient/123") 073 */ 074 public Reference(String theReference) { 075 super(theReference); 076 } 077 078 /** 079 * Constructor 080 * 081 * @param theReference The given reference as an IdType (e.g. "Patient/123" or "http://example.com/Patient/123") 082 */ 083 public Reference(IdType theReference) { 084 super(theReference); 085 } 086 087 /** 088 * Constructor 089 * 090 * @param theResource The resource represented by this reference 091 */ 092 public Reference(IAnyResource theResource) { 093 super(theResource); 094 } 095 096 /** 097 * @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 098 */ 099 public boolean hasReferenceElement() { 100 return this.reference != null && !this.reference.isEmpty(); 101 } 102 103 public boolean hasReference() { 104 return this.reference != null && !this.reference.isEmpty(); 105 } 106 107 /** 108 * @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 109 */ 110 public Reference setReferenceElement(StringType value) { 111 this.reference = value; 112 return this; 113 } 114 115 /** 116 * @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. 117 */ 118 public String getReference() { 119 return this.reference == null ? null : this.reference.getValue(); 120 } 121 122 /** 123 * @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. 124 */ 125 public Reference setReference(String value) { 126 if (Utilities.noString(value)) 127 this.reference = null; 128 else { 129 if (this.reference == null) 130 this.reference = new StringType(); 131 this.reference.setValue(value); 132 } 133 return this; 134 } 135 136 /** 137 * @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 138 */ 139 public StringType getDisplayElement() { 140 if (this.display == null) 141 if (Configuration.errorOnAutoCreate()) 142 throw new Error("Attempt to auto-create Reference.display"); 143 else if (Configuration.doAutoCreate()) 144 this.display = new StringType(); // bb 145 return this.display; 146 } 147 148 public boolean hasDisplayElement() { 149 return this.display != null && !this.display.isEmpty(); 150 } 151 152 public boolean hasDisplay() { 153 return this.display != null && !this.display.isEmpty(); 154 } 155 156 /** 157 * @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 158 */ 159 public Reference setDisplayElement(StringType value) { 160 this.display = value; 161 return this; 162 } 163 164 /** 165 * @return Plain text narrative that identifies the resource in addition to the resource reference. 166 */ 167 public String getDisplay() { 168 return this.display == null ? null : this.display.getValue(); 169 } 170 171 /** 172 * @param value Plain text narrative that identifies the resource in addition to the resource reference. 173 */ 174 public Reference setDisplay(String value) { 175 if (Utilities.noString(value)) 176 this.display = null; 177 else { 178 if (this.display == null) 179 this.display = new StringType(); 180 this.display.setValue(value); 181 } 182 return this; 183 } 184 185 protected void listChildren(List<Property> childrenList) { 186 super.listChildren(childrenList); 187 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)); 188 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)); 189 } 190 191 @Override 192 public void setProperty(String name, Base value) throws FHIRException { 193 if (name.equals("reference")) 194 this.reference = castToString(value); // StringType 195 else if (name.equals("display")) 196 this.display = castToString(value); // StringType 197 else 198 super.setProperty(name, value); 199 } 200 201 @Override 202 public Base addChild(String name) throws FHIRException { 203 if (name.equals("reference")) { 204 throw new FHIRException("Cannot call addChild on a primitive type Reference.reference"); 205 } 206 else if (name.equals("display")) { 207 throw new FHIRException("Cannot call addChild on a primitive type Reference.display"); 208 } 209 else 210 return super.addChild(name); 211 } 212 213 public String fhirType() { 214 return "Reference"; 215 216 } 217 218 public Reference copy() { 219 Reference dst = new Reference(); 220 copyValues(dst); 221 dst.reference = reference == null ? null : reference.copy(); 222 dst.display = display == null ? null : display.copy(); 223 return dst; 224 } 225 226 protected Reference typedCopy() { 227 return copy(); 228 } 229 230 @Override 231 public boolean equalsDeep(Base other) { 232 if (!super.equalsDeep(other)) 233 return false; 234 if (!(other instanceof Reference)) 235 return false; 236 Reference o = (Reference) other; 237 return compareDeep(reference, o.reference, true) && compareDeep(display, o.display, true); 238 } 239 240 @Override 241 public boolean equalsShallow(Base other) { 242 if (!super.equalsShallow(other)) 243 return false; 244 if (!(other instanceof Reference)) 245 return false; 246 Reference o = (Reference) other; 247 return compareValues(reference, o.reference, true) && compareValues(display, o.display, true); 248 } 249 250 public boolean isEmpty() { 251 return super.isEmpty() && (reference == null || reference.isEmpty()) && (display == null || display.isEmpty()) 252 ; 253 } 254 255 256} 257