feat: add core backend modules, inventory services, and patch scripts for AI Pharmacy API

This commit is contained in:
2026-09-15 11:15:15 +05:30
parent 22a03043ea
commit 1f9378d96c
41 changed files with 1413 additions and 130 deletions
+36
View File
@@ -0,0 +1,36 @@
const { pool } = require('./src/db/pool');
async function test() {
const actorId = 'act_admin';
console.log("Checking for actorId:", actorId);
// Pharmacy Drugs (CatalogueService)
const query1 = `
SELECT p.brand_name,
(SELECT COALESCE(SUM(qty_on_hand), 0) FROM batches WHERE product_id = p.id AND expiry > CURRENT_DATE AND tenant_id = $1) as total_stock
FROM products p
JOIN drugs d ON p.drug_id = d.id
WHERE p.tenant_id = $1 OR EXISTS (SELECT 1 FROM batches WHERE product_id = p.id AND tenant_id = $1) OR p.tenant_id IS NULL
`;
const res1 = await pool.query(query1, [actorId]);
console.log("Pharmacy Drugs stock:");
console.log(res1.rows);
// Inventory (InventoryService)
const query2 = `
SELECT p.brand_name, SUM(b.qty_on_hand) as sum_stock
FROM batches b
JOIN products p ON b.product_id = p.id
WHERE b.qty_on_hand > 0
AND b.expiry <= CURRENT_DATE + 3650
AND b.tenant_id = $1
GROUP BY p.brand_name
`;
const res2 = await pool.query(query2, [actorId]);
console.log("Inventory Stock:");
console.log(res2.rows);
process.exit();
}
test();