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
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
Method new()
Create a connection to a DHIS2 instance using basic authentication
Arguments
base_url
Base url e.g https://play.dhis2.org/
username
Registered username e.g "admin"
password
Registered password e.g "district"
api_token
Personal Access Token (PAT) to use instead of username and password
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/
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"))
Method get_metadata_fields()
Get all possible fields for a specific metadata resource from a DHIS2 instance
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")
)
Method get_any_analytic()
Get all any analytics resource from a DHIS2 instance to cater for long DHIS2 favorites
Examples
if (FALSE) { # interactive() && curl::has_internet()
# Load dhis2r
library(dhis2r)
# connect to the DHIS2 instance
dhis2_play_connection <- Dhis2r$new(base_url = "https://play.im.dhis2.org/stable-2-40-5",
username = "admin",
password = "district")
# 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")
}