001/*
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2025 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.jpa.config;
021
022import ca.uhn.fhir.batch2.api.IJobCoordinator;
023import ca.uhn.fhir.batch2.api.IJobPersistence;
024import ca.uhn.fhir.batch2.jobs.export.BulkDataExportProvider;
025import ca.uhn.fhir.batch2.jobs.expunge.DeleteExpungeJobSubmitterImpl;
026import ca.uhn.fhir.batch2.util.Batch2TaskHelper;
027import ca.uhn.fhir.context.FhirContext;
028import ca.uhn.fhir.context.FhirVersionEnum;
029import ca.uhn.fhir.context.support.IValidationSupport;
030import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster;
031import ca.uhn.fhir.interceptor.api.IInterceptorService;
032import ca.uhn.fhir.interceptor.executor.InterceptorService;
033import ca.uhn.fhir.interceptor.model.RequestPartitionId;
034import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
035import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
036import ca.uhn.fhir.jpa.api.model.ExpungeOptions;
037import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
038import ca.uhn.fhir.jpa.api.svc.ISearchUrlJobMaintenanceSvc;
039import ca.uhn.fhir.jpa.binary.interceptor.BinaryStorageInterceptor;
040import ca.uhn.fhir.jpa.binary.provider.BinaryAccessProvider;
041import ca.uhn.fhir.jpa.bulk.export.api.IBulkDataExportJobSchedulingHelper;
042import ca.uhn.fhir.jpa.bulk.export.svc.BulkDataExportJobSchedulingHelperImpl;
043import ca.uhn.fhir.jpa.bulk.export.svc.BulkExportHelperService;
044import ca.uhn.fhir.jpa.bulk.imprt.api.IBulkDataImportSvc;
045import ca.uhn.fhir.jpa.bulk.imprt.svc.BulkDataImportSvcImpl;
046import ca.uhn.fhir.jpa.cache.IResourceVersionSvc;
047import ca.uhn.fhir.jpa.cache.ISearchParamIdentityCacheSvc;
048import ca.uhn.fhir.jpa.cache.ResourceVersionSvcDaoImpl;
049import ca.uhn.fhir.jpa.dao.CacheTagDefinitionDao;
050import ca.uhn.fhir.jpa.dao.DaoSearchParamProvider;
051import ca.uhn.fhir.jpa.dao.HistoryBuilder;
052import ca.uhn.fhir.jpa.dao.HistoryBuilderFactory;
053import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
054import ca.uhn.fhir.jpa.dao.IJpaStorageResourceParser;
055import ca.uhn.fhir.jpa.dao.ISearchBuilder;
056import ca.uhn.fhir.jpa.dao.JpaStorageResourceParser;
057import ca.uhn.fhir.jpa.dao.MatchResourceUrlService;
058import ca.uhn.fhir.jpa.dao.ResourceHistoryCalculator;
059import ca.uhn.fhir.jpa.dao.SearchBuilderFactory;
060import ca.uhn.fhir.jpa.dao.TransactionProcessor;
061import ca.uhn.fhir.jpa.dao.data.IResourceIndexedSearchParamIdentityDao;
062import ca.uhn.fhir.jpa.dao.data.IResourceLinkDao;
063import ca.uhn.fhir.jpa.dao.data.IResourceModifiedDao;
064import ca.uhn.fhir.jpa.dao.data.IResourceSearchUrlDao;
065import ca.uhn.fhir.jpa.dao.data.ITagDefinitionDao;
066import ca.uhn.fhir.jpa.dao.expunge.ExpungeEverythingService;
067import ca.uhn.fhir.jpa.dao.expunge.ExpungeOperation;
068import ca.uhn.fhir.jpa.dao.expunge.ExpungeService;
069import ca.uhn.fhir.jpa.dao.expunge.IExpungeEverythingService;
070import ca.uhn.fhir.jpa.dao.expunge.IResourceExpungeService;
071import ca.uhn.fhir.jpa.dao.expunge.JpaResourceExpungeService;
072import ca.uhn.fhir.jpa.dao.expunge.ResourceTableFKProvider;
073import ca.uhn.fhir.jpa.dao.index.DaoResourceLinkResolver;
074import ca.uhn.fhir.jpa.dao.index.DaoSearchParamSynchronizer;
075import ca.uhn.fhir.jpa.dao.index.IdHelperService;
076import ca.uhn.fhir.jpa.dao.index.SearchParamWithInlineReferencesExtractor;
077import ca.uhn.fhir.jpa.dao.tx.HapiTransactionService;
078import ca.uhn.fhir.jpa.dao.validation.SearchParameterDaoValidator;
079import ca.uhn.fhir.jpa.delete.DeleteConflictFinderService;
080import ca.uhn.fhir.jpa.delete.DeleteConflictService;
081import ca.uhn.fhir.jpa.delete.ThreadSafeResourceDeleterSvc;
082import ca.uhn.fhir.jpa.entity.Search;
083import ca.uhn.fhir.jpa.entity.TermValueSet;
084import ca.uhn.fhir.jpa.esr.ExternallyStoredResourceServiceRegistry;
085import ca.uhn.fhir.jpa.graphql.DaoRegistryGraphQLStorageServices;
086import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor;
087import ca.uhn.fhir.jpa.interceptor.JpaConsentContextServices;
088import ca.uhn.fhir.jpa.interceptor.OverridePathBasedReferentialIntegrityForDeletesInterceptor;
089import ca.uhn.fhir.jpa.interceptor.validation.RepositoryValidatingRuleBuilder;
090import ca.uhn.fhir.jpa.model.config.PartitionSettings;
091import ca.uhn.fhir.jpa.model.dao.JpaPid;
092import ca.uhn.fhir.jpa.model.sched.ISchedulerService;
093import ca.uhn.fhir.jpa.packages.IHapiPackageCacheManager;
094import ca.uhn.fhir.jpa.packages.IPackageInstallerSvc;
095import ca.uhn.fhir.jpa.packages.JpaPackageCache;
096import ca.uhn.fhir.jpa.packages.NpmJpaValidationSupport;
097import ca.uhn.fhir.jpa.packages.PackageInstallerSvcImpl;
098import ca.uhn.fhir.jpa.packages.util.PackageUtils;
099import ca.uhn.fhir.jpa.partition.IPartitionLookupSvc;
100import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc;
101import ca.uhn.fhir.jpa.partition.PartitionLookupSvcImpl;
102import ca.uhn.fhir.jpa.partition.PartitionManagementProvider;
103import ca.uhn.fhir.jpa.partition.RequestPartitionHelperSvc;
104import ca.uhn.fhir.jpa.provider.DiffProvider;
105import ca.uhn.fhir.jpa.provider.IReplaceReferencesSvc;
106import ca.uhn.fhir.jpa.provider.InstanceReindexProvider;
107import ca.uhn.fhir.jpa.provider.ProcessMessageProvider;
108import ca.uhn.fhir.jpa.provider.ReplaceReferencesSvcImpl;
109import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider;
110import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider;
111import ca.uhn.fhir.jpa.provider.ValueSetOperationProvider;
112import ca.uhn.fhir.jpa.provider.ValueSetOperationProviderDstu2;
113import ca.uhn.fhir.jpa.sched.AutowiringSpringBeanJobFactory;
114import ca.uhn.fhir.jpa.sched.HapiSchedulerServiceImpl;
115import ca.uhn.fhir.jpa.search.ISynchronousSearchSvc;
116import ca.uhn.fhir.jpa.search.PersistedJpaBundleProvider;
117import ca.uhn.fhir.jpa.search.PersistedJpaBundleProviderFactory;
118import ca.uhn.fhir.jpa.search.PersistedJpaSearchFirstPageBundleProvider;
119import ca.uhn.fhir.jpa.search.ResourceSearchUrlSvc;
120import ca.uhn.fhir.jpa.search.SearchStrategyFactory;
121import ca.uhn.fhir.jpa.search.SearchUrlJobMaintenanceSvcImpl;
122import ca.uhn.fhir.jpa.search.SynchronousSearchSvcImpl;
123import ca.uhn.fhir.jpa.search.builder.QueryStack;
124import ca.uhn.fhir.jpa.search.builder.predicate.ComboNonUniqueSearchParameterPredicateBuilder;
125import ca.uhn.fhir.jpa.search.builder.predicate.ComboUniqueSearchParameterPredicateBuilder;
126import ca.uhn.fhir.jpa.search.builder.predicate.CoordsPredicateBuilder;
127import ca.uhn.fhir.jpa.search.builder.predicate.DatePredicateBuilder;
128import ca.uhn.fhir.jpa.search.builder.predicate.NumberPredicateBuilder;
129import ca.uhn.fhir.jpa.search.builder.predicate.QuantityNormalizedPredicateBuilder;
130import ca.uhn.fhir.jpa.search.builder.predicate.QuantityPredicateBuilder;
131import ca.uhn.fhir.jpa.search.builder.predicate.ResourceHistoryPredicateBuilder;
132import ca.uhn.fhir.jpa.search.builder.predicate.ResourceHistoryProvenancePredicateBuilder;
133import ca.uhn.fhir.jpa.search.builder.predicate.ResourceIdPredicateBuilder;
134import ca.uhn.fhir.jpa.search.builder.predicate.ResourceLinkPredicateBuilder;
135import ca.uhn.fhir.jpa.search.builder.predicate.ResourceTablePredicateBuilder;
136import ca.uhn.fhir.jpa.search.builder.predicate.SearchParamPresentPredicateBuilder;
137import ca.uhn.fhir.jpa.search.builder.predicate.StringPredicateBuilder;
138import ca.uhn.fhir.jpa.search.builder.predicate.TagPredicateBuilder;
139import ca.uhn.fhir.jpa.search.builder.predicate.TokenPredicateBuilder;
140import ca.uhn.fhir.jpa.search.builder.predicate.UriPredicateBuilder;
141import ca.uhn.fhir.jpa.search.builder.sql.GeneratedSql;
142import ca.uhn.fhir.jpa.search.builder.sql.SearchQueryBuilder;
143import ca.uhn.fhir.jpa.search.builder.sql.SearchQueryExecutor;
144import ca.uhn.fhir.jpa.search.builder.sql.SqlObjectFactory;
145import ca.uhn.fhir.jpa.search.builder.tasks.SearchTask;
146import ca.uhn.fhir.jpa.search.cache.DatabaseSearchCacheSvcImpl;
147import ca.uhn.fhir.jpa.search.cache.DatabaseSearchResultCacheSvcImpl;
148import ca.uhn.fhir.jpa.search.cache.ISearchCacheSvc;
149import ca.uhn.fhir.jpa.search.cache.ISearchResultCacheSvc;
150import ca.uhn.fhir.jpa.search.elastic.IndexNamePrefixLayoutStrategy;
151import ca.uhn.fhir.jpa.search.reindex.IInstanceReindexService;
152import ca.uhn.fhir.jpa.search.reindex.IResourceReindexingSvc;
153import ca.uhn.fhir.jpa.search.reindex.InstanceReindexServiceImpl;
154import ca.uhn.fhir.jpa.search.reindex.ResourceReindexer;
155import ca.uhn.fhir.jpa.search.reindex.ResourceReindexingSvcImpl;
156import ca.uhn.fhir.jpa.search.warm.CacheWarmingSvcImpl;
157import ca.uhn.fhir.jpa.search.warm.ICacheWarmingSvc;
158import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
159import ca.uhn.fhir.jpa.searchparam.config.SearchParamConfig;
160import ca.uhn.fhir.jpa.searchparam.extractor.IResourceLinkResolver;
161import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamProvider;
162import ca.uhn.fhir.jpa.sp.ISearchParamPresenceSvc;
163import ca.uhn.fhir.jpa.sp.SearchParamIdentityCacheSvcImpl;
164import ca.uhn.fhir.jpa.sp.SearchParamPresenceSvcImpl;
165import ca.uhn.fhir.jpa.subscription.ResourceModifiedMessagePersistenceSvcImpl;
166import ca.uhn.fhir.jpa.term.TermCodeSystemStorageSvcImpl;
167import ca.uhn.fhir.jpa.term.TermConceptMappingSvcImpl;
168import ca.uhn.fhir.jpa.term.TermReadSvcImpl;
169import ca.uhn.fhir.jpa.term.TermReindexingSvcImpl;
170import ca.uhn.fhir.jpa.term.ValueSetConceptAccumulator;
171import ca.uhn.fhir.jpa.term.ValueSetConceptAccumulatorFactory;
172import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
173import ca.uhn.fhir.jpa.term.api.ITermConceptMappingSvc;
174import ca.uhn.fhir.jpa.term.api.ITermReadSvc;
175import ca.uhn.fhir.jpa.term.api.ITermReindexingSvc;
176import ca.uhn.fhir.jpa.term.config.TermCodeSystemConfig;
177import ca.uhn.fhir.jpa.util.JpaHapiTransactionService;
178import ca.uhn.fhir.jpa.util.MemoryCacheService;
179import ca.uhn.fhir.jpa.util.PartitionedIdModeVerificationSvc;
180import ca.uhn.fhir.jpa.util.PersistenceContextProvider;
181import ca.uhn.fhir.jpa.validation.JpaValidationSupportChain;
182import ca.uhn.fhir.jpa.validation.ResourceLoaderImpl;
183import ca.uhn.fhir.jpa.validation.ValidationSettings;
184import ca.uhn.fhir.model.api.IPrimitiveDatatype;
185import ca.uhn.fhir.replacereferences.ReplaceReferencesPatchBundleSvc;
186import ca.uhn.fhir.rest.api.server.RequestDetails;
187import ca.uhn.fhir.rest.api.server.storage.IDeleteExpungeJobSubmitter;
188import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
189import ca.uhn.fhir.rest.server.interceptor.ResponseTerminologyTranslationInterceptor;
190import ca.uhn.fhir.rest.server.interceptor.ResponseTerminologyTranslationSvc;
191import ca.uhn.fhir.rest.server.interceptor.consent.IConsentContextServices;
192import ca.uhn.fhir.rest.server.interceptor.partition.RequestTenantPartitionInterceptor;
193import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
194import ca.uhn.fhir.subscription.api.IResourceModifiedMessagePersistenceSvc;
195import ca.uhn.fhir.util.IMetaTagSorter;
196import ca.uhn.fhir.util.MetaTagSorterAlphabetical;
197import ca.uhn.hapi.converters.canonical.VersionCanonicalizer;
198import jakarta.annotation.Nullable;
199import org.hl7.fhir.common.hapi.validation.support.UnknownCodeSystemWarningValidationSupport;
200import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain;
201import org.hl7.fhir.utilities.graphql.IGraphQLStorageServices;
202import org.springframework.beans.factory.annotation.Autowired;
203import org.springframework.context.annotation.Bean;
204import org.springframework.context.annotation.Configuration;
205import org.springframework.context.annotation.Import;
206import org.springframework.context.annotation.Lazy;
207import org.springframework.context.annotation.Primary;
208import org.springframework.context.annotation.Scope;
209import org.springframework.core.task.AsyncTaskExecutor;
210import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean;
211import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
212import org.springframework.scheduling.TaskScheduler;
213import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
214import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean;
215import org.springframework.transaction.PlatformTransactionManager;
216
217import java.util.Date;
218
219@Configuration
220// repositoryFactoryBeanClass: EnversRevisionRepositoryFactoryBean is needed primarily for unit testing
221@EnableJpaRepositories(
222                basePackages = "ca.uhn.fhir.jpa.dao.data",
223                repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
224@Import({
225        BeanPostProcessorConfig.class,
226        TermCodeSystemConfig.class,
227        SearchParamConfig.class,
228        ValidationSupportConfig.class,
229        Batch2SupportConfig.class,
230        JpaBulkExportConfig.class,
231        SearchConfig.class,
232        PackageLoaderConfig.class,
233        EnversAuditConfig.class,
234        MdmJpaConfig.class
235})
236public class JpaConfig {
237        public static final String JPA_VALIDATION_SUPPORT_CHAIN = "myJpaValidationSupportChain";
238        public static final String JPA_VALIDATION_SUPPORT = "myJpaValidationSupport";
239        public static final String TASK_EXECUTOR_NAME = "hapiJpaTaskExecutor";
240        public static final String GRAPHQL_PROVIDER_NAME = "myGraphQLProvider";
241        public static final String PERSISTED_JPA_BUNDLE_PROVIDER = "PersistedJpaBundleProvider";
242        public static final String PERSISTED_JPA_BUNDLE_PROVIDER_BY_SEARCH = "PersistedJpaBundleProvider_BySearch";
243        public static final String PERSISTED_JPA_SEARCH_FIRST_PAGE_BUNDLE_PROVIDER =
244                        "PersistedJpaSearchFirstPageBundleProvider";
245        public static final String HISTORY_BUILDER = "HistoryBuilder";
246        public static final String DEFAULT_PROFILE_VALIDATION_SUPPORT = "myDefaultProfileValidationSupport";
247        private static final String HAPI_DEFAULT_SCHEDULER_GROUP = "HAPI";
248
249        @Autowired
250        public JpaStorageSettings myStorageSettings;
251
252        @Autowired
253        private FhirContext myFhirContext;
254
255        @Bean
256        public ValidationSupportChain.CacheConfiguration validationSupportChainCacheConfiguration() {
257                return ValidationSupportChain.CacheConfiguration.defaultValues();
258        }
259
260        @Bean(name = JpaConfig.JPA_VALIDATION_SUPPORT_CHAIN)
261        @Primary
262        public IValidationSupport jpaValidationSupportChain() {
263                return new JpaValidationSupportChain(myFhirContext, validationSupportChainCacheConfiguration());
264        }
265
266        @Bean("myDaoRegistry")
267        public DaoRegistry daoRegistry() {
268                return new DaoRegistry();
269        }
270
271        @Lazy
272        @Bean
273        public CascadingDeleteInterceptor cascadingDeleteInterceptor(
274                        FhirContext theFhirContext,
275                        DaoRegistry theDaoRegistry,
276                        IInterceptorBroadcaster theInterceptorBroadcaster,
277                        ThreadSafeResourceDeleterSvc threadSafeResourceDeleterSvc) {
278                return new CascadingDeleteInterceptor(
279                                theFhirContext, theDaoRegistry, theInterceptorBroadcaster, threadSafeResourceDeleterSvc);
280        }
281
282        @Bean
283        public ExternallyStoredResourceServiceRegistry ExternallyStoredResourceServiceRegistry() {
284                return new ExternallyStoredResourceServiceRegistry();
285        }
286
287        @Lazy
288        @Bean
289        public ThreadSafeResourceDeleterSvc safeDeleter(
290                        DaoRegistry theDaoRegistry,
291                        IInterceptorBroadcaster theInterceptorBroadcaster,
292                        HapiTransactionService hapiTransactionService) {
293                return new ThreadSafeResourceDeleterSvc(theDaoRegistry, theInterceptorBroadcaster, hapiTransactionService);
294        }
295
296        @Lazy
297        @Bean
298        public ResponseTerminologyTranslationInterceptor responseTerminologyTranslationInterceptor(
299                        IValidationSupport theValidationSupport,
300                        ResponseTerminologyTranslationSvc theResponseTerminologyTranslationSvc) {
301                return new ResponseTerminologyTranslationInterceptor(
302                                theValidationSupport, theResponseTerminologyTranslationSvc);
303        }
304
305        @Bean
306        public ResponseTerminologyTranslationSvc responseTerminologyTranslationSvc(
307                        IValidationSupport theValidationSupport) {
308                return new ResponseTerminologyTranslationSvc(theValidationSupport);
309        }
310
311        @Bean
312        @Lazy
313        public IGraphQLStorageServices graphqlStorageServices() {
314                return new DaoRegistryGraphQLStorageServices();
315        }
316
317        @Bean
318        public ScheduledExecutorFactoryBean scheduledExecutorService() {
319                ScheduledExecutorFactoryBean b = new ScheduledExecutorFactoryBean();
320                b.setPoolSize(5);
321                b.afterPropertiesSet();
322                return b;
323        }
324
325        @Bean(name = "mySubscriptionTriggeringProvider")
326        @Lazy
327        public SubscriptionTriggeringProvider subscriptionTriggeringProvider() {
328                return new SubscriptionTriggeringProvider();
329        }
330
331        @Bean
332        @Lazy
333        public ValueSetOperationProvider valueSetOperationProvider(FhirContext theFhirContext) {
334                if (theFhirContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU2)) {
335                        return new ValueSetOperationProviderDstu2();
336                }
337                return new ValueSetOperationProvider();
338        }
339
340        @Bean
341        public IJpaStorageResourceParser jpaStorageResourceParser() {
342                return new JpaStorageResourceParser();
343        }
344
345        @Bean
346        public TransactionProcessor transactionProcessor() {
347                return new TransactionProcessor();
348        }
349
350        @Bean(name = "myAttachmentBinaryAccessProvider")
351        @Lazy
352        public BinaryAccessProvider binaryAccessProvider() {
353                return new BinaryAccessProvider();
354        }
355
356        @Bean(name = "myBinaryStorageInterceptor")
357        @Lazy
358        public BinaryStorageInterceptor<? extends IPrimitiveDatatype<byte[]>> binaryStorageInterceptor(
359                        JpaStorageSettings theStorageSettings, FhirContext theCtx) {
360                BinaryStorageInterceptor<? extends IPrimitiveDatatype<byte[]>> interceptor =
361                                new BinaryStorageInterceptor<>(theCtx);
362                interceptor.setAllowAutoInflateBinaries(theStorageSettings.isAllowAutoInflateBinaries());
363                interceptor.setAutoInflateBinariesMaximumSize(theStorageSettings.getAutoInflateBinariesMaximumBytes());
364                return interceptor;
365        }
366
367        @Bean
368        public MemoryCacheService memoryCacheService(JpaStorageSettings theStorageSettings) {
369                return new MemoryCacheService(theStorageSettings);
370        }
371
372        @Bean
373        @Primary
374        public IResourceLinkResolver daoResourceLinkResolver() {
375                return new DaoResourceLinkResolver<JpaPid>();
376        }
377
378        @Bean(name = PackageUtils.LOADER_WITH_CACHE)
379        public IHapiPackageCacheManager packageCacheManager() {
380                return new JpaPackageCache();
381        }
382
383        @Bean
384        public NpmJpaValidationSupport npmJpaValidationSupport() {
385                return new NpmJpaValidationSupport();
386        }
387
388        @Bean
389        public ValidationSettings validationSettings() {
390                return new ValidationSettings();
391        }
392
393        @Bean
394        public ISearchCacheSvc searchCacheSvc() {
395                return new DatabaseSearchCacheSvcImpl();
396        }
397
398        @Bean
399        public ISearchResultCacheSvc searchResultCacheSvc() {
400                return new DatabaseSearchResultCacheSvcImpl();
401        }
402
403        @Bean
404        public ITermConceptMappingSvc termConceptMappingSvc() {
405                return new TermConceptMappingSvcImpl();
406        }
407
408        @Bean
409        public TaskScheduler taskScheduler() {
410                ConcurrentTaskScheduler retVal = new ConcurrentTaskScheduler(
411                                scheduledExecutorService().getObject(),
412                                scheduledExecutorService().getObject());
413                return retVal;
414        }
415
416        @Bean(name = TASK_EXECUTOR_NAME)
417        public AsyncTaskExecutor taskExecutor() {
418                ConcurrentTaskScheduler retVal = new ConcurrentTaskScheduler(
419                                scheduledExecutorService().getObject(),
420                                scheduledExecutorService().getObject());
421                return retVal;
422        }
423
424        @Bean
425        public IResourceReindexingSvc resourceReindexingSvc() {
426                return new ResourceReindexingSvcImpl();
427        }
428
429        @Bean
430        @Lazy
431        public IInstanceReindexService instanceReindexService() {
432                return new InstanceReindexServiceImpl();
433        }
434
435        @Bean
436        @Lazy
437        public InstanceReindexProvider instanceReindexProvider(IInstanceReindexService theInstanceReindexService) {
438                return new InstanceReindexProvider(theInstanceReindexService);
439        }
440
441        @Bean
442        public ResourceReindexer resourceReindexer(FhirContext theFhirContext) {
443                return new ResourceReindexer(theFhirContext);
444        }
445
446        @Bean
447        public HapiFhirHibernateJpaDialect hibernateJpaDialect(FhirContext theFhirContext) {
448                return new HapiFhirHibernateJpaDialect(theFhirContext.getLocalizer());
449        }
450
451        @Bean
452        @Lazy
453        public OverridePathBasedReferentialIntegrityForDeletesInterceptor
454                        overridePathBasedReferentialIntegrityForDeletesInterceptor() {
455                return new OverridePathBasedReferentialIntegrityForDeletesInterceptor();
456        }
457
458        @Bean
459        public IRequestPartitionHelperSvc requestPartitionHelperService() {
460                return new RequestPartitionHelperSvc();
461        }
462
463        @Bean
464        public HapiTransactionService hapiTransactionService() {
465                return new JpaHapiTransactionService();
466        }
467
468        @Bean
469        public IInterceptorService jpaInterceptorService() {
470                return new InterceptorService();
471        }
472
473        @Bean
474        public IPackageInstallerSvc npmInstallerSvc() {
475                return new PackageInstallerSvcImpl();
476        }
477
478        @Bean
479        public IConsentContextServices consentContextServices() {
480                return new JpaConsentContextServices();
481        }
482
483        @Bean
484        @Lazy
485        public DiffProvider diffProvider() {
486                return new DiffProvider();
487        }
488
489        @Bean
490        @Lazy
491        public IPartitionLookupSvc partitionConfigSvc() {
492                return new PartitionLookupSvcImpl();
493        }
494
495        @Bean
496        @Lazy
497        public PartitionManagementProvider partitionManagementProvider() {
498                return new PartitionManagementProvider();
499        }
500
501        @Bean
502        @Lazy
503        public RequestTenantPartitionInterceptor requestTenantPartitionInterceptor() {
504                return new RequestTenantPartitionInterceptor();
505        }
506
507        @Bean
508        @Lazy
509        public TerminologyUploaderProvider terminologyUploaderProvider() {
510                return new TerminologyUploaderProvider();
511        }
512
513        @Bean
514        @Lazy
515        public ProcessMessageProvider processMessageProvider() {
516                return new ProcessMessageProvider();
517        }
518
519        @Bean
520        public ISchedulerService schedulerService() {
521                return new HapiSchedulerServiceImpl().setDefaultGroup(HAPI_DEFAULT_SCHEDULER_GROUP);
522        }
523
524        @Bean
525        public AutowiringSpringBeanJobFactory schedulerJobFactory() {
526                return new AutowiringSpringBeanJobFactory();
527        }
528
529        @Bean
530        public IBulkDataExportJobSchedulingHelper bulkDataExportJobSchedulingHelper(
531                        DaoRegistry theDaoRegistry,
532                        PlatformTransactionManager theTxManager,
533                        JpaStorageSettings theStorageSettings,
534                        BulkExportHelperService theBulkExportHelperSvc,
535                        IJobPersistence theJpaJobPersistence) {
536                return new BulkDataExportJobSchedulingHelperImpl(
537                                theDaoRegistry, theTxManager, theStorageSettings, theBulkExportHelperSvc, theJpaJobPersistence, null);
538        }
539
540        @Bean
541        @Lazy
542        public BulkDataExportProvider bulkDataExportProvider() {
543                return new BulkDataExportProvider();
544        }
545
546        @Bean
547        @Lazy
548        public IDeleteExpungeJobSubmitter deleteExpungeJobSubmitter() {
549                return new DeleteExpungeJobSubmitterImpl();
550        }
551
552        @Bean
553        @Lazy
554        public IBulkDataImportSvc bulkDataImportSvc() {
555                return new BulkDataImportSvcImpl();
556        }
557
558        @Bean
559        public PersistedJpaBundleProviderFactory persistedJpaBundleProviderFactory() {
560                return new PersistedJpaBundleProviderFactory();
561        }
562
563        @Bean
564        public SearchBuilderFactory searchBuilderFactory() {
565                return new SearchBuilderFactory();
566        }
567
568        @Bean
569        public SqlObjectFactory sqlBuilderFactory() {
570                return new SqlObjectFactory();
571        }
572
573        @Bean
574        public HibernatePropertiesProvider HibernatePropertiesProvider() {
575                return new HibernatePropertiesProvider();
576        }
577
578        @Bean
579        public HistoryBuilderFactory historyBuilderFactory() {
580                return new HistoryBuilderFactory();
581        }
582
583        @Bean
584        public IResourceVersionSvc resourceVersionSvc() {
585                return new ResourceVersionSvcDaoImpl();
586        }
587
588        @Bean
589        public ISearchParamIdentityCacheSvc searchParamIdentityCacheSvc(
590                        @Autowired IResourceIndexedSearchParamIdentityDao theResourceIndexedSearchParamIdentityDao,
591                        @Autowired PlatformTransactionManager theTxManager,
592                        @Autowired MemoryCacheService theMemoryCacheService) {
593                return new SearchParamIdentityCacheSvcImpl(
594                                myStorageSettings, theResourceIndexedSearchParamIdentityDao, theTxManager, theMemoryCacheService);
595        }
596
597        /* **************************************************************** *
598         * Prototype Beans Below                                            *
599         * **************************************************************** */
600
601        @Bean(name = PERSISTED_JPA_BUNDLE_PROVIDER)
602        @Scope("prototype")
603        public PersistedJpaBundleProvider newPersistedJpaBundleProvider(RequestDetails theRequest, String theUuid) {
604                return new PersistedJpaBundleProvider(theRequest, theUuid);
605        }
606
607        @Bean(name = PERSISTED_JPA_BUNDLE_PROVIDER_BY_SEARCH)
608        @Scope("prototype")
609        public PersistedJpaBundleProvider newPersistedJpaBundleProviderBySearch(
610                        RequestDetails theRequest, Search theSearch) {
611                return new PersistedJpaBundleProvider(theRequest, theSearch);
612        }
613
614        @Bean(name = PERSISTED_JPA_SEARCH_FIRST_PAGE_BUNDLE_PROVIDER)
615        @Scope("prototype")
616        public PersistedJpaSearchFirstPageBundleProvider newPersistedJpaSearchFirstPageBundleProvider(
617                        RequestDetails theRequest,
618                        SearchTask theSearchTask,
619                        ISearchBuilder theSearchBuilder,
620                        RequestPartitionId theRequestPartitionId) {
621                return new PersistedJpaSearchFirstPageBundleProvider(
622                                theSearchTask, theSearchBuilder, theRequest, theRequestPartitionId);
623        }
624
625        @Bean(name = RepositoryValidatingRuleBuilder.REPOSITORY_VALIDATING_RULE_BUILDER)
626        @Scope("prototype")
627        public RepositoryValidatingRuleBuilder repositoryValidatingRuleBuilder(IValidationSupport theValidationSupport) {
628                return new RepositoryValidatingRuleBuilder(theValidationSupport);
629        }
630
631        @Bean
632        @Scope("prototype")
633        public ComboUniqueSearchParameterPredicateBuilder newComboUniqueSearchParameterPredicateBuilder(
634                        SearchQueryBuilder theSearchSqlBuilder) {
635                return new ComboUniqueSearchParameterPredicateBuilder(theSearchSqlBuilder);
636        }
637
638        @Bean
639        @Scope("prototype")
640        public ComboNonUniqueSearchParameterPredicateBuilder newComboNonUniqueSearchParameterPredicateBuilder(
641                        SearchQueryBuilder theSearchSqlBuilder) {
642                return new ComboNonUniqueSearchParameterPredicateBuilder(theSearchSqlBuilder);
643        }
644
645        @Bean
646        @Scope("prototype")
647        public CoordsPredicateBuilder newCoordsPredicateBuilder(SearchQueryBuilder theSearchBuilder) {
648                return new CoordsPredicateBuilder(theSearchBuilder);
649        }
650
651        @Bean
652        @Scope("prototype")
653        public DatePredicateBuilder newDatePredicateBuilder(SearchQueryBuilder theSearchBuilder) {
654                return new DatePredicateBuilder(theSearchBuilder);
655        }
656
657        @Bean
658        @Scope("prototype")
659        public NumberPredicateBuilder newNumberPredicateBuilder(SearchQueryBuilder theSearchBuilder) {
660                return new NumberPredicateBuilder(theSearchBuilder);
661        }
662
663        @Bean
664        @Scope("prototype")
665        public QuantityPredicateBuilder newQuantityPredicateBuilder(SearchQueryBuilder theSearchBuilder) {
666                return new QuantityPredicateBuilder(theSearchBuilder);
667        }
668
669        @Bean
670        @Scope("prototype")
671        public QuantityNormalizedPredicateBuilder newQuantityNormalizedPredicateBuilder(
672                        SearchQueryBuilder theSearchBuilder) {
673                return new QuantityNormalizedPredicateBuilder(theSearchBuilder);
674        }
675
676        @Bean
677        @Scope("prototype")
678        public ResourceLinkPredicateBuilder newResourceLinkPredicateBuilder(
679                        QueryStack theQueryStack, SearchQueryBuilder theSearchBuilder, boolean theReversed) {
680                return new ResourceLinkPredicateBuilder(theQueryStack, theSearchBuilder, theReversed);
681        }
682
683        @Bean
684        @Scope("prototype")
685        public ResourceTablePredicateBuilder newResourceTablePredicateBuilder(SearchQueryBuilder theSearchBuilder) {
686                return new ResourceTablePredicateBuilder(theSearchBuilder);
687        }
688
689        @Bean
690        @Scope("prototype")
691        public TagPredicateBuilder newTagPredicateBuilder(SearchQueryBuilder theSearchBuilder) {
692                return new TagPredicateBuilder(theSearchBuilder);
693        }
694
695        @Bean
696        @Scope("prototype")
697        public ResourceIdPredicateBuilder newResourceIdPredicateBuilder(SearchQueryBuilder theSearchBuilder) {
698                return new ResourceIdPredicateBuilder(theSearchBuilder);
699        }
700
701        @Bean
702        @Scope("prototype")
703        public SearchParamPresentPredicateBuilder newSearchParamPresentPredicateBuilder(
704                        SearchQueryBuilder theSearchBuilder) {
705                return new SearchParamPresentPredicateBuilder(theSearchBuilder);
706        }
707
708        @Bean
709        @Scope("prototype")
710        public StringPredicateBuilder newStringPredicateBuilder(SearchQueryBuilder theSearchBuilder) {
711                return new StringPredicateBuilder(theSearchBuilder);
712        }
713
714        @Bean
715        @Scope("prototype")
716        public TokenPredicateBuilder newTokenPredicateBuilder(SearchQueryBuilder theSearchBuilder) {
717                return new TokenPredicateBuilder(theSearchBuilder);
718        }
719
720        @Bean
721        @Scope("prototype")
722        public ResourceHistoryPredicateBuilder newResourceHistoryPredicateBuilder(SearchQueryBuilder theSearchBuilder) {
723                return new ResourceHistoryPredicateBuilder(theSearchBuilder);
724        }
725
726        @Bean
727        @Scope("prototype")
728        public ResourceHistoryProvenancePredicateBuilder newResourceHistoryProvenancePredicateBuilder(
729                        SearchQueryBuilder theSearchBuilder) {
730                return new ResourceHistoryProvenancePredicateBuilder(theSearchBuilder);
731        }
732
733        @Bean
734        @Scope("prototype")
735        public UriPredicateBuilder newUriPredicateBuilder(SearchQueryBuilder theSearchBuilder) {
736                return new UriPredicateBuilder(theSearchBuilder);
737        }
738
739        @Bean
740        @Scope("prototype")
741        public SearchQueryExecutor newSearchQueryExecutor(GeneratedSql theGeneratedSql, Integer theMaxResultsToFetch) {
742                return new SearchQueryExecutor(theGeneratedSql, theMaxResultsToFetch);
743        }
744
745        @Bean(name = HISTORY_BUILDER)
746        @Scope("prototype")
747        public HistoryBuilder newHistoryBuilder(
748                        @Nullable String theResourceType,
749                        @Nullable JpaPid theResourceId,
750                        @Nullable Date theRangeStartInclusive,
751                        @Nullable Date theRangeEndInclusive) {
752                return new HistoryBuilder(theResourceType, theResourceId, theRangeStartInclusive, theRangeEndInclusive);
753        }
754
755        @Bean
756        @Primary
757        public ISearchParamProvider searchParamProvider() {
758                return new DaoSearchParamProvider();
759        }
760
761        @Bean
762        public IIdHelperService idHelperService() {
763                return new IdHelperService();
764        }
765
766        @Bean
767        public SearchStrategyFactory searchStrategyFactory(@Autowired(required = false) IFulltextSearchSvc theFulltextSvc) {
768                return new SearchStrategyFactory(myStorageSettings, theFulltextSvc);
769        }
770
771        @Bean
772        public DeleteConflictService deleteConflictService() {
773                return new DeleteConflictService();
774        }
775
776        @Bean
777        public DeleteConflictFinderService deleteConflictFinderService() {
778                return new DeleteConflictFinderService();
779        }
780
781        @Bean
782        public ExpungeService expungeService() {
783                return new ExpungeService();
784        }
785
786        @Bean
787        @Scope("prototype")
788        public ExpungeOperation expungeOperation(
789                        String theResourceName,
790                        IResourcePersistentId theResourceId,
791                        ExpungeOptions theExpungeOptions,
792                        RequestDetails theRequestDetails) {
793                return new ExpungeOperation(theResourceName, theResourceId, theExpungeOptions, theRequestDetails);
794        }
795
796        @Bean
797        public IExpungeEverythingService expungeEverythingService() {
798                return new ExpungeEverythingService();
799        }
800
801        @Bean
802        public IResourceExpungeService resourceExpungeService() {
803                return new JpaResourceExpungeService();
804        }
805
806        @Bean
807        public ISearchParamPresenceSvc searchParamPresenceService() {
808                return new SearchParamPresenceSvcImpl();
809        }
810
811        @Bean
812        public SearchParamWithInlineReferencesExtractor searchParamWithInlineReferencesExtractor() {
813                return new SearchParamWithInlineReferencesExtractor();
814        }
815
816        @Bean
817        public MatchResourceUrlService matchResourceUrlService() {
818                return new MatchResourceUrlService();
819        }
820
821        @Bean
822        public DaoSearchParamSynchronizer daoSearchParamSynchronizer() {
823                return new DaoSearchParamSynchronizer();
824        }
825
826        @Bean
827        public ResourceTableFKProvider resourceTableFKProvider() {
828                return new ResourceTableFKProvider();
829        }
830
831        @Bean
832        public ICacheWarmingSvc cacheWarmingSvc() {
833                return new CacheWarmingSvcImpl();
834        }
835
836        @Bean
837        public IndexNamePrefixLayoutStrategy indexLayoutStrategy() {
838                return new IndexNamePrefixLayoutStrategy();
839        }
840
841        @Bean
842        public ResourceLoaderImpl jpaResourceLoader() {
843                return new ResourceLoaderImpl();
844        }
845
846        @Bean
847        public UnknownCodeSystemWarningValidationSupport unknownCodeSystemWarningValidationSupport(
848                        FhirContext theFhirContext) {
849                return new UnknownCodeSystemWarningValidationSupport(theFhirContext);
850        }
851
852        @Bean
853        public ISynchronousSearchSvc synchronousSearchSvc() {
854                return new SynchronousSearchSvcImpl();
855        }
856
857        @Bean
858        public VersionCanonicalizer versionCanonicalizer(FhirContext theFhirContext) {
859                return new VersionCanonicalizer(theFhirContext);
860        }
861
862        @Bean
863        public SearchParameterDaoValidator searchParameterDaoValidator(
864                        FhirContext theFhirContext,
865                        JpaStorageSettings theStorageSettings,
866                        ISearchParamRegistry theSearchParamRegistry) {
867                return new SearchParameterDaoValidator(theFhirContext, theStorageSettings, theSearchParamRegistry);
868        }
869
870        @Bean
871        public ITermReadSvc terminologyService() {
872                return new TermReadSvcImpl();
873        }
874
875        @Bean
876        public ValueSetConceptAccumulatorFactory valueSetConceptAccumulatorFactory() {
877                return new ValueSetConceptAccumulatorFactory();
878        }
879
880        @Bean
881        @Scope("prototype")
882        public ValueSetConceptAccumulator valueSetConceptAccumulator(TermValueSet theTermValueSet) {
883                return valueSetConceptAccumulatorFactory().create(theTermValueSet);
884        }
885
886        @Bean
887        public ITermCodeSystemStorageSvc termCodeSystemStorageSvc() {
888                return new TermCodeSystemStorageSvcImpl();
889        }
890
891        @Bean
892        public ITermReindexingSvc termReindexingSvc() {
893                return new TermReindexingSvcImpl();
894        }
895
896        @Bean
897        @Scope("prototype")
898        public PersistenceContextProvider persistenceContextProvider() {
899                return new PersistenceContextProvider();
900        }
901
902        @Bean
903        public ResourceSearchUrlSvc resourceSearchUrlSvc(
904                        PersistenceContextProvider thePersistenceContextProvider,
905                        IResourceSearchUrlDao theResourceSearchUrlDao,
906                        MatchUrlService theMatchUrlService,
907                        FhirContext theFhirContext,
908                        PartitionSettings thePartitionSettings) {
909                return new ResourceSearchUrlSvc(
910                                thePersistenceContextProvider.getEntityManager(),
911                                theResourceSearchUrlDao,
912                                theMatchUrlService,
913                                theFhirContext,
914                                thePartitionSettings);
915        }
916
917        @Bean
918        public ISearchUrlJobMaintenanceSvc searchUrlJobMaintenanceSvc(ResourceSearchUrlSvc theResourceSearchUrlSvc) {
919                return new SearchUrlJobMaintenanceSvcImpl(theResourceSearchUrlSvc);
920        }
921
922        @Bean
923        public IResourceModifiedMessagePersistenceSvc subscriptionMessagePersistence(
924                        FhirContext theFhirContext,
925                        IResourceModifiedDao theIResourceModifiedDao,
926                        DaoRegistry theDaoRegistry,
927                        HapiTransactionService theHapiTransactionService) {
928                return new ResourceModifiedMessagePersistenceSvcImpl(
929                                theFhirContext, theIResourceModifiedDao, theDaoRegistry, theHapiTransactionService);
930        }
931
932        @Bean
933        public IMetaTagSorter metaTagSorter() {
934                return new MetaTagSorterAlphabetical();
935        }
936
937        @Bean
938        public ResourceHistoryCalculator resourceHistoryCalculator(
939                        FhirContext theFhirContext, HibernatePropertiesProvider theHibernatePropertiesProvider) {
940                return new ResourceHistoryCalculator(theFhirContext, theHibernatePropertiesProvider.isOracleDialect());
941        }
942
943        @Bean
944        public CacheTagDefinitionDao tagDefinitionDao(
945                        ITagDefinitionDao tagDefinitionDao, MemoryCacheService memoryCacheService) {
946                return new CacheTagDefinitionDao(tagDefinitionDao, memoryCacheService);
947        }
948
949        @Bean
950        public Batch2TaskHelper batch2TaskHelper() {
951                return new Batch2TaskHelper();
952        }
953
954        @Bean
955        public IReplaceReferencesSvc replaceReferencesSvc(
956                        DaoRegistry theDaoRegistry,
957                        HapiTransactionService theHapiTransactionService,
958                        IResourceLinkDao theResourceLinkDao,
959                        IJobCoordinator theJobCoordinator,
960                        ReplaceReferencesPatchBundleSvc theReplaceReferencesPatchBundle,
961                        Batch2TaskHelper theBatch2TaskHelper,
962                        JpaStorageSettings theStorageSettings) {
963                return new ReplaceReferencesSvcImpl(
964                                theDaoRegistry,
965                                theHapiTransactionService,
966                                theResourceLinkDao,
967                                theJobCoordinator,
968                                theReplaceReferencesPatchBundle,
969                                theBatch2TaskHelper,
970                                theStorageSettings);
971        }
972
973        @Bean
974        public ReplaceReferencesPatchBundleSvc replaceReferencesPatchBundleSvc(DaoRegistry theDaoRegistry) {
975                return new ReplaceReferencesPatchBundleSvc(theDaoRegistry);
976        }
977
978        @Bean
979        public PartitionedIdModeVerificationSvc partitionedIdModeVerificationSvc(
980                        PartitionSettings thePartitionSettings,
981                        HibernatePropertiesProvider theHibernatePropertiesProvider,
982                        PlatformTransactionManager theTxManager) {
983                return new PartitionedIdModeVerificationSvc(thePartitionSettings, theHibernatePropertiesProvider, theTxManager);
984        }
985}