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.match.matcher.matching.SubscriptionStrategyEvaluator;
026import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionQueryValidator;
027import org.springframework.context.annotation.Bean;
028import org.springframework.context.annotation.Configuration;
029import org.springframework.context.annotation.Lazy;
030
031@Configuration
032public class SubscriptionTopicConfig {
033        @Bean
034        SubscriptionTopicMatchingSubscriber subscriptionTopicMatchingSubscriber(FhirContext theFhirContext) {
035                switch (theFhirContext.getVersion().getVersion()) {
036                        case R5:
037                        case R4B:
038                                return new SubscriptionTopicMatchingSubscriber(theFhirContext);
039                        default:
040                                return null;
041                }
042        }
043
044        @Bean
045        @Lazy
046        SubscriptionTopicRegistry subscriptionTopicRegistry() {
047                return new SubscriptionTopicRegistry();
048        }
049
050        @Bean
051        @Lazy
052        SubscriptionTopicSupport subscriptionTopicSupport(
053                        FhirContext theFhirContext, DaoRegistry theDaoRegistry, SearchParamMatcher theSearchParamMatcher) {
054                return new SubscriptionTopicSupport(theFhirContext, theDaoRegistry, theSearchParamMatcher);
055        }
056
057        @Bean
058        SubscriptionTopicLoader subscriptionTopicLoader(FhirContext theFhirContext) {
059                switch (theFhirContext.getVersion().getVersion()) {
060                        case R5:
061                        case R4B:
062                                return new SubscriptionTopicLoader();
063                        default:
064                                return null;
065                }
066        }
067
068        @Bean
069        SubscriptionTopicRegisteringSubscriber subscriptionTopicRegisteringSubscriber(FhirContext theFhirContext) {
070                switch (theFhirContext.getVersion().getVersion()) {
071                        case R5:
072                        case R4B:
073                                return new SubscriptionTopicRegisteringSubscriber();
074                        default:
075                                return null;
076                }
077        }
078
079        @Bean
080        @Lazy
081        public SubscriptionQueryValidator subscriptionQueryValidator(
082                        DaoRegistry theDaoRegistry, SubscriptionStrategyEvaluator theSubscriptionStrategyEvaluator) {
083                return new SubscriptionQueryValidator(theDaoRegistry, theSubscriptionStrategyEvaluator);
084        }
085
086        @Bean
087        SubscriptionTopicValidatingInterceptor subscriptionTopicValidatingInterceptor(
088                        FhirContext theFhirContext, SubscriptionQueryValidator theSubscriptionQueryValidator) {
089                switch (theFhirContext.getVersion().getVersion()) {
090                        case R5:
091                        case R4B:
092                                return new SubscriptionTopicValidatingInterceptor(theFhirContext, theSubscriptionQueryValidator);
093                        default:
094                                return null;
095                }
096        }
097}