Skip to content

Commit

Permalink
Add suport for location lineage post processing
Browse files Browse the repository at this point in the history
  • Loading branch information
lincmba committed Jan 29, 2025
1 parent 91d6c85 commit cbb10e7
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.ListResource;
import org.hl7.fhir.r4.model.Location;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.hl7.fhir.r4.model.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartregister.helpers.LocationHelper;

import com.google.common.annotations.VisibleForTesting;
import com.google.fhir.gateway.ExceptionUtil;
Expand Down Expand Up @@ -247,9 +249,37 @@ public String postProcess(RequestDetailsReader request, HttpResponse response)
resultContent = this.fhirR4JsonParser.encodeResourceToString(practitionerDetailsBundle);
}

String requestPath = request.getRequestPath();
String method = request.getRequestType().name();

if (requestPath.contains("/Location")) {
IBaseResource parsedResource = this.fhirR4JsonParser.parseResource(resultContent);

if ("POST".equals(method) || "PUT".equals(method)) {
String locationId = getLocationId(method, requestPath, parsedResource);

if (StringUtils.isNotBlank(locationId)) {
LocationHelper.updateLocationLineage(locationId);
}
}
}

return resultContent;
}

private static String getLocationId(
String method, String requestPath, IBaseResource parsedResource) {
String locationId = null;

if ("PUT".equals(method)) {
String[] pathParts = requestPath.split("/");
locationId = pathParts[pathParts.length - 1];
} else if (parsedResource instanceof Location) {
locationId = ((Location) parsedResource).getIdElement().getIdPart();
}
return locationId;
}

private IBaseResource processRelatedEntityLocationSyncStrategy(
RequestDetailsReader request, HttpResponse response) throws IOException {
String resultContent;
Expand Down

0 comments on commit cbb10e7

Please sign in to comment.