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