Skip to content

Commit

Permalink
Refactor Location Hierarchy to Search by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Sep 6, 2023
1 parent 6301ea8 commit 180083f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion configuration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.smartregister</groupId>
<artifactId>hapi-fhir-opensrp-extensions</artifactId>
<version>0.0.21-SNAPSHOT</version>
<version>0.0.22-SNAPSHOT</version>
</parent>
<groupId>org.smartregister.hapi-fhir-opensrp-extensions</groupId>
<artifactId>configuration</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions location/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<parent>
<artifactId>hapi-fhir-opensrp-extensions</artifactId>
<groupId>org.smartregister</groupId>
<version>0.0.21-SNAPSHOT</version>
<version>0.0.22-SNAPSHOT</version>
</parent>

<description>The repository holds the location extensions on the HAPI server</description>
<groupId>org.smartregister.hapi-fhir-opensrp-extensions</groupId>
<name>HAPI FHIR OpenSRP Extensions (Locations)</name>
<packaging>jar</packaging>
<url>https://github.com/opensrp/hapi-fhir-opensrp-extensions</url>
<version>0.0.8-SNAPSHOT</version>
<version>0.0.9-SNAPSHOT</version>
<artifactId>location</artifactId>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,19 @@ public Class<? extends IBaseResource> 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<IBaseResource> 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);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.smartregister</groupId>
<artifactId>hapi-fhir-opensrp-extensions</artifactId>
<packaging>pom</packaging>
<version>0.0.21-SNAPSHOT</version>
<version>0.0.22-SNAPSHOT</version>
<name>HAPI FHIR OpenSRP Extensions</name>
<description>This repository holds all the code extensions on top of Hapi-FHIR</description>
<url>https://github.com/opensrp/hapi-fhir-opensrp-extensions</url>
Expand Down
2 changes: 1 addition & 1 deletion practitioner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>hapi-fhir-opensrp-extensions</artifactId>
<groupId>org.smartregister</groupId>
<version>0.0.21-SNAPSHOT</version>
<version>0.0.22-SNAPSHOT</version>
</parent>

<description>The repository holds the practitioner details extensions on the HAPI server</description>
Expand Down

0 comments on commit 180083f

Please sign in to comment.