001/*-
002 * #%L
003 * HAPI FHIR - Core Library
004 * %%
005 * Copyright (C) 2014 - 2025 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 */
020package ca.uhn.fhir.rest.client.api;
021
022import ca.uhn.fhir.model.primitive.IdDt;
023import ca.uhn.fhir.model.primitive.UriDt;
024import ca.uhn.fhir.rest.api.MethodOutcome;
025import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
026import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerException;
027import ca.uhn.fhir.rest.gclient.ICreate;
028import ca.uhn.fhir.rest.gclient.IDelete;
029import ca.uhn.fhir.rest.gclient.IFetchConformanceUntyped;
030import ca.uhn.fhir.rest.gclient.IGetPage;
031import ca.uhn.fhir.rest.gclient.IHistory;
032import ca.uhn.fhir.rest.gclient.IMeta;
033import ca.uhn.fhir.rest.gclient.IOperation;
034import ca.uhn.fhir.rest.gclient.IPatch;
035import ca.uhn.fhir.rest.gclient.IRawHttp;
036import ca.uhn.fhir.rest.gclient.IRead;
037import ca.uhn.fhir.rest.gclient.ITransaction;
038import ca.uhn.fhir.rest.gclient.IUntypedQuery;
039import ca.uhn.fhir.rest.gclient.IUpdate;
040import ca.uhn.fhir.rest.gclient.IValidate;
041import org.hl7.fhir.instance.model.api.IBaseBundle;
042import org.hl7.fhir.instance.model.api.IBaseResource;
043
044public interface IGenericClient extends IRestfulClient {
045
046        /**
047         * Fetch the capability statement for the server
048         */
049        IFetchConformanceUntyped capabilities();
050
051        /**
052         * Fluent method for the "create" operation, which creates a new resource instance on the server
053         */
054        ICreate create();
055
056        /**
057         * Fluent method for the "delete" operation, which performs a logical delete on a server resource
058         */
059        IDelete delete();
060
061        /**
062         * Retrieves the server's conformance statement
063         *
064         * @deprecated As of HAPI 3.0.0 this method has been deprecated, as the operation is now called "capabilities". Use {@link #capabilities()} instead
065         */
066        @Deprecated(since = "3.0.0", forRemoval = true)
067        IFetchConformanceUntyped fetchConformance();
068
069        /**
070         * Force the client to fetch the server's conformance statement and validate that it is appropriate for this client.
071         *
072         * @throws FhirClientConnectionException
073         *            if the conformance statement cannot be read, or if the client
074         * @throws FhirClientInappropriateForServerException
075         *            If the conformance statement indicates that the server is inappropriate for this client (e.g. it implements the wrong version of FHIR)
076         */
077        void forceConformanceCheck() throws FhirClientConnectionException;
078
079        /**
080         * Implementation of the "history" method
081         */
082        IHistory history();
083
084        /**
085         * 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.
086         */
087        IGetPage loadPage();
088
089        /**
090         * Fluent method for the "meta" operations, which can be used to get, add and remove tags and other
091         * Meta elements from a resource or across the server.
092         *
093         * @since 1.1
094         */
095        IMeta meta();
096
097        /**
098         * Implementation of the FHIR "extended operations" action
099         */
100        IOperation operation();
101
102        /**
103         * Fluent method for the "patch" operation, which performs a logical patch on a server resource
104         */
105        IPatch patch();
106
107        /**
108         * Fluent method for "read" and "vread" methods.
109         */
110        IRead read();
111
112        /**
113         * Provides access to raw HTTP operations that bypass FHIR resource parsing.
114         * This is useful for making non-FHIR HTTP requests through the same client
115         * infrastructure, including interceptors and authentication.
116         *
117         * @return A builder for constructing raw HTTP requests
118         * @since 8.6.0
119         */
120        IRawHttp rawHttpRequest();
121
122        /**
123         * Implementation of the "instance read" method.
124         *
125         * @param theType
126         *           The type of resource to load
127         * @param theId
128         *           The ID to load
129         * @return The resource
130         *
131         * @deprecated Use {@link #read() read() fluent method} instead (deprecated in HAPI FHIR 3.0.0)
132         */
133        @Deprecated
134        <T extends IBaseResource> T read(Class<T> theType, String theId);
135
136        /**
137         * Perform the "read" operation (retrieve the latest version of a resource instance by ID) using an absolute URL.
138         *
139         * @param theType
140         *           The resource type that is being retrieved
141         * @param theUrl
142         *           The absolute URL, e.g. "http://example.com/fhir/Patient/123"
143         * @return The returned resource from the server
144         * @deprecated Use {@link #read() read() fluent method} instead (deprecated in HAPI FHIR 3.0.0)
145         */
146        @Deprecated
147        <T extends IBaseResource> T read(Class<T> theType, UriDt theUrl);
148
149        /**
150         * Perform the "read" operation (retrieve the latest version of a resource instance by ID) using an absolute URL.
151         *
152         * @param theUrl
153         *           The absolute URL, e.g. "http://example.com/fhir/Patient/123"
154         * @return The returned resource from the server
155         * @deprecated Use {@link #read() read() fluent method} instead (deprecated in HAPI FHIR 3.0.0)
156         */
157        @Deprecated
158        IBaseResource read(UriDt theUrl);
159
160        /**
161         * 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.
162         */
163        @Override
164        void registerInterceptor(Object theInterceptor);
165
166        /**
167         * Search for resources matching a given set of criteria. Searching is a very powerful
168         * feature in FHIR with many features for specifying exactly what should be seaerched for
169         * and how it should be returned. See the <a href="http://www.hl7.org/fhir/search.html">specification on search</a>
170         * for more information.
171         */
172        <T extends IBaseBundle> IUntypedQuery<T> search();
173
174        /**
175         * 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
176         * useful for troubleshooting.
177         *
178         * @param theLogRequestAndResponse
179         *           Should requests and responses be logged
180         * @deprecated Use LoggingInterceptor as a client interceptor registered to your
181         *             client instead, as this provides much more fine-grained control over what is logged. This
182         *             method will be removed at some point (deprecated in HAPI 1.6 - 2016-06-16)
183         */
184        @Deprecated
185        void setLogRequestAndResponse(boolean theLogRequestAndResponse);
186
187        /**
188         * Send a transaction (collection of resources) to the server to be executed as a single unit
189         */
190        ITransaction transaction();
191
192        /**
193         * Remove an intercaptor that was previously registered using {@link IRestfulClient#registerInterceptor(Object)}
194         */
195        @Override
196        void unregisterInterceptor(Object theInterceptor);
197
198        /**
199         * Fluent method for the "update" operation, which updates a resource instance on the server
200         */
201        IUpdate update();
202
203        /**
204         * Implementation of the "instance update" method.
205         *
206         * @param theId
207         *           The ID to update
208         * @param theResource
209         *           The new resource body
210         * @return An outcome containing the results and possibly the new version ID
211         * @deprecated Use {@link #update() update() fluent method} instead (deprecated in HAPI FHIR 3.0.0)
212         */
213        @Deprecated
214        MethodOutcome update(IdDt theId, IBaseResource theResource);
215
216        /**
217         * Implementation of the "instance update" method.
218         *
219         * @param theId
220         *           The ID to update
221         * @param theResource
222         *           The new resource body
223         * @return An outcome containing the results and possibly the new version ID
224         * @deprecated Use {@link #update() update() fluent method} instead (deprecated in HAPI FHIR 3.0.0)
225         */
226        @Deprecated
227        MethodOutcome update(String theId, IBaseResource theResource);
228
229        /**
230         * Validate a resource
231         */
232        IValidate validate();
233
234        /**
235         * Implementation of the "type validate" method.
236         *
237         * @param theResource
238         *           The resource to validate
239         * @return An outcome containing any validation issues
240         * @deprecated Use {@link #validate() validate() fluent method} instead (deprecated in HAPI FHIR 3.0.0)
241         */
242        @Deprecated
243        MethodOutcome validate(IBaseResource theResource);
244
245        /**
246         * 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.
247         * <p>
248         * 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
249         * passed in will be queried.
250         * </p>
251         *
252         * @param theType
253         *           The type of resource to load
254         * @param theId
255         *           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"
256         * @return The resource
257         * @deprecated Use {@link #read() read() fluent method} instead (deprecated in HAPI FHIR 3.0.0)
258         */
259        @Deprecated
260        <T extends IBaseResource> T vread(Class<T> theType, IdDt theId);
261
262        /**
263         * Implementation of the "instance vread" method.
264         *
265         * @param theType
266         *           The type of resource to load
267         * @param theId
268         *           The ID to load
269         * @param theVersionId
270         *           The version ID
271         * @return The resource
272         * @deprecated Use {@link #read() read() fluent method} instead (deprecated in HAPI FHIR 3.0.0)
273         */
274        @Deprecated
275        <T extends IBaseResource> T vread(Class<T> theType, String theId, String theVersionId);
276}