001package ca.uhn.fhir.jpa.subscription.module.standalone; 002 003/*- 004 * #%L 005 * HAPI FHIR Subscription Server 006 * %% 007 * Copyright (C) 2014 - 2020 University Health Network 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.searchparam.SearchParameterMap; 025import ca.uhn.fhir.jpa.searchparam.registry.SearchParamRegistryImpl; 026import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamProvider; 027import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum; 028import ca.uhn.fhir.rest.api.CacheControlDirective; 029import ca.uhn.fhir.rest.api.server.IBundleProvider; 030import ca.uhn.fhir.rest.client.api.IGenericClient; 031import ca.uhn.fhir.rest.server.SimpleBundleProvider; 032import ca.uhn.fhir.util.BundleUtil; 033import org.hl7.fhir.instance.model.api.IBaseBundle; 034import org.hl7.fhir.instance.model.api.IBaseResource; 035import org.slf4j.Logger; 036import org.slf4j.LoggerFactory; 037import org.springframework.beans.factory.annotation.Autowired; 038import org.springframework.stereotype.Service; 039 040@Service 041public class FhirClientSearchParamProvider implements ISearchParamProvider { 042 private static final Logger ourLog = LoggerFactory.getLogger(FhirClientSearchParamProvider.class); 043 044 private IGenericClient myClient; 045 046 @Autowired 047 public FhirClientSearchParamProvider(IGenericClient theClient) { 048 myClient = theClient; 049 } 050 051 @Override 052 public IBundleProvider search(SearchParameterMap theParams) { 053 FhirContext fhirContext = myClient.getFhirContext(); 054 055 IBaseBundle bundle = myClient 056 .search() 057 .forResource(ResourceTypeEnum.SEARCHPARAMETER.getCode()) 058 .cacheControl(new CacheControlDirective().setNoCache(true)) 059 .execute(); 060 061 return new SimpleBundleProvider(BundleUtil.toListOfResources(fhirContext, bundle)); 062 } 063 064 @Override 065 public int refreshCache(SearchParamRegistryImpl theSearchParamRegistry, long theRefreshInterval) { 066 return theSearchParamRegistry.doRefresh(theRefreshInterval); 067 } 068}