11package ca .uhn .fhir .jpa .mdm .provider ;
22
33import ca .uhn .fhir .interceptor .model .RequestPartitionId ;
4+ import ca .uhn .fhir .jpa .entity .MdmLink ;
45import ca .uhn .fhir .jpa .entity .PartitionEntity ;
56import ca .uhn .fhir .jpa .searchparam .SearchParameterMap ;
67import ca .uhn .fhir .mdm .api .IMdmSettings ;
8+ import ca .uhn .fhir .mdm .model .MdmTransactionContext ;
79import ca .uhn .fhir .mdm .util .MdmResourceUtil ;
810import ca .uhn .fhir .rest .api .server .IBundleProvider ;
911import ca .uhn .fhir .rest .api .server .RequestDetails ;
1012import 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 ;
1115import org .hl7 .fhir .r4 .model .Bundle ;
16+ import org .hl7 .fhir .r4 .model .DecimalType ;
17+ import org .hl7 .fhir .r4 .model .Parameters ;
1218import org .hl7 .fhir .r4 .model .Patient ;
19+ import org .hl7 .fhir .r4 .model .StringType ;
1320import org .junit .jupiter .api .AfterEach ;
1421import org .junit .jupiter .api .BeforeEach ;
1522import org .junit .jupiter .api .Test ;
23+ import org .junit .jupiter .params .ParameterizedTest ;
24+ import org .junit .jupiter .params .provider .CsvSource ;
1625import org .springframework .beans .factory .annotation .Autowired ;
1726
1827import java .io .IOException ;
2130import static org .junit .jupiter .api .Assertions .assertEquals ;
2231import 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