Skip to content

Commit c8002da

Browse files
authored
[7332] Fix $mdm-query-links in partition mode (#7333)
* [7332] update mdm resource persistence id * [7332] add tests and changelog * [7332] update changelog * [7332] update test * [7332] update test * [7332] update changelog
1 parent 77a0956 commit c8002da

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: fix
3+
issue: 7332
4+
title: "In partition mode, the FHIR endpoint GET `$mdm-query-links` returned a 404 Not Found error when both source
5+
and golden resources existed in the partition. This has now been fixed."
6+

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public MdmLink setId(JpaPid theId) {
245245

246246
@Override
247247
public JpaPid getGoldenResourcePersistenceId() {
248-
return JpaPid.fromId(myGoldenResourcePid);
248+
return JpaPid.fromId(myGoldenResourcePid, myGoldenResourcePartitionId);
249249
}
250250

251251
@Override
@@ -260,7 +260,7 @@ public IMdmLink setGoldenResourcePersistenceId(JpaPid theGoldenResourcePid) {
260260

261261
@Override
262262
public JpaPid getSourcePersistenceId() {
263-
return JpaPid.fromId(mySourcePid);
263+
return JpaPid.fromId(mySourcePid, mySourcePartitionId);
264264
}
265265

266266
@Override
@@ -465,6 +465,8 @@ public String toString() {
465465
.append("myScore", myScore)
466466
.append("myRuleCount", myRuleCount)
467467
.append("myPartitionId", getPartitionId())
468+
.append("mySourcePartitionId", mySourcePartitionId)
469+
.append("myGoldenResourcePartitionId", myGoldenResourcePartitionId)
468470
.toString();
469471
}
470472

hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderCrossPartitionR4Test.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
package ca.uhn.fhir.jpa.mdm.provider;
22

33
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
4+
import ca.uhn.fhir.jpa.entity.MdmLink;
45
import ca.uhn.fhir.jpa.entity.PartitionEntity;
56
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
67
import ca.uhn.fhir.mdm.api.IMdmSettings;
8+
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
79
import ca.uhn.fhir.mdm.util.MdmResourceUtil;
810
import ca.uhn.fhir.rest.api.server.IBundleProvider;
911
import ca.uhn.fhir.rest.api.server.RequestDetails;
1012
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
13+
import ca.uhn.fhir.rest.server.interceptor.partition.RequestTenantPartitionInterceptor;
14+
import org.hl7.fhir.dstu3.model.UnsignedIntType;
1115
import org.hl7.fhir.r4.model.Bundle;
16+
import org.hl7.fhir.r4.model.DecimalType;
17+
import org.hl7.fhir.r4.model.Parameters;
1218
import org.hl7.fhir.r4.model.Patient;
19+
import org.hl7.fhir.r4.model.StringType;
1320
import org.junit.jupiter.api.AfterEach;
1421
import org.junit.jupiter.api.BeforeEach;
1522
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.CsvSource;
1625
import org.springframework.beans.factory.annotation.Autowired;
1726

1827
import java.io.IOException;
@@ -21,14 +30,16 @@
2130
import static org.junit.jupiter.api.Assertions.assertEquals;
2231
import static org.junit.jupiter.api.Assertions.assertTrue;
2332

24-
public class MdmProviderCrossPartitionR4Test extends BaseProviderR4Test{
33+
public class MdmProviderCrossPartitionR4Test extends BaseProviderR4Test {
2534
@Autowired
2635
private IMdmSettings myMdmSettings;
2736

2837
private static final String PARTITION_GOLDEN_RESOURCE = "PARTITION-GOLDEN";
2938

39+
private RequestTenantPartitionInterceptor requestTenantPartitionInterceptor;
40+
3041
@Override
31-
@BeforeEach
42+
@BeforeEach
3243
public void before() throws Exception {
3344
super.before();
3445

@@ -37,6 +48,10 @@ public void before() throws Exception {
3748
myPartitionLookupSvc.createPartition(new PartitionEntity().setId(1).setName(PARTITION_1), null);
3849
myPartitionLookupSvc.createPartition(new PartitionEntity().setId(2).setName(PARTITION_2), null);
3950
myPartitionLookupSvc.createPartition(new PartitionEntity().setId(3).setName(PARTITION_GOLDEN_RESOURCE), null);
51+
52+
requestTenantPartitionInterceptor = new RequestTenantPartitionInterceptor();
53+
requestTenantPartitionInterceptor.setPartitionSettings(myPartitionSettings);
54+
myInterceptorRegistry.registerInterceptor(requestTenantPartitionInterceptor);
4055
}
4156

4257
@Override
@@ -47,6 +62,7 @@ public void after() throws IOException {
4762
myPartitionSettings.setPartitioningEnabled(false);
4863
myMdmSettings.setSearchAllPartitionForMatch(false);
4964
myMdmSettings.setGoldenResourcePartitionName("");
65+
myInterceptorRegistry.unregisterInterceptor(requestTenantPartitionInterceptor);
5066
}
5167

5268

@@ -69,7 +85,7 @@ public void testCreateLinkWithMatchResultOnDifferentPartitionsWithoutSearchAllPa
6985
}
7086

7187
@Test
72-
public void testCreateLinkWithResourcesInSpecificPartition(){
88+
public void testCreateLinkWithResourcesInSpecificPartition() {
7389
myMdmSettings.setGoldenResourcePartitionName(PARTITION_GOLDEN_RESOURCE);
7490
myMdmSettings.setSearchAllPartitionForMatch(true);
7591

@@ -88,4 +104,33 @@ public void testCreateLinkWithResourcesInSpecificPartition(){
88104

89105
assertTrue(MdmResourceUtil.isGoldenRecord(searchResult.getAllResources().get(0)));
90106
}
107+
108+
@ParameterizedTest
109+
@CsvSource(value = {
110+
"false, '', 1", // Golden resource in same partition as source
111+
"true, PARTITION-GOLDEN, 3" // Golden resource in different partition than source
112+
})
113+
void testQueryMdmLinkWithPartition(boolean theSearchAllPartitions, String theGoldenResPartitionName, int theGoldenResPartitionId) {
114+
myMdmSettings.setSearchAllPartitionForMatch(theSearchAllPartitions);
115+
myMdmSettings.setGoldenResourcePartitionName(theGoldenResPartitionName);
116+
117+
Patient jane = createPatientOnPartition(buildJanePatient(), RequestPartitionId.fromPartitionId(1));
118+
MdmTransactionContext mdmContext =
119+
myMdmMatchLinkSvc.updateMdmLinksForMdmSource(jane, createContextForCreate("Patient"));
120+
121+
MdmLink mdmLink = (MdmLink) mdmContext.getMdmLinks().get(0);
122+
assertThat(mdmLink.getSourcePersistenceId().getPartitionId()).isEqualTo(1);
123+
assertThat(mdmLink.getGoldenResourcePersistenceId().getPartitionId()).isEqualTo(theGoldenResPartitionId);
124+
125+
myRequestDetails.setTenantId(PARTITION_1);
126+
Parameters result = (Parameters) myMdmProvider.queryLinks(null, null, null, null, new UnsignedIntType(0),
127+
new UnsignedIntType(10), new StringType(), myRequestDetails, new StringType("Patient"));
128+
129+
assertThat(result.getParameter()).hasSize(3);
130+
assertThat(result.getParameter().get(0).getName()).isEqualTo("self");
131+
assertThat(result.getParameter().get(1).getName()).isEqualTo("total");
132+
assertThat(((DecimalType) (result.getParameter().get(1).getValue())).getValueAsInteger()).isEqualTo(1);
133+
assertThat(result.getParameter().get(2).getName()).isEqualTo("link");
134+
assertThat(result.getParameter().get(2).getPart()).isNotEmpty();
135+
}
91136
}

0 commit comments

Comments
 (0)