๐Ÿฅ ADMA Laboratory Management System

API Documentation

Complete Developer Guide for Frontend Integration

๐Ÿ“‹ API Overview

Welcome to the ADMA Laboratory Management System API. This documentation provides comprehensive information for frontend developers to integrate with our lab management system.

Base URLs

Environment URL
Production https://labsapi.adma.pk/api
Development http://localhost:5000/api

Response Format

{
  "success": true,
  "data": { ... }
}

// Error Response
{
  "success": false,
  "message": "Error description"
}

๐Ÿ” Authentication

Most endpoints require JWT authentication. Include the token in the Authorization header.

POST /api/auth/login

Login to get authentication token

Request Example

// Login Request
fetch('/api/auth/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: "lab@example.com",
    password: "password123"
  })
})
.then(res => res.json())
.then(data => {
  const token = data.token;
  // Save token for future requests
});

Using the Token

// All authenticated requests
fetch('/api/test-orders', {
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  }
})

๐Ÿฅ Lab Management

GET /api/labs

Get all active labs

GET /api/labs/nearby?latitude=24.8607&longitude=67.0011&radius=10

Find nearby labs by location

GET /api/labs/:id

Get single lab details

Find Nearby Labs - Frontend Example

// Get user's location
navigator.geolocation.getCurrentPosition(async (position) => {
  const { latitude, longitude } = position.coords;
  
  const response = await fetch(
    `/api/labs/nearby?latitude=${latitude}&longitude=${longitude}&radius=10`
  );
  
  const { labs } = await response.json();
  // Display labs on map
});

๐Ÿงช Test Orders

Create and manage test orders for patients

POST /api/test-orders

Create new test order

GET /api/test-orders?status=pending

Get all test orders (with filters)

PUT /api/test-orders/:id/status

Update order status

Create Test Order - Frontend Example

async function createTestOrder(orderData) {
  const response = await fetch('/api/test-orders', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      patientName: "John Doe",
      patientPhone: "+92-300-1234567",
      patientCnic: "42101-1234567-8",
      labId: 1,
      testType: "blood_test",
      tests: ["CBC", "Blood Glucose"],
      preferredDate: "2026-02-20",
      preferredTime: "10:00 AM"
    })
  });
  
  return await response.json();
}

Order Status Values

Status Description
Pending Order created, waiting for lab confirmation
Confirmed Lab confirmed the order
Sample Collected Patient sample collected
Processing Tests are being performed
Completed Results ready
Cancelled Order cancelled

๐Ÿ“Š Test Results

POST /api/test-results

Create/Upload test results

GET /api/test-results/:orderId

Get test results for an order

GET /api/test-results/patient/:phone

Get all results for a patient

Get Patient Results - Frontend Example

// Fetch all results for a patient
async function getPatientResults(phoneNumber) {
  const response = await fetch(
    `/api/test-results/patient/${phoneNumber}`,
    {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    }
  );
  
  const { results } = await response.json();
  return results;
}

๐Ÿ”— Doctor Integration

Integration with ADMA Doctor Backend for seamless test ordering

POST /api/integration/create-test-order

Create test order from Doctor's prescription

POST /api/integration/verify-adma-card

Verify patient ADMA card

Doctor Order Flow

// Doctor sends test order from their system
const doctorOrder = {
  doctorId: "DOC001",
  doctorName: "Dr. Sarah Khan",
  hospitalName: "City Hospital",
  patient: {
    patientId: "P001",
    name: "John Doe",
    phone: "+92-300-1234567",
    admaCardNumber: "ADMA123456789"
  },
  labId: 1,
  testType: "blood_test",
  tests: ["CBC", "Liver Function Test"],
  priority: "urgent",
  notes: "Check liver function"
};

๐Ÿ”„ Complete Workflow

1

Patient Searches for Labs

Patient uses location-based search to find nearby labs

GET /api/labs/nearby?latitude=24.8607&longitude=67.0011
2

Verify ADMA Card (Optional)

Verify patient's ADMA card for coverage

POST /api/integration/verify-adma-card
3

Create Test Order

Patient or Doctor creates a test order

POST /api/test-orders
4

Lab Processes Order

Lab confirms, collects sample, runs tests

PUT /api/test-orders/:id/status
5

Upload Results

Lab uploads test results with report

POST /api/test-results
6

Patient Views Results

Patient retrieves results via order ID or phone number

GET /api/test-results/patient/:phone

โš ๏ธ Error Handling

Status Code Description
200 Success
201 Created
400 Bad Request - Invalid parameters
401 Unauthorized - Invalid or missing token
404 Not Found
500 Internal Server Error

Error Response Example

{
  "success": false,
  "message": "Invalid credentials"
}