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