Skip to contents

get_analytics_formatted() fetches data from the KHIS analytics data tables for a given period and data element(s), without performing any aggregation.

Usage

get_analytics_formatted(
  element_ids,
  start_date,
  end_date = NULL,
  level = c("country", "county", "subcounty", "ward", "facility"),
  organisations = NULL,
  ...
)

Arguments

element_ids

A vector of data element IDs for which to retrieve data. Required.

start_date

The start date to retrieve data. It is required and in the format YYYY-MM-dd.

end_date

The ending date for data retrieval (default is the current date).

level

The desired data granularity: "country" (the default), "county", "subcounty", "ward", or "facility".

organisations

A list of organization units ids to be filtered.

...

Other options that can be passed onto KHIS API.

Value

A tibble with detailed information, including:

  • Geographical identifiers (country, county, subcounty, ward, facility, depending on level)

  • Reporting period (month, year, fiscal year)

  • Data element names

  • Category options

  • Reported values

Details

  • Retrieves data directly from KHIS analytics tables.

  • Supports optional arguments for providing organization lists, data elements, and categories.

  • Allows specifying KHIS session objects, retry attempts, and logging verbosity.

Examples

# Clinical Breast Examination data elements
# XEX93uLsAm2 = CBE Abnormal
# cXe64Yk0QMY = CBE Normal
element_id = c('cXe64Yk0QMY', 'XEX93uLsAm2')

# Download data from February 2023 to current date
data <- get_analytics_formatted(element_ids = element_id,
                                start_date = '2023-02-01')
data
#> # A tibble: 159 × 9
#>    value country element     category period     month  year quarter fiscal_year
#>    <dbl> <chr>   <chr>       <chr>    <date>     <ord> <dbl> <fct>   <fct>      
#>  1   137 Kenya   CBE-Abnorm… 35-39 y… 2023-06-01 June   2023 Q4      2022/2023  
#>  2    18 Kenya   CBE-Abnorm… 56-74 y… 2024-04-01 April  2024 Q4      2023/2024  
#>  3   156 Kenya   CBE-Abnorm… 35-39 y… 2023-05-01 May    2023 Q4      2022/2023  
#>  4    28 Kenya   CBE-Abnorm… 56-74 y… 2024-05-01 May    2024 Q4      2023/2024  
#>  5    24 Kenya   CBE-Abnorm… 56-74 y… 2024-03-01 March  2024 Q3      2023/2024  
#>  6   150 Kenya   CBE-Abnorm… 35-39 y… 2023-07-01 July   2023 Q1      2023/2024  
#>  7   100 Kenya   CBE-Abnorm… 35-39 y… 2023-08-01 Augu…  2023 Q1      2023/2024  
#>  8   119 Kenya   CBE-Abnorm… 35-39 y… 2023-04-01 April  2023 Q4      2022/2023  
#>  9   116 Kenya   CBE-Abnorm… 35-39 y… 2023-02-01 Febr…  2023 Q3      2022/2023  
#> 10 11401 Kenya   CBE-Normal  35-39 y… 2023-12-01 Dece…  2023 Q2      2023/2024  
#> # ℹ 149 more rows