yay box search works!

This commit is contained in:
Ken Stevens 2020-01-21 16:04:34 -05:00
parent 3cb9a9f4a2
commit 992b62151b
2 changed files with 26 additions and 17 deletions

View File

@ -2111,22 +2111,37 @@ public class SearchBuilder implements ISearchBuilder {
} }
latitudeValue = parts[0]; latitudeValue = parts[0];
longitudeValue = parts[1]; longitudeValue = parts[1];
if (isBlank(latitudeValue) || isBlank(longitudeValue)) {
throw new IllegalArgumentException("Invalid position format '" + value + "'. Both latitude and longitude must be provided.");
}
} else { } else {
throw new IllegalArgumentException("Invalid position type: " + theParam.getClass()); throw new IllegalArgumentException("Invalid position type: " + theParam.getClass());
} }
Predicate latitude = null; QuantityParam distanceParam = myParams.getNearDistanceParam();
if (!isBlank(latitudeValue)) { Predicate latitudePredicate;
latitude = theBuilder.equal(theFrom.get("myLatitude"), latitudeValue); Predicate longitudePredicate;
if (distanceParam == null) {
latitudePredicate = theBuilder.equal(theFrom.get("myLatitude"), latitudeValue);
longitudePredicate = theBuilder.equal(theFrom.get("myLongitude"), longitudeValue);
} else {
// FIXME KHS suppress hash
Double distance = distanceParam.getValue().doubleValue();
if (distance < 0.0) {
throw new IllegalArgumentException("Invalid " + Location.SP_NEAR_DISTANCE + " parameter '" + distance + "' must be >= 0.0");
} }
Double latitude = Double.valueOf(latitudeValue);
Predicate longitude = null; latitudePredicate = theBuilder.and(
if (!isBlank(longitudeValue)) { theBuilder.greaterThanOrEqualTo(theFrom.get("myLatitude"), latitude - distance),
longitude = theBuilder.equal(theFrom.get("myLongitude"), longitudeValue); theBuilder.lessThanOrEqualTo(theFrom.get("myLatitude"), latitude + distance)
);
Double longitude = Double.valueOf(longitudeValue);
longitudePredicate = theBuilder.and(
theBuilder.greaterThanOrEqualTo(theFrom.get("myLongitude"), longitude - distance),
theBuilder.lessThanOrEqualTo(theFrom.get("myLongitude"), longitude + distance)
);
} }
Predicate singleCode = theBuilder.and(latitudePredicate, longitudePredicate);
Predicate singleCode = theBuilder.and(latitude, longitude);
return combineParamIndexPredicateWithParamNamePredicate(theResourceName, theParamName, theFrom, singleCode); return combineParamIndexPredicateWithParamNamePredicate(theResourceName, theParamName, theFrom, singleCode);
} }

View File

@ -3505,12 +3505,6 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
"&" + "&" +
Location.SP_NEAR_DISTANCE + "=" + (offset * 2) + "|http://unitsofmeasure.org|km", myFhirCtx.getResourceDefinition("Location")); Location.SP_NEAR_DISTANCE + "=" + (offset * 2) + "|http://unitsofmeasure.org|km", myFhirCtx.getResourceDefinition("Location"));
// FIXME KHS
// new SearchParameterMap();
// map.add(Location.SP_NEAR, new TokenParam());
// QuantityParam distance = new QuantityParam(ParamPrefixEnum.LESSTHAN_OR_EQUALS, );
// map.add(Location.SP_NEAR_DISTANCE, distance);
List<String> ids = toUnqualifiedVersionlessIdValues(myLocationDao.search(map)); List<String> ids = toUnqualifiedVersionlessIdValues(myLocationDao.search(map));
assertThat(ids, contains(locId)); assertThat(ids, contains(locId));
} }