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