001/*-
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2026 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.context.FhirContext;
023import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
024import ca.uhn.fhir.jpa.api.svc.IDeleteExpungeSvc;
025import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
026import ca.uhn.fhir.jpa.api.svc.IMdmClearHelperSvc;
027import ca.uhn.fhir.jpa.bulk.export.svc.BulkExportMdmEidMatchOnlyResourceExpander;
028import ca.uhn.fhir.jpa.bulk.export.svc.BulkExportMdmFullResourceExpander;
029import ca.uhn.fhir.jpa.bulk.mdm.MdmClearHelperSvcImpl;
030import ca.uhn.fhir.jpa.dao.mdm.JpaMdmLinkImplFactory;
031import ca.uhn.fhir.jpa.dao.mdm.MdmLinkDaoJpaImpl;
032import ca.uhn.fhir.jpa.entity.MdmLink;
033import ca.uhn.fhir.jpa.model.dao.JpaPid;
034import ca.uhn.fhir.mdm.api.IMdmLinkExpandSvc;
035import ca.uhn.fhir.mdm.dao.IMdmLinkDao;
036import ca.uhn.fhir.mdm.dao.IMdmLinkImplFactory;
037import ca.uhn.fhir.mdm.svc.IBulkExportMdmEidMatchOnlyResourceExpander;
038import ca.uhn.fhir.mdm.svc.IBulkExportMdmFullResourceExpander;
039import ca.uhn.fhir.mdm.svc.MdmEidMatchOnlyExpandSvc;
040import ca.uhn.fhir.mdm.svc.MdmExpandersHolder;
041import ca.uhn.fhir.mdm.svc.MdmExpansionCacheSvc;
042import ca.uhn.fhir.mdm.svc.MdmLinkExpandSvc;
043import ca.uhn.fhir.mdm.svc.MdmSearchExpansionSvc;
044import org.springframework.context.annotation.Bean;
045import org.springframework.context.annotation.Configuration;
046import org.springframework.context.annotation.Primary;
047
048@Configuration
049public class MdmJpaConfig {
050
051        @Bean
052        public MdmExpandersHolder mdmLinkExpandSvcHolder(
053                        FhirContext theFhirContext,
054                        IMdmLinkExpandSvc theMdmLinkExpandSvc,
055                        MdmEidMatchOnlyExpandSvc theMdmEidMatchOnlyLinkExpandSvc,
056                        IBulkExportMdmEidMatchOnlyResourceExpander<JpaPid> theBulkExportMdmEidMatchOnlyResourceExpander,
057                        IBulkExportMdmFullResourceExpander<JpaPid> theBulkExportMdmFullResourceExpander) {
058                return new MdmExpandersHolder(
059                                theFhirContext,
060                                theMdmLinkExpandSvc,
061                                theMdmEidMatchOnlyLinkExpandSvc,
062                                theBulkExportMdmFullResourceExpander,
063                                theBulkExportMdmEidMatchOnlyResourceExpander);
064        }
065
066        @Bean
067        public MdmEidMatchOnlyExpandSvc mdmEidMatchOnlyLinkExpandSvc(DaoRegistry theDaoRegistry) {
068                return new MdmEidMatchOnlyExpandSvc(theDaoRegistry);
069        }
070
071        @Bean
072        @Primary
073        public IMdmLinkExpandSvc mdmLinkExpandSvc() {
074                return new MdmLinkExpandSvc();
075        }
076
077        @Bean
078        public MdmSearchExpansionSvc mdmSearchExpansionSvc() {
079                return new MdmSearchExpansionSvc();
080        }
081
082        @Bean
083        public IMdmLinkDao<JpaPid, MdmLink> mdmLinkDao() {
084                return new MdmLinkDaoJpaImpl();
085        }
086
087        @Bean
088        public BulkExportMdmFullResourceExpander bulkExportMDMResourceExpander(
089                        MdmExpansionCacheSvc theMdmExpansionCacheSvc,
090                        IMdmLinkDao theMdmLinkDao,
091                        IIdHelperService<JpaPid> theIdHelperService,
092                        DaoRegistry theDaoRegistry,
093                        FhirContext theFhirContext) {
094                return new BulkExportMdmFullResourceExpander(
095                                theMdmExpansionCacheSvc, theMdmLinkDao, theIdHelperService, theDaoRegistry, theFhirContext);
096        }
097
098        @Bean
099        public BulkExportMdmEidMatchOnlyResourceExpander bulkExportMDMEidMatchOnlyResourceExpander(
100                        DaoRegistry theDaoRegistry,
101                        MdmEidMatchOnlyExpandSvc theMdmEidMatchOnlyLinkExpandSvc,
102                        FhirContext theFhirContext,
103                        IIdHelperService<JpaPid> theIdHelperService) {
104                return new BulkExportMdmEidMatchOnlyResourceExpander(
105                                theDaoRegistry, theMdmEidMatchOnlyLinkExpandSvc, theFhirContext, theIdHelperService);
106        }
107
108        @Bean
109        public IMdmLinkImplFactory<MdmLink> mdmLinkImplFactory() {
110                return new JpaMdmLinkImplFactory();
111        }
112
113        @Bean
114        public IMdmClearHelperSvc<JpaPid> helperSvc(IDeleteExpungeSvc<JpaPid> theDeleteExpungeSvc) {
115                return new MdmClearHelperSvcImpl(theDeleteExpungeSvc);
116        }
117}