001package org.hl7.fhir.dstu2.model; 002 003 004 005 006/* 007 Copyright (c) 2011+, HL7, Inc. 008 All rights reserved. 009 010 Redistribution and use in source and binary forms, with or without modification, 011 are permitted provided that the following conditions are met: 012 013 * Redistributions of source code must retain the above copyright notice, this 014 list of conditions and the following disclaimer. 015 * Redistributions in binary form must reproduce the above copyright notice, 016 this list of conditions and the following disclaimer in the documentation 017 and/or other materials provided with the distribution. 018 * Neither the name of HL7 nor the names of its contributors may be used to 019 endorse or promote products derived from this software without specific 020 prior written permission. 021 022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 023 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 024 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 025 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 026 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 027 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 028 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 029 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 030 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 031 POSSIBILITY OF SUCH DAMAGE. 032 033*/ 034 035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2 036import java.util.List; 037 038import ca.uhn.fhir.model.api.annotation.Child; 039import ca.uhn.fhir.model.api.annotation.DatatypeDef; 040import ca.uhn.fhir.model.api.annotation.Description; 041import org.hl7.fhir.instance.model.api.IAnyResource; 042import org.hl7.fhir.instance.model.api.IBaseReference; 043import org.hl7.fhir.instance.model.api.ICompositeType; 044import org.hl7.fhir.exceptions.FHIRException; 045import org.hl7.fhir.utilities.Utilities; 046/** 047 * A reference from one resource to another. 048 */ 049@DatatypeDef(name="Reference") 050public class Reference extends BaseReference implements IBaseReference, ICompositeType { 051 052 /** 053 * 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. 054 */ 055 @Child(name = "reference", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true) 056 @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." ) 057 protected StringType reference; 058 059 /** 060 * Plain text narrative that identifies the resource in addition to the resource reference. 061 */ 062 @Child(name = "display", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true) 063 @Description(shortDefinition="Text alternative for the resource", formalDefinition="Plain text narrative that identifies the resource in addition to the resource reference." ) 064 protected StringType display; 065 066 private static final long serialVersionUID = 22777321L; 067 068 /* 069 * Constructor 070 */ 071 public Reference() { 072 super(); 073 } 074 075 /** 076 * Constructor 077 * 078 * @param theReference The given reference string (e.g. "Patient/123" or "http://example.com/Patient/123") 079 */ 080 public Reference(String theReference) { 081 super(theReference); 082 } 083 084 /** 085 * Constructor 086 * 087 * @param theReference The given reference as an IdType (e.g. "Patient/123" or "http://example.com/Patient/123") 088 */ 089 public Reference(IdType theReference) { 090 super(theReference); 091 } 092 093 /** 094 * Constructor 095 * 096 * @param theResource The resource represented by this reference 097 */ 098 public Reference(IAnyResource theResource) { 099 super(theResource); 100 } 101 102 /** 103 * @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 104 */ 105 public boolean hasReferenceElement() { 106 return this.reference != null && !this.reference.isEmpty(); 107 } 108 109 public boolean hasReference() { 110 return this.reference != null && !this.reference.isEmpty(); 111 } 112 113 /** 114 * @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 115 */ 116 public Reference setReferenceElement(StringType value) { 117 this.reference = value; 118 return this; 119 } 120 121 /** 122 * @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. 123 */ 124 public String getReference() { 125 return this.reference == null ? null : this.reference.getValue(); 126 } 127 128 /** 129 * @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. 130 */ 131 public Reference setReference(String value) { 132 if (Utilities.noString(value)) 133 this.reference = null; 134 else { 135 if (this.reference == null) 136 this.reference = new StringType(); 137 this.reference.setValue(value); 138 } 139 return this; 140 } 141 142 /** 143 * @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 144 */ 145 public StringType getDisplayElement() { 146 if (this.display == null) 147 if (Configuration.errorOnAutoCreate()) 148 throw new Error("Attempt to auto-create Reference.display"); 149 else if (Configuration.doAutoCreate()) 150 this.display = new StringType(); // bb 151 return this.display; 152 } 153 154 public boolean hasDisplayElement() { 155 return this.display != null && !this.display.isEmpty(); 156 } 157 158 public boolean hasDisplay() { 159 return this.display != null && !this.display.isEmpty(); 160 } 161 162 /** 163 * @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 164 */ 165 public Reference setDisplayElement(StringType value) { 166 this.display = value; 167 return this; 168 } 169 170 /** 171 * @return Plain text narrative that identifies the resource in addition to the resource reference. 172 */ 173 public String getDisplay() { 174 return this.display == null ? null : this.display.getValue(); 175 } 176 177 /** 178 * @param value Plain text narrative that identifies the resource in addition to the resource reference. 179 */ 180 public Reference setDisplay(String value) { 181 if (Utilities.noString(value)) 182 this.display = null; 183 else { 184 if (this.display == null) 185 this.display = new StringType(); 186 this.display.setValue(value); 187 } 188 return this; 189 } 190 191 protected void listChildren(List<Property> childrenList) { 192 super.listChildren(childrenList); 193 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)); 194 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)); 195 } 196 197 @Override 198 public void setProperty(String name, Base value) throws FHIRException { 199 if (name.equals("reference")) 200 this.reference = castToString(value); // StringType 201 else if (name.equals("display")) 202 this.display = castToString(value); // StringType 203 else 204 super.setProperty(name, value); 205 } 206 207 @Override 208 public Base addChild(String name) throws FHIRException { 209 if (name.equals("reference")) { 210 throw new FHIRException("Cannot call addChild on a primitive type Reference.reference"); 211 } 212 else if (name.equals("display")) { 213 throw new FHIRException("Cannot call addChild on a primitive type Reference.display"); 214 } 215 else 216 return super.addChild(name); 217 } 218 219 public String fhirType() { 220 return "Reference"; 221 222 } 223 224 public Reference copy() { 225 Reference dst = new Reference(); 226 copyValues(dst); 227 dst.reference = reference == null ? null : reference.copy(); 228 dst.display = display == null ? null : display.copy(); 229 return dst; 230 } 231 232 protected Reference typedCopy() { 233 return copy(); 234 } 235 236 @Override 237 public boolean equalsDeep(Base other) { 238 if (!super.equalsDeep(other)) 239 return false; 240 if (!(other instanceof Reference)) 241 return false; 242 Reference o = (Reference) other; 243 return compareDeep(reference, o.reference, true) && compareDeep(display, o.display, true); 244 } 245 246 @Override 247 public boolean equalsShallow(Base other) { 248 if (!super.equalsShallow(other)) 249 return false; 250 if (!(other instanceof Reference)) 251 return false; 252 Reference o = (Reference) other; 253 return compareValues(reference, o.reference, true) && compareValues(display, o.display, true); 254 } 255 256 public boolean isEmpty() { 257 return super.isEmpty() && (reference == null || reference.isEmpty()) && (display == null || display.isEmpty()) 258 ; 259 } 260 261 262}