001/*-
002 * #%L
003 * HAPI FHIR Subscription 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.topic;
021
022import ca.uhn.fhir.context.FhirContext;
023import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
024import ca.uhn.fhir.jpa.searchparam.matcher.SearchParamMatcher;
025import ca.uhn.fhir.jpa.subscription.config.SubscriptionConfig;
026import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionQueryValidator;
027import ca.uhn.fhir.jpa.util.MemoryCacheService;
028import org.springframework.context.annotation.Bean;
029import org.springframework.context.annotation.Configuration;
030import org.springframework.context.annotation.Import;
031import org.springframework.context.annotation.Lazy;
032
033@Configuration
034@Import(SubscriptionConfig.class)
035public class SubscriptionTopicConfig {
036        @Bean
037        SubscriptionTopicMatchingSubscriber subscriptionTopicMatchingSubscriber(
038                        FhirContext theFhirContext, MemoryCacheService memoryCacheService) {
039                switch (theFhirContext.getVersion().getVersion()) {
040                        case R5:
041                        case R4B:
042                                return new SubscriptionTopicMatchingSubscriber(theFhirContext, memoryCacheService);
043                        default:
044                                return null;
045                }
046        }
047
048        @Bean
049        @Lazy
050        SubscriptionTopicRegistry subscriptionTopicRegistry() {
051                return new SubscriptionTopicRegistry();
052        }
053
054        @Bean
055        @Lazy
056        SubscriptionTopicSupport subscriptionTopicSupport(
057                        FhirContext theFhirContext, DaoRegistry theDaoRegistry, SearchParamMatcher theSearchParamMatcher) {
058                return new SubscriptionTopicSupport(theFhirContext, theDaoRegistry, theSearchParamMatcher);
059        }
060
061        @Bean
062        SubscriptionTopicLoader subscriptionTopicLoader(FhirContext theFhirContext) {
063                switch (theFhirContext.getVersion().getVersion()) {
064                        case R5:
065                        case R4B:
066                                return new SubscriptionTopicLoader();
067                        default:
068                                return null;
069                }
070        }
071
072        @Bean
073        SubscriptionTopicRegisteringSubscriber subscriptionTopicRegisteringSubscriber(FhirContext theFhirContext) {
074                switch (theFhirContext.getVersion().getVersion()) {
075                        case R5:
076                        case R4B:
077                                return new SubscriptionTopicRegisteringSubscriber();
078                        default:
079                                return null;
080                }
081        }
082
083        @Bean
084        SubscriptionTopicValidatingInterceptor subscriptionTopicValidatingInterceptor(
085                        FhirContext theFhirContext, SubscriptionQueryValidator theSubscriptionQueryValidator) {
086                switch (theFhirContext.getVersion().getVersion()) {
087                        case R5:
088                        case R4B:
089                                return new SubscriptionTopicValidatingInterceptor(theFhirContext, theSubscriptionQueryValidator);
090                        default:
091                                return null;
092                }
093        }
094}