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