From d0eb855391558f3f7817e61efd5342c7d2d72798 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Wed, 6 Nov 2024 13:20:37 -0500 Subject: [PATCH] Change Repository search interface from Map to Multimap (#6445) Change Map to Multimap to support multiple and clauses. --- .../ca/uhn/fhir/repository/Repository.java | 44 ++++++++++++++++++- .../7_6_0/6445-repository-api-multimap.yaml | 4 ++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6445-repository-api-multimap.yaml diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/repository/Repository.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/repository/Repository.java index e859a9ae569..c272656f47a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/repository/Repository.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/repository/Repository.java @@ -28,6 +28,8 @@ import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; import com.google.common.annotations.Beta; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseConformance; import org.hl7.fhir.instance.model.api.IBaseParameters; @@ -231,6 +233,23 @@ public interface Repository { // Querying starts here + /** + * Searches this repository + * + * @see FHIR search + * + * @param a Bundle type + * @param a Resource type + * @param bundleType the class of the Bundle type to return + * @param resourceType the class of the Resource type to search + * @param searchParameters the searchParameters for this search + * @return a Bundle with the results of the search + */ + default B search( + Class bundleType, Class resourceType, Multimap> searchParameters) { + return this.search(bundleType, resourceType, searchParameters, Collections.emptyMap()); + } + /** * Searches this repository * @@ -264,9 +283,32 @@ public interface Repository { B search( Class bundleType, Class resourceType, - Map> searchParameters, + Multimap> searchParameters, Map headers); + /** + * Searches this repository + * + * @see FHIR search + * + * @param a Bundle type + * @param a Resource type + * @param bundleType the class of the Bundle type to return + * @param resourceType the class of the Resource type to search + * @param searchParameters the searchParameters for this search + * @param headers headers for this request, typically key-value pairs of HTTP headers + * @return a Bundle with the results of the search + */ + default B search( + Class bundleType, + Class resourceType, + Map> searchParameters, + Map headers) { + ArrayListMultimap> multimap = ArrayListMultimap.create(); + searchParameters.forEach(multimap::put); + return this.search(bundleType, resourceType, multimap, headers); + } + // Paging starts here /** diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6445-repository-api-multimap.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6445-repository-api-multimap.yaml new file mode 100644 index 00000000000..841287f278d --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6445-repository-api-multimap.yaml @@ -0,0 +1,4 @@ +--- +type: add +issue: 6445 +title: "Add Multimap versions of the search() methods to Repository to support queries like `Patient?_tag=a&_tag=b`"