Syncs health facility data from the Kenya Master Health Facility Registry (KMHFR) API to ArcGIS Enterprise Feature Layer for Garissa County. Automates fetching, transforming, and publishing ~284 facilities with geographic coordinates and detailed attributes.
# Garissa Health Facilities to ArcGIS Sync
A Node.js script that synchronizes health facility data from the Kenya Master Health Facility Registry (KMHFR) API to an ArcGIS Enterprise Feature Layer.
## Overview
This script automates the end-to-end process of fetching all health facilities in Garissa County from the KMHFR API and pushing them as features to an ArcGIS Enterprise Feature Layer. It intelligently handles pagination, concurrent requests, error recovery, and batch uploads.
## What the Script Does
**STEP 1 — Fetch Facility List from KMHFR**
- Retrieves all facilities for Garissa County from the KMHFR API
- Handles pagination automatically (30 records per page, ~284 total facilities)
**STEP 2 — Fetch Full Facility Details**
- For each facility ID, fetches complete detail records including:
- Geographic coordinates (lat/long)
- Facility type and operational status
- Number of beds/cots
- Services offered
- Contact information
- County, sub-county, ward, and constituency information
- Uses concurrency control to avoid API rate limiting (default: 5 concurrent requests)
- Automatically skips facilities without valid coordinates
**STEP 3 — Transform to ArcGIS Features**
- Converts each facility into an ArcGIS Feature with:
- Point geometry (lon, lat)
- Flat attribute table with all facility details
**STEP 4 — Authenticate with ArcGIS Enterprise**
- Obtains a short-lived token using provided credentials
**STEP 5 — Push Features to ArcGIS**
- Uploads features in batches of 100 (optimal ArcGIS batch size)
- Includes retry logic for failed uploads
## Installation
1. Clone or download this repository
2. Install dependencies:
```bash
npm install
```
## Dependencies
- **axios** (`^1.15.2`): HTTP client for making requests to the KMHFR API
- **dotenv** (`^17.4.2`): Loads environment variables from a `.env` file
- **node-fetch** (`^3.3.2`): Provides the Fetch API for posting to ArcGIS REST endpoints
## Configuration
Edit the `CONFIG` object at the top of `syn …