From 180083f677cfcabb87b15e06b19308c311e4feae Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Wed, 30 Aug 2023 22:14:52 +0300 Subject: [PATCH] Refactor Location Hierarchy to Search by ID --- configuration/pom.xml | 2 +- location/pom.xml | 4 +-- .../LocationHierarchyResourceProvider.java | 25 ++++++------------- pom.xml | 2 +- practitioner/pom.xml | 2 +- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/configuration/pom.xml b/configuration/pom.xml index c2c05e1..5eb18b3 100755 --- a/configuration/pom.xml +++ b/configuration/pom.xml @@ -5,7 +5,7 @@ org.smartregister hapi-fhir-opensrp-extensions - 0.0.21-SNAPSHOT + 0.0.22-SNAPSHOT org.smartregister.hapi-fhir-opensrp-extensions configuration diff --git a/location/pom.xml b/location/pom.xml index a5c74c8..45f72c7 100755 --- a/location/pom.xml +++ b/location/pom.xml @@ -4,7 +4,7 @@ hapi-fhir-opensrp-extensions org.smartregister - 0.0.21-SNAPSHOT + 0.0.22-SNAPSHOT The repository holds the location extensions on the HAPI server @@ -12,7 +12,7 @@ HAPI FHIR OpenSRP Extensions (Locations) jar https://github.com/opensrp/hapi-fhir-opensrp-extensions - 0.0.8-SNAPSHOT + 0.0.9-SNAPSHOT location diff --git a/location/src/main/java/org/smartregister/extension/rest/LocationHierarchyResourceProvider.java b/location/src/main/java/org/smartregister/extension/rest/LocationHierarchyResourceProvider.java index 641daf2..47ae9e5 100755 --- a/location/src/main/java/org/smartregister/extension/rest/LocationHierarchyResourceProvider.java +++ b/location/src/main/java/org/smartregister/extension/rest/LocationHierarchyResourceProvider.java @@ -47,30 +47,19 @@ public Class getResourceType() { } @Search - public LocationHierarchy getLocationHierarchy( - @RequiredParam(name = IDENTIFIER) TokenParam identifier) { + public LocationHierarchy getLocationHierarchy(@RequiredParam(name = ID) TokenParam id) { SearchParameterMap paramMap = new SearchParameterMap(); - paramMap.add(IDENTIFIER, identifier); - - IBundleProvider locationBundle = locationIFhirResourceDao.search(paramMap); - List locations = - locationBundle != null - ? locationBundle.getResources(0, locationBundle.size()) - : new ArrayList<>(); - String locationId = EMPTY_STRING; - if (locations.size() > 0 - && locations.get(0) != null - && locations.get(0).getIdElement() != null) { - locationId = locations.get(0).getIdElement().getIdPart(); - } + paramMap.add(ID, id); + Location location = locationIFhirResourceDao.read(new IdType(id.getValue())); + String locationId = location != null ? location.getIdElement().getIdPart() : EMPTY_STRING; LocationHierarchyTree locationHierarchyTree = new LocationHierarchyTree(); LocationHierarchy locationHierarchy = new LocationHierarchy(); - if (StringUtils.isNotBlank(locationId) && locations.size() > 0) { + + if (StringUtils.isNotBlank(locationId)) { logger.info("Building Location Hierarchy of Location Id : " + locationId); - locationHierarchyTree.buildTreeFromList( - getLocationHierarchy(locationId, locations.get(0))); + locationHierarchyTree.buildTreeFromList(getLocationHierarchy(locationId, location)); StringType locationIdString = new StringType().setId(locationId).getIdElement(); locationHierarchy.setLocationId(locationIdString); locationHierarchy.setId(LOCATION_RESOURCE + locationId); diff --git a/pom.xml b/pom.xml index 191ce79..2d29c92 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.smartregister hapi-fhir-opensrp-extensions pom - 0.0.21-SNAPSHOT + 0.0.22-SNAPSHOT HAPI FHIR OpenSRP Extensions This repository holds all the code extensions on top of Hapi-FHIR https://github.com/opensrp/hapi-fhir-opensrp-extensions diff --git a/practitioner/pom.xml b/practitioner/pom.xml index fb6426d..3806fdc 100755 --- a/practitioner/pom.xml +++ b/practitioner/pom.xml @@ -4,7 +4,7 @@ hapi-fhir-opensrp-extensions org.smartregister - 0.0.21-SNAPSHOT + 0.0.22-SNAPSHOT The repository holds the practitioner details extensions on the HAPI server