library(dhis2r)
Connect to the DHIS2 instance using Dhis2r$new()
<- Dhis2r$new(base_url = "https://play.dhis2.org/",
dhis2_play_connection username = "admin",
password = "district",
api_version = "2.39.0.1",
api_version_position = "before")
$get_user_info()
dhis2_play_connection#> name email
#> "John Traore" "dummy@dhis2.org"
Get information about the account
$account_info
dhis2_play_connection#> created
#> "2013-04-18T17:15:08.407"
Get access rights information about the account
$access_rights
dhis2_play_connection#> manage externalize write read update delete
#> TRUE FALSE TRUE TRUE TRUE TRUE
Get all resources on which you can get metadata on.
$get_metadata()
dhis2_play_connection#> # A tibble: 87 × 4
#> displayName singular plural href
#> <chr> <chr> <chr> <chr>
#> 1 Analytics Table Hooks analyticsTableHook analy… http…
#> 2 Validation Notification Templates validationNotificationTemplate valid… http…
#> 3 Organisation Unit Levels organisationUnitLevel organ… http…
#> 4 Program Sections programSection progr… http…
#> 5 Relationship Types relationshipType relat… http…
#> 6 Program Stage Sections programStageSection progr… http…
#> 7 Message Conversations messageConversation messa… http…
#> 8 O Auth2 Clients oAuth2Client oAuth… http…
#> 9 Predictor Groups predictorGroup predi… http…
#> 10 Indicator Groups indicatorGroup indic… http…
#> # … with 77 more rows
Get metadata on Data Elements using the plural name
dataElements
.
$get_metadata(endpoint = "dataElements")
dhis2_play_connection#> # A tibble: 1,040 × 2
#> name id
#> <chr> <chr>
#> 1 Accute Flaccid Paralysis (Deaths < 5 yrs) FTRrcoaog83
#> 2 Acute Flaccid Paralysis (AFP) follow-up P3jJH5Tu5VC
#> 3 Acute Flaccid Paralysis (AFP) new FQ2o8UBlcrS
#> 4 Acute Flaccid Paralysis (AFP) referrals M62VHgYT2n0
#> 5 Additional medication WO8yRIZb7nb
#> 6 Additional notes related to facility uF1DLnZNlWe
#> 7 Admission Date eMyVanycQSC
#> 8 Age in years qrur9Dvnyt5
#> 9 Age of LLINs JuTpJ2Ywq5b
#> 10 Albendazole given at ANC (2nd trimester) hCVSHjcml9g
#> # … with 1,030 more rows
The code above only returns it’s name and code/ID used on DHIS2, we shall use the code to get analytics.
You can get more fields beyond ID and name
NOTE All resources have different fields
$get_metadata_fields(endpoint = "dataElements")
dhis2_play_connection#> [1] "access" "aggregationLevels" "aggregationType"
#> [4] "attributeValues" "categoryCombo" "code"
#> [7] "created" "createdBy" "dataElementGroups"
#> [10] "dataSetElements" "dimensionItem" "dimensionItemType"
#> [13] "displayFormName" "displayName" "displayShortName"
#> [16] "domainType" "externalAccess" "favorite"
#> [19] "favorites" "href" "id"
#> [22] "lastUpdated" "legendSets" "name"
#> [25] "optionSetValue" "publicAccess" "sharing"
#> [28] "shortName" "translations" "url"
#> [31] "user" "userAccesses" "userGroupAccesses"
#> [34] "valueType" "zeroIsSignificant"
$get_metadata_fields(endpoint = "organisationUnits")
dhis2_play_connection#> [1] "access" "ancestors" "attributeValues"
#> [4] "children" "code" "created"
#> [7] "dataSets" "dimensionItem" "dimensionItemType"
#> [10] "displayFormName" "displayName" "displayShortName"
#> [13] "externalAccess" "favorite" "favorites"
#> [16] "href" "id" "lastUpdated"
#> [19] "leaf" "legendSets" "level"
#> [22] "name" "openingDate" "organisationUnitGroups"
#> [25] "parent" "path" "programs"
#> [28] "sharing" "shortName" "translations"
#> [31] "userAccesses" "userGroupAccesses" "users"
$get_metadata_fields(endpoint = "indicators")
dhis2_play_connection#> [1] "access" "annualized"
#> [3] "attributeValues" "code"
#> [5] "created" "createdBy"
#> [7] "dataSets" "denominator"
#> [9] "denominatorDescription" "description"
#> [11] "dimensionItem" "dimensionItemType"
#> [13] "displayDenominatorDescription" "displayDescription"
#> [15] "displayFormName" "displayName"
#> [17] "displayNumeratorDescription" "displayShortName"
#> [19] "externalAccess" "favorite"
#> [21] "favorites" "href"
#> [23] "id" "indicatorGroups"
#> [25] "indicatorType" "lastUpdated"
#> [27] "legendSets" "name"
#> [29] "numerator" "numeratorDescription"
#> [31] "publicAccess" "sharing"
#> [33] "shortName" "translations"
#> [35] "url" "user"
#> [37] "userAccesses" "userGroupAccesses"
dataElements
$get_metadata(endpoint = "dataElements", fields = c("name","id","aggregationType"))
dhis2_play_connection#> # A tibble: 1,040 × 3
#> name aggregationType id
#> <chr> <chr> <chr>
#> 1 Accute Flaccid Paralysis (Deaths < 5 yrs) SUM FTRrcoaog83
#> 2 Acute Flaccid Paralysis (AFP) follow-up SUM P3jJH5Tu5VC
#> 3 Acute Flaccid Paralysis (AFP) new SUM FQ2o8UBlcrS
#> 4 Acute Flaccid Paralysis (AFP) referrals SUM M62VHgYT2n0
#> 5 Additional medication NONE WO8yRIZb7nb
#> 6 Additional notes related to facility SUM uF1DLnZNlWe
#> 7 Admission Date AVERAGE eMyVanycQSC
#> 8 Age in years AVERAGE qrur9Dvnyt5
#> 9 Age of LLINs SUM JuTpJ2Ywq5b
#> 10 Albendazole given at ANC (2nd trimester) SUM hCVSHjcml9g
#> # … with 1,030 more rows
organisationUnits
$get_metadata(endpoint = "organisationUnits",
dhis2_play_connectionfields = c("name","id", "level"))
#> # A tibble: 1,333 × 3
#> name id level
#> <chr> <chr> <int>
#> 1 Adonkia CHP Rp268JB6Ne4 4
#> 2 Afro Arab Clinic cDw53Ej8rju 4
#> 3 Agape CHP GvFqTavdpGE 4
#> 4 Ahamadyya Mission Cl plnHVbJR6p4 4
#> 5 Ahmadiyya Muslim Hospital BV4IomHvri4 4
#> 6 Air Port Centre, Lungi qjboFI0irVu 4
#> 7 Alkalia CHP dWOAzMcK2Wt 4
#> 8 Allen Town Health Post kbGqmM6ZWWV 4
#> 9 Approved School CHP eoYV2p74eVz 4
#> 10 Arab Clinic nq7F0t1Pz6t 4
#> # … with 1,323 more rows
You can use ":all"
in the fields to get all fields of
metadata associated with a resources
periodTypes
$get_metadata(endpoint = "periodTypes", fields = ":all")
dhis2_play_connection#> # A tibble: 18 × 4
#> name isoDuration isoFormat frequencyOrder
#> <chr> <chr> <chr> <int>
#> 1 Daily P1D yyyyMMdd 1
#> 2 Weekly P7D yyyyWn 7
#> 3 WeeklyWednesday P7D yyyyWedWn 7
#> 4 WeeklyThursday P7D yyyyThuWn 7
#> 5 WeeklySaturday P7D yyyySatWn 7
#> 6 WeeklySunday P7D yyyySunWn 7
#> 7 BiWeekly P14D yyyyBiWn 14
#> 8 Monthly P1M yyyyMM 30
#> 9 BiMonthly P2M yyyyMMB 61
#> 10 Quarterly P3M yyyyQn 91
#> 11 SixMonthly P6M yyyySn 182
#> 12 SixMonthlyApril P6M yyyyAprilSn 182
#> 13 SixMonthlyNov P6M yyyyNovSn 182
#> 14 Yearly P1Y yyyy 365
#> 15 FinancialApril P1Y yyyyApril 365
#> 16 FinancialJuly P1Y yyyyJuly 365
#> 17 FinancialOct P1Y yyyyOct 365
#> 18 FinancialNov P1Y yyyyNov 365
indicators
$get_metadata(endpoint = "indicators")
dhis2_play_connection#> # A tibble: 77 × 2
#> name id
#> <chr> <chr>
#> 1 ANC 1-3 Dropout Rate ReUHfIn0pTQ
#> 2 ANC 1 Coverage Uvn6LCg7dVU
#> 3 ANC 2 Coverage OdiHJayrsKo
#> 4 ANC 3 Coverage sB79w2hiLp8
#> 5 ANC => 4 Coverage AUqdhY4mpvp
#> 6 ANC IPT 1 Coverage dwEq7wi6nXV
#> 7 ANC IPT 2 Coverage c8fABiNpT0B
#> 8 ANC LLITN coverage Tt5TAvdfdVK
#> 9 ANC TT2 coverage puykO1tbcdi
#> 10 ANC visits per clinical professional Lzg9LtG1xg3
#> # … with 67 more rows
$get_analytics(analytic = "FTRrcoaog83", #Accute Flaccid Paralysis (Deaths < 5 yrs)
dhis2_play_connectionorg_unit = c("ImspTQPwCqd"), #Sierra Leone (National level)
period = "LAST_12_MONTHS",
output_scheme = "NAME")
#> # A tibble: 2 × 4
#> analytic org_unit period value
#> <fct> <fct> <chr> <dbl>
#> 1 Accute Flaccid Paralysis (Deaths < 5 yrs) Sierra Leone January 2023 23
#> 2 Accute Flaccid Paralysis (Deaths < 5 yrs) Sierra Leone February 2022 34