001package ca.uhn.fhir.jpa.search.lastn;
002
003/*-
004 * #%L
005 * HAPI FHIR JPA Server
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.context.FhirContext;
024import ca.uhn.fhir.jpa.search.lastn.json.CodeJson;
025import ca.uhn.fhir.jpa.search.lastn.json.ObservationJson;
026import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
027import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
028import org.hl7.fhir.instance.model.api.IBaseResource;
029
030import java.io.IOException;
031import java.util.Collection;
032import java.util.List;
033
034public interface IElasticsearchSvc {
035
036        /**
037         * Returns identifiers for the last most recent N observations that meet the specified criteria.
038         *
039         * @param theSearchParameterMap SearchParameterMap containing search parameters used for filtering the last N observations. Supported parameters include Subject, Patient, Code, Category and Max (the parameter used to determine N).
040         * @param theFhirContext        Current FhirContext.
041         * @param theMaxResultsToFetch  The maximum number of results to return for the purpose of paging.
042         * @return
043         */
044        List<String> executeLastN(SearchParameterMap theSearchParameterMap, FhirContext theFhirContext, Integer theMaxResultsToFetch);
045
046        /**
047         * Returns index document for a single Observation
048         *
049         * @param theDocumentID Identifier of Observation resource.
050         * @return
051         */
052        ObservationJson getObservationDocument(String theDocumentID);
053
054        /**
055         * Returns index document for a single Observation Code that either has a coding that matches a specified Code value and system or that has a specified text value.
056         *
057         * @param theCodeSystemHash A hash string constructed from a Code value and Code system used to match to an Observation Code.
058         * @param theText           A text value used to match to an Observation Code.
059         * @return
060         */
061        CodeJson getObservationCodeDocument(String theCodeSystemHash, String theText);
062
063        /**
064         * Creates or updates index for an Observation Resource.
065         *
066         * @param theDocumentId          Identifier for Observation resource.
067         * @param theObservationDocument Indexing document for Observation.
068         * @return True if Observation indexed successfully.
069         */
070        Boolean createOrUpdateObservationIndex(String theDocumentId, ObservationJson theObservationDocument);
071
072        /**
073         * Creates or updates index for an Observation Code.
074         *
075         * @param theCodeableConceptID       Identifier for Observation resource.
076         * @param theObservationCodeDocument Indexing document for Observation.
077         * @return True if Observation Code indexed successfully.
078         */
079        Boolean createOrUpdateObservationCodeIndex(String theCodeableConceptID, CodeJson theObservationCodeDocument);
080
081        /**
082         * Deletes index for an Observation Resource.
083         *
084         * @param theDocumentId Identifier for Observation resource.
085         */
086        void deleteObservationDocument(String theDocumentId);
087
088        /**
089         * Invoked when shutting down.
090         */
091        void close() throws IOException;
092
093        /**
094         * Returns inlined observation resource stored along with index mappings for matched identifiers
095         *
096         * @param thePids
097         * @return Resources list or empty if nothing found
098         */
099        List<IBaseResource> getObservationResources(Collection<ResourcePersistentId> thePids);
100
101}