Skip to main content

JavaScript SDK

Official JavaScript/Node.js SDK for Najeeb Health Suite API.

Installation

npm install @najeeb/health-suite-sdk

or

yarn add @najeeb/health-suite-sdk

Quick Start

import { NajeebClient } from '@najeeb/health-suite-sdk';

const client = new NajeebClient({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
});

// List patients
const patients = await client.patients.list();

// Create a patient
const patient = await client.patients.create({
national_id: '1234567890',
first_name: 'أحمد',
last_name: 'محمد',
date_of_birth: '1990-01-15',
gender: 'male',
insurance_number: 'INS-12345',
insurance_company: 'Insurance Co.',
policy_start_date: '2024-01-01',
address: {
street: '123 Main St',
city: 'Riyadh',
region: 'Riyadh',
},
});

Configuration

const client = new NajeebClient({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
baseUrl: 'https://api.najeeb.com/v1', // Optional, defaults to production
timeout: 30000, // Optional, request timeout in ms
});

API Methods

Patients

// List patients
const patients = await client.patients.list({
page: 1,
per_page: 20,
search: 'أحمد',
});

// Get patient
const patient = await client.patients.get('pat_123456');

// Create patient
const newPatient = await client.patients.create({
national_id: '1234567890',
first_name: 'أحمد',
// ... other fields
});

// Update patient
const updated = await client.patients.update('pat_123456', {
phone: '+966501234567',
});

// Delete patient
await client.patients.delete('pat_123456');

Claims

// List claims
const claims = await client.claims.list({
status: 'approved',
patient_id: 'pat_123456',
});

// Get claim
const claim = await client.claims.get('claim_123456');

// Submit claim
const newClaim = await client.claims.create({
patient_id: 'pat_123456',
provider_id: 'prov_789012',
service_date: '2024-01-15',
services: [
{
code: 'CPT-99213',
description: 'Office visit',
quantity: 1,
unit_price: 250.00,
},
],
diagnosis_codes: ['E11.9'],
});

// Update claim status
await client.claims.updateStatus('claim_123456', {
status: 'approved',
notes: 'Approved after review',
});

Providers

// List providers
const providers = await client.providers.list({
type: 'hospital',
city: 'Riyadh',
});

// Get provider
const provider = await client.providers.get('prov_123456');

// Check availability
const availability = await client.providers.getAvailability('prov_123456', {
date: '2024-01-20',
});

Authorizations

// List authorizations
const authorizations = await client.authorizations.list({
status: 'pending',
});

// Get authorization
const auth = await client.authorizations.get('auth_123456');

// Request authorization
const newAuth = await client.authorizations.create({
patient_id: 'pat_123456',
provider_id: 'prov_789012',
service_date: '2024-01-20',
services: [
{
code: 'CPT-27447',
description: 'Total knee arthroplasty',
quantity: 1,
estimated_cost: 50000.00,
},
],
diagnosis_codes: ['M17.11'],
urgency: 'routine',
});

// Approve authorization
await client.authorizations.approve('auth_123456', {
notes: 'Approved after review',
});

// Reject authorization
await client.authorizations.reject('auth_123456', {
notes: 'Not medically necessary',
});

Error Handling

try {
const patient = await client.patients.get('pat_123456');
} catch (error) {
if (error.code === 'NOT_FOUND') {
console.log('Patient not found');
} else if (error.code === 'UNAUTHORIZED') {
console.log('Authentication failed');
} else {
console.error('Error:', error.message);
}
}

Pagination

// Get all patients (auto-pagination)
const allPatients = await client.patients.listAll();

// Manual pagination
let page = 1;
let hasMore = true;

while (hasMore) {
const response = await client.patients.list({ page, per_page: 100 });
// Process response.data
hasMore = response.meta.page < response.meta.total_pages;
page++;
}

Webhooks

import { verifyWebhookSignature } from '@najeeb/health-suite-sdk';

app.post('/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['x-najeeb-signature'];
const secret = process.env.WEBHOOK_SECRET;

if (!verifyWebhookSignature(req.body, signature, secret)) {
return res.status(401).send('Invalid signature');
}

const event = JSON.parse(req.body);

switch (event.event_type) {
case 'claim.status_changed':
handleClaimStatusChanged(event.data.object);
break;
// ... other event types
}

res.status(200).send('OK');
});

TypeScript Support

The SDK includes full TypeScript definitions:

import { NajeebClient, Patient, Claim } from '@najeeb/health-suite-sdk';

const client = new NajeebClient({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
});

const patient: Patient = await client.patients.get('pat_123456');

Next Steps