001package ca.uhn.fhir.jpa.config.r5;
002
003import ca.uhn.fhir.context.FhirContext;
004import ca.uhn.fhir.context.ParserOptions;
005import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
006import ca.uhn.fhir.jpa.config.BaseConfigDstu3Plus;
007import ca.uhn.fhir.jpa.dao.FulltextSearchSvcImpl;
008import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
009import ca.uhn.fhir.jpa.dao.TransactionProcessor;
010import ca.uhn.fhir.jpa.dao.r5.TransactionProcessorVersionAdapterR5;
011import ca.uhn.fhir.jpa.provider.GraphQLProvider;
012import ca.uhn.fhir.jpa.term.TermLoaderSvcImpl;
013import ca.uhn.fhir.jpa.term.TermReadSvcR5;
014import ca.uhn.fhir.jpa.term.TermVersionAdapterSvcR5;
015import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
016import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
017import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc;
018import ca.uhn.fhir.jpa.term.api.ITermReadSvcR5;
019import ca.uhn.fhir.jpa.term.api.ITermVersionAdapterSvc;
020import ca.uhn.fhir.jpa.util.ResourceCountCache;
021import org.apache.commons.lang3.time.DateUtils;
022import org.hl7.fhir.r5.model.Bundle;
023import org.hl7.fhir.r5.model.Meta;
024import org.springframework.beans.factory.annotation.Autowire;
025import org.springframework.context.annotation.Bean;
026import org.springframework.context.annotation.Configuration;
027import org.springframework.context.annotation.Lazy;
028import org.springframework.context.annotation.Primary;
029import org.springframework.transaction.annotation.EnableTransactionManagement;
030
031/*
032 * #%L
033 * HAPI FHIR JPA Server
034 * %%
035 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
036 * %%
037 * Licensed under the Apache License, Version 2.0 (the "License");
038 * you may not use this file except in compliance with the License.
039 * You may obtain a copy of the License at
040 *
041 * http://www.apache.org/licenses/LICENSE-2.0
042 *
043 * Unless required by applicable law or agreed to in writing, software
044 * distributed under the License is distributed on an "AS IS" BASIS,
045 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
046 * See the License for the specific language governing permissions and
047 * limitations under the License.
048 * #L%
049 */
050
051@Configuration
052@EnableTransactionManagement
053public class BaseR5Config extends BaseConfigDstu3Plus {
054
055        @Override
056        public FhirContext fhirContext() {
057                return fhirContextR5();
058        }
059
060        @Bean
061        @Override
062        public ITermVersionAdapterSvc terminologyVersionAdapterSvc() {
063                return new TermVersionAdapterSvcR5();
064        }
065
066        @Bean
067        @Primary
068        public FhirContext fhirContextR5() {
069                FhirContext retVal = FhirContext.forR5();
070
071                // Don't strip versions in some places
072                ParserOptions parserOptions = retVal.getParserOptions();
073                parserOptions.setDontStripVersionsFromReferencesAtPaths("AuditEvent.entity.what");
074
075                return retVal;
076        }
077
078        @Bean
079        public TransactionProcessor.ITransactionProcessorVersionAdapter transactionProcessorVersionFacade() {
080                return new TransactionProcessorVersionAdapterR5();
081        }
082
083        @Bean(name = GRAPHQL_PROVIDER_NAME)
084        @Lazy
085        public GraphQLProvider graphQLProvider() {
086                return new GraphQLProvider(fhirContextR5(), validationSupportChain(), graphqlStorageServices());
087        }
088
089        @Bean(name = "myResourceCountsCache")
090        public ResourceCountCache resourceCountsCache() {
091                ResourceCountCache retVal = new ResourceCountCache(() -> systemDaoR5().getResourceCounts());
092                retVal.setCacheMillis(4 * DateUtils.MILLIS_PER_HOUR);
093                return retVal;
094        }
095
096        @Bean(autowire = Autowire.BY_TYPE)
097        public IFulltextSearchSvc searchDaoR5() {
098                FulltextSearchSvcImpl searchDao = new FulltextSearchSvcImpl();
099                return searchDao;
100        }
101
102        @Bean(name = "mySystemDaoR5", autowire = Autowire.BY_NAME)
103        public IFhirSystemDao<Bundle, Meta> systemDaoR5() {
104                ca.uhn.fhir.jpa.dao.r5.FhirSystemDaoR5 retVal = new ca.uhn.fhir.jpa.dao.r5.FhirSystemDaoR5();
105                return retVal;
106        }
107
108        @Bean(name = "mySystemProviderR5")
109        public ca.uhn.fhir.jpa.provider.r5.JpaSystemProviderR5 systemProviderR5() {
110                ca.uhn.fhir.jpa.provider.r5.JpaSystemProviderR5 retVal = new ca.uhn.fhir.jpa.provider.r5.JpaSystemProviderR5();
111                retVal.setContext(fhirContextR5());
112                retVal.setDao(systemDaoR5());
113                return retVal;
114        }
115
116        @Bean
117        public ITermLoaderSvc terminologyLoaderService(ITermDeferredStorageSvc theDeferredStorageSvc, ITermCodeSystemStorageSvc theCodeSystemStorageSvc) {
118                return new TermLoaderSvcImpl(theDeferredStorageSvc, theCodeSystemStorageSvc);
119        }
120
121        @Override
122        @Bean(autowire = Autowire.BY_TYPE)
123        public ITermReadSvcR5 terminologyService() {
124                return new TermReadSvcR5();
125        }
126
127}