{
  "ursId": "URS-016",
  "title": "Auto-decrement Inventory After Order Submission",
  "timestamp": "2026-09-29T02:24:46.612Z",
  "durationMs": 193941,
  "config": {
    "inboxUrl": "http://localhost:36065",
    "dbHost": "localhost",
    "dbPort": 41649,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Initial inventory",
      "status": "pass",
      "description": "Step 1: Initial inventory",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-01-logged-in.png",
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-01-initial-inventory.png"
      ],
      "explanation": "Logs in as a sales rep (Blair Bennett) and navigates to TRUNK-36 to record the starting quantities for NovaPatch and LiraLock. This establishes the known baseline so subsequent steps can prove the correct delta was applied after each order.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-09-29T02:25:19.685Z",
      "finishedAt": "2026-09-29T02:25:24.406Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/videos/step-01-initial-inventory.webm"
    },
    {
      "name": "Step 2: First order",
      "status": "pass",
      "description": "Step 2: First order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-02-account-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-02-devices-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-02-documents.png",
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-02-review.png",
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-02-order-submitted.png"
      ],
      "explanation": "Creates and submits a bill-only order for 3 NovaPatch and 2 LiraLock devices from trunk inventory. This exercises the full order-submission flow that should trigger an automatic inventory decrement in the database.",
      "expectedEmailTemplates": [
        "New Bill-Only Order"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.inventory_items_decrement"
      ],
      "startedAt": "2026-09-29T02:25:39.810Z",
      "finishedAt": "2026-09-29T02:26:40.688Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/videos/step-02-first-order.webm"
    },
    {
      "name": "Step 3: Verify first decrement",
      "status": "pass",
      "description": "Step 3: Verify first decrement",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-03-inventory-after-first-order.png"
      ],
      "explanation": "Navigates to TRUNK-36 immediately after the first order and confirms that NovaPatch and LiraLock quantities have each decreased by the ordered amount. This proves the inventory auto-decrement fires on order submission.",
      "startedAt": "2026-09-29T02:26:47.052Z",
      "finishedAt": "2026-09-29T02:26:47.052Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/videos/step-03-verify-decrement.webm"
    },
    {
      "name": "Step 4: Second order",
      "status": "pass",
      "description": "Step 4: Second order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-04-second-order-submitted.png",
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-04-inventory-after-second-order.png"
      ],
      "explanation": "Submits a second bill-only order and then re-checks the inventory to verify that quantities reflect both orders cumulatively. This proves the decrement is applied consistently across multiple successive submissions.",
      "expectedEmailTemplates": [
        "New Bill-Only Order"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.inventory_items_decrement"
      ],
      "startedAt": "2026-09-29T02:27:20.422Z",
      "finishedAt": "2026-09-29T02:27:23.052Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/videos/step-04-second-order.webm"
    },
    {
      "name": "Step 5: Shortage edge case",
      "status": "pass",
      "description": "Step 5: Shortage edge case",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-05-shortage-warning.png",
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-05-review-with-shortage.png",
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-05-shortage-result.png",
        "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/step-05-final-inventory.png"
      ],
      "explanation": "Orders more NovaPatch units than are available in trunk stock. The system permits submission in best-effort mode and consumes all remaining units, bringing the count to zero. This proves the system handles inventory shortages without blocking the order while still tracking the discrepancy.",
      "expectedEmailTemplates": [
        "New Bill-Only Order"
      ],
      "startedAt": "2026-09-29T02:27:47.145Z",
      "finishedAt": "2026-09-29T02:27:57.031Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/videos/step-05-shortage-edge-case.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Inventory items exist at trunk",
      "query": "SELECT ii.id, ii.di, ii.lot, ii.quantity_ready, ii.quantity_backordered, ii.quantity_in_transit\n      FROM inventory_items ii\n      WHERE ii.real_world_location_id = $1\n        AND ii.lot IN ($2, $3)\n      ORDER BY ii.lot",
      "status": "pass",
      "rows": [
        {
          "id": "349f34d2-a717-4429-9fa1-fd4762591b7a",
          "di": "07649988202247",
          "lot": "URS016-FL-001",
          "quantity_ready": 12,
          "quantity_backordered": 0,
          "quantity_in_transit": 0
        },
        {
          "id": "4f8551d2-ec58-4abf-b6df-b50b8d725a06",
          "di": "07649988202230",
          "lot": "URS016-SP-001",
          "quantity_ready": 0,
          "quantity_backordered": 0,
          "quantity_in_transit": 0
        }
      ],
      "assertion": "Both test inventory items (NovaPatch and LiraLock) should exist at TRUNK-36"
    },
    {
      "name": "Inventory quantities decremented",
      "query": "SELECT ii.lot, ii.quantity_ready,\n        CASE\n          WHEN ii.lot = $2 THEN 20\n          WHEN ii.lot = $3 THEN 15\n        END as initial_quantity,\n        CASE\n          WHEN ii.lot = $2 THEN 20 - ii.quantity_ready\n          WHEN ii.lot = $3 THEN 15 - ii.quantity_ready\n        END as total_decremented\n      FROM inventory_items ii\n      WHERE ii.real_world_location_id = $1\n        AND ii.lot IN ($2, $3)\n      ORDER BY ii.lot",
      "status": "pass",
      "rows": [
        {
          "lot": "URS016-FL-001",
          "quantity_ready": 12,
          "initial_quantity": 15,
          "total_decremented": 3
        },
        {
          "lot": "URS016-SP-001",
          "quantity_ready": 0,
          "initial_quantity": 20,
          "total_decremented": 20
        }
      ],
      "assertion": "Both inventory items should have quantity_ready less than their initial values"
    },
    {
      "name": "Recent billing orders created",
      "query": "SELECT bo.id, bo.order_number, bo.status, bo.procedure_date,\n        bo.created_at, bo.created_by_user_id\n      FROM billing_orders bo\n      WHERE bo.created_by_user_id = $1\n        AND bo.created_at > NOW() - INTERVAL '30 minutes'\n      ORDER BY bo.created_at DESC\n      LIMIT 5",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "order_number": "BO-3",
          "status": "submitted",
          "procedure_date": "2026-09-29T00:00:00.000Z",
          "created_at": "2026-09-29T02:27:51.885Z",
          "created_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456"
        },
        {
          "id": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
          "order_number": "BO-2",
          "status": "submitted",
          "procedure_date": "2026-09-29T00:00:00.000Z",
          "created_at": "2026-09-29T02:27:18.004Z",
          "created_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456"
        },
        {
          "id": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
          "order_number": "BO-1",
          "status": "submitted",
          "procedure_date": "2026-09-29T00:00:00.000Z",
          "created_at": "2026-09-29T02:26:37.635Z",
          "created_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456"
        }
      ],
      "assertion": "At least one billing order should have been created by Blair Bennett in the last 30 minutes"
    },
    {
      "name": "Billing order items reference correct products",
      "query": "SELECT boi.id, boi.billing_order_id, op.title as product_name,\n        boi.lot_number, boi.serial_number, boi.location_id,\n        boi.inventory_discrepancy\n      FROM billing_order_items boi\n      JOIN org_products op ON boi.product_id = op.id\n      JOIN billing_orders bo ON boi.billing_order_id = bo.id\n      WHERE bo.created_by_user_id = $1\n        AND bo.created_at > NOW() - INTERVAL '30 minutes'\n      ORDER BY bo.created_at DESC, op.title",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eafd-6bf0-7c93-92b8-6003ff7cea06",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": true
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-600bc12ec781",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-600c929a63e9",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-600dd7ddb0b5",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-600ec9a598dd",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-600f779ac300",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-6010bf50e1ff",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-601125a798da",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-6012c405f007",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-5fff1d8217b6",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": true
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-6000a91854d3",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": true
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-600125bfe73d",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": true
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-600217913008",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": true
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-60040f8e3ef2",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-6005d2368e4d",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-6006f52e284c",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-6007296f35d6",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-60080c7cdad6",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-600958151dfa",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafd-6bf0-7c93-92b8-600a4f15770c",
          "billing_order_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafc-e79b-7e67-ae30-bab8884dbea5",
          "billing_order_id": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
          "product_name": "LiraLock® Instrument SN",
          "lot_number": "URS016-FL-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafc-e79c-7641-8b24-c61c79a06b8a",
          "billing_order_id": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafc-e79c-7641-8b24-c61bb33179cf",
          "billing_order_id": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafc-4a80-78c6-bfbe-db79a662c6e7",
          "billing_order_id": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
          "product_name": "LiraLock® Instrument SN",
          "lot_number": "URS016-FL-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafc-4a80-78c6-bfbe-db7a0909a1af",
          "billing_order_id": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
          "product_name": "LiraLock® Instrument SN",
          "lot_number": "URS016-FL-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafc-4a80-78c6-bfbe-db7cde6799cf",
          "billing_order_id": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafc-4a80-78c6-bfbe-db7b346fe7d0",
          "billing_order_id": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        },
        {
          "id": "01a0eafc-4a80-78c6-bfbe-db7d12d256d2",
          "billing_order_id": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
          "product_name": "NovaPatch® PET",
          "lot_number": "URS016-SP-001",
          "serial_number": null,
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "inventory_discrepancy": false
        }
      ],
      "assertion": "Billing order items should reference NovaPatch and/or LiraLock products"
    },
    {
      "name": "Inventory history records bill_only_order removals",
      "query": "SELECT ih.id, ih.item_id, ih.quantity, ih.status, ih.info,\n        ih.created_at, ih.inventory_id\n      FROM inventory_history ih\n      WHERE ih.item_id IN (\n        SELECT id FROM inventory_items\n        WHERE real_world_location_id = $1\n          AND lot IN ($2, $3)\n      )\n      AND ih.created_at > NOW() - INTERVAL '30 minutes'\n      AND ih.info->>'action' = 'removed'\n      AND ih.info->>'reason' = 'bill_only_order'\n      ORDER BY ih.created_at DESC\n      LIMIT 20",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eafd-6c0b-7f6c-b64b-4d1943751c04",
          "item_id": "4f8551d2-ec58-4abf-b6df-b50b8d725a06",
          "quantity": 15,
          "status": "ready",
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
            "shortageQuantity": 0,
            "requestedQuantity": 15
          },
          "created_at": "2026-09-29T02:27:51.885Z",
          "inventory_id": "fa000001-0000-4000-8000-000000000001"
        },
        {
          "id": "01a0eafd-6c0b-7f6c-b64b-4d1ae89ee166",
          "item_id": "4f8551d2-ec58-4abf-b6df-b50b8d725a06",
          "quantity": 5,
          "status": "ready",
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
            "shortageQuantity": 5,
            "requestedQuantity": 20
          },
          "created_at": "2026-09-29T02:27:51.885Z",
          "inventory_id": "fa000001-0000-4000-8000-000000000001"
        },
        {
          "id": "01a0eafc-e7b0-74f6-b3ef-9fbf886fed15",
          "item_id": "349f34d2-a717-4429-9fa1-fd4762591b7a",
          "quantity": 1,
          "status": "ready",
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
            "shortageQuantity": 0,
            "requestedQuantity": 1
          },
          "created_at": "2026-09-29T02:27:18.004Z",
          "inventory_id": "fa000001-0000-4000-8000-000000000001"
        },
        {
          "id": "01a0eafc-e7b0-74f6-b3ef-9fc0d26f4dd6",
          "item_id": "4f8551d2-ec58-4abf-b6df-b50b8d725a06",
          "quantity": 2,
          "status": "ready",
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
            "shortageQuantity": 0,
            "requestedQuantity": 2
          },
          "created_at": "2026-09-29T02:27:18.004Z",
          "inventory_id": "fa000001-0000-4000-8000-000000000001"
        },
        {
          "id": "01a0eafc-4b08-74c7-9836-20aa5ae0667f",
          "item_id": "349f34d2-a717-4429-9fa1-fd4762591b7a",
          "quantity": 2,
          "status": "ready",
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
            "shortageQuantity": 0,
            "requestedQuantity": 2
          },
          "created_at": "2026-09-29T02:26:37.635Z",
          "inventory_id": "fa000001-0000-4000-8000-000000000001"
        },
        {
          "id": "01a0eafc-4b08-74c7-9836-20ab75e07aa7",
          "item_id": "4f8551d2-ec58-4abf-b6df-b50b8d725a06",
          "quantity": 3,
          "status": "ready",
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
            "shortageQuantity": 0,
            "requestedQuantity": 3
          },
          "created_at": "2026-09-29T02:26:37.635Z",
          "inventory_id": "fa000001-0000-4000-8000-000000000001"
        }
      ],
      "assertion": "Inventory history should contain records with action=removed and reason=bill_only_order"
    },
    {
      "name": "Inventory transactions created",
      "query": "SELECT it.id, it.source_type, it.source_id, it.created_at,\n        it.distributor_organization_id, it.manufacturer_organization_id\n      FROM inventory_transactions it\n      WHERE it.source_type = 'bill_only_order'\n        AND it.created_at > NOW() - INTERVAL '30 minutes'\n        AND (it.distributor_organization_id = $1 OR it.manufacturer_organization_id = $1)\n      ORDER BY it.created_at DESC\n      LIMIT 10",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eafd-6c07-72cb-acbe-55e5f0bd758a",
          "source_type": "bill_only_order",
          "source_id": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
          "created_at": "2026-09-29T02:27:51.885Z",
          "distributor_organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "manufacturer_organization_id": null
        },
        {
          "id": "01a0eafc-e7ac-75cb-ad8b-c0e37c52ce38",
          "source_type": "bill_only_order",
          "source_id": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
          "created_at": "2026-09-29T02:27:18.004Z",
          "distributor_organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "manufacturer_organization_id": null
        },
        {
          "id": "01a0eafc-4ac2-751e-a62e-b930ac680819",
          "source_type": "bill_only_order",
          "source_id": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
          "created_at": "2026-09-29T02:26:37.635Z",
          "distributor_organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "manufacturer_organization_id": null
        }
      ],
      "assertion": "Inventory transactions should exist with source_type = bill_only_order"
    },
    {
      "name": "No negative inventory quantities",
      "query": "SELECT ii.id, ii.lot, ii.quantity_ready\n      FROM inventory_items ii\n      WHERE ii.real_world_location_id = $1\n        AND ii.lot IN ($2, $3)\n        AND ii.quantity_ready < 0",
      "status": "pass",
      "rows": [],
      "assertion": "Inventory quantities should never go below zero (CHECK constraint enforced)"
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z",
  "auditStartTime": "2026-09-29T02:24:45.485Z",
  "emailEvidence": [
    {
      "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-1",
      "template": "New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-1",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/emails/2026-09-29T02-26-40-372Z-New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-1.png"
    },
    {
      "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-2",
      "template": "New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-2",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/emails/2026-09-29T02-27-19-489Z-New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-2.png"
    },
    {
      "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-3",
      "template": "New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-3",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-016-inventory-decrement/2026-09-29T02-24-46-611Z/screenshots/emails/2026-09-29T02-27-52-579Z-New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-3.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-09-29T02:25:17.501Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:25:29.261Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:25:41.528Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "surgery",
        "reason": "no_same_day_candidates",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 0,
        "flaggedCount": 0,
        "candidateCount": 0,
        "matchedSignals": {
          "patientId": false,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "review",
        "reason": "no_same_day_candidates",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 0,
        "flaggedCount": 0,
        "candidateCount": 0,
        "matchedSignals": {
          "patientId": false,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "decision",
      "action": "bill_only.link_purchase_order",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_purchase_order_selected",
        "performed": false,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "billing_order",
      "action": "status_change",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-4ba5-7d93-837c-0c79ad1fe38d",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-06T02:26:38.112Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-4bb3-74ec-b974-a151c24142b8",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-13T02:26:38.112Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "decision",
      "action": "bill_only_order.inventory_items_decrement",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
      "secondaryObjectId": null,
      "payload": {
        "reason": "inventory_items_decremented",
        "itemCount": 5,
        "performed": true,
        "entityType": "billing_order",
        "hasCaseToteItems": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "decision",
      "action": "bill_only_order.direct_po_import_on_create",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
      "secondaryObjectId": null,
      "payload": {
        "reason": "No uploaded PO documents",
        "performed": false,
        "entityType": "billing_order",
        "fileSourceOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "hasSelectedPurchaseOrderId": false,
        "purchaseOrderDocumentCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "decision",
      "action": "basicErp.deriveSalesOrder",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:37.635Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-4bb7-78e5-9a71-afb603d670cb",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-20T02:26:38.112Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:39.908Z",
      "eventType": "decision",
      "action": "bill_only.notifications.cc_incident_recipients",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
      "secondaryObjectId": null,
      "payload": {
        "reason": "order has no no-charge item with an incident reason",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:40.464Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafc-4aa0-7a25-96a2-7afa2738f1db",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eafc-5494-7e0a-9fb0-280ae1adb831/",
        "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-1",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:44.156Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:26:49.975Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:27:02.863Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "surgery",
        "reason": "acknowledged_not_duplicate",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 0,
        "flaggedCount": 1,
        "candidateCount": 1,
        "matchedSignals": {
          "patientId": true,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "decision",
      "action": "basicErp.deriveSalesOrder",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "review",
        "reason": "acknowledged_not_duplicate",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 0,
        "flaggedCount": 1,
        "candidateCount": 1,
        "matchedSignals": {
          "patientId": true,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "decision",
      "action": "bill_only.link_purchase_order",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_purchase_order_selected",
        "performed": false,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "decision",
      "action": "bill_only_order.inventory_items_decrement",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
      "secondaryObjectId": null,
      "payload": {
        "reason": "inventory_items_decremented",
        "itemCount": 3,
        "performed": true,
        "entityType": "billing_order",
        "hasCaseToteItems": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "decision",
      "action": "bill_only_order.direct_po_import_on_create",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
      "secondaryObjectId": null,
      "payload": {
        "reason": "No uploaded PO documents",
        "performed": false,
        "entityType": "billing_order",
        "fileSourceOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "hasSelectedPurchaseOrderId": false,
        "purchaseOrderDocumentCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "billing_order",
      "action": "status_change",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e7bb-7233-8b50-6095b6081e53",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-06T02:27:18.074Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e7bf-7ebb-a7a8-cf808f53ca0a",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-13T02:27:18.074Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.004Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e7c2-7280-9769-79cfa1b187fb",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-20T02:27:18.074Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:19.004Z",
      "eventType": "decision",
      "action": "bill_only.notifications.cc_incident_recipients",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
      "secondaryObjectId": null,
      "payload": {
        "reason": "order has no no-charge item with an incident reason",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:19.509Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafc-e7a6-7dfc-9006-bd7f89526d60",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eafc-ed48-796b-b1d8-483e02cdee3b/",
        "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-2",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:25.923Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:27:38.738Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "surgery",
        "reason": "acknowledged_not_duplicate",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 0,
        "flaggedCount": 2,
        "candidateCount": 2,
        "matchedSignals": {
          "patientId": true,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "decision",
      "action": "bill_only_order.inventory_items_decrement",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
      "secondaryObjectId": null,
      "payload": {
        "reason": "inventory_items_decremented",
        "itemCount": 20,
        "performed": true,
        "entityType": "billing_order",
        "hasCaseToteItems": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "decision",
      "action": "bill_only_order.direct_po_import_on_create",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
      "secondaryObjectId": null,
      "payload": {
        "reason": "No uploaded PO documents",
        "performed": false,
        "entityType": "billing_order",
        "fileSourceOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "hasSelectedPurchaseOrderId": false,
        "purchaseOrderDocumentCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "billing_order",
      "action": "status_change",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "decision",
      "action": "basicErp.deriveSalesOrder",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-6c19-73d9-ab74-aef85e13df88",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-06T02:27:51.960Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "decision",
      "action": "bill_only.link_purchase_order",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_purchase_order_selected",
        "performed": false,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-6c1c-705e-971a-2ae5cda57da8",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-13T02:27:51.960Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-6c1f-75bb-b4e6-68ae36e6ae1e",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-20T02:27:51.960Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:51.885Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "review",
        "reason": "acknowledged_not_duplicate",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 0,
        "flaggedCount": 2,
        "candidateCount": 2,
        "matchedSignals": {
          "patientId": true,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:52.095Z",
      "eventType": "decision",
      "action": "bill_only.notifications.cc_incident_recipients",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
      "secondaryObjectId": null,
      "payload": {
        "reason": "order has no no-charge item with an incident reason",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:52.598Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafd-6bff-7b8d-94bc-e20fd3b6cca3",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eafd-6e8b-7406-b352-7e3624c97e14/",
        "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-3",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    }
  ],
  "auditQuery": "SELECT\n    ae.created_at,\n    ae.event_type,\n    ae.action,\n    ae.user_id,\n    u.email AS user_email,\n    ae.organization_id,\n    o.name AS organization_name,\n    ae.object_id,\n    ae.secondary_object_id,\n    ae.payload,\n    ae.route,\n    ae.trace_id\n  FROM audit_events ae\n  LEFT JOIN users u ON u.id = ae.user_id\n  LEFT JOIN organizations o ON o.id = ae.organization_id\n  WHERE ae.created_at >= $1\n    AND ae.organization_id = ANY($2::uuid[])\n  ORDER BY ae.created_at ASC",
  "auditAssertions": [
    {
      "stepName": "Step 1: Initial inventory",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 2: First order",
      "expectedAction": "decision:bill_only_order.inventory_items_decrement",
      "found": true
    },
    {
      "stepName": "Step 4: Second order",
      "expectedAction": "decision:bill_only_order.inventory_items_decrement",
      "found": true
    }
  ],
  "emailAssertions": [
    {
      "stepName": "Step 2: First order",
      "expectedTemplate": "New Bill-Only Order",
      "found": true
    },
    {
      "stepName": "Step 4: Second order",
      "expectedTemplate": "New Bill-Only Order",
      "found": true
    },
    {
      "stepName": "Step 5: Shortage edge case",
      "expectedTemplate": "New Bill-Only Order",
      "found": true
    }
  ]
}