diff --git a/pom.xml b/pom.xml
index 1e50222..2a4ea48 100755
--- a/pom.xml
+++ b/pom.xml
@@ -8,10 +8,24 @@
fhir-common-utils
0.0.1-SNAPSHOT
+
+
+ nexus-releases
+ https://oss.sonatype.org/service/local/staging/deploy/maven2
+
+
+ nexus-snapshots
+ Nexus Snapshots Repository
+ false
+ https://oss.sonatype.org/content/repositories/snapshots
+
+
+
11
11
5.5.0
+ 4.13.1
@@ -25,5 +39,14 @@
org.hl7.fhir.r4
5.4.10
+
+
+
+ junit
+ junit
+ test
+ ${junit.version}
+
+
\ No newline at end of file
diff --git a/src/test/java/org/smartregister/model/location/LocationHierarchyTreeTest.java b/src/test/java/org/smartregister/model/location/LocationHierarchyTreeTest.java
new file mode 100644
index 0000000..3cbedb3
--- /dev/null
+++ b/src/test/java/org/smartregister/model/location/LocationHierarchyTreeTest.java
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2021 Ona Systems, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.smartregister.model.location;
+
+import org.hl7.fhir.r4.model.Location;
+import org.hl7.fhir.r4.model.Reference;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+
+public class LocationHierarchyTreeTest {
+
+ @Test
+ public void testAddLocationWithoutChildLocations() {
+ Location location = new Location();
+ location.setId("Location/1");
+ location.setName("Test Location");
+ Reference partOfReference = new Reference();
+ partOfReference.setReference("");
+ location.setPartOf(partOfReference);
+ LocationHierarchyTree locationHierarchyTree = new LocationHierarchyTree();
+ locationHierarchyTree.addLocation(location);
+
+ Tree tree = locationHierarchyTree.getLocationsHierarchy();
+ assertNotNull(tree);
+ assertNotNull(tree.getTree());
+ assertEquals("Location/1", tree.getTree().getTreeNodeId().getValue());
+ assertEquals("Location/1", tree.getTree().getTreeNode().getNodeId().getValue());
+ assertEquals("Test Location", tree.getTree().getTreeNode().getLabel().getValue());
+ assertNull(tree.getTree().getTreeNode().getParent().getValue());
+ assertEquals(0, tree.getTree().getTreeNode().getChildren().size());
+ }
+
+ @Test
+ public void testBuildTreeFromList() {
+ Location location1 = new Location();
+ location1.setId("Location/1");
+ location1.setName("Test Location");
+ Reference partOfReference = new Reference();
+ partOfReference.setReference("");
+ location1.setPartOf(partOfReference);
+
+ Location location2 = new Location();
+ location2.setId("Location/2");
+ location2.setName("Test Location 2");
+ partOfReference = new Reference();
+ partOfReference.setReference("Location/1");
+ location2.setPartOf(partOfReference);
+
+ Location location3 = new Location();
+ location3.setId("Location/3");
+ location3.setName("Test Location 3");
+ partOfReference = new Reference();
+ partOfReference.setReference("Location/2");
+ location3.setPartOf(partOfReference);
+
+ LocationHierarchyTree locationHierarchyTree = new LocationHierarchyTree();
+
+ List locationList = new ArrayList<>();
+ locationList.add(location1);
+ locationList.add(location2);
+ locationList.add(location3);
+
+ locationHierarchyTree.buildTreeFromList(locationList);
+ Tree tree = locationHierarchyTree.getLocationsHierarchy();
+ assertNotNull(tree);
+ assertNotNull(tree.getTree());
+ assertEquals("Location/1", tree.getTree().getTreeNodeId().getValue());
+ assertEquals("Location/1", tree.getTree().getTreeNode().getNodeId().getValue());
+ assertEquals("Test Location", tree.getTree().getTreeNode().getLabel().getValue());
+ assertNull(tree.getTree().getTreeNode().getParent().getValue());
+ assertEquals(1, tree.getTree().getTreeNode().getChildren().size());
+
+ assertEquals(
+ "Location/2",
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getNodeId()
+ .getValue());
+ assertEquals(
+ "Test Location 2",
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getLabel()
+ .getValue());
+ assertNotNull(
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getParent()
+ .getValue());
+ assertEquals(
+ "Location/1",
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getParent()
+ .getValue());
+ assertEquals(
+ 1,
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getChildren()
+ .size());
+
+ assertEquals(
+ "Location/3",
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getNodeId()
+ .getValue());
+ assertEquals(
+ "Test Location 3",
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getLabel()
+ .getValue());
+ assertNotNull(
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getParent()
+ .getValue());
+ assertEquals(
+ "Location/2",
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getParent()
+ .getValue());
+ assertEquals(
+ 0,
+ tree.getTree()
+ .getTreeNode()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getChildren()
+ .get(0)
+ .getChildren()
+ .getChildren()
+ .size());
+
+ assertNotNull(locationHierarchyTree.getLocationsHierarchy().getParentChildren());
+ assertEquals(2, locationHierarchyTree.getLocationsHierarchy().getParentChildren().size());
+ assertEquals(
+ "Location/1",
+ locationHierarchyTree
+ .getLocationsHierarchy()
+ .getParentChildren()
+ .get(0)
+ .getIdentifier()
+ .getValue());
+ assertEquals(
+ 1,
+ locationHierarchyTree
+ .getLocationsHierarchy()
+ .getParentChildren()
+ .get(0)
+ .getChildIdentifiers()
+ .size());
+ assertEquals(
+ "Location/2",
+ locationHierarchyTree
+ .getLocationsHierarchy()
+ .getParentChildren()
+ .get(0)
+ .getChildIdentifiers()
+ .get(0)
+ .getValue());
+
+ assertEquals(
+ "Location/2",
+ locationHierarchyTree
+ .getLocationsHierarchy()
+ .getParentChildren()
+ .get(1)
+ .getIdentifier()
+ .getValue());
+ assertEquals(
+ 1,
+ locationHierarchyTree
+ .getLocationsHierarchy()
+ .getParentChildren()
+ .get(1)
+ .getChildIdentifiers()
+ .size());
+ assertEquals(
+ "Location/3",
+ locationHierarchyTree
+ .getLocationsHierarchy()
+ .getParentChildren()
+ .get(1)
+ .getChildIdentifiers()
+ .get(0)
+ .getValue());
+ }
+}
diff --git a/src/test/java/org/smartregister/model/location/TreeNodeTest.java b/src/test/java/org/smartregister/model/location/TreeNodeTest.java
new file mode 100644
index 0000000..a7af27b
--- /dev/null
+++ b/src/test/java/org/smartregister/model/location/TreeNodeTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2021 Ona Systems, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.smartregister.model.location;
+
+import org.hl7.fhir.r4.model.Location;
+import org.hl7.fhir.r4.model.StringType;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+
+public class TreeNodeTest {
+
+ @Test
+ public void testAddingChild() {
+
+ StringType rootNodeName = new StringType();
+ rootNodeName.setValue("Root Node");
+
+ StringType rootNodeId = new StringType();
+ rootNodeId.setValue("Location/1");
+
+ StringType rootNodeLabel = new StringType();
+ rootNodeLabel.setValue("Root Location Node");
+
+ Location location = new Location();
+ location.setId("Location/1");
+
+ StringType childNodeName = new StringType();
+ childNodeName.setValue("Child Node");
+
+ StringType childNodeId = new StringType();
+ childNodeId.setValue("Location/2");
+
+ StringType childNodeLabel = new StringType();
+ childNodeLabel.setValue("Child Location Node");
+
+ TreeNode rootNode = new TreeNode(rootNodeName, rootNodeId, rootNodeLabel, location, null);
+ TreeNode childNode =
+ new TreeNode(childNodeName, childNodeId, childNodeLabel, location, rootNodeId);
+ rootNode.addChild(childNode);
+
+ assertEquals(
+ childNodeId.getValue(),
+ rootNode.findChild(childNodeId.getValue()).getNodeId().getValue());
+ assertEquals(
+ rootNodeId.getValue(),
+ rootNode.findChild(childNodeId.getValue()).getParent().getValue());
+ }
+
+ @Test
+ public void findInvalidChildren() {
+ StringType rootNodeName = new StringType();
+ rootNodeName.setValue("Root Node");
+
+ StringType rootNodeId = new StringType();
+ rootNodeId.setValue("Location/1");
+
+ StringType rootNodeLabel = new StringType();
+ rootNodeLabel.setValue("Root Location Node");
+
+ Location location = new Location();
+ location.setId("Location/1");
+
+ TreeNode rootNode = new TreeNode(rootNodeName, rootNodeId, rootNodeLabel, location, null);
+ assertEquals(0, rootNode.getChildren().size());
+ assertNull(rootNode.findChild("Location/2"));
+ }
+}
diff --git a/src/test/java/org/smartregister/model/location/TreeTest.java b/src/test/java/org/smartregister/model/location/TreeTest.java
new file mode 100644
index 0000000..c082c05
--- /dev/null
+++ b/src/test/java/org/smartregister/model/location/TreeTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2021 Ona Systems, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.smartregister.model.location;
+
+import org.hl7.fhir.r4.model.Location;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+
+public class TreeTest {
+
+ @Test
+ public void testAddingNodeWithOutParent() {
+ Tree tree = new Tree();
+ Location location = new Location();
+ location.setId("testId");
+ tree.addNode("Location/1", "test", location, null);
+
+ TreeNode treeNode = tree.getNode("Location/1");
+
+ assertEquals("Location/1", treeNode.getNodeId().getValue());
+ assertEquals("test", treeNode.getLabel().getValue());
+ assertEquals(location, treeNode.getNode());
+ assertNull(treeNode.getParent().getValue());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCannotReAddExistingNode() {
+ Tree tree = new Tree();
+ Location location = new Location();
+ location.setId("testId");
+ tree.addNode("Location/1", "test", location, null);
+ tree.addNode("Location/1", "test", location, null);
+ }
+
+ @Test
+ public void testAddingNodeWithValidParent() {
+ Tree tree = new Tree();
+ Location location = new Location();
+ location.setId("testId");
+ tree.addNode("Location/1", "test", location, null);
+ tree.addNode("Location/2", "test2", location, "Location/1");
+
+ TreeNode childNode = tree.getNode("Location/2");
+
+ assertEquals("Location/2", childNode.getNodeId().getValue());
+ assertEquals("test2", childNode.getLabel().getValue());
+ assertEquals(location, childNode.getNode());
+ assertNotNull(childNode.getParent().getValue());
+
+ String parentNodeId = childNode.getParent().getValue();
+
+ assertEquals("Location/1", parentNodeId);
+ }
+}
diff --git a/src/test/java/org/smartregister/model/practitioner/FhirCareTeamExtensionTest.java b/src/test/java/org/smartregister/model/practitioner/FhirCareTeamExtensionTest.java
new file mode 100644
index 0000000..3558064
--- /dev/null
+++ b/src/test/java/org/smartregister/model/practitioner/FhirCareTeamExtensionTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2022 Ona Systems, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.smartregister.model.practitioner;
+
+import org.hl7.fhir.r4.model.CareTeam;
+import org.hl7.fhir.r4.model.Identifier;
+import org.hl7.fhir.r4.model.Reference;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class FhirCareTeamExtensionTest {
+
+ @Test
+ public void testMapValues() {
+
+ CareTeam careTeam = new CareTeam();
+ List identifierList = new ArrayList<>();
+ Identifier identifier = new Identifier();
+ identifier.setUse(Identifier.IdentifierUse.OFFICIAL);
+ identifierList.add(identifier);
+ identifier.setValue("a2788d06-fdad-4a74-90ac-3ac4e243eee5");
+ careTeam.setIdentifier(identifierList);
+ careTeam.setName("Care Team A");
+ careTeam.setStatus(CareTeam.CareTeamStatus.ACTIVE);
+ Reference subjectRef = new Reference();
+ subjectRef.setDisplay("Demo FHIR Groups");
+ subjectRef.setReference("Group/206");
+ careTeam.setSubject(subjectRef);
+ List participantComponents = new ArrayList<>();
+ CareTeam.CareTeamParticipantComponent careTeamParticipantComponent =
+ new CareTeam.CareTeamParticipantComponent();
+ Reference member = new Reference();
+ member.setReference("Practitioner/152");
+ member.setDisplay("Test Practitioner");
+ careTeamParticipantComponent.setMember(member);
+ participantComponents.add(careTeamParticipantComponent);
+ careTeam.setParticipant(participantComponents);
+
+ FhirCareTeamExtension fhirCareTeamExtension = new FhirCareTeamExtension();
+ fhirCareTeamExtension = fhirCareTeamExtension.mapValues(careTeam);
+
+ assertNotNull(fhirCareTeamExtension);
+ assertEquals(careTeam.getId(), fhirCareTeamExtension.getId());
+ assertEquals(careTeam.getIdentifier(), fhirCareTeamExtension.getIdentifier());
+ assertEquals(careTeam.getStatus(), fhirCareTeamExtension.getStatus());
+ assertEquals(careTeam.getCategory(), fhirCareTeamExtension.getCategory());
+ assertEquals(careTeam.getName(), fhirCareTeamExtension.getName());
+ assertEquals(careTeam.getSubject(), fhirCareTeamExtension.getSubject());
+ assertEquals(careTeam.getEncounter(), fhirCareTeamExtension.getEncounter());
+ assertEquals(careTeam.getPeriod(), fhirCareTeamExtension.getPeriod());
+ assertEquals(careTeam.getParticipant(), fhirCareTeamExtension.getParticipant());
+ assertEquals(careTeam.getReasonCode(), fhirCareTeamExtension.getReasonCode());
+ assertEquals(careTeam.getReasonReference(), fhirCareTeamExtension.getReasonReference());
+ assertEquals(
+ careTeam.getManagingOrganization(),
+ fhirCareTeamExtension.getManagingOrganization());
+ assertEquals(careTeam.getTelecom(), fhirCareTeamExtension.getTelecom());
+ assertEquals(careTeam.getNote(), fhirCareTeamExtension.getNote());
+ }
+}
diff --git a/src/test/java/org/smartregister/model/practitioner/FhirOrganizationExtensionTest.java b/src/test/java/org/smartregister/model/practitioner/FhirOrganizationExtensionTest.java
new file mode 100644
index 0000000..b967f65
--- /dev/null
+++ b/src/test/java/org/smartregister/model/practitioner/FhirOrganizationExtensionTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2022 Ona Systems, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.smartregister.model.practitioner;
+
+import org.hl7.fhir.r4.model.*;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class FhirOrganizationExtensionTest {
+
+ @Test
+ public void testMapValues() {
+ Organization organization = new Organization();
+ List identifierList = new ArrayList<>();
+ Identifier identifier = new Identifier();
+ identifier.setUse(Identifier.IdentifierUse.OFFICIAL);
+ identifierList.add(identifier);
+ identifier.setValue("a2788d06-fdad-4a74-90ac-3ac4e243eee5");
+ organization.setIdentifier(identifierList);
+ organization.setId("");
+ organization.setActive(true);
+ List typeList = new ArrayList<>();
+ CodeableConcept type = new CodeableConcept();
+ type.setId("Test type");
+ List codings = new ArrayList<>();
+ Coding coding = new Coding();
+ coding.setCode("A");
+ codings.add(coding);
+ type.setCoding(codings);
+ typeList.add(type);
+ organization.setType(typeList);
+ organization.setName("Organization A");
+ List aliasList = new ArrayList<>();
+ StringType alias = new StringType();
+ alias.setValue("Organization A");
+ aliasList.add(alias);
+ organization.setAlias(aliasList);
+
+ FhirOrganizationExtension fhirOrganizationExtension = new FhirOrganizationExtension();
+ fhirOrganizationExtension = fhirOrganizationExtension.mapValues(organization);
+
+ assertNotNull(fhirOrganizationExtension);
+ assertEquals(organization.getId(), fhirOrganizationExtension.getId());
+ assertEquals(organization.getIdentifier(), fhirOrganizationExtension.getIdentifier());
+ assertEquals(organization.getActive(), fhirOrganizationExtension.getActive());
+ assertEquals(organization.getType(), fhirOrganizationExtension.getType());
+ assertEquals(organization.getName(), fhirOrganizationExtension.getName());
+ assertEquals(organization.getAlias(), fhirOrganizationExtension.getAlias());
+ assertEquals(organization.getTelecom(), fhirOrganizationExtension.getTelecom());
+ assertEquals(organization.getAddress(), fhirOrganizationExtension.getAddress());
+ assertEquals(organization.getPartOf(), fhirOrganizationExtension.getPartOf());
+ assertEquals(organization.getContact(), fhirOrganizationExtension.getContact());
+ assertEquals(organization.getEndpoint(), fhirOrganizationExtension.getEndpoint());
+ }
+}