
001/* 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2025 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.batch2.api.IJobCoordinator; 023import ca.uhn.fhir.batch2.util.Batch2TaskHelper; 024import ca.uhn.fhir.context.FhirContext; 025import ca.uhn.fhir.context.support.IValidationSupport; 026import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; 027import ca.uhn.fhir.jpa.api.IDaoRegistry; 028import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; 029import ca.uhn.fhir.jpa.api.dao.DaoRegistry; 030import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao; 031import ca.uhn.fhir.jpa.config.GeneratedDaoAndResourceProviderConfigR4; 032import ca.uhn.fhir.jpa.config.JpaConfig; 033import ca.uhn.fhir.jpa.dao.ITransactionProcessorVersionAdapter; 034import ca.uhn.fhir.jpa.dao.r4.TransactionProcessorVersionAdapterR4; 035import ca.uhn.fhir.jpa.dao.tx.HapiTransactionService; 036import ca.uhn.fhir.jpa.graphql.GraphQLProvider; 037import ca.uhn.fhir.jpa.graphql.GraphQLProviderWithIntrospection; 038import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc; 039import ca.uhn.fhir.jpa.provider.IReplaceReferencesSvc; 040import ca.uhn.fhir.jpa.provider.JpaSystemProvider; 041import ca.uhn.fhir.jpa.provider.merge.MergeValidationService; 042import ca.uhn.fhir.jpa.provider.merge.PatientMergeProvider; 043import ca.uhn.fhir.jpa.provider.merge.ResourceMergeService; 044import ca.uhn.fhir.jpa.provider.merge.ResourceUndoMergeService; 045import ca.uhn.fhir.jpa.term.TermLoaderSvcImpl; 046import ca.uhn.fhir.jpa.term.TermVersionAdapterSvcR4; 047import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; 048import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc; 049import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc; 050import ca.uhn.fhir.jpa.term.api.ITermVersionAdapterSvc; 051import ca.uhn.fhir.merge.MergeProvenanceSvc; 052import ca.uhn.fhir.replacereferences.PreviousResourceVersionRestorer; 053import ca.uhn.fhir.rest.server.util.ISearchParamRegistry; 054import org.hl7.fhir.r4.model.Bundle; 055import org.hl7.fhir.r4.model.Meta; 056import org.hl7.fhir.utilities.graphql.IGraphQLStorageServices; 057import org.springframework.context.annotation.Bean; 058import org.springframework.context.annotation.Configuration; 059import org.springframework.context.annotation.Import; 060import org.springframework.context.annotation.Lazy; 061import org.springframework.transaction.annotation.EnableTransactionManagement; 062 063@Configuration 064@EnableTransactionManagement 065@Import({FhirContextR4Config.class, GeneratedDaoAndResourceProviderConfigR4.class, JpaConfig.class}) 066public class JpaR4Config { 067 068 @Bean 069 public ITermVersionAdapterSvc terminologyVersionAdapterSvc() { 070 return new TermVersionAdapterSvcR4(); 071 } 072 073 @Bean 074 public ITransactionProcessorVersionAdapter transactionProcessorVersionFacade() { 075 return new TransactionProcessorVersionAdapterR4(); 076 } 077 078 @Bean(name = JpaConfig.GRAPHQL_PROVIDER_NAME) 079 @Lazy 080 public GraphQLProvider graphQLProvider( 081 FhirContext theFhirContext, 082 IGraphQLStorageServices theGraphqlStorageServices, 083 IValidationSupport theValidationSupport, 084 ISearchParamRegistry theSearchParamRegistry, 085 IDaoRegistry theDaoRegistry) { 086 return new GraphQLProviderWithIntrospection( 087 theFhirContext, 088 theValidationSupport, 089 theGraphqlStorageServices, 090 theSearchParamRegistry, 091 theDaoRegistry); 092 } 093 094 @Bean(name = "mySystemDaoR4") 095 public IFhirSystemDao<Bundle, Meta> systemDaoR4() { 096 ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4 retVal = new ca.uhn.fhir.jpa.dao.r4.FhirSystemDaoR4(); 097 return retVal; 098 } 099 100 @Bean(name = "mySystemProviderR4") 101 public JpaSystemProvider<Bundle, Meta> systemProviderR4(FhirContext theFhirContext) { 102 JpaSystemProvider<Bundle, Meta> retVal = new JpaSystemProvider<>(); 103 retVal.setContext(theFhirContext); 104 retVal.setDao(systemDaoR4()); 105 return retVal; 106 } 107 108 @Bean 109 public ITermLoaderSvc termLoaderService( 110 ITermDeferredStorageSvc theDeferredStorageSvc, ITermCodeSystemStorageSvc theCodeSystemStorageSvc) { 111 return new TermLoaderSvcImpl(theDeferredStorageSvc, theCodeSystemStorageSvc); 112 } 113 114 @Bean 115 public MergeValidationService mergeValidationService(FhirContext theFhirContext, DaoRegistry theDaoRegistry) { 116 return new MergeValidationService(theFhirContext, theDaoRegistry); 117 } 118 119 @Bean 120 public MergeProvenanceSvc mergeProvenanceSvc(DaoRegistry theDaoRegistry) { 121 return new MergeProvenanceSvc(theDaoRegistry); 122 } 123 124 @Bean 125 public ResourceMergeService resourceMergeService( 126 DaoRegistry theDaoRegistry, 127 IReplaceReferencesSvc theReplaceReferencesSvc, 128 HapiTransactionService theHapiTransactionService, 129 IRequestPartitionHelperSvc theRequestPartitionHelperSvc, 130 IJobCoordinator theJobCoordinator, 131 Batch2TaskHelper theBatch2TaskHelper, 132 JpaStorageSettings theStorageSettings, 133 MergeValidationService theMergeValidationService, 134 MergeProvenanceSvc theMergeProvenanceSvc) { 135 136 return new ResourceMergeService( 137 theStorageSettings, 138 theDaoRegistry, 139 theReplaceReferencesSvc, 140 theHapiTransactionService, 141 theRequestPartitionHelperSvc, 142 theJobCoordinator, 143 theBatch2TaskHelper, 144 theMergeValidationService, 145 theMergeProvenanceSvc); 146 } 147 148 @Bean 149 public ResourceUndoMergeService resourceUndoMergeService( 150 DaoRegistry theDaoRegistry, 151 MergeProvenanceSvc theMergeProvenanceSvc, 152 PreviousResourceVersionRestorer theResourceVersionRestorer, 153 MergeValidationService theMergeValidationService, 154 IRequestPartitionHelperSvc theRequestPartitionHelperSvc) { 155 return new ResourceUndoMergeService( 156 theDaoRegistry, 157 theMergeProvenanceSvc, 158 theResourceVersionRestorer, 159 theMergeValidationService, 160 theRequestPartitionHelperSvc); 161 } 162 163 @Bean 164 public PatientMergeProvider patientMergeProvider( 165 FhirContext theFhirContext, 166 DaoRegistry theDaoRegistry, 167 ResourceMergeService theResourceMergeService, 168 ResourceUndoMergeService theResourceUndoMergeService, 169 IInterceptorBroadcaster theInterceptorBroadcaster) { 170 171 return new PatientMergeProvider( 172 theFhirContext, 173 theDaoRegistry, 174 theResourceMergeService, 175 theResourceUndoMergeService, 176 theInterceptorBroadcaster); 177 } 178}