Get the organization units from a specific DHIS2 instance
Source:R/read_dhis2-helpers.R
get_organisation_units.Rd
Retrieves all organisational reporting units and their levels, then builds a hierarchy for each unit by tracing its ancestries from the deepest level up to the root.
Arguments
- login
A httr2_response object returned by the
dhis2_login()
function
Value
A data frame where each row represents a full hierarchy for the last-level unit by keeping the hierarchical organizational unit's name and ID at each level, using the official level names provided by the DHIS2 instance like "Country Name", "Country ID", etc.
Details
Fetches all organisation units via the
get_org_units()
function,Fetches all organisational unit levels via the
get_org_unit_levels()
function,Filters for organisational units at the deepest level,
Traces the parent hierarchy of each deepest unit up to the root,
Constructs a tabular structure where each row is a full lineage.
Examples
# establish the connection to the system
dhis2_login <- login(
type = "dhis2",
from = "https://smc.moh.gm/dhis",
user_name = "test",
password = "Gambia@123"
)
#> ✔ Logged in successfully!
# fetch the organisation units
org_units <- get_organisation_units(login = dhis2_login)