A framework-agnostic PHP 8.2+ library for integrating with NHIF Tanzania's ServiceHub and OCS (Online Claims Submission) APIs.
# PHP NHIF Tanzania API Wrapper
A framework-agnostic PHP 8.2+ library for integrating with NHIF Tanzania's ServiceHub and OCS (Online Claims Submission) APIs.
## Features
- Full coverage of NHIF ServiceHub API (Verification, Admissions, Approvals, Referrals, etc.)
- Full coverage of NHIF OCS API (Claims, Packages, Facilities, Reference)
- OAuth2 client credentials authentication with automatic token refresh
- PSR-18 HTTP client compatible (Guzzle included by default)
- PSR-16 cache support for token caching
- Laravel and Symfony framework integrations
- Strongly typed DTOs for request/response handling
## Requirements
- PHP 8.2 or higher
- Guzzle HTTP client (or any PSR-18 compatible client)
## Installation
```bash
composer require keenops/php-nhiftz
```
## Quick Start
### Basic Usage
```php
use Keenops\PhpNhiftz\NhifClient;
use Keenops\PhpNhiftz\Config\Configuration;
use Keenops\PhpNhiftz\Config\Environment;
$config = new Configuration(
clientId: 'your_client_id',
clientSecret: 'your_client_secret',
facilityCode: 'FAC001',
environment: Environment::SANDBOX, // or Environment::PRODUCTION
);
$nhif = new NhifClient($config);
$nhif->setUsername('your_username');
// Verify a card
$response = $nhif->serviceHub()->verification()->getCardDetails('12345678');
if ($response->isSuccessful()) {
$cardDetails = $response->json();
// Process card details...
}
```
### Card Verification with Biometrics
```php
use Keenops\PhpNhiftz\DTOs\ServiceHub\VerifyCardModel;
$verification = new VerifyCardModel(
cardNo: '12345678',
verifierId: 'VER001',
cardTypeId: '1',
visitTypeId: 1,
biometricMethod: 'fingerprint',
fpCode: 'R1',
);
$response = $nhif->serviceHub()->verification()->verifyCard($verification);
```
### Patient Admission
```php
use Keenops\PhpNhiftz\DTOs\ServiceHub\PatientAdmissionModel;
$admission = new PatientAdmissionModel(
authorizationNo: 'AUTH123',
fullName: 'John Doe',
gender: 'M',
dateOfBirth: new DateTime('1990-01-15'),
admissionTypeId: 1,
wardTypeId: …