Skip to content

Commit

Permalink
Initial commit of tests and potential hash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tadgh committed Feb 14, 2025
1 parent 46cb1bf commit 4c92983
Show file tree
Hide file tree
Showing 5 changed files with 1,335 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,8 @@ public Set<JpaPid> loadIncludes(SearchBuilderLoadIncludesParameters<JpaPid> theP
for (JpaPid next : pidsToInclude) {
if (!original.contains(next) && !allAdded.contains(next)) {
nextRoundMatches.add(next);
} else {
ourLog.trace("Skipping include since it has already been seen. [jpaPid={}]", next);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ private void doSearch() {
*/
int syncSize = mySyncSize;
while (resultIterator.hasNext()) {
myUnsyncedPids.add(resultIterator.next());
JpaPid next = resultIterator.next();
myUnsyncedPids.add(next);

boolean shouldSync = myUnsyncedPids.size() >= syncSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public boolean equals(Object theO) {
return false;
}
JpaPid jpaPid = (JpaPid) theO;
return Objects.equals(myId, jpaPid.myId) && Objects.equals(myPartitionIdValue, jpaPid.myPartitionIdValue);
return Objects.equals(myId, jpaPid.myId);
// return Objects.equals(myId, jpaPid.myId) && Objects.equals(myPartitionIdValue, jpaPid.myPartitionIdValue);
}

/**
Expand All @@ -151,7 +152,8 @@ public boolean equals(Object theO) {
*/
@Override
public int hashCode() {
return Objects.hash(myId, myPartitionIdValue);
// return Objects.hash(myId, myPartitionIdValue);
return Objects.hash(myId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
Expand All @@ -36,9 +37,12 @@
import org.hl7.fhir.r4.model.CapabilityStatement;
import org.hl7.fhir.r4.model.Condition;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.IntegerType;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
Expand All @@ -52,6 +56,7 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
Expand Down Expand Up @@ -83,6 +88,62 @@ public void after() throws Exception {
assertFalse(myPartitionSettings.isAllowUnqualifiedCrossPartitionReference());
}

@ParameterizedTest
@ValueSource(ints = {1, 50})
public void testPartitioningDoesNotReturnDuplicatesOnDoubleInclude(int theCount) {
myTenantClientInterceptor.setTenantId(TENANT_A);
IIdType patient = createPatient(withTenant(TENANT_A), withActiveTrue());
IIdType encounter = createEncounter(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("enc-"), withIdentifier("http://example.com/", "code"));
createObservation(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("obs-"), withObservationCode("http://example.com/", "code"), withEncounter(encounter.toUnqualifiedVersionless().toString()));
Parameters parameters = new Parameters();
parameters.addParameter().setName("_count").setValue(new IntegerType(theCount));
parameters.addParameter().setName("_format").setValue(new StringType("json"));
Bundle execute = myClient.search().forResource("Patient").include(new Include("*")).revInclude(new Include("*")).count(theCount).returnBundle(Bundle.class).execute();


List<String> foundIds = new ArrayList<>();
foundIds.addAll(execute.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList());
//Ensure no duplicates in first page
assertThat(foundIds).doesNotHaveDuplicates();

while (execute.getLink("next") != null) {
execute = myClient.loadPage().next(execute).execute();
foundIds.addAll(execute.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList());
}
assertThat(foundIds).doesNotHaveDuplicates();
assertThat(foundIds).hasSize(3);
}

@ParameterizedTest
@ValueSource(ints = {1, 50})
public void testPartitioningDoesNotReturnDuplicatesOnPatientEverything(int theCount) throws IOException {
myTenantClientInterceptor.setTenantId(TENANT_A);
IIdType patient = createPatient(withTenant(TENANT_A), withActiveTrue());
IIdType encounter = createEncounter(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("enc-"), withIdentifier("http://example.com/", "code"));
createObservation(withTenant(TENANT_A), withSubject(patient.toUnqualifiedVersionless().toString()), withId("obs-"), withObservationCode("http://example.com/", "code"), withEncounter(encounter.toUnqualifiedVersionless().toString()));

SystemRequestDetails systemRequestDetails = new SystemRequestDetails();
systemRequestDetails.setTenantId(TENANT_A);

Parameters parameters = new Parameters();
parameters.addParameter().setName("_count").setValue(new IntegerType(theCount));
parameters.addParameter().setName("_format").setValue(new StringType("json"));

Bundle everything = myClient.operation().onInstance(patient.toUnqualifiedVersionless().toString()).named("$everything").withParameters(parameters).returnResourceType(Bundle.class).execute();

List<String> foundIds = new ArrayList<>();
foundIds.addAll(everything.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList());
//Ensure no duplicates in first page
assertThat(foundIds).doesNotHaveDuplicates();

while (everything.getLink("next") != null) {
everything = myClient.loadPage().next(everything).execute();
foundIds.addAll(everything.getEntry().stream().map(entry -> entry.getResource().getIdElement().toUnqualifiedVersionless().toString()).toList());
}
assertThat(foundIds).doesNotHaveDuplicates();
assertThat(foundIds).hasSize(3);
}

@Test
public void testFetchCapabilityStatement() {
myTenantClientInterceptor.setTenantId(TENANT_A);
Expand Down
Loading

0 comments on commit 4c92983

Please sign in to comment.