Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add model and util classes in a separate library. #1

Merged
merged 3 commits into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Default ignored files
/shelf/
/workspace.xml
target/
.project
.classpath
.settings/
.DS_Store
.idea/
*.iml
*.ipr
*.iws
logfile
*.log*
.springBeans
.gradle/
Empty file modified README.md
100644 → 100755
Empty file.
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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>fhir-common-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<hapi.fhir.base.version>5.5.0</hapi.fhir.base.version>
</properties>

<dependencies>
<dependency>
<artifactId>hapi-fhir-base</artifactId>
<groupId>ca.uhn.hapi.fhir</groupId>
<version>${hapi.fhir.base.version}</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>org.hl7.fhir.r4</artifactId>
<version>5.4.10</version>
</dependency>
</dependencies>
</project>
84 changes: 84 additions & 0 deletions src/main/java/org/smartregister/model/location/ChildTreeNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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 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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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 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.apache.commons.lang3.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();
}
}
Loading