001package org.hl7.fhir.r4.model;
002
003import org.hl7.fhir.instance.model.api.IAnyResource;
004import org.hl7.fhir.instance.model.api.IBaseReference;
005import org.hl7.fhir.instance.model.api.IBaseResource;
006import org.hl7.fhir.instance.model.api.ICompositeType;
007import org.hl7.fhir.instance.model.api.IIdType;
008
009public abstract class BaseReference extends Type implements IBaseReference, ICompositeType {
010
011    /**
012     * This is not a part of the "wire format" resource, but can be changed/accessed by parsers
013     */
014    private transient IBaseResource resource;
015
016        public BaseReference(String theReference) {
017        setReference(theReference);
018        }
019
020    public BaseReference(IIdType theReference) {
021        if (theReference != null) {
022                setReference(theReference.getValue());
023        } else {
024                setReference(null);
025        }
026    }
027
028        public BaseReference(IAnyResource theResource) {
029                resource = theResource;
030        }
031
032        public BaseReference() {
033        }
034
035        /**
036     * Retrieves the actual resource referenced by this reference. Note that the resource itself is not
037     * a part of the FHIR "wire format" and is never transmitted or receieved inline, but this property
038     * may be changed/accessed by parsers.
039     */
040    public IBaseResource getResource() {
041        return resource;
042    }
043
044    @Override
045        public IIdType getReferenceElement() {
046                return new IdType(getReference());
047        }
048
049    abstract String getReference();
050
051    /**
052     * Sets the actual resource referenced by this reference. Note that the resource itself is not
053     * a part of the FHIR "wire format" and is never transmitted or receieved inline, but this property
054     * may be changed/accessed by parsers.
055     */
056    public void setResource(IBaseResource theResource) {
057        resource = theResource;
058    }
059
060    @Override
061        public boolean isEmpty() {
062                return resource == null && super.isEmpty();
063        }
064
065}