001package ca.uhn.fhir.rest.api.server;
002
003import org.hl7.fhir.instance.model.api.IBaseResource;
004import org.hl7.fhir.instance.model.api.IPrimitiveType;
005
006import java.util.Date;
007import java.util.List;
008
009/*
010 * #%L
011 * HAPI FHIR - Server Framework
012 * %%
013 * Copyright (C) 2014 - 2019 University Health Network
014 * %%
015 * Licensed under the Apache License, Version 2.0 (the "License");
016 * you may not use this file except in compliance with the License.
017 * You may obtain a copy of the License at
018 * 
019 * http://www.apache.org/licenses/LICENSE-2.0
020 * 
021 * Unless required by applicable law or agreed to in writing, software
022 * distributed under the License is distributed on an "AS IS" BASIS,
023 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
024 * See the License for the specific language governing permissions and
025 * limitations under the License.
026 * #L%
027 */
028
029
030public interface IBundleProvider {
031
032        /**
033         * If this method is implemented, provides an ID for the current
034         * page of results. This ID should be unique (at least within
035         * the current search as identified by {@link #getUuid()})
036         * so that it can be used to look up a specific page of results.
037         * <p>
038         * This can be used in order to allow the
039         * server paging mechanism to work using completely
040         * opaque links (links that do not encode any index/offset
041         * information), which can be useful on some servers.
042         * </p>
043         *
044         * @since 3.5.0
045         */
046        default String getCurrentPageId() {
047                return null;
048        }
049
050        /**
051         * If this method is implemented, provides an ID for the next
052         * page of results. This ID should be unique (at least within
053         * the current search as identified by {@link #getUuid()})
054         * so that it can be used to look up a specific page of results.
055         * <p>
056         * This can be used in order to allow the
057         * server paging mechanism to work using completely
058         * opaque links (links that do not encode any index/offset
059         * information), which can be useful on some servers.
060         * </p>
061         *
062         * @since 3.5.0
063         */
064        default String getNextPageId() {
065                return null;
066        }
067
068        /**
069         * If this method is implemented, provides an ID for the previous
070         * page of results. This ID should be unique (at least within
071         * the current search as identified by {@link #getUuid()})
072         * so that it can be used to look up a specific page of results.
073         * <p>
074         * This can be used in order to allow the
075         * server paging mechanism to work using completely
076         * opaque links (links that do not encode any index/offset
077         * information), which can be useful on some servers.
078         * </p>
079         *
080         * @since 3.5.0
081         */
082        default String getPreviousPageId() {
083                return null;
084        }
085
086        /**
087         * Returns the instant as of which this result was created. The
088         * result of this value is used to populate the <code>lastUpdated</code>
089         * value on search result/history result bundles.
090         */
091        IPrimitiveType<Date> getPublished();
092
093        /**
094         * Load the given collection of resources by index, plus any additional resources per the
095         * server's processing rules (e.g. _include'd resources, OperationOutcome, etc.). For example,
096         * if the method is invoked with index 0,10 the method might return 10 search results, plus an
097         * additional 20 resources which matched a client's _include specification.
098         * <p>
099         * Note that if this bundle provider was loaded using a
100         * page ID (i.e. via {@link ca.uhn.fhir.rest.server.IPagingProvider#retrieveResultList(String, String)}
101         * because {@link #getNextPageId()} provided a value on the
102         * previous page, then the indexes should be ignored and the
103         * whole page returned.
104         * </p>
105         *
106         * @param theFromIndex The low index (inclusive) to return
107         * @param theToIndex   The high index (exclusive) to return
108         * @return A list of resources. The size of this list must be at least <code>theToIndex - theFromIndex</code>.
109         */
110        List<IBaseResource> getResources(int theFromIndex, int theToIndex);
111
112        /**
113         * Returns the UUID associated with this search. Note that this
114         * does not need to return a non-null value unless it a
115         * IPagingProvider is being used that requires UUIDs
116         * being returned.
117         * <p>
118         * In other words, if you are using the default FifoMemoryPagingProvider in
119         * your server, it is fine for this method to simply return {@code null} since FifoMemoryPagingProvider
120         * does not use the value anyhow. On the other hand, if you are creating a custom
121         * IPagingProvider implementation you might use this method to communicate
122         * the search ID back to the provider.
123         * </p>
124         * <p>
125         * Note that the UUID returned by this method corresponds to
126         * the search, and not to the individual page.
127         * </p>
128         */
129        String getUuid();
130
131        /**
132         * Optionally may be used to signal a preferred page size to the server, e.g. because
133         * the implementing code recognizes that the resources which will be returned by this
134         * implementation are expensive to load so a smaller page size should be used. The value
135         * returned by this method will only be used if the client has not explicitly requested
136         * a page size.
137         *
138         * @return Returns the preferred page size or <code>null</code>
139         */
140        Integer preferredPageSize();
141
142        /**
143         * Returns the total number of results which match the given query (exclusive of any
144         * _include's or OperationOutcome). May return {@literal null} if the total size is not
145         * known or would be too expensive to calculate.
146         */
147        Integer size();
148
149}