001package org.hl7.fhir.r4.model;
002
003
004
005/*
006  Copyright (c) 2011+, HL7, Inc.
007  All rights reserved.
008  
009  Redistribution and use in source and binary forms, with or without modification, 
010  are permitted provided that the following conditions are met:
011  
012   * Redistributions of source code must retain the above copyright notice, this 
013     list of conditions and the following disclaimer.
014   * Redistributions in binary form must reproduce the above copyright notice, 
015     this list of conditions and the following disclaimer in the documentation 
016     and/or other materials provided with the distribution.
017   * Neither the name of HL7 nor the names of its contributors may be used to 
018     endorse or promote products derived from this software without specific 
019     prior written permission.
020  
021  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
022  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
023  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
024  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
025  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
026  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
027  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
028  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
029  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
030  POSSIBILITY OF SUCH DAMAGE.
031  
032*/
033
034
035// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
036
037import java.util.*;
038
039import org.hl7.fhir.utilities.Utilities;
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.ChildOrder;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.DatatypeDef;
044import ca.uhn.fhir.model.api.annotation.Block;
045import org.hl7.fhir.instance.model.api.*;
046import org.hl7.fhir.exceptions.FHIRException;
047/**
048 * A reference from one resource to another.
049 */
050@DatatypeDef(name="Reference")
051public class Reference extends BaseReference implements IBaseReference, ICompositeType {
052
053    /**
054     * 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     */
056    @Child(name = "reference", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true)
057    @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." )
058    protected StringType reference;
059
060    /**
061     * 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.
062
063The 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     */
065    @Child(name = "type", type = {UriType.class}, order=1, min=0, max=1, modifier=false, summary=true)
066    @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)." )
067    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/resource-types")
068    protected UriType type;
069
070    /**
071     * 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     */
073    @Child(name = "identifier", type = {Identifier.class}, order=2, min=0, max=1, modifier=false, summary=true)
074    @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." )
075    protected Identifier identifier;
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=3, 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 = 784245805L;
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(IIdType 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 StringType getReferenceElement_() { 
124      if (this.reference == null)
125        if (Configuration.errorOnAutoCreate())
126          throw new Error("Attempt to auto-create Reference.reference");
127        else if (Configuration.doAutoCreate())
128          this.reference = new StringType(); // bb
129      return this.reference;
130    }
131
132    public boolean hasReferenceElement() { 
133      return this.reference != null && !this.reference.isEmpty();
134    }
135
136    public boolean hasReference() { 
137      return this.reference != null && !this.reference.isEmpty();
138    }
139
140    /**
141     * @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
142     */
143    public Reference setReferenceElement(StringType value) { 
144      this.reference = value;
145      return this;
146    }
147
148    /**
149     * @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.
150     */
151    public String getReference() { 
152      return this.reference == null ? null : this.reference.getValue();
153    }
154
155    /**
156     * @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.
157     */
158    public Reference setReference(String value) { 
159      if (Utilities.noString(value))
160        this.reference = null;
161      else {
162        if (this.reference == null)
163          this.reference = new StringType();
164        this.reference.setValue(value);
165      }
166      return this;
167    }
168
169    /**
170     * @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.
171
172The 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
173     */
174    public UriType getTypeElement() { 
175      if (this.type == null)
176        if (Configuration.errorOnAutoCreate())
177          throw new Error("Attempt to auto-create Reference.type");
178        else if (Configuration.doAutoCreate())
179          this.type = new UriType(); // bb
180      return this.type;
181    }
182
183    public boolean hasTypeElement() { 
184      return this.type != null && !this.type.isEmpty();
185    }
186
187    public boolean hasType() { 
188      return this.type != null && !this.type.isEmpty();
189    }
190
191    /**
192     * @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.
193
194The 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
195     */
196    public Reference setTypeElement(UriType value) { 
197      this.type = value;
198      return this;
199    }
200
201    /**
202     * @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.
203
204The 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).
205     */
206    public String getType() { 
207      return this.type == null ? null : this.type.getValue();
208    }
209
210    /**
211     * @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.
212
213The 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).
214     */
215    public Reference setType(String value) { 
216      if (Utilities.noString(value))
217        this.type = null;
218      else {
219        if (this.type == null)
220          this.type = new UriType();
221        this.type.setValue(value);
222      }
223      return this;
224    }
225
226    /**
227     * @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.)
228     */
229    public Identifier getIdentifier() { 
230      if (this.identifier == null)
231        if (Configuration.errorOnAutoCreate())
232          throw new Error("Attempt to auto-create Reference.identifier");
233        else if (Configuration.doAutoCreate())
234          this.identifier = new Identifier(); // cc
235      return this.identifier;
236    }
237
238    public boolean hasIdentifier() { 
239      return this.identifier != null && !this.identifier.isEmpty();
240    }
241
242    /**
243     * @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.)
244     */
245    public Reference setIdentifier(Identifier value) { 
246      this.identifier = value;
247      return this;
248    }
249
250    /**
251     * @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
252     */
253    public StringType getDisplayElement() { 
254      if (this.display == null)
255        if (Configuration.errorOnAutoCreate())
256          throw new Error("Attempt to auto-create Reference.display");
257        else if (Configuration.doAutoCreate())
258          this.display = new StringType(); // bb
259      return this.display;
260    }
261
262    public boolean hasDisplayElement() { 
263      return this.display != null && !this.display.isEmpty();
264    }
265
266    public boolean hasDisplay() { 
267      return this.display != null && !this.display.isEmpty();
268    }
269
270    /**
271     * @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
272     */
273    public Reference setDisplayElement(StringType value) { 
274      this.display = value;
275      return this;
276    }
277
278    /**
279     * @return Plain text narrative that identifies the resource in addition to the resource reference.
280     */
281    public String getDisplay() { 
282      return this.display == null ? null : this.display.getValue();
283    }
284
285    /**
286     * @param value Plain text narrative that identifies the resource in addition to the resource reference.
287     */
288    public Reference setDisplay(String value) { 
289      if (Utilities.noString(value))
290        this.display = null;
291      else {
292        if (this.display == null)
293          this.display = new StringType();
294        this.display.setValue(value);
295      }
296      return this;
297    }
298
299 /**
300   * Convenience setter which sets the reference to the complete {@link IIdType#getValue() value} of the given
301   * reference.
302   *
303   * @param theReference The reference, or <code>null</code>
304   * @return 
305   * @return Returns a reference to this
306   */
307  public Reference setReferenceElement(IIdType theReference) {
308    if (theReference != null) {
309      setReference(theReference.getValue());
310    } else {
311      setReference(null);
312    }
313    return this;
314  }
315      protected void listChildren(List<Property> children) {
316        super.listChildren(children);
317        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));
318        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));
319        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));
320        children.add(new Property("display", "string", "Plain text narrative that identifies the resource in addition to the resource reference.", 0, 1, display));
321      }
322
323      @Override
324      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
325        switch (_hash) {
326        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);
327        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);
328        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);
329        case 1671764162: /*display*/  return new Property("display", "string", "Plain text narrative that identifies the resource in addition to the resource reference.", 0, 1, display);
330        default: return super.getNamedProperty(_hash, _name, _checkValid);
331        }
332
333      }
334
335      @Override
336      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
337        switch (hash) {
338        case -925155509: /*reference*/ return this.reference == null ? new Base[0] : new Base[] {this.reference}; // StringType
339        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // UriType
340        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : new Base[] {this.identifier}; // Identifier
341        case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType
342        default: return super.getProperty(hash, name, checkValid);
343        }
344
345      }
346
347      @Override
348      public Base setProperty(int hash, String name, Base value) throws FHIRException {
349        switch (hash) {
350        case -925155509: // reference
351          this.reference = castToString(value); // StringType
352          return value;
353        case 3575610: // type
354          this.type = castToUri(value); // UriType
355          return value;
356        case -1618432855: // identifier
357          this.identifier = castToIdentifier(value); // Identifier
358          return value;
359        case 1671764162: // display
360          this.display = castToString(value); // StringType
361          return value;
362        default: return super.setProperty(hash, name, value);
363        }
364
365      }
366
367      @Override
368      public Base setProperty(String name, Base value) throws FHIRException {
369        if (name.equals("reference")) {
370          this.reference = castToString(value); // StringType
371        } else if (name.equals("type")) {
372          this.type = castToUri(value); // UriType
373        } else if (name.equals("identifier")) {
374          this.identifier = castToIdentifier(value); // Identifier
375        } else if (name.equals("display")) {
376          this.display = castToString(value); // StringType
377        } else
378          return super.setProperty(name, value);
379        return value;
380      }
381
382      @Override
383      public Base makeProperty(int hash, String name) throws FHIRException {
384        switch (hash) {
385        case -925155509:  return getReferenceElement_();
386        case 3575610:  return getTypeElement();
387        case -1618432855:  return getIdentifier(); 
388        case 1671764162:  return getDisplayElement();
389        default: return super.makeProperty(hash, name);
390        }
391
392      }
393
394      @Override
395      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
396        switch (hash) {
397        case -925155509: /*reference*/ return new String[] {"string"};
398        case 3575610: /*type*/ return new String[] {"uri"};
399        case -1618432855: /*identifier*/ return new String[] {"Identifier"};
400        case 1671764162: /*display*/ return new String[] {"string"};
401        default: return super.getTypesForProperty(hash, name);
402        }
403
404      }
405
406      @Override
407      public Base addChild(String name) throws FHIRException {
408        if (name.equals("reference")) {
409          throw new FHIRException("Cannot call addChild on a primitive type Reference.reference");
410        }
411        else if (name.equals("type")) {
412          throw new FHIRException("Cannot call addChild on a primitive type Reference.type");
413        }
414        else if (name.equals("identifier")) {
415          this.identifier = new Identifier();
416          return this.identifier;
417        }
418        else if (name.equals("display")) {
419          throw new FHIRException("Cannot call addChild on a primitive type Reference.display");
420        }
421        else
422          return super.addChild(name);
423      }
424
425  public String fhirType() {
426    return "Reference";
427
428  }
429
430      public Reference copy() {
431        Reference dst = new Reference();
432        copyValues(dst);
433        return dst;
434      }
435
436      public void copyValues(Reference dst) {
437        super.copyValues(dst);
438        dst.reference = reference == null ? null : reference.copy();
439        dst.type = type == null ? null : type.copy();
440        dst.identifier = identifier == null ? null : identifier.copy();
441        dst.display = display == null ? null : display.copy();
442      }
443
444      protected Reference typedCopy() {
445        return copy();
446      }
447
448      @Override
449      public boolean equalsDeep(Base other_) {
450        if (!super.equalsDeep(other_))
451          return false;
452        if (!(other_ instanceof Reference))
453          return false;
454        Reference o = (Reference) other_;
455        return compareDeep(reference, o.reference, true) && compareDeep(type, o.type, true) && compareDeep(identifier, o.identifier, true)
456           && compareDeep(display, o.display, true);
457      }
458
459      @Override
460      public boolean equalsShallow(Base other_) {
461        if (!super.equalsShallow(other_))
462          return false;
463        if (!(other_ instanceof Reference))
464          return false;
465        Reference o = (Reference) other_;
466        return compareValues(reference, o.reference, true) && compareValues(type, o.type, true) && compareValues(display, o.display, true)
467          ;
468      }
469
470      public boolean isEmpty() {
471        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(reference, type, identifier
472          , display);
473      }
474
475
476}