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.ISearchParamRegistry;
10  import ca.uhn.fhir.jpa.dao.r4.SearchParamExtractorR4;
11  import ca.uhn.fhir.jpa.dao.r4.SearchParamRegistryR4;
12  import ca.uhn.fhir.jpa.graphql.JpaStorageServices;
13  import ca.uhn.fhir.jpa.provider.r4.TerminologyUploaderProviderR4;
14  import ca.uhn.fhir.jpa.term.HapiTerminologySvcR4;
15  import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
16  import ca.uhn.fhir.jpa.term.IHapiTerminologySvcR4;
17  import ca.uhn.fhir.jpa.term.TerminologyLoaderSvcImpl;
18  import ca.uhn.fhir.jpa.util.ResourceCountCache;
19  import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainR4;
20  import ca.uhn.fhir.validation.IValidatorModule;
21  import org.apache.commons.lang3.time.DateUtils;
22  import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
23  import org.hl7.fhir.r4.hapi.rest.server.GraphQLProvider;
24  import org.hl7.fhir.r4.hapi.validation.FhirInstanceValidator;
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.reference");
71  
72  		return retVal;
73  	}
74  
75  	@Bean(name = "myGraphQLProvider")
76  	@Lazy
77  	public GraphQLProvider graphQLProvider() {
78  		return new GraphQLProvider(fhirContextR4(), validationSupportChainR4(), graphqlStorageServices());
79  	}
80  
81  	@Bean
82  	@Lazy
83  	public GraphQLEngine.IGraphQLStorageServices graphqlStorageServices() {
84  		return new JpaStorageServices();
85  	}
86  
87  	@Bean(name = "myInstanceValidatorR4")
88  	@Lazy
89  	public IValidatorModule instanceValidatorR4() {
90  		FhirInstanceValidator val = new FhirInstanceValidator();
91  		val.setBestPracticeWarningLevel(BestPracticeWarningLevel.Warning);
92  		val.setValidationSupport(validationSupportChainR4());
93  		return val;
94  	}
95  
96  	@Bean(name = "myJpaValidationSupportR4", autowire = Autowire.BY_NAME)
97  	public ca.uhn.fhir.jpa.dao.r4.IJpaValidationSupportR4 jpaValidationSupportR4() {
98  		ca.uhn.fhir.jpa.dao.r4.JpaValidationSupportR4 retVal = new ca.uhn.fhir.jpa.dao.r4.JpaValidationSupportR4();
99  		return retVal;
100 	}
101 
102 	@Bean(name = "myResourceCountsCache")
103 	public ResourceCountCache resourceCountsCache() {
104 		ResourceCountCache retVal = new ResourceCountCache(() -> systemDaoR4().getResourceCounts());
105 		retVal.setCacheMillis(60 * DateUtils.MILLIS_PER_SECOND);
106 		return retVal;
107 	}
108 
109 	@Bean(autowire = Autowire.BY_TYPE)
110 	public IFulltextSearchSvc searchDaoR4() {
111 		FulltextSearchSvcImpl searchDao = new FulltextSearchSvcImpl();
112 		return searchDao;
113 	}
114 
115 	@Bean(autowire = Autowire.BY_TYPE)
116 	public SearchParamExtractorR4 searchParamExtractor() {
117 		return new SearchParamExtractorR4();
118 	}
119 
120 	@Bean
121 	public ISearchParamRegistry searchParamRegistry() {
122 		return new SearchParamRegistryR4();
123 	}
124 
125 	@Bean(name = "mySystemDaoR4", autowire = Autowire.BY_NAME)
126 	public IFhirSystemDao<org.hl7.fhir.r4.model.Bundle, org.hl7.fhir.r4.model.Meta> systemDaoR4() {
127 		ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4 retVal = new ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4();
128 		return retVal;
129 	}
130 
131 	@Bean(name = "mySystemProviderR4")
132 	public ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4 systemProviderR4() {
133 		ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4 retVal = new ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4();
134 		retVal.setContext(fhirContextR4());
135 		retVal.setDao(systemDaoR4());
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 IHapiTerminologySvcR4 terminologyService() {
146 		return new HapiTerminologySvcR4();
147 	}
148 
149 	@Bean(autowire = Autowire.BY_TYPE)
150 	public TerminologyUploaderProviderR4 terminologyUploaderProvider() {
151 		TerminologyUploaderProviderR4 retVal = new TerminologyUploaderProviderR4();
152 		retVal.setContext(fhirContextR4());
153 		return retVal;
154 	}
155 
156 	@Primary
157 	@Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChainR4")
158 	public IValidationSupport validationSupportChainR4() {
159 		return new JpaValidationSupportChainR4();
160 	}
161 
162 }