001package org.hl7.fhir.r4.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 Thu, Dec 27, 2018 10:06-0500 for FHIR v4.0.0
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import ca.uhn.fhir.model.api.annotation.Child;
038import ca.uhn.fhir.model.api.annotation.ChildOrder;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.DatatypeDef;
041import ca.uhn.fhir.model.api.annotation.Block;
042import org.hl7.fhir.instance.model.api.*;
043import org.hl7.fhir.exceptions.FHIRException;
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 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.
052     */
053    @Child(name = "reference", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true)
054    @Description(shortDefinition="Literal reference, Relative, internal or absolute URL", 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." )
055    protected StringType reference;
056
057    /**
058     * The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.
059
060The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).
061     */
062    @Child(name = "type", type = {UriType.class}, order=1, min=0, max=1, modifier=false, summary=true)
063    @Description(shortDefinition="Type the reference refers to (e.g. \"Patient\")", formalDefinition="The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.\n\nThe type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. \"Patient\" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources)." )
064    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/resource-types")
065    protected UriType type;
066
067    /**
068     * An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.
069     */
070    @Child(name = "identifier", type = {Identifier.class}, order=2, min=0, max=1, modifier=false, summary=true)
071    @Description(shortDefinition="Logical reference, when literal reference is not known", formalDefinition="An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference." )
072    protected Identifier identifier;
073
074    /**
075     * Plain text narrative that identifies the resource in addition to the resource reference.
076     */
077    @Child(name = "display", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true)
078    @Description(shortDefinition="Text alternative for the resource", formalDefinition="Plain text narrative that identifies the resource in addition to the resource reference." )
079    protected StringType display;
080
081    private static final long serialVersionUID = 784245805L;
082
083  /**
084   * Constructor
085   */
086    public Reference() {
087      super();
088    }
089
090    /**
091     * Constructor
092     * 
093     * @param theReference The given reference string (e.g. "Patient/123" or "http://example.com/Patient/123")
094     */
095    public Reference(String theReference) {
096      super(theReference);
097    }
098
099    /**
100     * Constructor
101     * 
102     * @param theReference The given reference as an IdType (e.g. "Patient/123" or "http://example.com/Patient/123")
103     */
104    public Reference(IIdType theReference) {
105      super(theReference);
106    }
107
108    /**
109     * Constructor
110     * 
111     * @param theResource The resource represented by this reference
112     */
113    public Reference(IAnyResource theResource) {
114      super(theResource);
115    }
116
117    /**
118     * @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
119     */
120    public StringType getReferenceElement_() { 
121      if (this.reference == null)
122        if (Configuration.errorOnAutoCreate())
123          throw new Error("Attempt to auto-create Reference.reference");
124        else if (Configuration.doAutoCreate())
125          this.reference = new StringType(); // bb
126      return this.reference;
127    }
128
129    public boolean hasReferenceElement() { 
130      return this.reference != null && !this.reference.isEmpty();
131    }
132
133    public boolean hasReference() { 
134      return this.reference != null && !this.reference.isEmpty();
135    }
136
137    /**
138     * @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
139     */
140    public Reference setReferenceElement(StringType value) { 
141      this.reference = value;
142      return this;
143    }
144
145    /**
146     * @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.
147     */
148    @Override
149    public String getReference() {
150      return this.reference == null ? null : this.reference.getValue();
151    }
152
153    /**
154     * @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.
155     */
156    public Reference setReference(String value) { 
157      if (Utilities.noString(value))
158        this.reference = null;
159      else {
160        if (this.reference == null)
161          this.reference = new StringType();
162        this.reference.setValue(value);
163      }
164      return this;
165    }
166
167    /**
168     * @return {@link #type} (The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.
169
170The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
171     */
172    public UriType getTypeElement() { 
173      if (this.type == null)
174        if (Configuration.errorOnAutoCreate())
175          throw new Error("Attempt to auto-create Reference.type");
176        else if (Configuration.doAutoCreate())
177          this.type = new UriType(); // bb
178      return this.type;
179    }
180
181    public boolean hasTypeElement() { 
182      return this.type != null && !this.type.isEmpty();
183    }
184
185    public boolean hasType() { 
186      return this.type != null && !this.type.isEmpty();
187    }
188
189    /**
190     * @param value {@link #type} (The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.
191
192The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
193     */
194    public Reference setTypeElement(UriType value) { 
195      this.type = value;
196      return this;
197    }
198
199    /**
200     * @return The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.
201
202The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).
203     */
204    public String getType() { 
205      return this.type == null ? null : this.type.getValue();
206    }
207
208    /**
209     * @param value The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.
210
211The type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. "Patient" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).
212     */
213    public Reference setType(String value) { 
214      if (Utilities.noString(value))
215        this.type = null;
216      else {
217        if (this.type == null)
218          this.type = new UriType();
219        this.type.setValue(value);
220      }
221      return this;
222    }
223
224    /**
225     * @return {@link #identifier} (An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.)
226     */
227    public Identifier getIdentifier() { 
228      if (this.identifier == null)
229        if (Configuration.errorOnAutoCreate())
230          throw new Error("Attempt to auto-create Reference.identifier");
231        else if (Configuration.doAutoCreate())
232          this.identifier = new Identifier(); // cc
233      return this.identifier;
234    }
235
236    public boolean hasIdentifier() { 
237      return this.identifier != null && !this.identifier.isEmpty();
238    }
239
240    /**
241     * @param value {@link #identifier} (An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.)
242     */
243    public Reference setIdentifier(Identifier value) { 
244      this.identifier = value;
245      return this;
246    }
247
248    /**
249     * @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
250     */
251    public StringType getDisplayElement() { 
252      if (this.display == null)
253        if (Configuration.errorOnAutoCreate())
254          throw new Error("Attempt to auto-create Reference.display");
255        else if (Configuration.doAutoCreate())
256          this.display = new StringType(); // bb
257      return this.display;
258    }
259
260    public boolean hasDisplayElement() { 
261      return this.display != null && !this.display.isEmpty();
262    }
263
264    public boolean hasDisplay() { 
265      return this.display != null && !this.display.isEmpty();
266    }
267
268    /**
269     * @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
270     */
271    public Reference setDisplayElement(StringType value) { 
272      this.display = value;
273      return this;
274    }
275
276    /**
277     * @return Plain text narrative that identifies the resource in addition to the resource reference.
278     */
279    public String getDisplay() { 
280      return this.display == null ? null : this.display.getValue();
281    }
282
283    /**
284     * @param value Plain text narrative that identifies the resource in addition to the resource reference.
285     */
286    public Reference setDisplay(String value) { 
287      if (Utilities.noString(value))
288        this.display = null;
289      else {
290        if (this.display == null)
291          this.display = new StringType();
292        this.display.setValue(value);
293      }
294      return this;
295    }
296
297 /**
298   * Convenience setter which sets the reference to the complete {@link IIdType#getValue() value} of the given
299   * reference.
300   *
301   * @param theReference The reference, or <code>null</code>
302   * @return 
303   * @return Returns a reference to this
304   */
305  public Reference setReferenceElement(IIdType theReference) {
306    if (theReference != null) {
307      setReference(theReference.getValue());
308    } else {
309      setReference(null);
310    }
311    return this;
312  }
313      protected void listChildren(List<Property> children) {
314        super.listChildren(children);
315        children.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, 1, reference));
316        children.add(new Property("type", "uri", "The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.\n\nThe type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. \"Patient\" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).", 0, 1, type));
317        children.add(new Property("identifier", "Identifier", "An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.", 0, 1, identifier));
318        children.add(new Property("display", "string", "Plain text narrative that identifies the resource in addition to the resource reference.", 0, 1, display));
319      }
320
321      @Override
322      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
323        switch (_hash) {
324        case -925155509: /*reference*/  return 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, 1, reference);
325        case 3575610: /*type*/  return new Property("type", "uri", "The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.\n\nThe type is the Canonical URL of Resource Definition that is the type this reference refers to. References are URLs that are relative to http://hl7.org/fhir/StructureDefinition/ e.g. \"Patient\" is a reference to http://hl7.org/fhir/StructureDefinition/Patient. Absolute URLs are only allowed for logical models (and can only be used in references in logical models, not resources).", 0, 1, type);
326        case -1618432855: /*identifier*/  return new Property("identifier", "Identifier", "An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.", 0, 1, identifier);
327        case 1671764162: /*display*/  return new Property("display", "string", "Plain text narrative that identifies the resource in addition to the resource reference.", 0, 1, display);
328        default: return super.getNamedProperty(_hash, _name, _checkValid);
329        }
330
331      }
332
333      @Override
334      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
335        switch (hash) {
336        case -925155509: /*reference*/ return this.reference == null ? new Base[0] : new Base[] {this.reference}; // StringType
337        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // UriType
338        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : new Base[] {this.identifier}; // Identifier
339        case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType
340        default: return super.getProperty(hash, name, checkValid);
341        }
342
343      }
344
345      @Override
346      public Base setProperty(int hash, String name, Base value) throws FHIRException {
347        switch (hash) {
348        case -925155509: // reference
349          this.reference = castToString(value); // StringType
350          return value;
351        case 3575610: // type
352          this.type = castToUri(value); // UriType
353          return value;
354        case -1618432855: // identifier
355          this.identifier = castToIdentifier(value); // Identifier
356          return value;
357        case 1671764162: // display
358          this.display = castToString(value); // StringType
359          return value;
360        default: return super.setProperty(hash, name, value);
361        }
362
363      }
364
365      @Override
366      public Base setProperty(String name, Base value) throws FHIRException {
367        if (name.equals("reference")) {
368          this.reference = castToString(value); // StringType
369        } else if (name.equals("type")) {
370          this.type = castToUri(value); // UriType
371        } else if (name.equals("identifier")) {
372          this.identifier = castToIdentifier(value); // Identifier
373        } else if (name.equals("display")) {
374          this.display = castToString(value); // StringType
375        } else
376          return super.setProperty(name, value);
377        return value;
378      }
379
380      @Override
381      public Base makeProperty(int hash, String name) throws FHIRException {
382        switch (hash) {
383        case -925155509:  return (Base) getReferenceElement();
384        case 3575610:  return getTypeElement();
385        case -1618432855:  return getIdentifier(); 
386        case 1671764162:  return getDisplayElement();
387        default: return super.makeProperty(hash, name);
388        }
389
390      }
391
392      @Override
393      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
394        switch (hash) {
395        case -925155509: /*reference*/ return new String[] {"string"};
396        case 3575610: /*type*/ return new String[] {"uri"};
397        case -1618432855: /*identifier*/ return new String[] {"Identifier"};
398        case 1671764162: /*display*/ return new String[] {"string"};
399        default: return super.getTypesForProperty(hash, name);
400        }
401
402      }
403
404      @Override
405      public Base addChild(String name) throws FHIRException {
406        if (name.equals("reference")) {
407          throw new FHIRException("Cannot call addChild on a primitive type Reference.reference");
408        }
409        else if (name.equals("type")) {
410          throw new FHIRException("Cannot call addChild on a primitive type Reference.type");
411        }
412        else if (name.equals("identifier")) {
413          this.identifier = new Identifier();
414          return this.identifier;
415        }
416        else if (name.equals("display")) {
417          throw new FHIRException("Cannot call addChild on a primitive type Reference.display");
418        }
419        else
420          return super.addChild(name);
421      }
422
423  public String fhirType() {
424    return "Reference";
425
426  }
427
428      public Reference copy() {
429        Reference dst = new Reference();
430        copyValues(dst);
431        dst.reference = reference == null ? null : reference.copy();
432        dst.type = type == null ? null : type.copy();
433        dst.identifier = identifier == null ? null : identifier.copy();
434        dst.display = display == null ? null : display.copy();
435        return dst;
436      }
437
438      protected Reference typedCopy() {
439        return copy();
440      }
441
442      @Override
443      public boolean equalsDeep(Base other_) {
444        if (!super.equalsDeep(other_))
445          return false;
446        if (!(other_ instanceof Reference))
447          return false;
448        Reference o = (Reference) other_;
449        return compareDeep(reference, o.reference, true) && compareDeep(type, o.type, true) && compareDeep(identifier, o.identifier, true)
450           && compareDeep(display, o.display, true);
451      }
452
453      @Override
454      public boolean equalsShallow(Base other_) {
455        if (!super.equalsShallow(other_))
456          return false;
457        if (!(other_ instanceof Reference))
458          return false;
459        Reference o = (Reference) other_;
460        return compareValues(reference, o.reference, true) && compareValues(type, o.type, true) && compareValues(display, o.display, true)
461          ;
462      }
463
464      public boolean isEmpty() {
465        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(reference, type, identifier
466          , display);
467      }
468
469
470}
471