001package ca.uhn.fhir.jpa.config.r4;
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.ITransactionProcessorVersionAdapter;
010import ca.uhn.fhir.jpa.dao.r4.TransactionProcessorVersionAdapterR4;
011import ca.uhn.fhir.jpa.provider.GraphQLProvider;
012import ca.uhn.fhir.jpa.term.TermLoaderSvcImpl;
013import ca.uhn.fhir.jpa.term.TermReadSvcR4;
014import ca.uhn.fhir.jpa.term.TermVersionAdapterSvcR4;
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.ITermReadSvcR4;
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.r4.model.Bundle;
023import org.hl7.fhir.r4.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 BaseR4Config extends BaseConfigDstu3Plus {
054
055        public static FhirContext ourFhirContext = FhirContext.forR4();
056
057        @Override
058        public FhirContext fhirContext() {
059                return fhirContextR4();
060        }
061
062        @Bean
063        @Override
064        public ITermVersionAdapterSvc terminologyVersionAdapterSvc() {
065                return new TermVersionAdapterSvcR4();
066        }
067
068        @Bean
069        @Primary
070        public FhirContext fhirContextR4() {
071                FhirContext retVal = ourFhirContext;
072
073                // Don't strip versions in some places
074                ParserOptions parserOptions = retVal.getParserOptions();
075                parserOptions.setDontStripVersionsFromReferencesAtPaths("AuditEvent.entity.what");
076
077                return retVal;
078        }
079
080        @Bean
081        public ITransactionProcessorVersionAdapter transactionProcessorVersionFacade() {
082                return new TransactionProcessorVersionAdapterR4();
083        }
084
085        @Bean(name = GRAPHQL_PROVIDER_NAME)
086        @Lazy
087        public GraphQLProvider graphQLProvider() {
088                return new GraphQLProvider(fhirContextR4(), validationSupportChain(), graphqlStorageServices());
089        }
090
091        @Bean(name = "myResourceCountsCache")
092        public ResourceCountCache resourceCountsCache() {
093                ResourceCountCache retVal = new ResourceCountCache(() -> systemDaoR4().getResourceCounts());
094                retVal.setCacheMillis(4 * DateUtils.MILLIS_PER_HOUR);
095                return retVal;
096        }
097
098        @Bean(autowire = Autowire.BY_TYPE)
099        public IFulltextSearchSvc searchDaoR4() {
100                FulltextSearchSvcImpl searchDao = new FulltextSearchSvcImpl();
101                return searchDao;
102        }
103
104        @Bean(name = "mySystemDaoR4", autowire = Autowire.BY_NAME)
105        public IFhirSystemDao<Bundle, Meta> systemDaoR4() {
106                ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4 retVal = new ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4();
107                return retVal;
108        }
109
110        @Bean(name = "mySystemProviderR4")
111        public ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4 systemProviderR4() {
112                ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4 retVal = new ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4();
113                retVal.setContext(fhirContextR4());
114                retVal.setDao(systemDaoR4());
115                return retVal;
116        }
117
118        @Bean
119        public ITermLoaderSvc termLoaderService(ITermDeferredStorageSvc theDeferredStorageSvc, ITermCodeSystemStorageSvc theCodeSystemStorageSvc) {
120                return new TermLoaderSvcImpl(theDeferredStorageSvc, theCodeSystemStorageSvc);
121        }
122
123        @Override
124        @Bean(autowire = Autowire.BY_TYPE)
125        public ITermReadSvcR4 terminologyService() {
126                return new TermReadSvcR4();
127        }
128
129}