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