001package ca.uhn.fhir.rest.gclient;
002
003import ca.uhn.fhir.model.api.Include;
004import ca.uhn.fhir.rest.api.SearchStyleEnum;
005import ca.uhn.fhir.rest.api.SearchTotalModeEnum;
006import ca.uhn.fhir.rest.api.SortSpec;
007import ca.uhn.fhir.rest.api.SummaryEnum;
008import ca.uhn.fhir.rest.param.DateRangeParam;
009import org.hl7.fhir.instance.model.api.IBaseBundle;
010
011import java.util.Collection;
012import java.util.List;
013import java.util.Map;
014
015/*
016 * #%L
017 * HAPI FHIR - Core Library
018 * %%
019 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
020 * %%
021 * Licensed under the Apache License, Version 2.0 (the "License");
022 * you may not use this file except in compliance with the License.
023 * You may obtain a copy of the License at
024 *
025 *      http://www.apache.org/licenses/LICENSE-2.0
026 *
027 * Unless required by applicable law or agreed to in writing, software
028 * distributed under the License is distributed on an "AS IS" BASIS,
029 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
030 * See the License for the specific language governing permissions and
031 * limitations under the License.
032 * #L%
033 */
034
035public interface IQuery<Y> extends IBaseQuery<IQuery<Y>>, IClientExecutable<IQuery<Y>, Y> {
036
037        /**
038         * {@inheritDoc}
039         */
040        // This is here as an overridden method to allow mocking clients with Mockito to work
041        @Override
042        IQuery<Y> and(ICriterion<?> theCriterion);
043
044        /**
045         * Specifies the <code>_count</code> parameter, which indicates to the server how many resources should be returned
046         * on a single page.
047         *
048         * @since 1.4
049         */
050        IQuery<Y> count(int theCount);
051
052        /**
053         * Specifies the <code>_offset</code> parameter, which indicates to the server the offset of the query. Use
054         * with {@link #count(int)}.
055         *
056         * This parameter is not part of the FHIR standard, all servers might not implement it.
057         *
058         * @since 5.2
059         */
060        IQuery<Y> offset(int theOffset);
061
062        /**
063         * Add an "_include" specification or an "_include:recurse" specification. If you are using
064         * a constant from one of the built-in structures you can select whether you want recursive
065         * behaviour by using the following syntax:
066         * <ul>
067         * <li><b>Recurse:</b> <code>.include(Patient.INCLUDE_ORGANIZATION.asRecursive())</code>
068         * <li><b>No Recurse:</b> <code>.include(Patient.INCLUDE_ORGANIZATION.asNonRecursive())</code>
069         * </ul>
070         */
071        IQuery<Y> include(Include theInclude);
072
073        /**
074         * Add a "_lastUpdated" specification
075         *
076         * @since HAPI FHIR 1.1 - Note that option was added to FHIR itself in DSTU2
077         */
078        IQuery<Y> lastUpdated(DateRangeParam theLastUpdated);
079
080        /**
081         * Specifies the <code>_count</code> parameter, which indicates to the server how many resources should be returned
082         * on a single page.
083         *
084         * @deprecated This parameter is badly named, since FHIR calls this parameter "_count" and not "_limit". Use {@link #count(int)} instead (it also sets the _count parameter)
085         * @see #count(int)
086         */
087        @Deprecated
088        IQuery<Y> limitTo(int theLimitTo);
089
090        /**
091         * Request that the client return the specified bundle type, e.g. <code>org.hl7.fhir.dstu2.model.Bundle.class</code>
092         * or <code>ca.uhn.fhir.model.dstu2.resource.Bundle.class</code>
093         */
094        <B extends IBaseBundle> IQuery<B> returnBundle(Class<B> theClass);
095
096        /**
097         * Request that the server modify the response using the <code>_total</code> param
098         *
099         * THIS IS AN EXPERIMENTAL FEATURE - Use with caution, as it may be
100         * removed or modified in a future version.
101         */
102        IQuery<Y> totalMode(SearchTotalModeEnum theTotalMode);
103
104        /**
105         * Add a "_revinclude" specification
106         *
107         * @since HAPI FHIR 1.0 - Note that option was added to FHIR itself in DSTU2
108         */
109        IQuery<Y> revInclude(Include theIncludeTarget);
110
111        /**
112         * Adds a sort criteria
113         *
114         * @see #sort(SortSpec) for an alternate way of speciyfing sorts
115         */
116        ISort<Y> sort();
117
118        /**
119         * Adds a sort using a {@link SortSpec} object
120         *
121         * @see #sort() for an alternate way of speciyfing sorts
122         */
123        IQuery<Y> sort(SortSpec theSortSpec);
124
125        /**
126         * Forces the query to perform the search using the given method (allowable methods are described in the
127         * <a href="http://www.hl7.org/fhir/search.html">FHIR Search Specification</a>)
128         * <p>
129         * This can be used to force the use of an HTTP POST instead of an HTTP GET
130         * </p>
131         *
132         * @see SearchStyleEnum
133         * @since 0.6
134         */
135        IQuery<Y> usingStyle(SearchStyleEnum theStyle);
136
137        /**
138         * {@inheritDoc}
139         */
140        // This is here as an overridden method to allow mocking clients with Mockito to work
141        @Override
142        IQuery<Y> where(ICriterion<?> theCriterion);
143
144        /**
145         * Matches any of the profiles given as argument. This would result in an OR search for resources matching one or more profiles.
146         * To do an AND search, make multiple calls to {@link #withProfile(String)}.
147         *
148         * @param theProfileUris The URIs of a given profile to search for resources which match.
149         */
150        IQuery<Y> withAnyProfile(Collection<String> theProfileUris);
151
152        IQuery<Y> withIdAndCompartment(String theResourceId, String theCompartmentName);
153
154        /**
155         * Match only resources where the resource has the given profile declaration. This parameter corresponds to
156         * the <code>_profile</code> URL parameter.
157         *
158         * @param theProfileUri The URI of a given profile to search for resources which match
159         */
160        IQuery<Y> withProfile(String theProfileUri);
161
162        /**
163         * Match only resources where the resource has the given security tag. This parameter corresponds to
164         * the <code>_security</code> URL parameter.
165         *
166         * @param theSystem The tag code system, or <code>null</code> to match any code system (this may not be supported on all servers)
167         * @param theCode   The tag code. Must not be <code>null</code> or empty.
168         */
169        IQuery<Y> withSecurity(String theSystem, String theCode);
170
171        /**
172         * Match only resources where the resource has the given tag. This parameter corresponds to
173         * the <code>_tag</code> URL parameter.
174         *
175         * @param theSystem The tag code system, or <code>null</code> to match any code system (this may not be supported on all servers)
176         * @param theCode   The tag code. Must not be <code>null</code> or empty.
177         */
178        IQuery<Y> withTag(String theSystem, String theCode);
179
180//      Y execute();
181
182}