Title: | Client for the 'DHIS2' Web API |
---|---|
Description: | Connect and pull data from a 'DHIS2 (District Health Information Software 2)' instance into R. |
Authors: | Robinson Amanyiraho [cre, aut, cph] |
Maintainer: | Robinson Amanyiraho <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.0 |
Built: | 2024-11-21 14:21:16 UTC |
Source: | https://github.com/amanyiraho/dhis2r |
Provide additional error information
dhis2_error_message(resp)
dhis2_error_message(resp)
resp |
response to be captured |
An error character vector
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
An R6 class called Dhis2r.
You can use a DHIS2 instance connection to get data several times without needing to manually supply your user credentials on each API call.
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
new()
Create a connection to a DHIS2 instance using basic authentication
Dhis2r$new( base_url, username = NULL, password = NULL, api_token = NULL, api_version = NULL, api_version_position = c("after", "before") )
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/
A new 'Dhis2r' object
get_user_info()
Get information of the logged in user
Dhis2r$get_user_info()
A vector
get_metadata()
Get metadata about any available resource from a DHIS2 instance e.g "dataElements", "organisationUnits", "indicators", "periodTypes"
Dhis2r$get_metadata(endpoint = NULL, fields = c("name", "id"))
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")
A data frame
get_metadata_fields()
Get all possible fields for a specific metadata resource from a DHIS2 instance
Dhis2r$get_metadata_fields(endpoint)
endpoint
a resource, get the available resources using 'get_metadata()' without any arguments
A vector of all possible fields for a specific metadata
get_analytics()
Get all possible analytics resources from a DHIS2 instance i.e
Dhis2r$get_analytics( analytic, org_unit, period, output_scheme = c("UID", "NAME") )
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
A data frame of the analytics resource
get_any_analytic()
Get all any analytics resource from a DHIS2 instance to cater for long DHIS2 favorites
Dhis2r$get_any_analytic(endpoint_url)
endpoint_url
string part of Analytic(s) from a DHIS2 instance api endpoint starting from 'analytics.json?dimension='
A data frame of the analytics resource
clone()
The objects of this class are cloneable with this method.
Dhis2r$clone(deep = FALSE)
deep
Whether to make a deep clone.
# 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")
# 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")
The relative periods are relative to the current date and allow e.g. for creating dynamic reports
data(relative_periods)
data(relative_periods)
A data frame with 30 rows and 2 columns:
Period type
Relative period to be used
"https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-239/introduction.html"