From 04b60a4a16c7ccdac4ab29bf2888ecf902aceb5a Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Tue, 21 Jan 2020 16:18:42 -0500 Subject: [PATCH] no distance and zero distance tested --- .../ca/uhn/fhir/jpa/dao/SearchBuilder.java | 8 +---- .../FhirResourceDaoDstu3SearchNoFtTest.java | 29 ++++++++++++++++--- 2 files changed, 26 insertions(+), 11 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 fadecd6a8be..f50b9367810 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 @@ -468,12 +468,6 @@ public class SearchBuilder implements ISearchBuilder { String theParamName, List theList, SearchFilterParser.CompareOperation operation) { - - // FIXME KHS - if ("Location".equals(theResourceName) && Location.SP_NEAR_DISTANCE.equals(theParamName)) { - return null; - } - Join join = createJoin(JoinEnum.QUANTITY, theParamName); if (theList.get(0).getMissing() != null) { @@ -2121,7 +2115,7 @@ public class SearchBuilder implements ISearchBuilder { QuantityParam distanceParam = myParams.getNearDistanceParam(); Predicate latitudePredicate; Predicate longitudePredicate; - if (distanceParam == null) { + if (distanceParam == null || distanceParam.getValue().doubleValue() == 0.0) { latitudePredicate = theBuilder.equal(theFrom.get("myLatitude"), latitudeValue); longitudePredicate = theBuilder.equal(theFrom.get("myLongitude"), longitudeValue); } else { 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 9cc64412461..9c81def77c3 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 @@ -3473,7 +3473,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { } @Test - public void testNearSearchExact() { + public void testNearSearchDistanceNoDistance() { Location loc = new Location(); double latitude = 1000.0; double longitude = 2000.0; @@ -3481,9 +3481,30 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { loc.setPosition(position); String locId = myLocationDao.create(loc).getId().toUnqualifiedVersionless().getValue(); - SearchParameterMap map = new SearchParameterMap(); - map.add(Location.SP_NEAR, new TokenParam(latitude + ":" + longitude)); - map.add(Location.SP_NEAR_DISTANCE, new QuantityParam(0L)); + SearchParameterMap map = myMatchUrlService.translateMatchUrl( + "Location?" + + Location.SP_NEAR + "=" + latitude + ":" + longitude, + myFhirCtx.getResourceDefinition("Location")); + + List ids = toUnqualifiedVersionlessIdValues(myLocationDao.search(map)); + assertThat(ids, contains(locId)); + } + + @Test + public void testNearSearchDistanceZero() { + Location loc = new Location(); + double latitude = 1000.0; + double longitude = 2000.0; + Location.LocationPositionComponent position = new Location.LocationPositionComponent().setLatitude(latitude).setLongitude(longitude); + loc.setPosition(position); + String locId = myLocationDao.create(loc).getId().toUnqualifiedVersionless().getValue(); + + SearchParameterMap map = myMatchUrlService.translateMatchUrl( + "Location?" + + Location.SP_NEAR + "=" + latitude + ":" + longitude + + "&" + + Location.SP_NEAR_DISTANCE + "=0||", + myFhirCtx.getResourceDefinition("Location")); List ids = toUnqualifiedVersionlessIdValues(myLocationDao.search(map)); assertThat(ids, contains(locId));