diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SynchronousSearchSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SynchronousSearchSvcImpl.java index 89f77e51b14..9ee267f2de5 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SynchronousSearchSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SynchronousSearchSvcImpl.java @@ -171,6 +171,8 @@ public class SynchronousSearchSvcImpl implements ISynchronousSearchSvc { throw new InternalErrorException(Msg.code(1164) + e); } + // TODO - do we want to do this + // before or after the STORAGE_PREACCESS_RESOURCES interceptor? // truncate the list we retrieved - if needed int receivedResourceCount = -1; if (hasACount) { diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/ConsentEventsDaoR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/ConsentEventsDaoR4Test.java index 0c1e49496f6..c043768b4b3 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/ConsentEventsDaoR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/ConsentEventsDaoR4Test.java @@ -29,11 +29,11 @@ import org.slf4j.LoggerFactory; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import javax.servlet.ServletException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.leftPad; @@ -54,7 +54,7 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { private List myPatientIds; private List myObservationIdsOddOnly; private List myObservationIdsEvenOnly; - private List myObservationIdsWithVersions; + private List myObservationIdsWithoutVersions; private List myPatientIdsEvenOnly; @AfterEach @@ -64,13 +64,16 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { } @BeforeEach - public void before() throws ServletException { + @Override + public void beforeInitMocks() throws Exception { + super.beforeInitMocks(); RestfulServer restfulServer = new RestfulServer(); restfulServer.setPagingProvider(myPagingProvider); when(mySrd.getServer()).thenReturn(restfulServer); myStorageSettings.setSearchPreFetchThresholds(Arrays.asList(20, 50, 190)); + restfulServer.setDefaultPageSize(null); } @Test @@ -147,6 +150,7 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { @Test public void testSearchAndBlockSome_LoadSynchronous() { + // setup create50Observations(); AtomicInteger hitCount = new AtomicInteger(0); @@ -281,6 +285,7 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { @Test public void testSearchAndBlockSomeOnIncludes_LoadSynchronous() { + // setup create50Observations(); AtomicInteger hitCount = new AtomicInteger(0); @@ -328,9 +333,8 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { * returned results because we create it then update it in create50Observations() */ assertEquals(1, hitCount.get()); - assertEquals(myObservationIdsWithVersions.subList(90, myObservationIdsWithVersions.size()), sort(interceptedResourceIds)); + assertEquals(sort(myObservationIdsWithoutVersions.subList(90, myObservationIdsWithoutVersions.size())), sort(interceptedResourceIds)); returnedIdValues.forEach(t -> assertTrue(new IdType(t).getIdPartAsLong() % 2 == 0)); - } @Test @@ -363,7 +367,7 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { private void create50Observations() { myPatientIds = new ArrayList<>(); myObservationIds = new ArrayList<>(); - myObservationIdsWithVersions = new ArrayList<>(); + myObservationIdsWithoutVersions = new ArrayList<>(); Patient p = new Patient(); p.setActive(true); @@ -383,9 +387,9 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { final Observation obs1 = new Observation(); obs1.setStatus(Observation.ObservationStatus.FINAL); obs1.addIdentifier().setSystem("urn:system").setValue("I" + leftPad("" + i, 5, '0')); - IIdType obs1id = myObservationDao.create(obs1).getId().toUnqualifiedVersionless(); + IIdType obs1id = myObservationDao.create(obs1).getId();//.toUnqualifiedVersionless(); myObservationIds.add(obs1id.toUnqualifiedVersionless().getValue()); - myObservationIdsWithVersions.add(obs1id.toUnqualifiedVersionless().getValue()); + myObservationIdsWithoutVersions.add(obs1id.toUnqualifiedVersionless().getValue()); obs1.setId(obs1id); if (obs1id.getIdPartAsLong() % 2 == 0) { @@ -394,7 +398,7 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { obs1.getSubject().setReference(oddPid); } myObservationDao.update(obs1); - myObservationIdsWithVersions.add(obs1id.toUnqualifiedVersionless().getValue()); + myObservationIdsWithoutVersions.add(obs1id.toUnqualifiedVersionless().getValue()); } @@ -483,14 +487,26 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { } } - private static List sort(List... theLists) { + private List sort(List... theLists) { + return sort(id -> { + String idParsed = id.substring(id.indexOf("/") + 1); + if (idParsed.contains("/_history")) { + idParsed = idParsed.substring(0, idParsed.indexOf("/")); + } + return Long.parseLong(idParsed); + }, theLists); + } + + private List sort(Function theParser, List... theLists) { ArrayList retVal = new ArrayList<>(); for (List next : theLists) { retVal.addAll(next); } retVal.sort((o0, o1) -> { - long i0 = Long.parseLong(o0.substring(o0.indexOf('/') + 1)); - long i1 = Long.parseLong(o1.substring(o1.indexOf('/') + 1)); +// long i0 = Long.parseLong(o0.substring(o0.indexOf('/') + 1)); +// long i1 = Long.parseLong(o1.substring(o1.indexOf('/') + 1)); + long i0 = theParser.apply(o0); + long i1 = theParser.apply(o1); return (int) (i0 - i1); }); return retVal; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ResponsePage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ResponsePage.java index d14548fef69..c488173b069 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ResponsePage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ResponsePage.java @@ -482,9 +482,11 @@ public class ResponsePage { } } - if (myTotalRequestedResourcesFetched != -1 && theSecondBuilder.myTotalRequestedResourcesFetched != -1 + if (myTotalRequestedResourcesFetched != -1 + && theSecondBuilder.myTotalRequestedResourcesFetched != -1 && addedNewResources > 0) { - myTotalRequestedResourcesFetched += addedNewResources; //theSecondBuilder.myTotalRequestedResourcesFetched; + myTotalRequestedResourcesFetched += + addedNewResources; // theSecondBuilder.myTotalRequestedResourcesFetched; } // primitives can always be added