001/*- 002 * #%L 003 * HAPI FHIR JPA Server 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.jpa.search.lastn; 021 022import ca.uhn.fhir.context.FhirContext; 023import ca.uhn.fhir.jpa.search.lastn.json.CodeJson; 024import ca.uhn.fhir.jpa.search.lastn.json.ObservationJson; 025import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; 026import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId; 027import org.hl7.fhir.instance.model.api.IBaseResource; 028 029import java.io.IOException; 030import java.util.Collection; 031import java.util.List; 032 033public interface IElasticsearchSvc { 034 035 /** 036 * Returns identifiers for the last most recent N observations that meet the specified criteria. 037 * 038 * @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). 039 * @param theFhirContext Current FhirContext. 040 * @param theMaxResultsToFetch The maximum number of results to return for the purpose of paging. 041 * @return 042 */ 043 List<String> executeLastN( 044 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<? extends IResourcePersistentId> thePids); 100}