Dhis2r {dhis2r}R Documentation

Connect and pull/get data from a DHIS2 instance

Description

To create a DHIS2 connection, you need a DHIS2 base URL, username, password, and an API version The R6 Class called 'Dhis2r' representing a DHIS2 instance connection

Format

An R6 class called Dhis2r.

Details

You can use a DHIS2 instance connection to get data several times without needing to manually supply your user credentials on each API call.

Public fields

request_sent

The request used to perform an API call

name

Name of the user

access_rights

The access rights the user has on the DHIS2 instance

account_info

Information of the logged account credentials

Methods

Public methods


Method new()

Create a connection to a DHIS2 instance using basic authentication

Usage
Dhis2r$new(
  base_url,
  username,
  password,
  api_version = NULL,
  api_version_position = c("after", "before")
)
Arguments
base_url

Base url e.g https://play.dhis2.org/

username

Registered username e.g "admin"

password

Registered password e.g "district"

api_version

The api version e.g "33"

api_version_position

position where the api_version is after or before in web API url i.e /api/

Returns

A new 'Dhis2r' object


Method get_user_info()

Get information of the logged in user

Usage
Dhis2r$get_user_info()
Returns

A vector


Method get_metadata()

Get metadata about any available resource from a DHIS2 instance e.g "dataElements", "organisationUnits", "indicators", "periodTypes"

Usage
Dhis2r$get_metadata(endpoint = NULL, fields = c("name", "id"))
Arguments
endpoint

a resource, get the available resources using 'get_metadata()' without any arguments

fields

The specific columns to be return in the dataframe e.g c("name","id")

Returns

A data frame


Method get_metadata_fields()

Get all possible fields for a specific metadata resource from a DHIS2 instance

Usage
Dhis2r$get_metadata_fields(endpoint = NULL)
Arguments
endpoint

a resource, get the available resources using 'get_metadata()' without any arguments

Returns

A vector of all possible fields for a specific metadata


Method get_analytics()

Get all possible analytics resources from a DHIS2 instance i.e

Usage
Dhis2r$get_analytics(
  analytic,
  org_unit,
  period,
  output_scheme = c("UID", "NAME")
)
Arguments
analytic

vector of ID of specific analytic(s) from a DHIS2 instance

org_unit

vector of ID of specific organisation unit(s) from a DHIS2 instance

period

vector of relative or fixed periods from a DHIS2 instance

output_scheme

Output type ID or Names of fields

Returns

A vector of all possible fields for a specific metadata


Method clone()

The objects of this class are cloneable with this method.

Usage
Dhis2r$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

## Not run: 
# connect to the DHIS2 instance
dhis2_play_connection <- Dhis2r$new(base_url = "https://play.dhis2.org/",
 username = "admin",  password = "district",api_version = "2.39.0.1")

# get all the available resources
dhis2_play_connection$get_metadata()

# get organisation Units with the default fields i.e c("name","id")

dhis2_play_connection$get_metadata(endpoint = "organisationUnits")

# get a vector of all possible fields of a organisation unit resource
dhis2_play_connection$get_metadata_fields(endpoint = "organisationUnits")

# get organisation Units with additional fields i.e c("name","id", "level")

dhis2_play_connection$get_metadata(endpoint = "organisationUnits",
fields =  c("name","id", "level"))

dhis2_play_connection$get_analytics(analytic = c("Uvn6LCg7dVU"),
org_unit =   c("O6uvpzGd5pu", "fdc6uOvgoji"),
period = "LAST_12_MONTHS",
 output_scheme = "NAME")


## End(Not run)

[Package dhis2r version 0.1.1 Index]