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