View Javadoc
1   package ca.uhn.fhir.rest.client;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import java.util.List;
24  import java.util.Map;
25  
26  import ca.uhn.fhir.model.api.Bundle;
27  import ca.uhn.fhir.model.api.IQueryParameterType;
28  import ca.uhn.fhir.model.api.IResource;
29  import ca.uhn.fhir.model.dstu.resource.Conformance;
30  import ca.uhn.fhir.model.primitive.DateTimeDt;
31  import ca.uhn.fhir.model.primitive.IdDt;
32  import ca.uhn.fhir.model.primitive.UriDt;
33  import ca.uhn.fhir.rest.api.MethodOutcome;
34  import ca.uhn.fhir.rest.client.api.IRestfulClient;
35  import ca.uhn.fhir.rest.gclient.ICreate;
36  import ca.uhn.fhir.rest.gclient.IDelete;
37  import ca.uhn.fhir.rest.gclient.IGetPage;
38  import ca.uhn.fhir.rest.gclient.IGetTags;
39  import ca.uhn.fhir.rest.gclient.ITransaction;
40  import ca.uhn.fhir.rest.gclient.IUntypedQuery;
41  import ca.uhn.fhir.rest.gclient.IUpdate;
42  
43  public interface IGenericClient {
44  	/**
45  	 * Retrieves and returns the server conformance statement
46  	 */
47  	Conformance conformance();
48  
49  	/**
50  	 * Fluent method for the "create" operation, which creates a new resource instance on the server
51  	 */
52  	ICreate create();
53  
54  	/**
55  	 * Implementation of the "type create" method.
56  	 * 
57  	 * @param theResource
58  	 *            The resource to create
59  	 * @return An outcome
60  	 * @deprecated Use {@link #create() fluent method instead}. This method will be removed.
61  	 * 
62  	 */
63  	MethodOutcome create(IResource theResource);
64  
65  	/**
66  	 * Fluent method for the "delete" operation, which performs a logical delete on a server resource
67  	 */
68  	IDelete delete();
69  
70  	/**
71  	 * Implementation of the "delete instance" method.
72  	 * 
73  	 * @param theType
74  	 *            The type of resource to delete
75  	 * @param theId
76  	 *            the ID of the resource to delete
77  	 * @return An outcome
78  	 * @deprecated Use {@link #delete()) instead
79  	 */
80  	MethodOutcome delete(Class<? extends IResource> theType, IdDt theId);
81  
82  	/**
83  	 * Implementation of the "delete instance" method.
84  	 * 
85  	 * @param theType
86  	 *            The type of resource to delete
87  	 * @param theId
88  	 *            the ID of the resource to delete
89  	 * @return An outcome
90  	 * @deprecated Use {@link #delete()) instead
91  	 */
92  	MethodOutcome delete(Class<? extends IResource> theType, String theId);
93  
94  	/**
95  	 * Fluent method for the "get tags" operation
96  	 */
97  	IGetTags getTags();
98  
99  	/**
100 	 * Implementation of the "history instance" method.
101 	 * 
102 	 * @param theType
103 	 *            The type of resource to return the history for, or <code>null<code> to search for history across all resources
104 	 * @param theId
105 	 *            The ID of the resource to return the history for, or <code>null</code> to search for all resource instances. Note that if this param is not null, <code>theType</code> must also not
106 	 *            be null
107 	 * @param theSince
108 	 *            If not null, request that the server only return resources updated since this time
109 	 * @param theLimit
110 	 *            If not null, request that the server return no more than this number of resources. Note that the server may return less even if more are available, but should not return more
111 	 *            according to the FHIR specification.
112 	 * @return A bundle containing returned resources
113 	 */
114 	<T extends IResource> Bundle history(Class<T> theType, IdDt theIdDt, DateTimeDt theSince, Integer theLimit);
115 
116 	/**
117 	 * Implementation of the "history instance" method.
118 	 * 
119 	 * @param theType
120 	 *            The type of resource to return the history for, or <code>null<code> to search for history across all resources
121 	 * @param theId
122 	 *            The ID of the resource to return the history for, or <code>null</code> to search for all resource instances. Note that if this param is not null, <code>theType</code> must also not
123 	 *            be null
124 	 * @param theSince
125 	 *            If not null, request that the server only return resources updated since this time
126 	 * @param theLimit
127 	 *            If not null, request that the server return no more than this number of resources. Note that the server may return less even if more are available, but should not return more
128 	 *            according to the FHIR specification.
129 	 * @return A bundle containing returned resources
130 	 */
131 	<T extends IResource> Bundle history(Class<T> theType, String theIdDt, DateTimeDt theSince, Integer theLimit);
132 
133 	/**
134 	 * Loads the previous/next bundle of resources from a paged set, using the link specified in the "link type=next" tag within the atom bundle.
135 	 * 
136 	 * @see Bundle#getLinkNext()
137 	 */
138 	IGetPage loadPage();
139 
140 	/**
141 	 * Implementation of the "instance read" method. This method will only ever do a "read" for the latest version of a given resource instance, even if the ID passed in contains a version. If you
142 	 * wish to request a specific version of a resource (the "vread" operation), use {@link #vread(Class, IdDt)} instead.
143 	 * <p>
144 	 * Note that if an absolute resource ID is passed in (i.e. a URL containing a protocol and host as well as the resource type and ID) the server base for the client will be ignored, and the URL
145 	 * passed in will be queried.
146 	 * </p>
147 	 * 
148 	 * @param theType
149 	 *            The type of resource to load
150 	 * @param theId
151 	 *            The ID to load, including the resource ID and the resource version ID. Valid values include "Patient/123/_history/222", or "http://example.com/fhir/Patient/123/_history/222"
152 	 * @return The resource
153 	 */
154 	<T extends IResource> T read(Class<T> theType, IdDt theId);
155 
156 	/**
157 	 * Implementation of the "instance read" method.
158 	 * 
159 	 * @param theType
160 	 *            The type of resource to load
161 	 * @param theId
162 	 *            The ID to load
163 	 * @return The resource
164 	 */
165 	<T extends IResource> T read(Class<T> theType, String theId);
166 
167 	/**
168 	 * Perform the "read" operation (retrieve the latest version of a resource instance by ID) using an absolute URL.
169 	 * 
170 	 * @param theType
171 	 *            The resource type that is being retrieved
172 	 * @param theUrl
173 	 *            The absolute URL, e.g. "http://example.com/fhir/Patient/123"
174 	 * @return The returned resource from the server
175 	 */
176 	<T extends IResource> T read(Class<T> theType, UriDt theUrl);
177 
178 	/**
179 	 * Perform the "read" operation (retrieve the latest version of a resource instance by ID) using an absolute URL.
180 	 * 
181 	 * @param theUrl
182 	 *            The absolute URL, e.g. "http://example.com/fhir/Patient/123"
183 	 * @return The returned resource from the server
184 	 */
185 	IResource read(UriDt theUrl);
186 
187 	/**
188 	 * Register a new interceptor for this client. An interceptor can be used to add additional logging, or add security headers, or pre-process responses, etc.
189 	 */
190 	void registerInterceptor(IClientInterceptor theInterceptor);
191 
192 	IUntypedQuery search();
193 
194 	/**
195 	 * Implementation of the "instance search" method.
196 	 * 
197 	 * @param theType
198 	 *            The type of resource to load
199 	 * @param theParams
200 	 * @return
201 	 */
202 	<T extends IResource> Bundle search(Class<T> theType, Map<String, List<IQueryParameterType>> theParams);
203 
204 	/**
205 	 * Perform the "search" operation using an absolute URL.
206 	 * 
207 	 * @param theType
208 	 *            The primary resource type that is being retrieved
209 	 * @param theUrl
210 	 *            The absolute URL, e.g. "http://example.com/fhir/Patient/123"
211 	 * @return The returned bundle from the server
212 	 */
213 	<T extends IResource> Bundle search(Class<T> theType, UriDt theUrl);
214 
215 	Bundle search(UriDt theUrl);
216 
217 	/**
218 	 * If set to <code>true</code>, the client will log all requests and all responses. This is probably not a good production setting since it will result in a lot of extra logging, but it can be
219 	 * useful for troubleshooting.
220 	 * 
221 	 * @param theLogRequestAndResponse
222 	 *            Should requests and responses be logged
223 	 */
224 	void setLogRequestAndResponse(boolean theLogRequestAndResponse);
225 
226 	/**
227 	 * Send a transaction (collection of resources) to the server to be executed as a single unit
228 	 */
229 	ITransaction transaction();
230 
231 	/**
232 	 * Implementation of the "transaction" method.
233 	 * 
234 	 * @param theResources
235 	 *            The resources to create/update in a single transaction
236 	 * @return A list of resource stubs (<b>these will not be fully populated</b>) containing IDs and other {@link IResource#getResourceMetadata() metadata}
237 	 * @deprecated Use {@link #transaction()}
238 	 * 
239 	 */
240 	List<IResource> transaction(List<IResource> theResources);
241 
242 	/**
243 	 * Remove an intercaptor that was previously registered using {@link IRestfulClient#registerInterceptor(IClientInterceptor)}
244 	 */
245 	void unregisterInterceptor(IClientInterceptor theInterceptor);
246 
247 	/**
248 	 * Fluent method for the "update" operation, which performs a logical delete on a server resource
249 	 */
250 	IUpdate update();
251 
252 	/**
253 	 * Implementation of the "instance update" method.
254 	 * 
255 	 * @param theId
256 	 *            The ID to update
257 	 * @param theResource
258 	 *            The new resource body
259 	 * @return An outcome containing the results and possibly the new version ID
260 	 */
261 	MethodOutcome update(IdDt theIdDt, IResource theResource);
262 
263 	/**
264 	 * Implementation of the "instance update" method.
265 	 * 
266 	 * @param theId
267 	 *            The ID to update
268 	 * @param theResource
269 	 *            The new resource body
270 	 * @return An outcome containing the results and possibly the new version ID
271 	 */
272 	MethodOutcome update(String theIdDt, IResource theResource);
273 
274 	/**
275 	 * Implementation of the "type validate" method.
276 	 * 
277 	 * @param theId
278 	 *            The ID to validate
279 	 * @param theResource
280 	 *            The resource to validate
281 	 * @return An outcome containing any validation issues
282 	 */
283 	MethodOutcome validate(IResource theResource);
284 
285 	/**
286 	 * Implementation of the "instance vread" method. Note that this method expects <code>theId</code> to contain a resource ID as well as a version ID, and will fail if it does not.
287 	 * <p>
288 	 * Note that if an absolute resource ID is passed in (i.e. a URL containing a protocol and host as well as the resource type and ID) the server base for the client will be ignored, and the URL
289 	 * passed in will be queried.
290 	 * </p>
291 	 * 
292 	 * @param theType
293 	 *            The type of resource to load
294 	 * @param theId
295 	 *            The ID to load, including the resource ID and the resource version ID. Valid values include "Patient/123/_history/222", or "http://example.com/fhir/Patient/123/_history/222"
296 	 * @return The resource
297 	 */
298 	<T extends IResource> T vread(Class<T> theType, IdDt theId);
299 
300 	/**
301 	 * Implementation of the "instance vread" method.
302 	 * 
303 	 * @param theType
304 	 *            The type of resource to load
305 	 * @param theId
306 	 *            The ID to load
307 	 * @param theVersionId
308 	 *            The version ID
309 	 * @return The resource
310 	 * @deprecated Deprecated in 0.7 - IdDt can contain an ID and a version, so this class doesn't make a lot of sense
311 	 */
312 	<T extends IResource> T vread(Class<T> theType, IdDt theId, IdDt theVersionId);
313 
314 	/**
315 	 * Implementation of the "instance vread" method.
316 	 * 
317 	 * @param theType
318 	 *            The type of resource to load
319 	 * @param theId
320 	 *            The ID to load
321 	 * @param theVersionId
322 	 *            The version ID
323 	 * @return The resource
324 	 */
325 	<T extends IResource> T vread(Class<T> theType, String theId, String theVersionId);
326 
327 }