\n",
- "
Important: this step could have a huge influence on reporting rates!\n",
- " Activity can be evaluated over
1 year or
across all years, based on grouping:
group_by(OU_ID, YEAR):
\n",
- "
\n",
- " - With
YEAR → “active that year” \n",
- " - Without
YEAR → “ever active over the entire extracted period” \n",
- "
\n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "002e7fbf-1f68-4419-be2d-f16d8c72936d",
- "metadata": {
- "papermill": {
- "duration": 0.173961,
- "end_time": "2026-01-16T10:24:05.948136",
- "exception": false,
- "start_time": "2026-01-16T10:24:05.774175",
- "status": "completed"
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "papermill": {
+ "duration": 0.000107,
+ "end_time": "2026-01-16T10:24:01.626760",
+ "exception": false,
+ "start_time": "2026-01-16T10:24:01.626653",
+ "status": "completed"
+ },
+ "tags": []
+ },
+ "source": [
+ "#### 3.3. Identify `OPEN` facilities (denominator)\n",
+ "The \"OPEN\" variable indicates whether a facility is considered structurally open for a given reporting period.\n",
+ "\n",
+ "A facility is flagged as open (OPEN = 1) for a period if both of the following conditions are met:\n",
+ "1. No explicit closure in the facility name. The facility name does not contain closure keywords such as “CLOTUR”, “FERMÉ”, “FERMEE”, or similar.\n",
+ "\n",
+ "2. The period falls within the facility’s opening and closing dates. The opening date is not after the reporting period, and the closing date is not before or equal to the reporting period.\n",
+ "\n",
+ "If either of these conditions is not met, the facility is considered not open (OPEN = 0) for that period."
+ ],
+ "id": "89c3e5c8-4a4e-497d-9d75-2aed2e8fe619"
},
- "tags": [],
- "vscode": {
- "languageId": "r"
- }
- },
- "outputs": [],
- "source": [
- "# Flag facilities with at least one report in the year\n",
- "facility_master_routine_01 <- facility_master_routine %>%\n",
- " group_by(OU_ID, YEAR) %>%\n",
- " mutate(ACTIVE_THIS_YEAR = max(ACTIVE_THIS_PERIOD, na.rm = TRUE)) %>% # use max() to flag if ACTIVE_THIS_PERIOD is 1 at least once\n",
- " ungroup()"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "160c08ec-cc9a-4e1a-99ec-f703db83a71d",
- "metadata": {
- "papermill": {
- "duration": 9.8e-05,
- "end_time": "2026-01-16T10:24:05.948452",
- "exception": false,
- "start_time": "2026-01-16T10:24:05.948354",
- "status": "completed"
+ {
+ "cell_type": "code",
+ "metadata": {
+ "papermill": {
+ "duration": 1.317923,
+ "end_time": "2026-01-16T10:24:02.944800",
+ "exception": false,
+ "start_time": "2026-01-16T10:24:01.626877",
+ "status": "completed"
+ },
+ "tags": [],
+ "vscode": {
+ "languageId": "r"
+ }
+ },
+ "source": [
+ "# 3.3 Identify OPEN facilities from naming and opening/closing dates\n",
+ "facility_master_routine <- facility_master_routine %>%\n",
+ " dplyr::mutate(\n",
+ " period_date = as.Date(zoo::as.yearmon(as.character(PERIOD), \"%Y%m\")),\n",
+ " NAME_CLOSED = stringr::str_detect(toupper(OU_NAME), \"CLOTUR|FERM(E|EE)?\"),\n",
+ " OPEN_BY_DATE = !(is.na(OPENING_DATE) | as.Date(OPENING_DATE) > period_date |\n",
+ " (!is.na(CLOSED_DATE) & as.Date(CLOSED_DATE) <= period_date)),\n",
+ " OPEN = ifelse(!NAME_CLOSED & OPEN_BY_DATE, 1, 0)\n",
+ " )\n"
+ ],
+ "execution_count": null,
+ "outputs": [],
+ "id": "0b71f1d8-2048-4b62-865c-9acfe61b5b89"
},
- "tags": []
- },
- "source": [
- "#### 3.5. Compute Weighting factor based on \"volume of activity\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "4420e559-4134-4fc3-8950-9972ebede00e",
- "metadata": {
- "papermill": {
- "duration": 0.520673,
- "end_time": "2026-01-16T10:24:06.469233",
- "exception": false,
- "start_time": "2026-01-16T10:24:05.948560",
- "status": "completed"
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#### 3.4. Identify \"Active\" facilities for each YEAR (denominator)"
+ ],
+ "id": "657fd6ca"
},
- "tags": [],
- "vscode": {
- "languageId": "r"
- }
- },
- "outputs": [],
- "source": [
- "log_msg(glue(\"Computing volume of activity using indicator: {paste(VOLUME_ACTIVITY_INDICATORS, collapse=', ')}\"))\n",
- "\n",
- "# Compute MEAN_REPORTED_CASES_BY_HF as total cases over months with activity\n",
- "mean_monthly_cases <- dhis2_routine %>% \n",
- " mutate(total_cases_by_hf_month = rowSums(across(all_of(VOLUME_ACTIVITY_INDICATORS)), na.rm = TRUE)) %>%\n",
- " group_by(ADM2_ID, OU_ID) %>% \n",
- " summarise(\n",
- " total_cases_by_hf_year = sum(total_cases_by_hf_month, na.rm = TRUE),\n",
- " number_of_reporting_months = length(which(total_cases_by_hf_month > 0)),\n",
- " .groups = \"drop\"\n",
- " ) %>% \n",
- " mutate(MEAN_REPORTED_CASES_BY_HF = total_cases_by_hf_year / number_of_reporting_months) %>%\n",
- " select(ADM2_ID, OU_ID, MEAN_REPORTED_CASES_BY_HF)\n",
- "\n",
- "mean_monthly_cases_adm2 <- mean_monthly_cases %>% \n",
- " select(ADM2_ID, MEAN_REPORTED_CASES_BY_HF) %>% \n",
- " group_by(ADM2_ID) %>% \n",
- " summarise(SUMMED_MEAN_REPORTED_CASES_BY_ADM2 = sum(MEAN_REPORTED_CASES_BY_HF, na.rm=TRUE), \n",
- " NR_OF_HF = n())\n",
- "\n",
- "# Compute weights\n",
- "hf_weights <- mean_monthly_cases %>% \n",
- " left_join(mean_monthly_cases_adm2, by = \"ADM2_ID\") %>%\n",
- " mutate(WEIGHT = MEAN_REPORTED_CASES_BY_HF / SUMMED_MEAN_REPORTED_CASES_BY_ADM2 * NR_OF_HF)\n",
- "\n",
- "# Join with rest of data\n",
- "facility_master_routine_02 <- facility_master_routine_01 %>%\n",
- " left_join(hf_weights %>% select(OU_ID, WEIGHT), by = c(\"OU_ID\"))"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "2fed8529-70e9-4e2e-a498-fe3dd7499bb3",
- "metadata": {
- "papermill": {
- "duration": 0.000108,
- "end_time": "2026-01-16T10:24:06.469622",
- "exception": false,
- "start_time": "2026-01-16T10:24:06.469514",
- "status": "completed"
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "