search by source reported incorrect size (#2705)
* issue reproduced in test and fixed * changelog
This commit is contained in:
parent
d574c4625b
commit
c498522c78
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 2705
|
||||
title: "When searching by source, if deleted resources are matched, the search returned an incorrect size. This has been corrected."
|
|
@ -559,9 +559,9 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
|
|||
bundleProvider.setSize(count.intValue());
|
||||
} else {
|
||||
Integer queryCount = getQueryCount(theLoadSynchronousUpTo, theParams);
|
||||
if (queryCount == null || queryCount > pids.size()) {
|
||||
if (queryCount == null || queryCount > resources.size()) {
|
||||
// No limit, last page or everything was fetched within the limit
|
||||
bundleProvider.setSize(getTotalCount(queryCount, theParams.getOffset(), pids.size()));
|
||||
bundleProvider.setSize(getTotalCount(queryCount, theParams.getOffset(), resources.size()));
|
||||
} else {
|
||||
bundleProvider.setSize(null);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
|||
import ca.uhn.fhir.jpa.util.TestUtil;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.param.TokenAndListParam;
|
||||
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
|
@ -12,6 +13,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
|||
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
|
||||
import org.apache.commons.text.RandomStringGenerator;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.IdType;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
|
@ -218,6 +220,31 @@ public class FhirResourceDaoR4SourceTest extends BaseJpaR4Test {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithSource() {
|
||||
Patient patient = new Patient();
|
||||
String patientId = "Patient/pt-001";
|
||||
patient.setId(patientId);
|
||||
String source = "urn:source:0";
|
||||
patient.getMeta().setSource(source);
|
||||
patient.addName().setFamily("Presley");
|
||||
myPatientDao.update(patient);
|
||||
SearchParameterMap map = SearchParameterMap.newSynchronous();
|
||||
map.add(Constants.PARAM_SOURCE, new StringParam(source));
|
||||
{
|
||||
IBundleProvider result = myPatientDao.search(map);
|
||||
assertThat(toUnqualifiedVersionlessIdValues(result), containsInAnyOrder(patientId));
|
||||
}
|
||||
myPatientDao.delete(new IdType(patientId));
|
||||
{
|
||||
myCaptureQueriesListener.clear();
|
||||
IBundleProvider result = myPatientDao.search(map);
|
||||
myCaptureQueriesListener.logSelectQueries();
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void assertConflictException(String theResourceType, ResourceVersionConflictException e) {
|
||||
assertThat(e.getMessage(), matchesPattern(
|
||||
"Unable to delete [a-zA-Z]+/[0-9]+ because at least one resource has a reference to this resource. First reference found was resource " + theResourceType + "/[0-9]+ in path [a-zA-Z]+.[a-zA-Z]+"));
|
||||
|
|
Loading…
Reference in New Issue