feat: implement core dispensing, identity, and integration modules with authentication middleware

This commit is contained in:
2026-09-11 11:21:53 +05:30
parent a579da0f70
commit 22a03043ea
21 changed files with 869 additions and 688 deletions
+112 -63
View File
@@ -1,9 +1,11 @@
const fs = require('fs');
const API_KEY = "DUMUqJrNeyuaPDSZSsMf91qjgwc5K3N7";
const collection = {
info: {
name: "Pharmacy Core API",
description: "API collection for Pharmacy Core API",
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: [
@@ -16,6 +18,11 @@ const collection = {
key: "token",
value: "",
type: "string"
},
{
key: "apiKey",
value: API_KEY,
type: "string"
}
],
auth: {
@@ -31,26 +38,100 @@ const collection = {
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: [],
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: "{}",
raw: JSON.stringify(sample, null, 2),
options: {
raw: {
language: "json"
@@ -73,96 +154,65 @@ function createFolder(name, endpoints, prefix) {
const modules = [
{
name: "Auth / Identity",
name: "1. Auth & Identity",
prefix: "/v1/auth",
endpoints: [
{ method: "GET", path: "/me", name: "Get Current User" },
{ method: "PUT", path: "/me", name: "Update Current User" },
{ method: "POST", path: "/register", name: "Register" },
{ method: "POST", path: "/login", name: "Login" },
{ method: "POST", path: "/logout", name: "Logout" },
{ method: "POST", path: "/token", name: "Refresh Token" }
{ 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: "Catalogue",
name: "2. Catalogue",
prefix: "/v1",
endpoints: [
{ method: "GET", path: "/drugs", name: "Get Drugs" },
{ 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/:product_id/batches", name: "Get Product Batches" }
{ method: "GET", path: "/products/prd_4410/batches", name: "Get Product Batches" }
]
},
{
name: "Inventory",
name: "3. Inventory",
prefix: "/v1/inventory",
endpoints: [
{ method: "POST", path: "/grn", name: "Create GRN" },
{ 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/:batch_no", name: "Recall Batch" }
{ method: "GET", path: "/recall/B4421", name: "Recall Batch" }
]
},
{
name: "Dispensing (Orders)",
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: "/:id/invoice/pdf", name: "Get Invoice PDF" },
{ method: "POST", path: "/", name: "Create Order" },
{ method: "PATCH", path: "/:id/items", name: "Update Order Items" },
{ method: "POST", path: "/:id/precheck", name: "Precheck Order" },
{ method: "POST", path: "/:id/dispense", name: "Dispense Order" }
{ method: "GET", path: "/ord_001/invoice/pdf", name: "Get Invoice PDF" }
]
},
{
name: "Audit",
prefix: "/v1/audit",
endpoints: [
{ method: "GET", path: "/ai-calls", name: "Get AI Calls" },
{ method: "GET", path: "/overrides", name: "Get Overrides" },
{ method: "GET", path: "/h1-register", name: "Get H1 Register Audit" },
{ method: "GET", path: "/sales-register", name: "Get Sales Register" },
{ method: "GET", path: "/dashboard-metrics", name: "Get Dashboard Metrics" }
]
},
{
name: "Prescription",
prefix: "/v1/rx",
endpoints: [
{ method: "POST", path: "/", name: "Upload Prescription" },
{ method: "GET", path: "/", name: "Get Prescriptions" },
{ method: "GET", path: "/:id", name: "Get Prescription by ID" },
{ method: "POST", path: "/:id/confirm", name: "Confirm Prescription" }
]
},
{
name: "AI",
prefix: "/v1/ai",
endpoints: [
{ method: "POST", path: "/voice", name: "Voice AI" }
]
},
{
name: "Integration",
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: "POST", path: "/telegaruda/prescription", name: "Receive Telegaruda Rx" },
{ method: "GET", path: "/telegaruda/patient/:patientId", name: "Fetch Telegaruda Patient" },
{ method: "GET", path: "/hospital/prescriptions", name: "Get Hospital Prescriptions" }
{ method: "GET", path: "/hospital/prescriptions", name: "Get Hospital Prescriptions" },
{ method: "POST", path: "/telegaruda/prescription", name: "Receive Telegaruda Rx" }
]
},
{
name: "Upload",
prefix: "/v1/upload",
name: "6. Audit & Analytics",
prefix: "/v1/audit",
endpoints: [
{ method: "POST", path: "/", name: "Upload File" },
{ method: "GET", path: "/presigned", name: "Get Presigned URL" }
{ 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" }
]
}
];
@@ -171,6 +221,5 @@ modules.forEach(mod => {
collection.item.push(createFolder(mod.name, mod.endpoints, mod.prefix));
});
// Write to file
fs.writeFileSync('postman_collection.json', JSON.stringify(collection, null, 2));
console.log('Collection generated at postman_collection.json');
console.log('Collection successfully generated and saved to postman_collection.json');