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.FulltextSearchSvcImpl;
7   import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
8   import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
9   import ca.uhn.fhir.jpa.dao.ISearchParamRegistry;
10  import ca.uhn.fhir.jpa.dao.dstu3.SearchParamExtractorDstu3;
11  import ca.uhn.fhir.jpa.dao.dstu3.SearchParamRegistryDstu3;
12  import ca.uhn.fhir.jpa.provider.dstu3.TerminologyUploaderProviderDstu3;
13  import ca.uhn.fhir.jpa.term.HapiTerminologySvcDstu3;
14  import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
15  import ca.uhn.fhir.jpa.term.IHapiTerminologySvcDstu3;
16  import ca.uhn.fhir.jpa.term.TerminologyLoaderSvcImpl;
17  import ca.uhn.fhir.jpa.util.ResourceCountCache;
18  import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainDstu3;
19  import ca.uhn.fhir.validation.IValidatorModule;
20  import org.apache.commons.lang3.time.DateUtils;
21  import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport;
22  import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator;
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(name = "myInstanceValidatorDstu3")
73  	@Lazy
74  	public IValidatorModule instanceValidatorDstu3() {
75  		FhirInstanceValidator val = new FhirInstanceValidator();
76  		val.setBestPracticeWarningLevel(IResourceValidator.BestPracticeWarningLevel.Warning);
77  		val.setValidationSupport(validationSupportChainDstu3());
78  		return val;
79  	}
80  
81  	@Bean(name = "myJpaValidationSupportDstu3", autowire = Autowire.BY_NAME)
82  	public ca.uhn.fhir.jpa.dao.dstu3.IJpaValidationSupportDstu3 jpaValidationSupportDstu3() {
83  		ca.uhn.fhir.jpa.dao.dstu3.JpaValidationSupportDstu3 retVal = new ca.uhn.fhir.jpa.dao.dstu3.JpaValidationSupportDstu3();
84  		return retVal;
85  	}
86  
87  
88  	@Bean(name = "myResourceCountsCache")
89  	public ResourceCountCache resourceCountsCache() {
90  		ResourceCountCache retVal = new ResourceCountCache(() -> systemDaoDstu3().getResourceCounts());
91  		retVal.setCacheMillis(60 * DateUtils.MILLIS_PER_SECOND);
92  		return retVal;
93  	}
94  
95  	@Bean(autowire = Autowire.BY_TYPE)
96  	public IFulltextSearchSvc searchDaoDstu3() {
97  		FulltextSearchSvcImpl searchDao = new FulltextSearchSvcImpl();
98  		return searchDao;
99  	}
100 
101 	@Bean(autowire = Autowire.BY_TYPE)
102 	public SearchParamExtractorDstu3 searchParamExtractor() {
103 		return new SearchParamExtractorDstu3();
104 	}
105 
106 	@Bean
107 	public ISearchParamRegistry searchParamRegistry() {
108 		return new SearchParamRegistryDstu3();
109 	}
110 
111 	@Bean(name = "mySystemDaoDstu3", autowire = Autowire.BY_NAME)
112 	public IFhirSystemDao<org.hl7.fhir.dstu3.model.Bundle, org.hl7.fhir.dstu3.model.Meta> systemDaoDstu3() {
113 		ca.uhn.fhir.jpa.dao.dstu3.FhirSystemDaoDstu3 retVal = new ca.uhn.fhir.jpa.dao.dstu3.FhirSystemDaoDstu3();
114 		return retVal;
115 	}
116 
117 	@Bean(name = "mySystemProviderDstu3")
118 	public ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3 systemProviderDstu3() {
119 		ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3 retVal = new ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3();
120 		retVal.setContext(fhirContextDstu3());
121 		retVal.setDao(systemDaoDstu3());
122 		return retVal;
123 	}
124 
125 	@Bean(autowire = Autowire.BY_TYPE)
126 	public IHapiTerminologyLoaderSvc terminologyLoaderService() {
127 		return new TerminologyLoaderSvcImpl();
128 	}
129 
130 	@Bean(autowire = Autowire.BY_TYPE)
131 	public IHapiTerminologySvcDstu3 terminologyService() {
132 		return new HapiTerminologySvcDstu3();
133 	}
134 
135 	@Bean(autowire = Autowire.BY_TYPE)
136 	public TerminologyUploaderProviderDstu3 terminologyUploaderProvider() {
137 		TerminologyUploaderProviderDstu3 retVal = new TerminologyUploaderProviderDstu3();
138 		retVal.setContext(fhirContextDstu3());
139 		return retVal;
140 	}
141 
142 	@Primary
143 	@Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChainDstu3")
144 	public IValidationSupport validationSupportChainDstu3() {
145 		return new JpaValidationSupportChainDstu3();
146 	}
147 
148 }