View Javadoc
1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  package ca.uhn.fhir.model.dstu.composite;
18  
19  /*
20   * #%L
21   * HAPI FHIR - Core Library
22   * %%
23   * Copyright (C) 2014 University Health Network
24   * %%
25   * Licensed under the Apache License, Version 2.0 (the "License");
26   * you may not use this file except in compliance with the License.
27   * You may obtain a copy of the License at
28   * 
29   *      http://www.apache.org/licenses/LICENSE-2.0
30   * 
31   * Unless required by applicable law or agreed to in writing, software
32   * distributed under the License is distributed on an "AS IS" BASIS,
33   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34   * See the License for the specific language governing permissions and
35   * limitations under the License.
36   * #L%
37   */
38  
39  import java.util.List;
40  
41  import ca.uhn.fhir.model.api.ICompositeDatatype;
42  import ca.uhn.fhir.model.api.IElement;
43  import ca.uhn.fhir.model.api.IResource;
44  import ca.uhn.fhir.model.api.annotation.Child;
45  import ca.uhn.fhir.model.api.annotation.DatatypeDef;
46  import ca.uhn.fhir.model.api.annotation.Description;
47  import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
48  import ca.uhn.fhir.model.primitive.IdDt;
49  import ca.uhn.fhir.model.primitive.StringDt;
50  
51  /**
52   * HAPI/FHIR <b>ResourceReferenceDt</b> Datatype
53   * (A reference from one resource to another)
54   *
55   * <p>
56   * <b>Definition:</b>
57   * A reference from one resource to another
58   * </p> 
59   *
60   * <p>
61   * <b>Requirements:</b>
62   * 
63   * </p> 
64   */
65  @DatatypeDef(name="ResourceReferenceDt") 
66  public class ResourceReferenceDt
67          extends  BaseResourceReferenceDt         implements ICompositeDatatype
68  {
69  
70  	/**
71  	 * Constructor
72  	 */
73  	public ResourceReferenceDt() {
74  		// nothing
75  	}
76  
77  	/**
78  	 * Constructor which creates a resource reference containing the actual resource in question.
79  	 * <p>
80  	 * <b> When using this in a server:</b> Generally if this is serialized, it will be serialized as a contained
81  	 * resource, so this should not be used if the intent is not to actually supply the referenced resource. This is not
82  	 * a hard-and-fast rule however, as the server can be configured to not serialized this resource, or to load an ID
83  	 * and contain even if this constructor is not used.
84  	 * </p>
85  	 * 
86  	 * @param theResource
87  	 *            The resource instance
88  	 */
89  	public ResourceReferenceDt(IResource theResource) {
90  		super(theResource);
91  	}
92  
93  	/**
94  	 * Constructor which accepts a reference directly (this can be an ID, a partial/relative URL or a complete/absolute
95  	 * URL)
96  	 * 
97  	 * @param theId
98  	 *            The reference itself
99  	 */
100 	public ResourceReferenceDt(String theId) {
101 		setReference(new IdDt(theId));
102 	}
103 
104 	/**
105 	 * Constructor which accepts a reference directly (this can be an ID, a partial/relative URL or a complete/absolute
106 	 * URL)
107 	 * 
108 	 * @param theId
109 	 *            The reference itself
110 	 */
111 	public ResourceReferenceDt(IdDt theResourceId) {
112 		setReference(theResourceId);
113 	}
114 
115 	@Child(name="reference", type=IdDt.class, order=0, min=0, max=1)	
116 	@Description(
117 		shortDefinition="Relative, internal or absolute URL reference",
118 		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"
119 	)
120 	private IdDt myReference;
121 	
122 	@Child(name="display", type=StringDt.class, order=1, min=0, max=1)	
123 	@Description(
124 		shortDefinition="Text alternative for the resource",
125 		formalDefinition="Plain text narrative that identifies the resource in addition to the resource reference"
126 	)
127 	private StringDt myDisplay;
128 	
129 
130 	@Override
131 	public boolean isEmpty() {
132 		return super.isBaseEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(  myReference,  myDisplay);
133 	}
134 	
135 	@Override
136 	public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) {
137 		return ca.uhn.fhir.util.ElementUtil.allPopulatedChildElements(theType, myReference, myDisplay);
138 	}
139 
140 	/**
141 	 * Gets the value(s) for <b>reference</b> (Relative, internal or absolute URL reference).
142 	 * creating it if it does
143 	 * not exist. Will not return <code>null</code>.
144 	 *
145      * <p>
146      * <b>Definition:</b>
147      * 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
148      * </p> 
149 	 */
150 	public IdDt getReference() {  
151 		if (myReference == null) {
152 			myReference = new IdDt();
153 		}
154 		return myReference;
155 	}
156 
157 	/**
158 	 * Sets the value(s) for <b>reference</b> (Relative, internal or absolute URL reference)
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 ResourceReferenceDt setReference(IdDt theValue) {
166 		myReference = theValue;
167 		return this;
168 	}
169 
170  	/**
171 	 * Sets the value for <b>reference</b> (Relative, internal or absolute URL reference)
172 	 *
173      * <p>
174      * <b>Definition:</b>
175      * 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
176      * </p> 
177 	 */
178 	public ResourceReferenceDt setReference( String theId) {
179 		myReference = new IdDt(theId); 
180 		return this; 
181 	}
182 
183  
184 	/**
185 	 * Gets the value(s) for <b>display</b> (Text alternative for the resource).
186 	 * creating it if it does
187 	 * not exist. Will not return <code>null</code>.
188 	 *
189      * <p>
190      * <b>Definition:</b>
191      * Plain text narrative that identifies the resource in addition to the resource reference
192      * </p> 
193 	 */
194 	public StringDt getDisplay() {  
195 		if (myDisplay == null) {
196 			myDisplay = new StringDt();
197 		}
198 		return myDisplay;
199 	}
200 
201 	/**
202 	 * Sets the value(s) for <b>display</b> (Text alternative for the resource)
203 	 *
204      * <p>
205      * <b>Definition:</b>
206      * Plain text narrative that identifies the resource in addition to the resource reference
207      * </p> 
208 	 */
209 	public ResourceReferenceDt setDisplay(StringDt theValue) {
210 		myDisplay = theValue;
211 		return this;
212 	}
213 
214  	/**
215 	 * Sets the value for <b>display</b> (Text alternative for the resource)
216 	 *
217      * <p>
218      * <b>Definition:</b>
219      * Plain text narrative that identifies the resource in addition to the resource reference
220      * </p> 
221 	 */
222 	public ResourceReferenceDt setDisplay( String theString) {
223 		myDisplay = new StringDt(theString); 
224 		return this; 
225 	}
226 
227  
228 
229 
230 }