TypeScript client for NHIF Tanzania member verification, NIDA lookup, and authorization number flow for HMIS and clinic systems.
# NHIF Tanzania API Client
TypeScript client for NHIF Tanzania member verification, NIDA lookup, and authorization number flow for HMIS and clinic systems.
This repo is for connecting an HMIS, clinic system, or hospital app to the current NHIF Tanzania verification flow.
It handles the parts most systems need every day: login to NHIF, checking a member by NIDA or NHIF card number, resolving the real card number, and getting the visit authorization number.
The authorization number is important because it is the approval/reference NHIF gives for that patient visit. In a clinic workflow it should move with the patient through reception, doctor, lab, pharmacy, cashier, and claims. Without it, the visit can be hard to claim, audit, or prove later.
## What it uses
- TypeScript
- Node.js 18+ fetch
- No runtime dependencies
- Works well in Next.js API routes, server actions, Express, or any Node backend
## Why this exists
Some older NHIF examples use old token and verification endpoints. The current Service Portal flow uses:
- `externalouth/connect/token` for login
- `AuthorizationService/api/Verification/GetCardDetailsExt` for member lookup
- `AuthorizationService/api/Verification/AuthorizeCard` for the authorization number
This package keeps that flow in one clean place so your main app code stays simple.
## Install
From npm, once published:
```bash
npm install nhif-tanzania-api-client
```
From GitHub:
```bash
npm install github:your-name/nhif-tanzania-api-client
```
## Environment
Create a `.env` file in your app. Do not commit it.
```env
NHIF_USERNAME=
NHIF_PASSWORD=
NHIF_MODE=production
NHIF_TOKEN_URL=
verification.nhif.or.tz
NHIF_AUTHORIZATION_BASE_URL=
verification.nhif.or.tz
NHIF_CLIENT_ID=
NHIF_CLIENT_SECRET=
NHIF_SCOPE=MedicalService
NHIF_VISIT_TYPE_ID=1
NHIF_ENFORCE_ONLINE_FORM=true
NHIF_METHOD_USED=Online
NHIF_BIOMETRIC_METHOD=None
NHIF_NARRATION=undefined
```
Only put real usern …