Skip to content

Commit

Permalink
Implement Pagination for REL Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Aug 22, 2024
1 parent f019b8c commit c866fd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ public static List<LocationHierarchy> getLocationsHierarchy(List<String> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -257,6 +258,7 @@ private IBaseResource processRelatedEntityLocationSyncStrategy(
fhirR4Client.getFhirContext().getRestfulClientFactory().setSocketTimeout(300000);

List<Bundle.BundleEntryComponent> allResults = new ArrayList<>();
int totalResultMatches = 0;

String requestPath =
request.getRequestPath()
Expand Down Expand Up @@ -305,21 +307,28 @@ private IBaseResource processRelatedEntityLocationSyncStrategy(
.collect(Collectors.toList());

allResults.addAll(entryComponentList);
totalResultMatches += entryComponentList.size();
}

resultContent = new BasicResponseHandler().handleResponse(response);

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;
}
Expand Down

0 comments on commit c866fd4

Please sign in to comment.