OpenFn pipeline: routes community NCD screening referrals from OpenMRS to E-Buzima health centers with WhatsApp notifications — Rwanda
# NCD Community Referral Pipeline
An OpenFn workflow that polls OpenMRS for community NCD screening encounters with high readings and automatically creates patient referrals in E-Buzima (ERPNext), with WhatsApp notifications to the health center and the patient.
**Districts covered:** Kamonyi · Rusizi · Nyamasheke · Karongi
---
## How it works
```
Every 15 minutes
↓
1. Fetch NCD encounters from OpenMRS (since last run)
↓
2. Check obs values against configured thresholds (Hypertension / Diabetes)
↓
3. Fetch full patient details + route to the right health center
↓
4. Create Patient + Appointment in the health center's E-Buzima tenant
↓
5. Send WhatsApp to health center staff + patient
```
---
## Repository layout
```
project.yaml OpenFn workflow definition
jobs/
1-fetch-encounters.js Poll OpenMRS for new NCD encounters
2-check-thresholds.js Filter by obs vs configured thresholds
3-enrich-patient.js Fetch patient demographics + routing
4-create-erpnext-patient.js Upsert Patient + Appointment in E-Buzima
5-send-whatsapp.js WhatsApp notifications (HC + patient)
seed/
ncd-screening-config.json Concept UUIDs + threshold values → load into OpenFn Collection
rw-facility-routing.json Location UUID → health center mapping → load into OpenFn Collection
```
---
## Setup
### 1. Configure credentials in OpenFn
Create three credentials in your OpenFn project:
| Name | Type | Fields |
|---|---|---|
| `OpenMRS` | HTTP | `baseUrl`, `username`, `password` |
| `EBuzima API` | HTTP | `api_key`, `api_secret` |
| `WhatsApp Meta API` | HTTP | `token` (Bearer), `phone_number_id` |
### 2. Load Collections
In the OpenFn UI, create two Collections and upload the seed files:
| Collection name | Seed file |
|---|---|
| `ncd-screening-config` | `seed/ncd-screening-config.json` |
| `rw-facility-routing` | `seed/rw-facility-routing.json` |
### 3. Replace placeholder values
In `seed/rw-facility-routing.json`, replac …