001/*
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2023 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.r4;
021
022import ca.uhn.fhir.context.FhirContext;
023import ca.uhn.fhir.context.support.IValidationSupport;
024import ca.uhn.fhir.jpa.api.IDaoRegistry;
025import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
026import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
027import ca.uhn.fhir.jpa.config.GeneratedDaoAndResourceProviderConfigR4;
028import ca.uhn.fhir.jpa.config.JpaConfig;
029import ca.uhn.fhir.jpa.dao.ITransactionProcessorVersionAdapter;
030import ca.uhn.fhir.jpa.dao.r4.TransactionProcessorVersionAdapterR4;
031import ca.uhn.fhir.jpa.graphql.GraphQLProvider;
032import ca.uhn.fhir.jpa.graphql.GraphQLProviderWithIntrospection;
033import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
034import ca.uhn.fhir.jpa.provider.r4.IMemberMatchConsentHook;
035import ca.uhn.fhir.jpa.provider.r4.MemberMatchR4ResourceProvider;
036import ca.uhn.fhir.jpa.provider.r4.MemberMatcherR4Helper;
037import ca.uhn.fhir.jpa.term.TermLoaderSvcImpl;
038import ca.uhn.fhir.jpa.term.TermVersionAdapterSvcR4;
039import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
040import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
041import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc;
042import ca.uhn.fhir.jpa.term.api.ITermVersionAdapterSvc;
043import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
044import org.hl7.fhir.r4.model.Bundle;
045import org.hl7.fhir.r4.model.Consent;
046import org.hl7.fhir.r4.model.Coverage;
047import org.hl7.fhir.r4.model.Meta;
048import org.hl7.fhir.r4.model.Patient;
049import org.hl7.fhir.utilities.graphql.IGraphQLStorageServices;
050import org.springframework.beans.factory.annotation.Autowired;
051import org.springframework.context.annotation.Bean;
052import org.springframework.context.annotation.Configuration;
053import org.springframework.context.annotation.Import;
054import org.springframework.context.annotation.Lazy;
055import org.springframework.transaction.annotation.EnableTransactionManagement;
056
057@Configuration
058@EnableTransactionManagement
059@Import({FhirContextR4Config.class, GeneratedDaoAndResourceProviderConfigR4.class, JpaConfig.class})
060public class JpaR4Config {
061
062        @Bean
063        public ITermVersionAdapterSvc terminologyVersionAdapterSvc() {
064                return new TermVersionAdapterSvcR4();
065        }
066
067        @Bean
068        public ITransactionProcessorVersionAdapter transactionProcessorVersionFacade() {
069                return new TransactionProcessorVersionAdapterR4();
070        }
071
072        @Bean(name = JpaConfig.GRAPHQL_PROVIDER_NAME)
073        @Lazy
074        public GraphQLProvider graphQLProvider(
075                        FhirContext theFhirContext,
076                        IGraphQLStorageServices theGraphqlStorageServices,
077                        IValidationSupport theValidationSupport,
078                        ISearchParamRegistry theSearchParamRegistry,
079                        IDaoRegistry theDaoRegistry) {
080                return new GraphQLProviderWithIntrospection(
081                                theFhirContext,
082                                theValidationSupport,
083                                theGraphqlStorageServices,
084                                theSearchParamRegistry,
085                                theDaoRegistry);
086        }
087
088        @Bean(name = "mySystemDaoR4")
089        public IFhirSystemDao<Bundle, Meta> systemDaoR4() {
090                ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4 retVal = new ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4();
091                return retVal;
092        }
093
094        @Bean(name = "mySystemProviderR4")
095        public JpaSystemProvider<Bundle, Meta> systemProviderR4(FhirContext theFhirContext) {
096                JpaSystemProvider<Bundle, Meta> retVal = new JpaSystemProvider<>();
097                retVal.setContext(theFhirContext);
098                retVal.setDao(systemDaoR4());
099                return retVal;
100        }
101
102        @Bean
103        public ITermLoaderSvc termLoaderService(
104                        ITermDeferredStorageSvc theDeferredStorageSvc, ITermCodeSystemStorageSvc theCodeSystemStorageSvc) {
105                return new TermLoaderSvcImpl(theDeferredStorageSvc, theCodeSystemStorageSvc);
106        }
107
108        @Bean
109        public MemberMatcherR4Helper memberMatcherR4Helper(
110                        @Autowired FhirContext theContext,
111                        @Autowired IFhirResourceDao<Coverage> theCoverageDao,
112                        @Autowired IFhirResourceDao<Patient> thePatientDao,
113                        @Autowired IFhirResourceDao<Consent> theConsentDao,
114                        @Autowired(required = false) IMemberMatchConsentHook theExtensionProvider) {
115                return new MemberMatcherR4Helper(
116                                theContext, theCoverageDao, thePatientDao, theConsentDao, theExtensionProvider);
117        }
118
119        @Bean
120        public MemberMatchR4ResourceProvider memberMatchR4ResourceProvider(
121                        FhirContext theFhirContext, MemberMatcherR4Helper theMemberMatchR4Helper) {
122                return new MemberMatchR4ResourceProvider(theFhirContext, theMemberMatchR4Helper);
123        }
124}