async function testDispense() { console.log("1. Logging in as jayam_web_ai..."); const tokenResponse = await fetch("http://localhost:8080/v1/auth/token", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ grant_type: "client_credentials", client_id: "jayam_web_ai", client_secret: "my_secret_key" }) }); const token = (await tokenResponse.json()).access_token; console.log("\n2. Running Precheck for a pregnant patient..."); const precheckResponse = await fetch("http://localhost:8080/v1/orders/ord_123/precheck", { method: "POST", headers: { "Authorization": `Bearer ${token}`, "X-Actor-Id": "usr_ph_1234", "Content-Type": "application/json" }, body: JSON.stringify({ clinical_context: { pregnancy: { status: "pregnant" } }, items: [ { product_id: "prd_4410", qty: 30 } // Losar 50 ] }) }); console.log("Precheck Results:", JSON.stringify(await precheckResponse.json(), null, 2)); console.log("\n3. Executing Dispense transaction (requesting 30 units of Losar 50)..."); const dispenseResponse = await fetch("http://localhost:8080/v1/orders/ord_123/dispense", { method: "POST", headers: { "Authorization": `Bearer ${token}`, "X-Actor-Id": "usr_ph_1234", "Idempotency-Key": "random-uuid-here-" + Date.now(), "Content-Type": "application/json" }, body: JSON.stringify({ subject_ref: "pat_123", items: [ { product_id: "prd_4410", qty: 30 } ] }) }); console.log("Dispense Status:", dispenseResponse.status); console.log("Dispense Results:", JSON.stringify(await dispenseResponse.json(), null, 2)); } testDispense();