226 lines
6.1 KiB
JavaScript
226 lines
6.1 KiB
JavaScript
const fs = require('fs');
|
|
|
|
const API_KEY = "DUMUqJrNeyuaPDSZSsMf91qjgwc5K3N7";
|
|
|
|
const collection = {
|
|
info: {
|
|
name: "AI Pharmacy Core API",
|
|
description: "Complete Postman testing collection for AI Pharmacy Core API with pre-configured headers, authentication, and sample payloads.",
|
|
schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
|
},
|
|
variable: [
|
|
{
|
|
key: "baseUrl",
|
|
value: "http://localhost:8080",
|
|
type: "string"
|
|
},
|
|
{
|
|
key: "token",
|
|
value: "",
|
|
type: "string"
|
|
},
|
|
{
|
|
key: "apiKey",
|
|
value: API_KEY,
|
|
type: "string"
|
|
}
|
|
],
|
|
auth: {
|
|
type: "bearer",
|
|
bearer: [
|
|
{
|
|
key: "token",
|
|
value: "{{token}}",
|
|
type: "string"
|
|
}
|
|
]
|
|
},
|
|
item: []
|
|
};
|
|
|
|
const sampleBodies = {
|
|
"/v1/auth/register": {
|
|
username: "pharmacist_jayam",
|
|
password: "Pharmacy@2026",
|
|
hospital_id: "hosp_001",
|
|
pharmacy_name: "Jayam Medicos & Pharmacy",
|
|
dl_number: "DL-TN-123456",
|
|
gstin: "33AAAAA0000A1Z5",
|
|
pharmacist_reg_number: "REG-TN-987654",
|
|
address: "123 Main Road, Anna Nagar, Chennai, Tamil Nadu - 600040"
|
|
},
|
|
"/v1/auth/login": {
|
|
username: "pharmacist_jayam",
|
|
password: "Pharmacy@2026"
|
|
},
|
|
"/v1/auth/token": {
|
|
grant_type: "client_credentials",
|
|
client_id: "pharmacy-v1-staging",
|
|
client_secret: "my_secret_key"
|
|
},
|
|
"/v1/drugs": {
|
|
id: "drg_101",
|
|
generic_name: "Amoxicillin and Potassium Clavulanate",
|
|
atc_code: "J01CR02",
|
|
schedule: "H1",
|
|
is_nti: false,
|
|
pregnancy_category: "B"
|
|
},
|
|
"/v1/inventory/grn": {
|
|
supplier_id: "sup_001",
|
|
product_id: "prd_4410",
|
|
batch_no: "BATCH-2026-01",
|
|
expiry: "2027-12-31",
|
|
qty_on_hand: 500,
|
|
purchase_price: 45.00
|
|
},
|
|
"/v1/orders": {
|
|
subject_ref: "patient_001",
|
|
prescription_id: "rx_001",
|
|
payment_method: "cash",
|
|
items: [
|
|
{
|
|
batch_no: "B4421",
|
|
qty: 10,
|
|
unit_price: 7.85
|
|
}
|
|
]
|
|
},
|
|
"/v1/integration/hospital/patient-sync": {
|
|
hospital_patient_id: "PAT-2026-8891",
|
|
full_name: "Ramesh Kumar",
|
|
contact_number: "9876543210",
|
|
email: "ramesh@example.com",
|
|
allergies: "Penicillin"
|
|
}
|
|
};
|
|
|
|
function createFolder(name, endpoints, prefix) {
|
|
const items = endpoints.map(ep => {
|
|
const method = ep.method.toUpperCase();
|
|
const fullPath = (prefix + ep.path).replace(/\/$/, "");
|
|
const urlParts = fullPath.split('/').filter(p => p !== '');
|
|
|
|
const headers = [
|
|
{
|
|
key: "x-api-key",
|
|
value: "{{apiKey}}",
|
|
type: "text"
|
|
}
|
|
];
|
|
|
|
if (['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
headers.push({
|
|
key: "Content-Type",
|
|
value: "application/json",
|
|
type: "text"
|
|
});
|
|
}
|
|
|
|
const request = {
|
|
method: method,
|
|
header: headers,
|
|
url: {
|
|
raw: `{{baseUrl}}${fullPath}`,
|
|
host: ["{{baseUrl}}"],
|
|
path: urlParts
|
|
}
|
|
};
|
|
|
|
if (['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
const sample = sampleBodies[fullPath] || sampleBodies[ep.path] || {};
|
|
request.body = {
|
|
mode: "raw",
|
|
raw: JSON.stringify(sample, null, 2),
|
|
options: {
|
|
raw: {
|
|
language: "json"
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
return {
|
|
name: ep.name || `${method} ${ep.path}`,
|
|
request: request
|
|
};
|
|
});
|
|
|
|
return {
|
|
name: name,
|
|
item: items
|
|
};
|
|
}
|
|
|
|
const modules = [
|
|
{
|
|
name: "1. Auth & Identity",
|
|
prefix: "/v1/auth",
|
|
endpoints: [
|
|
{ method: "POST", path: "/register", name: "Register Pharmacist" },
|
|
{ method: "POST", path: "/login", name: "Pharmacist Login" },
|
|
{ method: "POST", path: "/token", name: "Hospital M2M Auth Token" },
|
|
{ method: "GET", path: "/me", name: "Get Current Profile" },
|
|
{ method: "PUT", path: "/me", name: "Update Profile" },
|
|
{ method: "POST", path: "/logout", name: "Logout" }
|
|
]
|
|
},
|
|
{
|
|
name: "2. Catalogue",
|
|
prefix: "/v1",
|
|
endpoints: [
|
|
{ method: "GET", path: "/drugs", name: "Get All Drugs" },
|
|
{ method: "POST", path: "/drugs", name: "Create Drug" },
|
|
{ method: "GET", path: "/drugs/search", name: "Search Drugs" },
|
|
{ method: "GET", path: "/products/prd_4410/batches", name: "Get Product Batches" }
|
|
]
|
|
},
|
|
{
|
|
name: "3. Inventory",
|
|
prefix: "/v1/inventory",
|
|
endpoints: [
|
|
{ method: "POST", path: "/grn", name: "Create Goods Received Note (GRN)" },
|
|
{ method: "GET", path: "/expiring", name: "Get Expiring Stock" },
|
|
{ method: "GET", path: "/low-stock", name: "Get Low Stock" },
|
|
{ method: "POST", path: "/adjustments", name: "Stock Adjustment" },
|
|
{ method: "GET", path: "/recall/B4421", name: "Recall Batch" }
|
|
]
|
|
},
|
|
{
|
|
name: "4. Dispensing & Orders",
|
|
prefix: "/v1/orders",
|
|
endpoints: [
|
|
{ method: "POST", path: "/", name: "Create Dispensing Order" },
|
|
{ method: "GET", path: "/history", name: "Get Order History" },
|
|
{ method: "GET", path: "/h1-register", name: "Get H1 Register" },
|
|
{ method: "GET", path: "/ord_001/invoice/pdf", name: "Get Invoice PDF" }
|
|
]
|
|
},
|
|
{
|
|
name: "5. Integration (Hospital & Telegaruda)",
|
|
prefix: "/v1/integration",
|
|
endpoints: [
|
|
{ method: "POST", path: "/hospital/patient-sync", name: "Sync Hospital Patient" },
|
|
{ method: "GET", path: "/hospital/patients", name: "Get Hospital Patients" },
|
|
{ method: "GET", path: "/hospital/prescriptions", name: "Get Hospital Prescriptions" },
|
|
{ method: "POST", path: "/telegaruda/prescription", name: "Receive Telegaruda Rx" }
|
|
]
|
|
},
|
|
{
|
|
name: "6. Audit & Analytics",
|
|
prefix: "/v1/audit",
|
|
endpoints: [
|
|
{ method: "GET", path: "/dashboard-metrics", name: "Get Dashboard Metrics" },
|
|
{ method: "GET", path: "/ai-calls", name: "Get AI Calls Log" },
|
|
{ method: "GET", path: "/overrides", name: "Get Safety Overrides Log" }
|
|
]
|
|
}
|
|
];
|
|
|
|
modules.forEach(mod => {
|
|
collection.item.push(createFolder(mod.name, mod.endpoints, mod.prefix));
|
|
});
|
|
|
|
fs.writeFileSync('postman_collection.json', JSON.stringify(collection, null, 2));
|
|
console.log('Collection successfully generated and saved to postman_collection.json');
|