|
12 | 12 | import ca.uhn.fhir.jpa.model.config.PartitionSettings;
|
13 | 13 | import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
14 | 14 | import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
| 15 | +import ca.uhn.fhir.model.api.Include; |
15 | 16 | import ca.uhn.fhir.rest.api.Constants;
|
16 | 17 | import ca.uhn.fhir.rest.api.server.RequestDetails;
|
17 | 18 | import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
|
|
36 | 37 | import org.hl7.fhir.r4.model.CapabilityStatement;
|
37 | 38 | import org.hl7.fhir.r4.model.Condition;
|
38 | 39 | import org.hl7.fhir.r4.model.IdType;
|
| 40 | +import org.hl7.fhir.r4.model.IntegerType; |
39 | 41 | import org.hl7.fhir.r4.model.Organization;
|
| 42 | +import org.hl7.fhir.r4.model.Parameters; |
40 | 43 | import org.hl7.fhir.r4.model.Patient;
|
41 | 44 | import org.hl7.fhir.r4.model.Resource;
|
| 45 | +import org.hl7.fhir.r4.model.StringType; |
42 | 46 | import org.junit.jupiter.api.AfterEach;
|
43 | 47 | import org.junit.jupiter.api.BeforeEach;
|
44 | 48 | import org.junit.jupiter.api.Disabled;
|
|
52 | 56 |
|
53 | 57 | import java.io.IOException;
|
54 | 58 | import java.nio.charset.StandardCharsets;
|
| 59 | +import java.util.ArrayList; |
55 | 60 | import java.util.Arrays;
|
56 | 61 | import java.util.Collection;
|
57 | 62 | import java.util.Date;
|
@@ -83,6 +88,62 @@ public void after() throws Exception {
|
83 | 88 | assertFalse(myPartitionSettings.isAllowUnqualifiedCrossPartitionReference());
|
84 | 89 | }
|
85 | 90 |
|
| 91 | + @ParameterizedTest |
| 92 | + @ValueSource(ints = {1, 50}) |
| 93 | + public void testPartitioningDoesNotReturnDuplicatesOnDoubleInclude(int theCount) { |
| 94 | + myTenantClientInterceptor.setTenantId(TENANT_A); |
| 95 | + IIdType patient = createPatient(withTenant(TENANT_A), withActiveTrue()); |
| 96 | + IIdType encounter = createEncounter(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("enc-"), withIdentifier("http://example.com/", "code")); |
| 97 | + createObservation(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("obs-"), withObservationCode("http://example.com/", "code"), withEncounter(encounter.toUnqualifiedVersionless().toString())); |
| 98 | + Parameters parameters = new Parameters(); |
| 99 | + parameters.addParameter().setName("_count").setValue(new IntegerType(theCount)); |
| 100 | + parameters.addParameter().setName("_format").setValue(new StringType("json")); |
| 101 | + Bundle execute = myClient.search().forResource("Patient").include(new Include("*")).revInclude(new Include("*")).count(theCount).returnBundle(Bundle.class).execute(); |
| 102 | + |
| 103 | + |
| 104 | + List<String> foundIds = new ArrayList<>(); |
| 105 | + foundIds.addAll(execute.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList()); |
| 106 | + //Ensure no duplicates in first page |
| 107 | + assertThat(foundIds).doesNotHaveDuplicates(); |
| 108 | + |
| 109 | + while (execute.getLink("next") != null) { |
| 110 | + execute = myClient.loadPage().next(execute).execute(); |
| 111 | + foundIds.addAll(execute.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList()); |
| 112 | + } |
| 113 | + assertThat(foundIds).doesNotHaveDuplicates(); |
| 114 | + assertThat(foundIds).hasSize(3); |
| 115 | + } |
| 116 | + |
| 117 | + @ParameterizedTest |
| 118 | + @ValueSource(ints = {1, 50}) |
| 119 | + public void testPartitioningDoesNotReturnDuplicatesOnPatientEverything(int theCount) throws IOException { |
| 120 | + myTenantClientInterceptor.setTenantId(TENANT_A); |
| 121 | + IIdType patient = createPatient(withTenant(TENANT_A), withActiveTrue()); |
| 122 | + IIdType encounter = createEncounter(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("enc-"), withIdentifier("http://example.com/", "code")); |
| 123 | + createObservation(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("obs-"), withObservationCode("http://example.com/", "code"), withEncounter(encounter.toUnqualifiedVersionless().toString())); |
| 124 | + |
| 125 | + SystemRequestDetails systemRequestDetails = new SystemRequestDetails(); |
| 126 | + systemRequestDetails.setTenantId(TENANT_A); |
| 127 | + |
| 128 | + Parameters parameters = new Parameters(); |
| 129 | + parameters.addParameter().setName("_count").setValue(new IntegerType(theCount)); |
| 130 | + parameters.addParameter().setName("_format").setValue(new StringType("json")); |
| 131 | + |
| 132 | + Bundle everything = myClient.operation().onInstance(patient.toUnqualifiedVersionless().toString()).named("$everything").withParameters(parameters).returnResourceType(Bundle.class).execute(); |
| 133 | + |
| 134 | + List<String> foundIds = new ArrayList<>(); |
| 135 | + foundIds.addAll(everything.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList()); |
| 136 | + //Ensure no duplicates in first page |
| 137 | + assertThat(foundIds).doesNotHaveDuplicates(); |
| 138 | + |
| 139 | + while (everything.getLink("next") != null) { |
| 140 | + everything = myClient.loadPage().next(everything).execute(); |
| 141 | + foundIds.addAll(everything.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList()); |
| 142 | + } |
| 143 | + assertThat(foundIds).doesNotHaveDuplicates(); |
| 144 | + assertThat(foundIds).hasSize(3); |
| 145 | + } |
| 146 | + |
86 | 147 | @Test
|
87 | 148 | public void testFetchCapabilityStatement() {
|
88 | 149 | myTenantClientInterceptor.setTenantId(TENANT_A);
|
|
0 commit comments