-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from opensrp/location-hierarchy-api
Create a Location Hierarchy API
- Loading branch information
Showing
15 changed files
with
1,183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.smartregister</groupId> | ||
<artifactId>hapi-fhir-opensrp-extensions</artifactId> | ||
<packaging>jar</packaging> | ||
<version>0.0.1-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> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<spring.version>5.2.4.RELEASE</spring.version> | ||
</properties> | ||
|
||
<distributionManagement> | ||
<snapshotRepository> | ||
<id>nexus-snapshots</id> | ||
<name>Nexus Snapshots Repository</name> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
<uniqueVersion>false</uniqueVersion> | ||
</snapshotRepository> | ||
<repository> | ||
<id>nexus-releases</id> | ||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jdbc</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api --> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- This dependency includes the core HAPI-FHIR classes --> | ||
<dependency> | ||
<groupId>ca.uhn.hapi.fhir</groupId> | ||
<artifactId>hapi-fhir-base</artifactId> | ||
<version>5.4.0</version> | ||
</dependency> | ||
|
||
<!-- This dependency includes the JPA server itself, which is packaged separately from the org.smartregister.opensrp.xyz.rest of HAPI FHIR --> | ||
<dependency> | ||
<groupId>ca.uhn.hapi.fhir</groupId> | ||
<artifactId>hapi-fhir-jpaserver-base</artifactId> | ||
<version>5.4.0</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jcl</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<!-- Test Dependencies--> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
</project> |
60 changes: 60 additions & 0 deletions
60
src/main/java/org/smartregister/extension/model/ChildTreeNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.smartregister.extension.model; | ||
|
||
import ca.uhn.fhir.model.api.annotation.Child; | ||
import ca.uhn.fhir.model.api.annotation.DatatypeDef; | ||
import ca.uhn.fhir.util.ElementUtil; | ||
import org.hl7.fhir.instance.model.api.ICompositeType; | ||
import org.hl7.fhir.r4.model.StringType; | ||
import org.hl7.fhir.r4.model.Type; | ||
|
||
@DatatypeDef(name = "ChildTreeNode") | ||
public class ChildTreeNode extends Type implements ICompositeType { | ||
|
||
@Child(name = "childId", type = { StringType.class }, order = 0, min = 1, max = 1, modifier = false, summary = false) | ||
private StringType childId; | ||
|
||
@Child(name = "treeNode", type = { TreeNode.class }) | ||
private TreeNode treeNode; | ||
|
||
public ChildTreeNode() { | ||
treeNode = new TreeNode(); | ||
} | ||
|
||
public StringType getChildId() { | ||
return childId; | ||
} | ||
|
||
public ChildTreeNode setChildId(StringType childId) { | ||
this.childId = childId; | ||
return this; | ||
} | ||
|
||
public TreeNode getChildren() { | ||
if (treeNode == null) { | ||
treeNode = new TreeNode(); | ||
} | ||
return treeNode; | ||
} | ||
|
||
public ChildTreeNode setChildren(TreeNode children) { | ||
this.treeNode = children; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Type copy() { | ||
ChildTreeNode childTreeNode = new ChildTreeNode(); | ||
copyValues(childTreeNode); | ||
return childTreeNode; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return ElementUtil.isEmpty(childId); | ||
} | ||
|
||
@Override | ||
protected Type typedCopy() { | ||
return copy(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/org/smartregister/extension/model/LocationHierarchy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.smartregister.extension.model; | ||
|
||
import ca.uhn.fhir.model.api.annotation.Child; | ||
import ca.uhn.fhir.model.api.annotation.Description; | ||
import ca.uhn.fhir.model.api.annotation.ResourceDef; | ||
import org.hl7.fhir.r4.model.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@ResourceDef(name = "LocationHierarchy", profile = "http://hl7.org/fhir/profiles/custom-resource") | ||
public class LocationHierarchy extends Location { | ||
|
||
@Child( | ||
name = "locationId", | ||
type = { StringType.class }, | ||
order = 5, | ||
min = 0, | ||
max = 1, | ||
modifier = false, | ||
summary = true | ||
) | ||
@Description( | ||
shortDefinition = "Unique id to the location", | ||
formalDefinition = "Id of the location whose location hierarchy will be displayed." | ||
) | ||
protected StringType locationId; | ||
|
||
@Child(name = "LocationHierarchyTree", type = { LocationHierarchyTree.class }) | ||
@Description( | ||
shortDefinition = "Complete Location Hierarchy Tree", | ||
formalDefinition = "Consists of Location Hierarchy Tree and Parent Child Identifiers List" | ||
) | ||
private LocationHierarchyTree locationHierarchyTree; | ||
|
||
@Override | ||
public Location copy() { | ||
Location location = new Location(); | ||
Bundle bundle = new Bundle(); | ||
List<Bundle.BundleEntryComponent> theEntry = new ArrayList<>(); | ||
Bundle.BundleEntryComponent entryComponent = new Bundle.BundleEntryComponent(); | ||
entryComponent.setResource(new Bundle()); | ||
theEntry.add(entryComponent); | ||
bundle.setEntry(theEntry); | ||
this.copyValues(location); | ||
return location; | ||
} | ||
|
||
@Override | ||
public ResourceType getResourceType() { | ||
return ResourceType.Bundle; | ||
} | ||
|
||
public StringType getLocationId() { | ||
return locationId; | ||
} | ||
|
||
public void setLocationId(StringType locationId) { | ||
this.locationId = locationId; | ||
|
||
} | ||
|
||
public LocationHierarchyTree getLocationHierarchyTree() { | ||
return locationHierarchyTree; | ||
} | ||
|
||
public void setLocationHierarchyTree(LocationHierarchyTree locationHierarchyTree) { | ||
this.locationHierarchyTree = locationHierarchyTree; | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/org/smartregister/extension/model/LocationHierarchyTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.smartregister.extension.model; | ||
|
||
import ca.uhn.fhir.model.api.annotation.Child; | ||
import ca.uhn.fhir.model.api.annotation.DatatypeDef; | ||
import ca.uhn.fhir.util.ElementUtil; | ||
import org.hl7.fhir.instance.model.api.ICompositeType; | ||
import org.hl7.fhir.r4.model.Location; | ||
import org.hl7.fhir.r4.model.StringType; | ||
import org.hl7.fhir.r4.model.Type; | ||
import org.thymeleaf.util.StringUtils; | ||
|
||
import java.util.List; | ||
|
||
@DatatypeDef(name = "LocationHierarchyTree") | ||
public class LocationHierarchyTree extends Type implements ICompositeType { | ||
|
||
@Child(name = "locationsHierarchy") | ||
private Tree locationsHierarchy; | ||
|
||
public LocationHierarchyTree() { | ||
this.locationsHierarchy = new Tree(); | ||
} | ||
|
||
public void addLocation(Location l) { | ||
StringType idString = new StringType(); | ||
idString.setValue(l.getId()); | ||
if (!locationsHierarchy.hasNode(idString.getValue())) { | ||
if (l.getPartOf() == null || StringUtils.isEmpty(l.getPartOf().getReference())) { | ||
locationsHierarchy.addNode(idString.getValue(), l.getName(), l, null); | ||
} else { | ||
//get Parent Location | ||
StringType parentId = new StringType(); | ||
parentId.setValue(l.getPartOf().getReference()); | ||
locationsHierarchy.addNode(idString.getValue(), l.getName(), l, parentId.getValue()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* WARNING: Overrides existing locations | ||
* | ||
* @param locations | ||
*/ | ||
public void buildTreeFromList(List<Location> locations) { | ||
for (Location location : locations) { | ||
addLocation(location); | ||
} | ||
} | ||
|
||
public Tree getLocationsHierarchy() { | ||
return locationsHierarchy; | ||
} | ||
|
||
public LocationHierarchyTree setLocationsHierarchy(Tree locationsHierarchy) { | ||
this.locationsHierarchy = locationsHierarchy; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Type copy() { | ||
LocationHierarchyTree locationHierarchyTree = new LocationHierarchyTree(); | ||
copyValues(locationHierarchyTree); | ||
return locationHierarchyTree; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return ElementUtil.isEmpty(locationsHierarchy); | ||
} | ||
|
||
@Override | ||
protected Type typedCopy() { | ||
return copy(); | ||
} | ||
} | ||
|
61 changes: 61 additions & 0 deletions
61
src/main/java/org/smartregister/extension/model/ParentChildrenMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.smartregister.extension.model; | ||
|
||
import ca.uhn.fhir.model.api.annotation.Child; | ||
import ca.uhn.fhir.model.api.annotation.DatatypeDef; | ||
import ca.uhn.fhir.util.ElementUtil; | ||
import org.hl7.fhir.instance.model.api.ICompositeType; | ||
import org.hl7.fhir.r4.model.StringType; | ||
import org.hl7.fhir.r4.model.Type; | ||
|
||
import java.util.List; | ||
|
||
@DatatypeDef(name = "ParentChildrenMap") | ||
public class ParentChildrenMap extends Type implements ICompositeType { | ||
|
||
@Child(name = "identifier", type = { StringType.class }, order = 0, min = 1, max = 1, modifier = false, summary = false) | ||
private StringType identifier; | ||
|
||
@Child(name = "childIdentifiers", type = { StringType.class }, | ||
order = 1, | ||
min = 0, | ||
max = -1, | ||
modifier = false, | ||
summary = false) | ||
private List<StringType> childIdentifiers; | ||
|
||
public StringType getIdentifier() { | ||
return identifier; | ||
} | ||
|
||
public ParentChildrenMap setIdentifier(StringType identifier) { | ||
this.identifier = identifier; | ||
return this; | ||
} | ||
|
||
public List<StringType> getChildIdentifiers() { | ||
return childIdentifiers; | ||
} | ||
|
||
public ParentChildrenMap setChildIdentifiers(List<StringType> childIdentifiers) { | ||
this.childIdentifiers = childIdentifiers; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Type copy() { | ||
ParentChildrenMap parentChildrenMap = new ParentChildrenMap(); | ||
copyValues(parentChildrenMap); | ||
return parentChildrenMap; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return ElementUtil.isEmpty(identifier); | ||
} | ||
|
||
@Override | ||
protected Type typedCopy() { | ||
return copy(); | ||
} | ||
|
||
} |
Oops, something went wrong.