Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import ca.uhn.fhir.jpa.model.search.SearchBuilderLoadIncludesParameters;
import ca.uhn.fhir.jpa.model.search.SearchRuntimeDetails;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.mdm.svc.MdmExpandersHolder;
import ca.uhn.fhir.mdm.svc.IBulkExportMdmResourceExpander;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
Expand All @@ -56,6 +56,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -86,7 +87,7 @@ public class JpaBulkExportProcessor implements IBulkExportProcessor<JpaPid> {
private EntityManager myEntityManager;
private IHapiTransactionService myHapiTransactionService;
private ISearchParamRegistry mySearchParamRegistry;
private MdmExpandersHolder myMdmExpandersHolder;
private IBulkExportMdmResourceExpander myBulkExportMdmResourceExpander;

@Autowired
public JpaBulkExportProcessor(
Expand All @@ -99,7 +100,8 @@ public JpaBulkExportProcessor(
EntityManager theEntityManager,
IHapiTransactionService theHapiTransactionService,
ISearchParamRegistry theSearchParamRegistry,
MdmExpandersHolder theMdmExpandersHolder) {
@Qualifier("bulkExportMdmResourceExpander")
IBulkExportMdmResourceExpander theBulkExportMdmResourceExpander) {
myContext = theContext;
myBulkExportHelperSvc = theBulkExportHelperSvc;
myStorageSettings = theStorageSettings;
Expand All @@ -109,7 +111,7 @@ public JpaBulkExportProcessor(
myEntityManager = theEntityManager;
myHapiTransactionService = theHapiTransactionService;
mySearchParamRegistry = theSearchParamRegistry;
myMdmExpandersHolder = theMdmExpandersHolder;
myBulkExportMdmResourceExpander = theBulkExportMdmResourceExpander;
}

@Override
Expand Down Expand Up @@ -349,7 +351,7 @@ protected RuntimeSearchParam getPatientSearchParamForCurrentResourceType(String
public void expandMdmResources(List<IBaseResource> theResources) {
for (IBaseResource resource : theResources) {
if (!PATIENT_BULK_EXPORT_FORWARD_REFERENCE_RESOURCE_TYPES.contains(resource.fhirType())) {
myMdmExpandersHolder.getBulkExportMDMResourceExpanderInstance().annotateResource(resource);
myBulkExportMdmResourceExpander.annotateResource(resource);
}
}
}
Expand Down Expand Up @@ -405,9 +407,8 @@ private LinkedHashSet<JpaPid> getExpandedPatientList(

if (theParameters.isExpandMdm()) {
RequestPartitionId partitionId = theParameters.getPartitionIdOrAllPartitions();
patientPidsToExport.addAll(myMdmExpandersHolder
.getBulkExportMDMResourceExpanderInstance()
.expandGroup(theParameters.getGroupId(), partitionId));
patientPidsToExport.addAll(
myBulkExportMdmResourceExpander.expandGroup(theParameters.getGroupId(), partitionId));
}
return patientPidsToExport;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import ca.uhn.fhir.jpa.dao.SearchBuilderFactory;
import ca.uhn.fhir.jpa.dao.tx.IHapiTransactionService;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.mdm.svc.MdmExpandersHolder;
import ca.uhn.fhir.mdm.svc.IBulkExportMdmResourceExpander;
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
import jakarta.persistence.EntityManager;
import org.springframework.context.annotation.Bean;
Expand All @@ -48,7 +48,7 @@ public IBulkExportProcessor<JpaPid> jpaBulkExportProcessor(
EntityManager theEntityManager,
IHapiTransactionService theHapiTransactionService,
ISearchParamRegistry theSearchParamRegistry,
MdmExpandersHolder theMdmExpandersHolder) {
IBulkExportMdmResourceExpander theBulkExportMdmResourceExpander) {
return new JpaBulkExportProcessor(
theFhirContext,
theBulkExportHelperService,
Expand All @@ -59,7 +59,7 @@ public IBulkExportProcessor<JpaPid> jpaBulkExportProcessor(
theEntityManager,
theHapiTransactionService,
theSearchParamRegistry,
theMdmExpandersHolder);
theBulkExportMdmResourceExpander);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@
import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.mdm.api.IMdmLinkExpandSvc;
import ca.uhn.fhir.mdm.api.IMdmSettings;
import ca.uhn.fhir.mdm.api.MdmModeEnum;
import ca.uhn.fhir.mdm.dao.IMdmLinkDao;
import ca.uhn.fhir.mdm.dao.IMdmLinkImplFactory;
import ca.uhn.fhir.mdm.svc.BulkExportMdmEidMatchOnlyResourceExpander;
import ca.uhn.fhir.mdm.svc.BulkExportMdmResourceExpander;
import ca.uhn.fhir.mdm.svc.IBulkExportMdmResourceExpander;
import ca.uhn.fhir.mdm.svc.MdmEidMatchOnlyExpandSvc;
import ca.uhn.fhir.mdm.svc.MdmExpandersHolder;
import ca.uhn.fhir.mdm.svc.MdmExpansionCacheSvc;
import ca.uhn.fhir.mdm.svc.MdmLinkExpandSvc;
import ca.uhn.fhir.mdm.svc.MdmSearchExpansionSvc;
import ca.uhn.fhir.mdm.util.EIDHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
Expand All @@ -47,29 +50,45 @@
public class MdmJpaConfig {

@Bean
public MdmExpandersHolder mdmLinkExpandSvcHolder(
FhirContext theFhirContext,
IMdmLinkExpandSvc theMdmLinkExpandSvc,
MdmEidMatchOnlyExpandSvc theMdmEidMatchOnlyLinkExpandSvc,
BulkExportMdmEidMatchOnlyResourceExpander theBulkExportMdmEidMatchOnlyResourceExpander,
BulkExportMdmResourceExpander theBulkExportMdmResourceExpander) {
return new MdmExpandersHolder(
theFhirContext,
theMdmLinkExpandSvc,
theMdmEidMatchOnlyLinkExpandSvc,
theBulkExportMdmResourceExpander,
theBulkExportMdmEidMatchOnlyResourceExpander);
public MdmEidMatchOnlyExpandSvc mdmEidMatchOnlyLinkExpandSvc(
IMdmSettings theMdmSettings, DaoRegistry theDaoRegistry, FhirContext theFhirContext) {
MdmEidMatchOnlyExpandSvc mdmEidMatchOnlyExpandSvc = new MdmEidMatchOnlyExpandSvc(theDaoRegistry);
mdmEidMatchOnlyExpandSvc.setMyEidHelper(new EIDHelper(theFhirContext, theMdmSettings));
return mdmEidMatchOnlyExpandSvc;
}

@Bean
public MdmEidMatchOnlyExpandSvc mdmEidMatchOnlyLinkExpandSvc(DaoRegistry theDaoRegistry) {
return new MdmEidMatchOnlyExpandSvc(theDaoRegistry);
@Primary
public IMdmLinkExpandSvc mdmLinkExpandSvc(
IMdmSettings theMdmSettings, DaoRegistry theDaoRegistry, FhirContext theFhirContext) {
IMdmLinkExpandSvc res;
if (isEidMatchOnly(theMdmSettings)) {
res = mdmEidMatchOnlyLinkExpandSvc(theMdmSettings, theDaoRegistry, theFhirContext);
} else {
res = new MdmLinkExpandSvc();
}
return res;
}

@Bean
@Primary
public IMdmLinkExpandSvc mdmLinkExpandSvc() {
return new MdmLinkExpandSvc();
public IBulkExportMdmResourceExpander bulkExportMdmResourceExpander(
MdmExpansionCacheSvc theMdmExpansionCacheSvc,
IMdmLinkDao theMdmLinkDao,
IIdHelperService<JpaPid> theIdHelperService,
DaoRegistry theDaoRegistry,
FhirContext theFhirContext,
MdmEidMatchOnlyExpandSvc theMdmEidMatchOnlyLinkExpandSvc,
IMdmSettings theMdmSettings) {

IBulkExportMdmResourceExpander res;
if (isEidMatchOnly(theMdmSettings)) {
res = new BulkExportMdmEidMatchOnlyResourceExpander(
theDaoRegistry, theMdmEidMatchOnlyLinkExpandSvc, theFhirContext, theIdHelperService);
} else {
res = new BulkExportMdmResourceExpander(
theMdmExpansionCacheSvc, theMdmLinkDao, theIdHelperService, theDaoRegistry, theFhirContext);
}
return res;
}

@Bean
Expand All @@ -82,27 +101,6 @@ public IMdmLinkDao<JpaPid, MdmLink> mdmLinkDao() {
return new MdmLinkDaoJpaImpl();
}

@Bean
public BulkExportMdmResourceExpander bulkExportMDMResourceExpander(
MdmExpansionCacheSvc theMdmExpansionCacheSvc,
IMdmLinkDao theMdmLinkDao,
IIdHelperService<JpaPid> theIdHelperService,
DaoRegistry theDaoRegistry,
FhirContext theFhirContext) {
return new BulkExportMdmResourceExpander(
theMdmExpansionCacheSvc, theMdmLinkDao, theIdHelperService, theDaoRegistry, theFhirContext);
}

@Bean
public BulkExportMdmEidMatchOnlyResourceExpander bulkExportMDMEidMatchOnlyResourceExpander(
DaoRegistry theDaoRegistry,
MdmEidMatchOnlyExpandSvc theMdmEidMatchOnlyLinkExpandSvc,
FhirContext theFhirContext,
IIdHelperService<JpaPid> theIdHelperService) {
return new BulkExportMdmEidMatchOnlyResourceExpander(
theDaoRegistry, theMdmEidMatchOnlyLinkExpandSvc, theFhirContext, theIdHelperService);
}

@Bean
public IMdmLinkImplFactory<MdmLink> mdmLinkImplFactory() {
return new JpaMdmLinkImplFactory();
Expand All @@ -112,4 +110,11 @@ public IMdmLinkImplFactory<MdmLink> mdmLinkImplFactory() {
public IMdmClearHelperSvc<JpaPid> helperSvc(IDeleteExpungeSvc<JpaPid> theDeleteExpungeSvc) {
return new MdmClearHelperSvcImpl(theDeleteExpungeSvc);
}

private boolean isEidMatchOnly(IMdmSettings theMdmSettings) {
return theMdmSettings.getMode() == MdmModeEnum.MATCH_ONLY
&& theMdmSettings.getMdmRules() != null
&& theMdmSettings.getMdmRules().getEnterpriseEIDSystems() != null
&& !theMdmSettings.getMdmRules().getEnterpriseEIDSystems().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import ca.uhn.fhir.jpa.model.search.SearchBuilderLoadIncludesParameters;
import ca.uhn.fhir.jpa.model.search.SearchRuntimeDetails;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.mdm.svc.MdmExpandersHolder;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
import ca.uhn.fhir.rest.api.server.RequestDetails;
Expand Down Expand Up @@ -130,9 +129,6 @@ public JpaPid next() {
@Mock
private IIdHelperService<JpaPid> myIdHelperService;

@Mock
private MdmExpandersHolder myMdmExpandersHolder;

@Mock
private IBulkExportMdmResourceExpander myBulkExportMDMResourceExpander;

Expand Down Expand Up @@ -298,8 +294,6 @@ public void getResourcePidIterator_groupExportStyleWithPatientResource_returnsIt
// mdm expansion stuff
final JpaPid mdmExpandedPatientId = JpaPid.fromId(4567L);
if (theMdm) {

when(myMdmExpandersHolder.getBulkExportMDMResourceExpanderInstance()).thenReturn(myBulkExportMDMResourceExpander);
// mock the call to expandGroup method of the expander
when(myBulkExportMDMResourceExpander.expandGroup(parameters.getGroupId(), getPartitionIdFromParams(thePartitioned)))
.thenReturn(Set.of(mdmExpandedPatientId));
Expand Down Expand Up @@ -395,7 +389,6 @@ public void getResourcePidIterator_groupExportStyleWithNonPatientResource_return
.thenReturn(observationResultsIterator);

if (theMdm) {
when(myMdmExpandersHolder.getBulkExportMDMResourceExpanderInstance()).thenReturn(myBulkExportMDMResourceExpander);
// mock the call to expandGroup method of the expander
when(myBulkExportMDMResourceExpander.expandGroup(parameters.getGroupId(), getPartitionIdFromParams(thePartitioned)))
.thenReturn(Collections.emptySet());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package ca.uhn.fhir.jpa.mdm.helper;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.mdm.api.IMdmLinkExpandSvc;
import ca.uhn.fhir.mdm.api.IMdmSettings;
import ca.uhn.fhir.mdm.rules.config.MdmRuleValidator;
import ca.uhn.fhir.mdm.rules.config.MdmSettings;
import ca.uhn.fhir.mdm.svc.MdmLinkExpandSvc;
import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -39,4 +43,10 @@ IMdmSettings mdmSettings(MdmRuleValidator theMdmRuleValidator) throws IOExceptio
.setPreventEidUpdates(myPreventEidUpdates)
.setPreventMultipleEids(myPreventMultipleEids);
}

@Bean
@Primary
public IMdmLinkExpandSvc mdmLinkExpandSvc() {
return new MdmLinkExpandSvc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import ca.uhn.fhir.jpa.mdm.helper.testmodels.MDMState;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.mdm.api.IMdmSettings;
import ca.uhn.fhir.mdm.interceptor.MdmReadVirtualizationInterceptor;
import ca.uhn.fhir.mdm.svc.MdmExpandersHolder;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
Expand Down Expand Up @@ -129,7 +127,7 @@ public void testRead_ObservationReferencingSourcePatient(boolean theUseClientAss
Observation obs = myObservationDao.read(myObservationReferencingSourcePatientA0Id, mySrd);

// Verify
assertEquals(mySourcePatientA0Id.getValue(), obs.getSubject().getReference());
assertEquals(myGoldenResourcePatientAId.getValue(), obs.getSubject().getReference());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import ca.uhn.fhir.mdm.rules.config.MdmRuleValidator;
import ca.uhn.fhir.mdm.rules.config.MdmSettings;
import ca.uhn.fhir.mdm.rules.json.MdmRulesJson;
import ca.uhn.fhir.mdm.svc.MdmExpandersHolder;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome;
Expand Down Expand Up @@ -75,6 +74,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -102,11 +102,11 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;


@ContextConfiguration(classes = {BulkExportUseCaseTestConfig.class})
public class BulkExportUseCaseTest extends BaseResourceProviderR4Test {
private static final Logger ourLog = LoggerFactory.getLogger(BulkExportUseCaseTest.class);

private static final String TEST_PATIENT_EID_SYS = "http://patient-eid-sys";
static final String TEST_PATIENT_EID_SYS = "http://patient-eid-sys";
@Autowired
private IJobCoordinator myJobCoordinator;

Expand All @@ -120,10 +120,7 @@ public class BulkExportUseCaseTest extends BaseResourceProviderR4Test {
private IBatch2WorkChunkRepository myWorkChunkRepository;
@Autowired
private IInterceptorService myInterceptorService;
@Autowired
private MdmRuleValidator myMdmRulesValidator;
@Autowired
private MdmExpandersHolder myMdmExpandersHolder;


@BeforeEach
public void beforeEach() {
Expand Down Expand Up @@ -685,12 +682,6 @@ public void testExportEmptyResult() {

@Nested
public class GroupBulkExportTests {

@AfterEach
void tearDown() {
restoreMdmSettingsToDefault();
}

@Test
public void testGroupExportSuccessfulyExportsPatientForwardReferences() {
BundleBuilder bb = new BundleBuilder(myFhirContext);
Expand Down Expand Up @@ -1865,8 +1856,6 @@ private IIdType createPatient() {

@Test
void testGroupExportWithMdmEnabled_EidMatchOnly() {

createAndSetMdmSettingsForEidMatchOnly();
BundleBuilder bb = new BundleBuilder(myFhirContext);

//In this test, we create two patients with the same Eid value for the eid system specified in mdm rules
Expand Down Expand Up @@ -1918,23 +1907,6 @@ void testGroupExportWithMdmEnabled_EidMatchOnly() {

}


private void createAndSetMdmSettingsForEidMatchOnly() {
MdmSettings mdmSettings = new MdmSettings(myMdmRulesValidator);
mdmSettings.setEnabled(true);
mdmSettings.setMdmMode(MdmModeEnum.MATCH_ONLY);
MdmRulesJson rules = new MdmRulesJson();
rules.setMdmTypes(List.of("Patient"));
rules.addEnterpriseEIDSystem("Patient", TEST_PATIENT_EID_SYS);
mdmSettings.setMdmRules(rules);

myMdmExpandersHolder.setMdmSettings(mdmSettings);
}

private void restoreMdmSettingsToDefault() {
myMdmExpandersHolder.setMdmSettings(new MdmSettings(myMdmRulesValidator));
}

private static void assertResourcesIds(List<IBaseResource> theResources, String... theExpectedResourceIds) {
assertThat(theResources).hasSize(theExpectedResourceIds.length);
assertThat(theResources)
Expand Down
Loading
Loading