diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_2_0/5668-chained-sort-near.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_2_0/5668-chained-sort-near.yaml new file mode 100644 index 00000000000..56e06ca402a --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_2_0/5668-chained-sort-near.yaml @@ -0,0 +1,4 @@ +--- +type: fix +issue: 5668 +title: "Added support for sorting on a chained `location.near` search. This allows you to sort location by nearness via a chained search. Thanks to Nicolai Gjøderum (@nigtrifork) for the contribution!" diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java index 80e7ca803d4..9cd22443e97 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java @@ -384,14 +384,20 @@ public class QueryStack { List> params = theParams.get(theParamName); if (params != null && !params.isEmpty() && !params.get(0).isEmpty()) { IQueryParameterType locationParam = params.get(0).get(0); - final SpecialParam specialParam = new SpecialParam().setValue(locationParam.getValueAsQueryToken(myFhirContext)); + final SpecialParam specialParam = + new SpecialParam().setValue(locationParam.getValueAsQueryToken(myFhirContext)); ParsedLocationParam location = ParsedLocationParam.from(theParams, specialParam); double latitudeValue = location.getLatitudeValue(); double longitudeValue = location.getLongitudeValue(); - final CoordsPredicateBuilder coordsPredicateBuilder = mySqlBuilder.addCoordsPredicateBuilder(resourceLinkPredicateBuilder.getColumnTargetResourceId()); - mySqlBuilder.addSortCoordsNear(coordsPredicateBuilder, latitudeValue, longitudeValue, theAscending); + final CoordsPredicateBuilder coordsPredicateBuilder = mySqlBuilder.addCoordsPredicateBuilder( + resourceLinkPredicateBuilder.getColumnTargetResourceId()); + mySqlBuilder.addSortCoordsNear( + coordsPredicateBuilder, latitudeValue, longitudeValue, theAscending); } else { - String msg = myFhirContext.getLocalizer().getMessageSanitized(QueryStack.class, "cantSortOnCoordParamWithoutValues", theParamName); + String msg = myFhirContext + .getLocalizer() + .getMessageSanitized( + QueryStack.class, "cantSortOnCoordParamWithoutValues", theParamName); throw new InvalidRequestException(Msg.code(2497) + msg); } return; diff --git a/pom.xml b/pom.xml index f7645206246..f527f848e35 100644 --- a/pom.xml +++ b/pom.xml @@ -674,6 +674,11 @@ Trifork Martin Zacho Grønhøj + + nigtrifork + Trifork + Nicolai Gjøderum + augla August Langhout