This commit is contained in:
jamesagnew 2018-08-11 15:25:01 -04:00
parent 8284734a07
commit e0b188d574
2 changed files with 69 additions and 7 deletions

View File

@ -69,6 +69,7 @@ import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import javax.annotation.Nonnull;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import javax.persistence.criteria.*; import javax.persistence.criteria.*;
@ -1835,19 +1836,15 @@ public class SearchBuilder implements ISearchBuilder {
nextRoundMatches = pidsToInclude; nextRoundMatches = pidsToInclude;
} while (includes.size() > 0 && nextRoundMatches.size() > 0 && addedSomeThisRound); } while (includes.size() > 0 && nextRoundMatches.size() > 0 && addedSomeThisRound);
ourLog.info("Loaded {} {} in {} rounds and {} ms", new Object[] {allAdded.size(), theReverseMode ? "_revincludes" : "_includes", roundCounts, w.getMillisAndRestart()}); ourLog.info("Loaded {} {} in {} rounds and {} ms", allAdded.size(), theReverseMode ? "_revincludes" : "_includes", roundCounts, w.getMillisAndRestart());
return allAdded; return allAdded;
} }
private void searchForIdsWithAndOr(SearchParameterMap theParams) { private void searchForIdsWithAndOr(@Nonnull SearchParameterMap theParams) {
SearchParameterMap params = theParams;
if (params == null) {
params = new SearchParameterMap();
}
myParams = theParams; myParams = theParams;
for (Entry<String, List<List<? extends IQueryParameterType>>> nextParamEntry : params.entrySet()) { for (Entry<String, List<List<? extends IQueryParameterType>>> nextParamEntry : myParams.entrySet()) {
String nextParamName = nextParamEntry.getKey(); String nextParamName = nextParamEntry.getKey();
List<List<? extends IQueryParameterType>> andOrParams = nextParamEntry.getValue(); List<List<? extends IQueryParameterType>> andOrParams = nextParamEntry.getValue();
searchForIdsWithAndOr(myResourceName, nextParamName, andOrParams); searchForIdsWithAndOr(myResourceName, nextParamName, andOrParams);

View File

@ -198,6 +198,71 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
} }
/**
* See #1053
*
* Note that I don't know that _lastUpdate actually should apply to reverse includes. The
* spec doesn't say one way or ther other, but it seems like sensible behaviour to me.
*
* Definitely the $everything operation depends on this behaviour, so if we change it
* we need to account for the everything operation...
*/
@Test
public void testLastUpdateShouldApplyToReverseIncludes() {
SearchParameterMap map;
List<String> ids;
// This gets updated in a sec..
Organization org = new Organization();
org.setActive(false);
org.setId("O1");
myOrganizationDao.update(org);
Date beforeAll = new Date();
ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100);
Patient p = new Patient();
p.setId("P1");
p.setActive(true);
p.setManagingOrganization(new Reference("Organization/O1"));
myPatientDao.update(p);
ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100);
Date beforeOrg = new Date();
ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100);
org = new Organization();
org.setActive(true);
org.setId("O1");
myOrganizationDao.update(org);
ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast(100);
Date afterAll = new Date();
// Everything should come back
map = new SearchParameterMap();
map.setLastUpdated(new DateRangeParam().setLowerBoundInclusive(beforeAll));
map.addRevInclude(Patient.INCLUDE_ORGANIZATION);
ids = toUnqualifiedVersionlessIdValues(myOrganizationDao.search(map));
assertThat(ids, contains("Organization/O1", "Patient/P1"));
// Search before everything
map = new SearchParameterMap();
map.setLastUpdated(new DateRangeParam().setLowerBoundInclusive(beforeOrg));
map.addInclude(Patient.INCLUDE_ORGANIZATION);
ids = toUnqualifiedVersionlessIdValues(myOrganizationDao.search(map));
assertThat(ids, contains("Organization/O1"));
// Search after everything
map = new SearchParameterMap();
map.setLastUpdated(new DateRangeParam().setLowerBoundInclusive(afterAll));
map.addInclude(Patient.INCLUDE_ORGANIZATION);
ids = toUnqualifiedVersionlessIdValues(myOrganizationDao.search(map));
assertThat(ids, empty());
}
@Test @Test
public void testEverythingTimings() { public void testEverythingTimings() {
String methodName = "testEverythingTimings"; String methodName = "testEverythingTimings";