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    public String getReference() { 
133      return this.reference == null ? null : this.reference.getValue();
134    }
135
136    /**
137     * @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.
138     */
139    public Reference setReference(String value) { 
140      if (Utilities.noString(value))
141        this.reference = null;
142      else {
143        if (this.reference == null)
144          this.reference = new StringType();
145        this.reference.setValue(value);
146      }
147      return this;
148    }
149
150    /**
151     * @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
152     */
153    public StringType getDisplayElement() { 
154      if (this.display == null)
155        if (Configuration.errorOnAutoCreate())
156          throw new Error("Attempt to auto-create Reference.display");
157        else if (Configuration.doAutoCreate())
158          this.display = new StringType(); // bb
159      return this.display;
160    }
161
162    public boolean hasDisplayElement() { 
163      return this.display != null && !this.display.isEmpty();
164    }
165
166    public boolean hasDisplay() { 
167      return this.display != null && !this.display.isEmpty();
168    }
169
170    /**
171     * @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
172     */
173    public Reference setDisplayElement(StringType value) { 
174      this.display = value;
175      return this;
176    }
177
178    /**
179     * @return Plain text narrative that identifies the resource in addition to the resource reference.
180     */
181    public String getDisplay() { 
182      return this.display == null ? null : this.display.getValue();
183    }
184
185    /**
186     * @param value Plain text narrative that identifies the resource in addition to the resource reference.
187     */
188    public Reference setDisplay(String value) { 
189      if (Utilities.noString(value))
190        this.display = null;
191      else {
192        if (this.display == null)
193          this.display = new StringType();
194        this.display.setValue(value);
195      }
196      return this;
197    }
198
199 /**
200   * Convenience setter which sets the reference to the complete {@link IIdType#getValue() value} of the given
201   * reference.
202   *
203   * @param theReference The reference, or <code>null</code>
204   * @return 
205   * @return Returns a reference to this
206   */
207  public Reference setReferenceElement(IIdType theReference) {
208    if (theReference != null) {
209      setReference(theReference.getValue());
210    } else {
211      setReference(null);
212    }
213    return this;
214  }
215      protected void listChildren(List<Property> childrenList) {
216        super.listChildren(childrenList);
217        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));
218        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));
219      }
220
221      @Override
222      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
223        switch (hash) {
224        case -925155509: /*reference*/ return this.reference == null ? new Base[0] : new Base[] {this.reference}; // StringType
225        case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType
226        default: return super.getProperty(hash, name, checkValid);
227        }
228
229      }
230
231      @Override
232      public void setProperty(int hash, String name, Base value) throws FHIRException {
233        switch (hash) {
234        case -925155509: // reference
235          this.reference = castToString(value); // StringType
236          break;
237        case 1671764162: // display
238          this.display = castToString(value); // StringType
239          break;
240        default: super.setProperty(hash, name, value);
241        }
242
243      }
244
245      @Override
246      public void setProperty(String name, Base value) throws FHIRException {
247        if (name.equals("reference"))
248          this.reference = castToString(value); // StringType
249        else if (name.equals("display"))
250          this.display = castToString(value); // StringType
251        else
252          super.setProperty(name, value);
253      }
254
255      @Override
256      public Base makeProperty(int hash, String name) throws FHIRException {
257        switch (hash) {
258        case -925155509: throw new FHIRException("Cannot make property reference as it is not a complex type"); // StringType
259        case 1671764162: throw new FHIRException("Cannot make property display as it is not a complex type"); // StringType
260        default: return super.makeProperty(hash, name);
261        }
262
263      }
264
265      @Override
266      public Base addChild(String name) throws FHIRException {
267        if (name.equals("reference")) {
268          throw new FHIRException("Cannot call addChild on a primitive type Reference.reference");
269        }
270        else if (name.equals("display")) {
271          throw new FHIRException("Cannot call addChild on a primitive type Reference.display");
272        }
273        else
274          return super.addChild(name);
275      }
276
277  public String fhirType() {
278    return "Reference";
279
280  }
281
282      public Reference copy() {
283        Reference dst = new Reference();
284        copyValues(dst);
285        dst.reference = reference == null ? null : reference.copy();
286        dst.display = display == null ? null : display.copy();
287        return dst;
288      }
289
290      protected Reference typedCopy() {
291        return copy();
292      }
293
294      @Override
295      public boolean equalsDeep(Base other) {
296        if (!super.equalsDeep(other))
297          return false;
298        if (!(other instanceof Reference))
299          return false;
300        Reference o = (Reference) other;
301        return compareDeep(reference, o.reference, true) && compareDeep(display, o.display, true);
302      }
303
304      @Override
305      public boolean equalsShallow(Base other) {
306        if (!super.equalsShallow(other))
307          return false;
308        if (!(other instanceof Reference))
309          return false;
310        Reference o = (Reference) other;
311        return compareValues(reference, o.reference, true) && compareValues(display, o.display, true);
312      }
313
314      public boolean isEmpty() {
315        return super.isEmpty() && (reference == null || reference.isEmpty()) && (display == null || display.isEmpty())
316          ;
317      }
318
319
320}
321