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