From b80e71773d47c77997b1b883affc1877ba0c4aa7 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Fri, 13 Mar 2020 18:36:43 -0700 Subject: [PATCH] Tidy, fix up tests --- .../ca/uhn/fhir/jpa/dao/SearchBuilder.java | 5 +-- .../predicate/PredicateBuilderReference.java | 1 - .../FhirResourceDaoDstu3SearchNoFtTest.java | 38 ++++--------------- .../FhirResourceDaoR4SearchNoHashesTest.java | 10 ++--- 4 files changed, 13 insertions(+), 41 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java index 334e402828d..e8ea57d4ad0 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java @@ -180,8 +180,8 @@ public class SearchBuilder implements ISearchBuilder { } /** - * A search is a candidate for Composite Unique SP if unique indexes are enabled, we are not in - * @return + * A search is a candidate for Composite Unique SP if unique indexes are enabled, there is no EverythingMode, and the + * parameters all have no modifiers. */ private boolean isCompositeUniqueSpCandidate() { return myDaoConfig.isUniqueIndexesEnabled() && @@ -272,7 +272,6 @@ public class SearchBuilder implements ISearchBuilder { myAlsoIncludePids = new ArrayList<>(1); } myAlsoIncludePids.add(pid); - //Won't this fail on non-long IDs? Or does IdHelperService massage this? myQueryRoot.addPredicate(myCriteriaBuilder.equal(join.get("myTargetResourcePid").as(Long.class), pid.getIdAsLong())); } else { Predicate targetTypePredicate = myCriteriaBuilder.equal(join.get("myTargetResourceType").as(String.class), myResourceName); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderReference.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderReference.java index f3b9fe459fd..adee294a5dc 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderReference.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderReference.java @@ -869,7 +869,6 @@ class PredicateBuilderReference extends BasePredicateBuilder { Predicate sourceTypePredicate = myCriteriaBuilder.equal(join.get("myTargetResourceType"), theResourceType); Predicate sourcePidPredicate = join.get("mySourceResourcePid").in(subQ); Predicate andPredicate = myCriteriaBuilder.and(pathPredicate, sourcePidPredicate, sourceTypePredicate); - //Predicate andPredicate = myCriteriaBuilder.and(pathPredicate, predicate, sourceTypePredicate); myQueryRoot.addPredicate(andPredicate); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java index 00b6ff177ae..52d642c340b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java @@ -351,7 +351,6 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { @Test public void testHasParameterChained() { IIdType pid0; - IIdType oid0; { Device device = new Device(); device.addIdentifier().setSystem("urn:system").setValue("DEVICEID"); @@ -366,39 +365,15 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { obs.setDevice(new Reference(devId)); obs.setSubject(new Reference(pid0)); obs.setCode(new CodeableConcept(new Coding("sys", "val", "disp"))); - oid0 = myObservationDao.create(obs, mySrd).getId().toUnqualifiedVersionless(); + myObservationDao.create(obs, mySrd).getId().toUnqualifiedVersionless(); } - SearchParameterMap hasWithChainParamQuery = new SearchParameterMap(); + SearchParameterMap params = new SearchParameterMap(); - hasWithChainParamQuery.setLoadSynchronous(true); - hasWithChainParamQuery.add("_has", new HasParam("Observation", "subject", "device.identifier", "urn:system|DEVICEID")); - // Patient?_has:Observation:subject:device.identifier=urn:system|DEVICEID - myCaptureQueriesListener.clear(); - assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(hasWithChainParamQuery)), contains(pid0.getValue())); - ourLog.warn(myCaptureQueriesListener.getSelectQueriesForCurrentThread().stream().map(q -> q.getSql(true, true)).collect(Collectors.joining("******"))); - } - - @Test - public void testHasParameterReverseChained() { - IIdType pid0; - { - Device device = new Device(); - device.addIdentifier().setSystem("urn:system").setValue("DEVICEID"); - IIdType devId = myDeviceDao.create(device, mySrd).getId().toUnqualifiedVersionless(); - - Patient patient = new Patient(); - patient.setGender(AdministrativeGender.MALE); - pid0 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); - - Observation obs = new Observation(); - obs.addIdentifier().setSystem("urn:system").setValue("FOO"); - obs.setDevice(new Reference(devId)); - obs.setSubject(new Reference(pid0)); - myObservationDao.create(obs, mySrd).getId(); - } - - SearchParameterMap params; + // Target exists and is linked + params.setLoadSynchronous(true); + params.add("_has", new HasParam("Observation", "subject", "device.identifier", "urn:system|DEVICEID")); + assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(params)), contains(pid0.getValue())); // No targets exist params = new SearchParameterMap(); @@ -412,6 +387,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { params.add("_has", new HasParam("Observation", "subject", "identifier", "urn:system|NOLINK")); assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(params)), empty()); } + @Test public void testHasParameterInvalidResourceType() { SearchParameterMap params = new SearchParameterMap(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java index 9d1bbe51f52..a19a466c9c0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java @@ -497,12 +497,10 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { SearchParameterMap params; -// KHS JA When we switched _has from two queries to a nested subquery, we broke support for chains within _has -// We have decided for now to prefer the performance optimization of the subquery over the slower full capability -// params = new SearchParameterMap(); -// params.setLoadSynchronous(true); -// params.add("_has", new HasParam("Observation", "subject", "device.identifier", "urn:system|DEVICEID")); -// assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(params)), contains(pid0.getValue())); + params = new SearchParameterMap(); + params.setLoadSynchronous(true); + params.add("_has", new HasParam("Observation", "subject", "device.identifier", "urn:system|DEVICEID")); + assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(params)), contains(pid0.getValue())); // No targets exist params = new SearchParameterMap();