View Javadoc
1   package ca.uhn.fhir.jpa.config.r4;
2   
3   import ca.uhn.fhir.context.FhirContext;
4   import ca.uhn.fhir.context.ParserOptions;
5   import ca.uhn.fhir.jpa.config.BaseConfig;
6   import ca.uhn.fhir.jpa.dao.FulltextSearchSvcImpl;
7   import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
8   import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
9   import ca.uhn.fhir.jpa.dao.TransactionProcessor;
10  import ca.uhn.fhir.jpa.dao.r4.TransactionProcessorVersionAdapterR4;
11  import ca.uhn.fhir.jpa.graphql.JpaStorageServices;
12  import ca.uhn.fhir.jpa.provider.r4.TerminologyUploaderProviderR4;
13  import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorR4;
14  import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
15  import ca.uhn.fhir.jpa.searchparam.registry.SearchParamRegistryR4;
16  import ca.uhn.fhir.jpa.term.HapiTerminologySvcR4;
17  import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
18  import ca.uhn.fhir.jpa.term.IHapiTerminologySvcR4;
19  import ca.uhn.fhir.jpa.term.TerminologyLoaderSvcImpl;
20  import ca.uhn.fhir.jpa.util.ResourceCountCache;
21  import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainR4;
22  import ca.uhn.fhir.validation.IValidatorModule;
23  import org.apache.commons.lang3.time.DateUtils;
24  import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
25  import org.hl7.fhir.r4.hapi.rest.server.GraphQLProvider;
26  import org.hl7.fhir.r4.hapi.validation.CachingValidationSupport;
27  import org.hl7.fhir.r4.hapi.validation.FhirInstanceValidator;
28  import org.hl7.fhir.r4.model.Bundle;
29  import org.hl7.fhir.r4.utils.GraphQLEngine;
30  import org.hl7.fhir.r4.utils.IResourceValidator.BestPracticeWarningLevel;
31  import org.springframework.beans.factory.annotation.Autowire;
32  import org.springframework.context.annotation.Bean;
33  import org.springframework.context.annotation.Configuration;
34  import org.springframework.context.annotation.Lazy;
35  import org.springframework.context.annotation.Primary;
36  import org.springframework.transaction.annotation.EnableTransactionManagement;
37  
38  /*
39   * #%L
40   * HAPI FHIR JPA Server
41   * %%
42   * Copyright (C) 2014 - 2019 University Health Network
43   * %%
44   * Licensed under the Apache License, Version 2.0 (the "License");
45   * you may not use this file except in compliance with the License.
46   * You may obtain a copy of the License at
47   * 
48   * http://www.apache.org/licenses/LICENSE-2.0
49   * 
50   * Unless required by applicable law or agreed to in writing, software
51   * distributed under the License is distributed on an "AS IS" BASIS,
52   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53   * See the License for the specific language governing permissions and
54   * limitations under the License.
55   * #L%
56   */
57  
58  @Configuration
59  @EnableTransactionManagement
60  public class BaseR4Config extends BaseConfig {
61  
62  	@Override
63  	public FhirContext fhirContext() {
64  		return fhirContextR4();
65  	}
66  
67  	@Bean
68  	@Primary
69  	public FhirContext fhirContextR4() {
70  		FhirContext retVal = FhirContext.forR4();
71  
72  		// Don't strip versions in some places
73  		ParserOptions parserOptions = retVal.getParserOptions();
74  		parserOptions.setDontStripVersionsFromReferencesAtPaths("AuditEvent.entity.what");
75  
76  		return retVal;
77  	}
78  
79  	@Bean
80  	public TransactionProcessor.ITransactionProcessorVersionAdapter transactionProcessorVersionFacade() {
81  		return new TransactionProcessorVersionAdapterR4();
82  	}
83  
84  	@Bean
85  	public TransactionProcessor<Bundle, Bundle.BundleEntryComponent> transactionProcessor() {
86  		return new TransactionProcessor<>();
87  	}
88  
89  	@Bean(name = "myGraphQLProvider")
90  	@Lazy
91  	public GraphQLProvider graphQLProvider() {
92  		return new GraphQLProvider(fhirContextR4(), validationSupportChainR4(), graphqlStorageServices());
93  	}
94  
95  	@Bean
96  	@Lazy
97  	public GraphQLEngine.IGraphQLStorageServices graphqlStorageServices() {
98  		return new JpaStorageServices();
99  	}
100 
101 	@Bean(name = "myInstanceValidatorR4")
102 	@Lazy
103 	public IValidatorModule instanceValidatorR4() {
104 		FhirInstanceValidator val = new FhirInstanceValidator();
105 		val.setBestPracticeWarningLevel(BestPracticeWarningLevel.Warning);
106 		val.setValidationSupport(validationSupportChainR4());
107 		return val;
108 	}
109 
110 	@Bean
111 	public JpaValidationSupportChainR4 jpaValidationSupportChain() {
112 		return new JpaValidationSupportChainR4();
113 	}
114 
115 	@Bean(name = "myJpaValidationSupportR4", autowire = Autowire.BY_NAME)
116 	public ca.uhn.fhir.jpa.dao.r4.IJpaValidationSupportR4 jpaValidationSupportR4() {
117 		ca.uhn.fhir.jpa.dao.r4.JpaValidationSupportR4 retVal = new ca.uhn.fhir.jpa.dao.r4.JpaValidationSupportR4();
118 		return retVal;
119 	}
120 
121 	@Bean(name = "myResourceCountsCache")
122 	public ResourceCountCache resourceCountsCache() {
123 		ResourceCountCache retVal = new ResourceCountCache(() -> systemDaoR4().getResourceCounts());
124 		retVal.setCacheMillis(10 * DateUtils.MILLIS_PER_MINUTE);
125 		return retVal;
126 	}
127 
128 	@Bean(autowire = Autowire.BY_TYPE)
129 	public IFulltextSearchSvc searchDaoR4() {
130 		FulltextSearchSvcImpl searchDao = new FulltextSearchSvcImpl();
131 		return searchDao;
132 	}
133 
134 	@Bean(autowire = Autowire.BY_TYPE)
135 	public SearchParamExtractorR4 searchParamExtractor() {
136 		return new SearchParamExtractorR4();
137 	}
138 
139 	@Bean
140 	public ISearchParamRegistry searchParamRegistry() {
141 		return new SearchParamRegistryR4();
142 	}
143 
144 	@Bean(name = "mySystemDaoR4", autowire = Autowire.BY_NAME)
145 	public IFhirSystemDao<org.hl7.fhir.r4.model.Bundle, org.hl7.fhir.r4.model.Meta> systemDaoR4() {
146 		ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4 retVal = new ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4();
147 		return retVal;
148 	}
149 
150 	@Bean(name = "mySystemProviderR4")
151 	public ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4 systemProviderR4() {
152 		ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4 retVal = new ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4();
153 		retVal.setContext(fhirContextR4());
154 		retVal.setDao(systemDaoR4());
155 		return retVal;
156 	}
157 
158 	@Bean(autowire = Autowire.BY_TYPE)
159 	public IHapiTerminologyLoaderSvc terminologyLoaderService() {
160 		return new TerminologyLoaderSvcImpl();
161 	}
162 
163 	@Bean(autowire = Autowire.BY_TYPE)
164 	public IHapiTerminologySvcR4 terminologyService() {
165 		return new HapiTerminologySvcR4();
166 	}
167 
168 	@Bean(autowire = Autowire.BY_TYPE)
169 	public TerminologyUploaderProviderR4 terminologyUploaderProvider() {
170 		TerminologyUploaderProviderR4 retVal = new TerminologyUploaderProviderR4();
171 		retVal.setContext(fhirContextR4());
172 		return retVal;
173 	}
174 
175 	@Primary
176 	@Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChainR4")
177 	public IValidationSupport validationSupportChainR4() {
178 		return new CachingValidationSupport(jpaValidationSupportChain());
179 	}
180 
181 }