View Javadoc
1   package ca.uhn.fhir.jpa.config;
2   
3   import ca.uhn.fhir.context.FhirContext;
4   import ca.uhn.fhir.jpa.dao.*;
5   import ca.uhn.fhir.jpa.term.HapiTerminologySvcDstu2;
6   import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
7   import ca.uhn.fhir.jpa.util.ResourceCountCache;
8   import ca.uhn.fhir.model.dstu2.composite.MetaDt;
9   import ca.uhn.fhir.validation.IValidatorModule;
10  import org.apache.commons.lang3.time.DateUtils;
11  import org.hl7.fhir.instance.hapi.validation.CachingValidationSupport;
12  import org.hl7.fhir.instance.hapi.validation.DefaultProfileValidationSupport;
13  import org.hl7.fhir.instance.hapi.validation.FhirInstanceValidator;
14  import org.hl7.fhir.instance.hapi.validation.ValidationSupportChain;
15  import org.hl7.fhir.r4.utils.IResourceValidator;
16  import org.springframework.beans.factory.annotation.Autowire;
17  import org.springframework.context.annotation.Bean;
18  import org.springframework.context.annotation.Configuration;
19  import org.springframework.context.annotation.Lazy;
20  import org.springframework.context.annotation.Primary;
21  import org.springframework.transaction.annotation.EnableTransactionManagement;
22  
23  /*
24   * #%L
25   * HAPI FHIR JPA Server
26   * %%
27   * Copyright (C) 2014 - 2018 University Health Network
28   * %%
29   * Licensed under the Apache License, Version 2.0 (the "License");
30   * you may not use this file except in compliance with the License.
31   * You may obtain a copy of the License at
32   * 
33   * http://www.apache.org/licenses/LICENSE-2.0
34   * 
35   * Unless required by applicable law or agreed to in writing, software
36   * distributed under the License is distributed on an "AS IS" BASIS,
37   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38   * See the License for the specific language governing permissions and
39   * limitations under the License.
40   * #L%
41   */
42  
43  @Configuration
44  @EnableTransactionManagement
45  public class BaseDstu2Config extends BaseConfig {
46  
47  	private static FhirContext ourFhirContextDstu2;
48  	private static FhirContext ourFhirContextDstu2Hl7Org;
49  
50  	@Bean
51  	@Primary
52  	public FhirContext defaultFhirContext() {
53  		return fhirContextDstu2();
54  	}
55  
56  	@Override
57  	public FhirContext fhirContext() {
58  		return fhirContextDstu2();
59  	}
60  
61  	@Bean(name = "myFhirContextDstu2")
62  	@Lazy
63  	public FhirContext fhirContextDstu2() {
64  		if (ourFhirContextDstu2 == null) {
65  			ourFhirContextDstu2 = FhirContext.forDstu2();
66  		}
67  		return ourFhirContextDstu2;
68  	}
69  
70  	@Bean(name = "myFhirContextDstu2Hl7Org")
71  	@Lazy
72  	public FhirContext fhirContextDstu2Hl7Org() {
73  		if (ourFhirContextDstu2Hl7Org == null) {
74  			ourFhirContextDstu2Hl7Org = FhirContext.forDstu2Hl7Org();
75  		}
76  		return ourFhirContextDstu2Hl7Org;
77  	}
78  
79  	@Bean(name = "myInstanceValidatorDstu2")
80  	@Lazy
81  	public IValidatorModule instanceValidatorDstu2() {
82  		FhirInstanceValidator retVal = new FhirInstanceValidator();
83  		retVal.setBestPracticeWarningLevel(IResourceValidator.BestPracticeWarningLevel.Warning);
84  		retVal.setValidationSupport(new CachingValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(), jpaValidationSupportDstu2())));
85  		return retVal;
86  	}
87  
88  	@Bean(name = "myJpaValidationSupportDstu2", autowire = Autowire.BY_NAME)
89  	public ca.uhn.fhir.jpa.dao.IJpaValidationSupportDstu2 jpaValidationSupportDstu2() {
90  		ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2 retVal = new ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2();
91  		return retVal;
92  	}
93  
94  	@Bean(name = "myResourceCountsCache")
95  	public ResourceCountCache resourceCountsCache() {
96  		ResourceCountCache retVal = new ResourceCountCache(() -> systemDaoDstu2().getResourceCounts());
97  		retVal.setCacheMillis(60 * DateUtils.MILLIS_PER_SECOND);
98  		return retVal;
99  	}
100 
101 	@Bean(autowire = Autowire.BY_TYPE)
102 	public IFulltextSearchSvc searchDao() {
103 		FulltextSearchSvcImpl searchDao = new FulltextSearchSvcImpl();
104 		return searchDao;
105 	}
106 
107 	@Bean(autowire = Autowire.BY_TYPE)
108 	public SearchParamExtractorDstu2 searchParamExtractor() {
109 		return new SearchParamExtractorDstu2();
110 	}
111 
112 	@Bean
113 	public ISearchParamRegistry searchParamRegistry() {
114 		return new SearchParamRegistryDstu2();
115 	}
116 
117 	@Bean(name = "mySystemDaoDstu2", autowire = Autowire.BY_NAME)
118 	public IFhirSystemDao<ca.uhn.fhir.model.dstu2.resource.Bundle, MetaDt> systemDaoDstu2() {
119 		ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu2 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu2();
120 		return retVal;
121 	}
122 
123 	@Bean(name = "mySystemProviderDstu2")
124 	public ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2 systemProviderDstu2() {
125 		ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2 retVal = new ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2();
126 		retVal.setDao(systemDaoDstu2());
127 		retVal.setContext(fhirContextDstu2());
128 		return retVal;
129 	}
130 
131 	@Bean(autowire = Autowire.BY_TYPE)
132 	public IHapiTerminologySvc terminologyService() {
133 		return new HapiTerminologySvcDstu2();
134 	}
135 
136 }