Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dhis2/dhis2-java-sdk
Java SDK for DHIS2
https://github.com/dhis2/dhis2-java-sdk
android dhis2 integration java sdk
Last synced: 7 days ago
JSON representation
Java SDK for DHIS2
- Host: GitHub
- URL: https://github.com/dhis2/dhis2-java-sdk
- Owner: dhis2
- License: bsd-3-clause
- Created: 2022-04-29T13:54:10.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-19T19:52:59.000Z (7 months ago)
- Last Synced: 2024-04-19T20:53:26.598Z (7 months ago)
- Topics: android, dhis2, integration, java, sdk
- Language: Java
- Homepage: https://developers.dhis2.org/docs/integration/dhis2-java-sdk
- Size: 479 KB
- Stars: 7
- Watchers: 10
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DHIS2 Java SDK
![Maven Central](https://img.shields.io/maven-central/v/org.hisp.dhis.integration.sdk/dhis2-java-sdk)
![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/org.hisp.dhis.integration.sdk/dhis2-java-sdk?server=https%3A%2F%2Foss.sonatype.org)
![Build Status](https://github.com/dhis2/dhis2-java-sdk/workflows/CI/badge.svg)DHIS2 Java SDK is a _lightweight_ library that hides the nuts and bolts of DHIS2 Web API interactions behind a fluent Java API and type-safe resource models. It is powered by [OkHttp](https://square.github.io/okhttp/) and compatible with Android.
## Minimum Requirements
- Java 8
### Android
- Android 5.0 (API Level 21)
## Binaries
### Maven Release Distribution
#### Java API
```xml...
org.hisp.dhis.integration.sdk
jackson-resource-model
[v40.2.2|v40.0|v2.39.1|v2.38.1|v2.37.7|v2.36.11|v2.35.13]
3.0.0
org.hisp.dhis.integration.sdk
dhis2-java-sdk
3.0.0
...
```
#### Android API
```xml...
org.hisp.dhis.integration.sdk
android-jackson-resource-model
[v40.2.2|v40.0|v2.39.1|v2.38.1|v2.37.7|v2.36.11|v2.35.13]
3.0.0
org.hisp.dhis.integration.sdk
dhis2-java-sdk
3.0.0
...
```
### Maven Snapshot Distribution
```xml
...
...
org.hisp.dhis.integration.sdk
dhis2-java-sdk
3.0.1-SNAPSHOT
...
oss.sonatype.org
https://oss.sonatype.org/content/repositories/snapshots
false
true
...
```
## Basic Usage Examples
Create a client that authenticates with a personal access token:
```java
import org.hisp.dhis.integration.sdk.Dhis2ClientBuilder;
import org.hisp.dhis.integration.sdk.api.Dhis2Client;
...
...
Dhis2Client dhis2Client = Dhis2ClientBuilder.newClient( "https://play.dhis2.org/40.2.2/api", "d2pat_apheulkR1x7ac8vr9vcxrFkXlgeRiFc94200032556" ).build();
```Create a client that authenticates with basic credentials:
```java
import org.hisp.dhis.integration.sdk.Dhis2ClientBuilder;
import org.hisp.dhis.integration.sdk.api.Dhis2Client;
...Dhis2Client dhis2Client = Dhis2ClientBuilder.newClient( "https://play.dhis2.org/40.2.2/api", "admin", "district" ).build()
```Fetch an organisation unit:
```java
import org.hisp.dhis.api.model.v40_2_2.OrganisationUnit;
...
OrganisationUnit organisationUnit = dhis2Client.get( "organisationUnits/{id}", "fdc6uOvgoji" ).transfer()
.returnAs( OrganisationUnit.class );
```Fetch all organisation units:
```java
import org.hisp.dhis.api.model.v40_2_2.OrganisationUnit;
...
Iterable organisationUnits = dhis2Client.get( "organisationUnits" )
.withoutPaging().transfer().returnAs( OrganisationUnit.class, "organisationUnits" );for ( OrganisationUnit organisationUnit : organisationUnits )
{
...
}
```Fetch organisation units over multiple pages:
```java
import org.hisp.dhis.api.model.v40_2_2.OrganisationUnit;
...
Iterable organisationUnits = dhis2Client.get( "organisationUnits" )
.withPaging().transfer().returnAs( OrganisationUnit.class, "organisationUnits" );for ( OrganisationUnit organisationUnit : organisationUnits )
{
...
}
```Fetch all organisation units IDs over multiple pages:
```java
import org.hisp.dhis.api.model.v40_2_2.OrganisationUnit;
...
Iterable organisationUnits = dhis2Client.get( "organisationUnits" )
.withField( "id" )
.withPaging().transfer().returnAs( OrganisationUnit.class, "organisationUnits" );for ( OrganisationUnit organisationUnit : organisationUnits )
{
...
}
```Fetch organisation units belonging to the third level of the organisation unit hierarchy over multiple pages:
```java
import org.hisp.dhis.api.model.v40_2_2.OrganisationUnit;
...
Iterable organisationUnits = dhis2Client.get( "organisationUnits" )
.withFilter( "level:eq:3" )
.withPaging().transfer().returnAs( OrganisationUnit.class, "organisationUnits" );for ( OrganisationUnit organisationUnit : organisationUnits )
{
...
}
```Create a Tracked Entity Instance:
```java
import org.hisp.dhis.api.model.v40_2_2.AttributeInfo;
import org.hisp.dhis.api.model.v40_2_2.Body;
import org.hisp.dhis.api.model.v40_2_2.EnrollmentInfo;
import org.hisp.dhis.api.model.v40_2_2.ReservedValue;
import org.hisp.dhis.api.model.v40_2_2.TrackedEntityInfo;
import org.hisp.dhis.api.model.v40_2_2.TrackerImportReport;
...String uniqueSystemIdentifier = dhis2Client
.get( "trackedEntityAttributes/HlKXyR5qr2e/generate" ).transfer()
.returnAs( ReservedValue.class )
.getValue().get();TrackerImportReport trackerImportReport = dhis2Client.post( "tracker" )
.withResource( new Body().withTrackedEntities( Arrays.asList( new TrackedEntityInfo()
.withOrgUnit( orgUnitId )
.withTrackedEntityType( "MCPQUTHX1Ze" )
.withEnrollments( Arrays.asList( new EnrollmentInfo()
.withOrgUnit( orgUnitId )
.withProgram( "w0qPtIW0JYu" )
.withEnrolledAt( new Date() )
.withOccurredAt( new Date() )
.withAttributes( Arrays.asList(
new AttributeInfo().withAttribute( "HlKXyR5qr2e" ).withValue( uniqueSystemIdentifier ),
new AttributeInfo().withAttribute( "oindugucx72" ).withValue( "Male" ),
new AttributeInfo().withAttribute( "NI0QRzJvQ0k" ).withValue( "2023-01-01" ) ) ) ) ) ) ) )
.withParameter( "async", "false" )
.transfer()
.returnAs( TrackerImportReport.class );if ( !trackerImportReport.getStatus().equals( TrackerImportReport.StatusRef.OK ) )
{
...
}
```