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 023import org.hl7.fhir.instance.model.api.IAnyResource; 024import org.hl7.fhir.instance.model.api.IBaseReference; 025import org.hl7.fhir.instance.model.api.IBaseResource; 026import org.hl7.fhir.instance.model.api.ICompositeType; 027import org.hl7.fhir.instance.model.api.IIdType; 028 029public abstract class BaseReference extends Type implements IBaseReference, ICompositeType { 030 031 /** 032 * This is not a part of the "wire format" resource, but can be changed/accessed by parsers 033 */ 034 private transient IBaseResource resource; 035 036 public BaseReference(String theReference) { 037 setReference(theReference); 038 } 039 040 public BaseReference(IdType theReference) { 041 if (theReference != null) { 042 setReference(theReference.getValue()); 043 } else { 044 setReference(null); 045 } 046 } 047 048 public BaseReference(IAnyResource theResource) { 049 resource = theResource; 050 } 051 052 public BaseReference() { 053 } 054 055 /** 056 * Retrieves the actual resource referenced by this reference. Note that the resource itself is not 057 * a part of the FHIR "wire format" and is never transmitted or receieved inline, but this property 058 * may be changed/accessed by parsers. 059 */ 060 public IBaseResource getResource() { 061 return resource; 062 } 063 064 @Override 065 public IIdType getReferenceElement() { 066 return new IdType(getReference()); 067 } 068 069 abstract String getReference(); 070 071 /** 072 * Sets the actual resource referenced by this reference. Note that the resource itself is not 073 * a part of the FHIR "wire format" and is never transmitted or receieved inline, but this property 074 * may be changed/accessed by parsers. 075 */ 076 public IBaseReference setResource(IBaseResource theResource) { 077 resource = theResource; 078 return this; 079 } 080 081 @Override 082 public boolean isEmpty() { 083 return resource == null && super.isEmpty(); 084 } 085 086}