001/*
002 * #%L
003 * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
004 * %%
005 * Copyright (C) 2014 - 2023 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036package ca.uhn.fhir.model.dstu2.composite;
037
038import java.util.List;
039
040import org.hl7.fhir.instance.model.api.IIdType;
041
042import ca.uhn.fhir.model.api.ICompositeDatatype;
043import ca.uhn.fhir.model.api.IElement;
044import ca.uhn.fhir.model.api.IResource;
045import ca.uhn.fhir.model.api.annotation.Child;
046import ca.uhn.fhir.model.api.annotation.DatatypeDef;
047import ca.uhn.fhir.model.api.annotation.Description;
048import ca.uhn.fhir.model.api.annotation.SimpleSetter;
049import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
050import ca.uhn.fhir.model.primitive.IdDt;
051import ca.uhn.fhir.model.primitive.StringDt;
052
053/**
054 * HAPI/FHIR <b>ResourceReferenceDt</b> Datatype
055 * (A reference from one resource to another)
056 *
057 * <p>
058 * <b>Definition:</b>
059 * A reference from one resource to another
060 * </p> 
061 *
062 * <p>
063 * <b>Requirements:</b>
064 * 
065 * </p> 
066 */
067@DatatypeDef(name="reference") 
068public class ResourceReferenceDt
069        extends  BaseResourceReferenceDt         implements ICompositeDatatype
070{
071
072        /**
073         * Constructor
074         */
075        public ResourceReferenceDt() {
076                // nothing
077        }
078
079        /**
080         * Constructor which creates a resource reference containing the actual resource in question.
081         * <p>
082         * <b> When using this in a server:</b> Generally if this is serialized, it will be serialized as a contained
083         * resource, so this should not be used if the intent is not to actually supply the referenced resource. This is not
084         * a hard-and-fast rule however, as the server can be configured to not serialized this resource, or to load an ID
085         * and contain even if this constructor is not used.
086         * </p>
087         * 
088         * @param theResource
089         *            The resource instance
090         */
091        @SimpleSetter()
092        public ResourceReferenceDt(IResource theResource) {
093                super(theResource);
094        }
095
096        /**
097         * Constructor which accepts a reference directly (this can be an ID, a partial/relative URL or a complete/absolute
098         * URL)
099         * 
100         * @param theId
101         *            The reference itself
102         */
103        public ResourceReferenceDt(String theId) {
104                setReference(new IdDt(theId));
105        }
106
107        /**
108         * Constructor which accepts a reference directly (this can be an ID, a partial/relative URL or a complete/absolute
109         * URL)
110         * 
111         * @param theResourceId
112         *            The reference itself
113         */
114        public ResourceReferenceDt(IdDt theResourceId) {
115                setReference(theResourceId);
116        }
117
118        /**
119         * Constructor which accepts a reference directly (this can be an ID, a partial/relative URL or a complete/absolute
120         * URL)
121         * 
122         * @param theResourceId
123         *            The reference itself
124         */
125        public ResourceReferenceDt(IIdType theResourceId) {
126                setReference(theResourceId);
127        }
128
129        @Child(name="reference", type=IdDt.class, order=0, min=0, max=1)        
130        @Description(
131                shortDefinition="Relative, internal or absolute URL reference",
132                formalDefinition="A reference to a location at which the other resource is found. The reference may 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"
133        )
134        private IdDt myReference;
135        
136        @Child(name="display", type=StringDt.class, order=1, min=0, max=1)      
137        @Description(
138                shortDefinition="Text alternative for the resource",
139                formalDefinition="Plain text narrative that identifies the resource in addition to the resource reference"
140        )
141        private StringDt myDisplay;
142        
143
144        @Override
145        public boolean isEmpty() {
146                return super.isBaseEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(  myReference,  myDisplay);
147        }
148        
149        @Override
150        public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) {
151                return ca.uhn.fhir.util.ElementUtil.allPopulatedChildElements(theType, myReference, myDisplay);
152        }
153
154        /**
155         * Gets the value(s) for <b>reference</b> (Relative, internal or absolute URL reference).
156         * creating it if it does
157         * not exist. Will not return <code>null</code>.
158         *
159     * <p>
160     * <b>Definition:</b>
161     * A reference to a location at which the other resource is found. The reference may 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
162     * </p> 
163         */
164        @Override
165        public IdDt getReference() {
166                if (myReference == null) {
167                        myReference = new IdDt();
168                }
169                return myReference;
170        }
171
172        @Override
173        public IdDt getReferenceElement() {
174                return getReference();
175        }
176
177
178        /**
179         * Sets the value(s) for <b>reference</b> (Relative, internal or absolute URL reference)
180         *
181     * <p>
182     * <b>Definition:</b>
183     * A reference to a location at which the other resource is found. The reference may 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
184     * </p> 
185         */
186        @Override
187        public ResourceReferenceDt setReference(IdDt theValue) {
188                myReference = theValue;
189                return this;
190        }
191
192        /**
193         * Sets the value for <b>reference</b> (Relative, internal or absolute URL reference)
194         *
195     * <p>
196     * <b>Definition:</b>
197     * A reference to a location at which the other resource is found. The reference may 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
198     * </p> 
199         */
200        @Override
201        public ResourceReferenceDt setReference(String theId) {
202                myReference = new IdDt(theId); 
203                return this; 
204        }
205
206 
207        /**
208         * Gets the value(s) for <b>display</b> (Text alternative for the resource).
209         * creating it if it does
210         * not exist. Will not return <code>null</code>.
211         *
212     * <p>
213     * <b>Definition:</b>
214     * Plain text narrative that identifies the resource in addition to the resource reference
215     * </p> 
216         */
217        public StringDt getDisplay() {  
218                if (myDisplay == null) {
219                        myDisplay = new StringDt();
220                }
221                return myDisplay;
222        }
223
224        /**
225         * Sets the value(s) for <b>display</b> (Text alternative for the resource)
226         *
227     * <p>
228     * <b>Definition:</b>
229     * Plain text narrative that identifies the resource in addition to the resource reference
230     * </p> 
231         */
232        public ResourceReferenceDt setDisplay(StringDt theValue) {
233                myDisplay = theValue;
234                return this;
235        }
236
237        /**
238         * Sets the value for <b>display</b> (Text alternative for the resource)
239         *
240     * <p>
241     * <b>Definition:</b>
242     * Plain text narrative that identifies the resource in addition to the resource reference
243     * </p> 
244         */
245        @Override
246        public ResourceReferenceDt setDisplay(String theString) {
247                myDisplay = new StringDt(theString); 
248                return this; 
249        }
250
251        @Override
252        public StringDt getDisplayElement() {
253                return getDisplay();
254        }
255
256 
257
258
259}