diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmReadVirtualizationInterceptorTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmReadVirtualizationInterceptorTest.java index 46162b8afad1..e2bc5a10c85c 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmReadVirtualizationInterceptorTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmReadVirtualizationInterceptorTest.java @@ -20,7 +20,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -31,13 +30,10 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.slf4j.LoggerFactory.getLogger; @ContextConfiguration(classes = {MdmHelperConfig.class}) public class MdmReadVirtualizationInterceptorTest extends BaseMdmR4Test { - private static final Logger ourLog = getLogger(MdmReadVirtualizationInterceptorTest.class); - @RegisterExtension @Autowired public MdmHelperR4 myMdmHelper; diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/interceptor/MdmReadVirtualizationInterceptor.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/interceptor/MdmReadVirtualizationInterceptor.java index 4399173154f6..8571d416f477 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/interceptor/MdmReadVirtualizationInterceptor.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/interceptor/MdmReadVirtualizationInterceptor.java @@ -1,3 +1,22 @@ +/*- + * #%L + * HAPI FHIR - Master Data Management + * %% + * Copyright (C) 2014 - 2024 Smile CDR, Inc. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ package ca.uhn.fhir.mdm.interceptor; import ca.uhn.fhir.context.FhirContext; @@ -8,10 +27,10 @@ import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.api.model.PersistentIdToForcedIdMap; import ca.uhn.fhir.jpa.api.svc.IIdHelperService; +import ca.uhn.fhir.jpa.dao.tx.HapiTransactionService; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.mdm.dao.IMdmLinkDao; import ca.uhn.fhir.mdm.model.MdmPidTuple; -import ca.uhn.fhir.mdm.rules.config.MdmSettings; import ca.uhn.fhir.mdm.svc.MdmSearchExpansionSvc; import ca.uhn.fhir.rest.api.server.IPreResourceShowDetails; import ca.uhn.fhir.rest.api.server.RequestDetails; @@ -20,6 +39,7 @@ import ca.uhn.fhir.util.ResourceReferenceInfo; import com.google.common.collect.ListMultimap; import com.google.common.collect.MultimapBuilder; +import jakarta.annotation.Nonnull; import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -69,10 +89,10 @@ public class MdmReadVirtualizationInterceptor
private DaoRegistry myDaoRegistry;
@Autowired
- private MdmSettings myMdmSettings;
+ private MdmSearchExpansionSvc myMdmSearchExpansionSvc;
@Autowired
- private MdmSearchExpansionSvc myMdmSearchExpansionSvc;
+ private HapiTransactionService myTxService;
@Hook(Pointcut.STORAGE_PRESEARCH_REGISTERED)
public void hook(RequestDetails theRequestDetails, SearchParameterMap theSearchParameterMap) {
@@ -86,26 +106,12 @@ public void preShowResources(RequestDetails theRequestDetails, IPreResourceShowD
ListMultimap sourcePids =
- myIdHelperService.getPidsOrThrowException(RequestPartitionId.allPartitions(), List.copyOf(allIds));
- Collection allPersistentIds = new HashSet<>();
- tuples.forEach(t -> allPersistentIds.add(t.getGoldenPid()));
- tuples.forEach(t -> allPersistentIds.add(t.getSourcePid()));
- PersistentIdToForcedIdMap persistentIdToFhirIdMap =
- myIdHelperService.translatePidsToForcedIds(allPersistentIds);
+ CandidateMdmLinkedResources candidates =
+ findCandidateMdmLinkedResources(candidateResourceIds, candidateReferences);
// Loop through each link and figure out whether we need to remap anything
- for (MdmPidTuple tuple : tuples) {
- Optional tuple : candidates.getTuples()) {
+ Optional findCandidateMdmLinkedResources(
+ ListMultimap sourcePids =
+ myIdHelperService.getPidsOrThrowException(RequestPartitionId.allPartitions(), List.copyOf(allIds));
+ Collection allPersistentIds = new HashSet<>();
+ tuples.forEach(t -> allPersistentIds.add(t.getGoldenPid()));
+ tuples.forEach(t -> allPersistentIds.add(t.getSourcePid()));
+ PersistentIdToForcedIdMap persistentIdToFhirIdMap =
+ myIdHelperService.translatePidsToForcedIds(allPersistentIds);
+ return new CandidateMdmLinkedResources<>(tuples, persistentIdToFhirIdMap);
+ });
+ }
+
/**
* @return Returns a map where the keys are a typed ID (Patient/ABC) and the values are the index of
* that resource within the {@link IPreResourceShowDetails}
@@ -211,6 +242,25 @@ private IIdType newIdType(String targetId) {
* Is the given resource a candidate for virtualization?
*/
private boolean isRemapCandidate(String theResourceType) {
- return myMdmSettings.isSupportedMdmType(theResourceType);
+ return "Patient".equals(theResourceType);
+ }
+
+ private static class CandidateMdmLinkedResources > {
+ private final Collection myPersistentIdToFhirIdMap;
+
+ public CandidateMdmLinkedResources(
+ Collection thePersistentIdToForcedIdMap) {
+ this.myTuples = thePidTuples;
+ this.myPersistentIdToFhirIdMap = thePersistentIdToForcedIdMap;
+ }
+
+ public Collection