Package 'dhis2r'

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

Help Index


Provide additional error information

Description

Provide additional error information

Usage

dhis2_error_message(resp)

Arguments

resp

response to be captured

Value

An error character vector


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 = NULL,
  password = NULL,
  api_token = NULL,
  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_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/

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)
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 data frame of the analytics resource


Method get_any_analytic()

Get all any analytics resource from a DHIS2 instance to cater for long DHIS2 favorites

Usage
Dhis2r$get_any_analytic(endpoint_url)
Arguments
endpoint_url

string part of Analytic(s) from a DHIS2 instance api endpoint starting from 'analytics.json?dimension='

Returns

A data frame of the analytics resource


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

# 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")

Relative periods in DHIS2

Description

The relative periods are relative to the current date and allow e.g. for creating dynamic reports

Usage

data(relative_periods)

Format

A data frame with 30 rows and 2 columns:

period_type

Period type

period

Relative period to be used

Source

"https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-239/introduction.html"