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