From c866fd408763ef004d217b0ab5ecbaa44d9b7231 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Thu, 22 Aug 2024 19:34:55 +0300 Subject: [PATCH] Implement Pagination for REL Sync --- .../PractitionerDetailsEndpointHelper.java | 4 ++-- .../gateway/plugins/SyncAccessDecision.java | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java index 78e5bb0..1ef9e96 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java @@ -572,8 +572,8 @@ public static List getLocationsHierarchy(List locatio return locationsIdentifiers.parallelStream() .map( locationsIdentifier -> - new LocationHierarchyEndpointHelper(r4FHIRClient).getLocationHierarchy( - locationsIdentifier, null, null)) + new LocationHierarchyEndpointHelper(r4FHIRClient) + .getLocationHierarchy(locationsIdentifier, null, null)) .filter( locationHierarchy -> !org.smartregister.utils.Constants.LOCATION_RESOURCE_NOT_FOUND diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java index d3ef717..cb78dab 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java @@ -1,5 +1,6 @@ package org.smartregister.fhir.gateway.plugins; +import static ca.uhn.fhir.rest.api.Constants.PARAM_SUMMARY; import static org.smartregister.fhir.gateway.plugins.EnvUtil.getEnvironmentVar; import java.io.FileReader; @@ -257,6 +258,7 @@ private IBaseResource processRelatedEntityLocationSyncStrategy( fhirR4Client.getFhirContext().getRestfulClientFactory().setSocketTimeout(300000); List allResults = new ArrayList<>(); + int totalResultMatches = 0; String requestPath = request.getRequestPath() @@ -305,6 +307,7 @@ private IBaseResource processRelatedEntityLocationSyncStrategy( .collect(Collectors.toList()); allResults.addAll(entryComponentList); + totalResultMatches += entryComponentList.size(); } resultContent = new BasicResponseHandler().handleResponse(response); @@ -312,14 +315,20 @@ private IBaseResource processRelatedEntityLocationSyncStrategy( IBaseResource responseResource = this.fhirR4JsonParser.parseResource(resultContent); if (responseResource instanceof Bundle) { - ((Bundle) responseResource).getEntry().addAll(allResults); - ((Bundle) responseResource).setTotal(((Bundle) responseResource).getEntry().size()); + if (request.getParameters().containsKey(PARAM_SUMMARY)) { + ((Bundle) responseResource) + .setTotal(((Bundle) responseResource).getTotal() + totalResultMatches); + } else { - Bundle.BundleLinkComponent selfLinkComponent = new Bundle.BundleLinkComponent(); - selfLinkComponent.setRelation(Bundle.LINK_SELF); - selfLinkComponent.setUrl(request.getCompleteUrl()); + ((Bundle) responseResource).getEntry().addAll(allResults); + ((Bundle) responseResource).setTotal(((Bundle) responseResource).getEntry().size()); - ((Bundle) responseResource).setLink(Collections.singletonList(selfLinkComponent)); + Bundle.BundleLinkComponent selfLinkComponent = new Bundle.BundleLinkComponent(); + selfLinkComponent.setRelation(Bundle.LINK_SELF); + selfLinkComponent.setUrl(request.getCompleteUrl()); + + ((Bundle) responseResource).setLink(Collections.singletonList(selfLinkComponent)); + } } return responseResource; }