{
  "ursId": "URS-081",
  "title": "Bill-only automated replenishment",
  "timestamp": "2026-09-29T02:31:00.928Z",
  "durationMs": 115627,
  "config": {
    "inboxUrl": "http://localhost:37307",
    "dbHost": "localhost",
    "dbPort": 38985,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Manufacturer enables automated replenishment",
      "status": "pass",
      "description": "Step 1: Manufacturer enables automated replenishment",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-01-automation-off.png",
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-01-automation-configured.png",
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-01-automation-saved.png"
      ],
      "explanation": "Alex Admin (Vantis manufacturer) opens Settings → Automation → Bill-Only Orders and switches on \"Enable automated replenishment\". Enabling reveals the timing radio (default \"On bill-only submission\") and the \"Replenishment order requires approval\" switch (default on); saving shows the \"Automated replenishment settings saved\" toast and writes an organization-settings audit event. This establishes the manufacturer setting the whole chain is gated on — the automation is off by default and setup deliberately leaves it off so this step proves the UI enablement path.",
      "expectedAuditActions": [
        "organization_settings:bill_only_replenishment_settings_changed"
      ],
      "startedAt": "2026-09-29T02:31:10.848Z",
      "finishedAt": "2026-09-29T02:31:13.121Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/videos/step-01-enable-automation.webm"
    },
    {
      "name": "Step 2: Rep submits a trunk bill-only with replenishment requested",
      "status": "pass",
      "description": "Step 2: Rep submits a trunk bill-only with replenishment requested",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-02-devices-replenish-checked.png",
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-02-review-replenish-requested.png",
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-02-submitted.png"
      ],
      "explanation": "Blair Bennett (Corveta distributor rep) submits a bill-only at /billing/new drawing from her trunk: 2 units of URS081-PLATE and 1 unit of URS081-SCREW. With the automation on and no override blocking it, the \"Replenish trunk stock\" master toggle and every per-unit Replenish checkbox are checked by default, and the review step prints \"Replenish: Requested\" per lot. Submitting persists replenishment_requested=true on every unit row — the consumption record the trigger later reads.",
      "startedAt": "2026-09-29T02:31:37.679Z",
      "finishedAt": "2026-09-29T02:31:43.321Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/videos/step-02-trunk-bill-only.webm"
    },
    {
      "name": "Step 3: Submission trigger generates the replenishment order",
      "status": "pass",
      "description": "Step 3: Submission trigger generates the replenishment order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-03-order-in-list.png"
      ],
      "explanation": "In production, Restate delivers BillOnlyOrderObject.handleOrderCreatedDelayed one hour after submission (the void/edit grace window) and that handler runs the replenishment trigger. The suite invokes the same handler through the Restate ingress — the identical invocation, delivered early — and then observes the outcome: an order_requests row with order_type=replenishment appears, linked to the bill-only via source_billing_order_id, and the orders list shows it as a Replenishment order awaiting approval (the requires-approval switch suppressed auto-approval).",
      "expectedAuditActions": [
        "decision:create_replenishment_order_on_bill_only"
      ],
      "startedAt": "2026-09-29T02:31:51.995Z",
      "finishedAt": "2026-09-29T02:31:51.995Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/videos/step-03-order-generated.webm"
    },
    {
      "name": "Step 4: Replenishment order matches the consumed items and links back",
      "status": "pass",
      "description": "Step 4: Replenishment order matches the consumed items and links back",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-04-order-items-and-link.png",
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-04-link-lands-on-bill-only.png"
      ],
      "explanation": "The generated order's detail page lists exactly the products the bill-only consumed — the plate and the screw — and its Related section renders the \"Created from bill-only\" link (DF-4805) that navigates to the triggering bill-only. The DB validations pin the quantities exactly: requested 2 and 1, matching the flagged unit rows one-to-one. This is the core of the requirement: the generated order equals what was used.",
      "startedAt": "2026-09-29T02:31:56.817Z",
      "finishedAt": "2026-09-29T02:31:57.613Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/videos/step-04-order-detail.webm"
    },
    {
      "name": "Step 5: Bill-only links to its replenishment order",
      "status": "pass",
      "description": "Step 5: Bill-only links to its replenishment order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-05-related-replenishment-order.png"
      ],
      "explanation": "The bill-only's own detail page closes the loop: its Related rail lists \"Replenishment order\" with the generated order's number, linking to the order detail. Together with Step 4 this proves the DF-4805 bidirectional link, whose single source of truth is order_requests.source_billing_order_id.",
      "startedAt": "2026-09-29T02:32:02.558Z",
      "finishedAt": "2026-09-29T02:32:02.558Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/videos/step-05-bill-only-link.webm"
    },
    {
      "name": "Step 6: Bill-only with no lines flagged generates no order",
      "status": "pass",
      "description": "Step 6: Bill-only with no lines flagged generates no order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-06-replenish-unchecked.png",
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-06-review-no-replenish.png",
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-06-submitted.png"
      ],
      "explanation": "Blair submits a second trunk bill-only but clears the \"Replenish trunk stock\" master toggle, which unchecks every per-unit Replenish box; the review step shows no replenishment request. When the trigger fires for this bill-only it records the decision performed=false with reason no_items_flagged and creates nothing — the negative control proving orders are generated only from explicit per-line requests.",
      "expectedAuditActions": [
        "decision:create_replenishment_order_on_bill_only"
      ],
      "startedAt": "2026-09-29T02:32:22.355Z",
      "finishedAt": "2026-09-29T02:32:29.750Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/videos/step-06-no-replenish.webm"
    },
    {
      "name": "Step 7: Agency override blocks replenishment for the rep",
      "status": "pass",
      "description": "Step 7: Agency override blocks replenishment for the rep",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-07-agency-override-off.png",
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-07-rep-toggle-blocked.png",
        "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/step-07-agency-override-restored.png"
      ],
      "explanation": "Dan Distributor (Corveta admin) switches off \"Allow automated replenishment for this agency\" on the organization settings page — a hard block for every rep in the agency. Blair's wizard then renders the replenishment toggle disabled with \"Automated replenishment is turned off for your agency.\", and she cannot re-enable it. Dan then restores the override to the inherit state. Both changes are audited on Corveta.",
      "expectedAuditActions": [
        "organization_settings:bill_only_replenishment_agency_override_changed"
      ],
      "startedAt": "2026-09-29T02:32:35.521Z",
      "finishedAt": "2026-09-29T02:32:54.936Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/videos/step-07-agency-off.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Automation settings change audited",
      "query": "SELECT id, action, user_id, payload, created_at\n    FROM audit_events\n    WHERE organization_id = $1\n      AND created_at >= $2\n      AND event_type = 'organization_settings'\n      AND action = 'bill_only_replenishment_settings_changed'\n      AND user_id = $3\n    ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb00-7c64-7e5d-8bae-9d08556d657a",
          "action": "bill_only_replenishment_settings_changed",
          "user_id": "f6a7b8c9-d0e1-2345-f123-456789012345",
          "payload": "{\"previous\":{},\"automatedReplenishmentTiming\":\"on_submission\",\"automatedReplenishmentEnabled\":true,\"automatedReplenishmentRequiresApproval\":true}",
          "created_at": "2026-09-29T02:31:12.535Z"
        }
      ],
      "assertion": "Saving the automation should write an audit_events row (event_type=organization_settings, action=bill_only_replenishment_settings_changed) by Alex whose payload records automatedReplenishmentEnabled=true."
    },
    {
      "name": "Automation settings persisted on the manufacturer",
      "query": "SELECT settings->'billOnly' AS bill_only FROM organizations WHERE id = $1",
      "status": "pass",
      "rows": [
        {
          "bill_only": "{\"automatedReplenishmentTiming\":\"on_submission\",\"automatedReplenishmentEnabled\":true,\"automatedReplenishmentRequiresApproval\":true}"
        }
      ],
      "assertion": "organizations.settings.billOnly on Vantis should persist automatedReplenishmentEnabled=true with on_submission timing and requires-approval on (the Step 1 configuration)."
    },
    {
      "name": "Bill-only lines persisted the replenishment flags",
      "query": "SELECT bo.id, bo.patient_id, bo.status,\n      COUNT(*) FILTER (WHERE boi.parent_billing_order_item_id IS NULL)::int AS top_level_rows,\n      COUNT(*) FILTER (WHERE boi.replenishment_requested)::int AS flagged_rows\n    FROM billing_orders bo\n    JOIN billing_order_items boi ON boi.billing_order_id = bo.id\n    WHERE bo.sales_organization_id = $1\n      AND bo.manufacturer_organization_id = $2\n      AND bo.patient_id LIKE $3 || '%'\n      AND bo.created_at >= $4\n    GROUP BY bo.id, bo.patient_id, bo.status\n    ORDER BY MIN(bo.created_at)",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb00-e861-7caf-a765-619e454f76f2",
          "patient_id": "URS081-MRN-1790649062965-1",
          "status": "submitted",
          "top_level_rows": 3,
          "flagged_rows": 3
        },
        {
          "id": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
          "patient_id": "URS081-MRN-1790649062965-2",
          "status": "submitted",
          "top_level_rows": 1,
          "flagged_rows": 0
        }
      ],
      "assertion": "Two URS-081 bill-onlys should exist: one with 3 unit rows all carrying replenishment_requested=true (Step 2), and one with a single unflagged row (Step 6)."
    },
    {
      "name": "Replenishment order generated with the expected shape",
      "query": "SELECT id, request_number, status, order_type,\n      requesting_organization_id, fulfilling_organization_id, requested_by_user_id,\n      receiving_rep_user_id, location_id, source_billing_order_id,\n      submission_grace_until, notes, created_at\n    FROM order_requests\n    WHERE source_billing_order_id = $1",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-033f-7247-93f9-84f6371a6f26",
          "request_number": "OR-2",
          "status": "submitted",
          "order_type": "replenishment",
          "requesting_organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "fulfilling_organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "requested_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "receiving_rep_user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "location_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "source_billing_order_id": "01a0eb00-e861-7caf-a765-619e454f76f2",
          "submission_grace_until": null,
          "notes": "Replenishment order for bill-only BO-1",
          "created_at": "2026-09-29T02:31:47.232Z"
        }
      ],
      "assertion": "Exactly one order_requests row should point at bill-only #1: order_type=replenishment, Corveta requesting from Vantis, requested by and receiving to Blair, at Blair's trunk, no submission grace window, status=submitted (awaiting approval), notes naming the bill-only."
    },
    {
      "name": "Order items match the consumed units and await approval",
      "query": "SELECT oi.id, oi.product_id, p.sku, oi.requested_quantity,\n      oi.pending_quantity, oi.approved_quantity\n    FROM order_request_items oi\n    JOIN org_products p ON p.id = oi.product_id\n    WHERE oi.order_request_id = $1\n    ORDER BY p.sku",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-034b-7641-92e7-281d6aafeaa6",
          "product_id": "08100000-0000-4000-8000-000000000011",
          "sku": "URS081-PLATE",
          "requested_quantity": 2,
          "pending_quantity": 2,
          "approved_quantity": 0
        },
        {
          "id": "01a0eb01-034b-7641-92e7-281e73e14397",
          "product_id": "08100000-0000-4000-8000-000000000012",
          "sku": "URS081-SCREW",
          "requested_quantity": 1,
          "pending_quantity": 1,
          "approved_quantity": 0
        }
      ],
      "assertion": "The order should have exactly two items matching the bill-only's consumption — URS081-PLATE × 2 and URS081-SCREW × 1 — each with pending_quantity equal to requested_quantity and approved_quantity 0 (requires-approval suppressed auto-approval)."
    },
    {
      "name": "Replenishment creation decision recorded",
      "query": "SELECT id, action, object_id, secondary_object_id,\n      payload->>'performed' AS performed, payload->>'reason' AS reason, created_at\n    FROM audit_events\n    WHERE organization_id = $1\n      AND created_at >= $2\n      AND event_type = 'decision'\n      AND action = $3\n      AND object_id = $4\n    ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-0387-7f5b-9fa8-861045b1a5e1",
          "action": "create_replenishment_order_on_bill_only",
          "object_id": "01a0eb00-e861-7caf-a765-619e454f76f2",
          "secondary_object_id": "01a0eb01-033f-7247-93f9-84f6371a6f26",
          "performed": "true",
          "reason": "replenishment_order_created",
          "created_at": "2026-09-29T02:31:47.232Z"
        }
      ],
      "assertion": "The trigger should log a decision (action=create_replenishment_order_on_bill_only) against bill-only #1 with performed=true, reason=replenishment_order_created, and the created order as secondary_object_id, scoped to the manufacturer organization."
    },
    {
      "name": "Auto-approval suppressed on the generated order",
      "query": "SELECT id, action, payload->>'performed' AS performed,\n      payload->>'reason' AS reason, created_at\n    FROM audit_events\n    WHERE organization_id = $3\n      AND created_at >= $1\n      AND event_type = 'decision'\n      AND action = 'auto_approve_order'\n      AND object_id = $2\n    ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-034e-76cf-a104-ff457904b3a6",
          "action": "auto_approve_order",
          "performed": "false",
          "reason": "Auto-approval suppressed by caller",
          "created_at": "2026-09-29T02:31:47.232Z"
        }
      ],
      "assertion": "With the requires-approval switch on, order creation should log auto_approve_order with performed=false (auto-approval suppressed) for the generated order."
    },
    {
      "name": "Unflagged bill-only skipped with no order created",
      "query": "SELECT id, payload->>'performed' AS performed, payload->>'reason' AS reason,\n      (SELECT COUNT(*)::int FROM order_requests r WHERE r.source_billing_order_id = $4) AS spawned_orders\n    FROM audit_events\n    WHERE organization_id = $1\n      AND created_at >= $2\n      AND event_type = 'decision'\n      AND action = $3\n      AND object_id = $4\n    ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-9d3e-7de9-94dd-4556dad90fc7",
          "performed": "false",
          "reason": "no_items_flagged",
          "spawned_orders": 0
        }
      ],
      "assertion": "The trigger should log performed=false with reason=no_items_flagged against bill-only #2, and no order_requests row may point at it."
    },
    {
      "name": "Agency override changes audited",
      "query": "SELECT id, payload, created_at\n    FROM audit_events\n    WHERE organization_id = $1\n      AND created_at >= $2\n      AND event_type = 'organization_settings'\n      AND action = 'bill_only_replenishment_agency_override_changed'\n      AND user_id = $3\n    ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-bf62-7e34-aa73-842732a6bdae",
          "payload": "{\"previous\":null,\"agencyReplenishmentEnabled\":false}",
          "created_at": "2026-09-29T02:32:35.377Z"
        },
        {
          "id": "01a0eb02-0b0a-7081-a686-2d6dc0cbb444",
          "payload": "{\"previous\":false,\"agencyReplenishmentEnabled\":null}",
          "created_at": "2026-09-29T02:32:54.791Z"
        }
      ],
      "assertion": "Dan turning the agency override off and back on should write two bill_only_replenishment_agency_override_changed audit rows on Corveta: first storing false (hard block), then null (inherit)."
    },
    {
      "name": "Multi-tenant isolation: no URS-081 rows outside the participating orgs",
      "query": "SELECT\n      (SELECT COUNT(*)::int FROM org_products\n        WHERE sku LIKE 'URS081-%' AND organization_id <> $1) AS foreign_products,\n      (SELECT COUNT(*)::int FROM order_requests\n        WHERE source_billing_order_id = $3\n          AND (requesting_organization_id NOT IN ($1, $2)\n            OR fulfilling_organization_id NOT IN ($1, $2))) AS foreign_orders,\n      (SELECT COUNT(*)::int FROM audit_events\n        WHERE event_type = 'decision' AND action = $4 AND object_id = $3\n          AND organization_id <> $1) AS foreign_decisions",
      "status": "pass",
      "rows": [
        {
          "foreign_products": 0,
          "foreign_orders": 0,
          "foreign_decisions": 0
        }
      ],
      "assertion": "No organization other than Vantis owns a URS081 product, no org outside the Vantis/Corveta pair appears on the generated order, and the replenishment decisions are scoped to the manufacturer only."
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z",
  "auditStartTime": "2026-09-29T02:30:59.122Z",
  "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-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/emails/2026-09-29T02-31-42-050Z-New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-1.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-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/screenshots/emails/2026-09-29T02-32-25-189Z-New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-3.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-09-29T02:31:06.377Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:31:12.535Z",
      "eventType": "organization_settings",
      "action": "bill_only_replenishment_settings_changed",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "previous": {},
        "automatedReplenishmentTiming": "on_submission",
        "automatedReplenishmentEnabled": true,
        "automatedReplenishmentRequiresApproval": true
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:16.478Z",
      "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:31:29.627Z",
      "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:31:40.237Z",
      "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:31:40.237Z",
      "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": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "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:31:40.237Z",
      "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:31:40.237Z",
      "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": "01a0eb00-e8ac-74c9-ba94-bcdbee76d57b",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb00-e861-7caf-a765-619e454f76f2",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-20T02:31:40.445Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:40.237Z",
      "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": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:40.237Z",
      "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:31:40.237Z",
      "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": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "inventory_items_decremented",
        "itemCount": 3,
        "performed": true,
        "entityType": "billing_order",
        "hasCaseToteItems": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:40.237Z",
      "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": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "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:31:40.237Z",
      "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": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:40.237Z",
      "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": "01a0eb00-e8a7-7087-beed-33b5b8cf8593",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb00-e861-7caf-a765-619e454f76f2",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-13T02:31:40.445Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:40.237Z",
      "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": "01a0eb00-e8a0-7911-9408-ecef98d8e8e2",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb00-e861-7caf-a765-619e454f76f2",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-06T02:31:40.445Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:41.597Z",
      "eventType": "decision",
      "action": "bill_only.notifications.cc_incident_recipients",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "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:31:42.117Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eb00-eef0-796b-ab60-d31285936af7/",
        "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:31:45.587Z",
      "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:31:47.232Z",
      "eventType": "decision",
      "action": "order_request_created",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-033f-7247-93f9-84f6371a6f26",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Order request OR-2 created (importSource=manual)",
        "priority": "normal",
        "itemCount": 2,
        "orderType": "replenishment",
        "performed": true,
        "entityType": "order_request",
        "importSource": "manual",
        "requestNumber": "OR-2",
        "selfFulfilled": false,
        "resolvedLocationId": "a6e7f8a9-b0c1-2345-0123-456789012345",
        "resolvedSalesAccountId": null,
        "fulfillingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:47.232Z",
      "eventType": "decision",
      "action": "create_replenishment_order_on_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "secondaryObjectId": "01a0eb01-033f-7247-93f9-84f6371a6f26",
      "payload": {
        "reason": "replenishment_order_created",
        "timing": "on_submission",
        "trigger": "submission",
        "locations": [
          "a6e7f8a9-b0c1-2345-0123-456789012345"
        ],
        "performed": true,
        "entityType": "billing_order",
        "orderRequestIds": [
          "01a0eb01-033f-7247-93f9-84f6371a6f26"
        ],
        "requiresApproval": true,
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:47.232Z",
      "eventType": "checklist",
      "action": "checklists.create",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-0359-73d1-9adc-4bc46483084e",
      "secondaryObjectId": null,
      "payload": {
        "title": "Order OR-2",
        "source": {
          "type": "order_request",
          "orderRequestId": "01a0eb01-033f-7247-93f9-84f6371a6f26"
        }
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:47.232Z",
      "eventType": "decision",
      "action": "auto_approve_order",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-033f-7247-93f9-84f6371a6f26",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Auto-approval suppressed by caller",
        "performed": false,
        "entityType": "order_request",
        "importSource": "manual",
        "selfFulfilled": false,
        "hasBlockingIssues": false,
        "hasMissingPoIssue": false,
        "hasDuplicateIssues": false,
        "resolvedLocationId": "a6e7f8a9-b0c1-2345-0123-456789012345",
        "preventAutoApproval": true,
        "needsAutoApproveGate": false,
        "fulfillingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "allowAutoApproveImportedOrders": false,
        "partialOrderAutoApprovalEnabled": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:47.909Z",
      "eventType": "decision",
      "action": "generate_dof",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Generated successfully",
        "performed": true,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:47.955Z",
      "eventType": "decision",
      "action": "send_dof_notification",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Invoice generated, no blocking issues",
        "performed": true,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:48.021Z",
      "eventType": "decision",
      "action": "send_bill_only_submitted_notification",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Notification sent",
        "performed": true,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:48.039Z",
      "eventType": "decision",
      "action": "call_org_logic",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb00-e861-7caf-a765-619e454f76f2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Org logic called but not executed",
        "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:31:53.751Z",
      "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:31:59.365Z",
      "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:32:04.282Z",
      "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:32:16.628Z",
      "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:32:24.327Z",
      "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": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "secondaryObjectId": null,
      "payload": {
        "reason": "inventory_items_decremented",
        "itemCount": 1,
        "performed": true,
        "entityType": "billing_order",
        "hasCaseToteItems": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:24.327Z",
      "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": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "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:32:24.327Z",
      "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": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:24.327Z",
      "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": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:24.327Z",
      "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": "01a0eb01-9455-7fb3-994a-7cd133373cbf",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-06T02:32:24.404Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:24.327Z",
      "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": "01a0eb01-945c-7546-9481-87d0b3bd6bc8",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-20T02:32:24.404Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:24.327Z",
      "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:32:24.327Z",
      "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": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "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:32:24.327Z",
      "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:32:24.327Z",
      "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": "01a0eb01-9459-74cd-9dc4-abcab1132c47",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-13T02:32:24.404Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:24.327Z",
      "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:32:24.698Z",
      "eventType": "decision",
      "action": "bill_only.notifications.cc_incident_recipients",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "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:32:25.212Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eb01-976e-7ab1-9ab8-7ba61e7fcdab/",
        "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-3",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.682Z",
      "eventType": "decision",
      "action": "create_replenishment_order_on_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_items_flagged",
        "trigger": "submission",
        "performed": false,
        "entityType": "billing_order",
        "orderRequestIds": [],
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.854Z",
      "eventType": "decision",
      "action": "generate_dof",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Generated successfully",
        "performed": true,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.906Z",
      "eventType": "decision",
      "action": "send_dof_notification",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Invoice generated, no blocking issues",
        "performed": true,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.948Z",
      "eventType": "decision",
      "action": "send_bill_only_submitted_notification",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Notification sent",
        "performed": true,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.958Z",
      "eventType": "decision",
      "action": "call_org_logic",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb01-943e-77b3-9c81-3eaa93356e3d",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Org logic called but not executed",
        "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:32:31.548Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "dan.distributor@corvetasurgical.com",
      "userId": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "dan.distributor@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:32:35.377Z",
      "eventType": "organization_settings",
      "action": "bill_only_replenishment_agency_override_changed",
      "userEmail": "dan.distributor@corvetasurgical.com",
      "userId": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "secondaryObjectId": null,
      "payload": {
        "previous": null,
        "agencyReplenishmentEnabled": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:37.150Z",
      "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:32:48.343Z",
      "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": "all_candidates_vetoed",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 2,
        "flaggedCount": 0,
        "candidateCount": 2,
        "matchedSignals": {
          "patientId": false,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:54.791Z",
      "eventType": "organization_settings",
      "action": "bill_only_replenishment_agency_override_changed",
      "userEmail": "dan.distributor@corvetasurgical.com",
      "userId": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "secondaryObjectId": null,
      "payload": {
        "previous": false,
        "agencyReplenishmentEnabled": null
      },
      "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: Manufacturer enables automated replenishment",
      "expectedAction": "organization_settings:bill_only_replenishment_settings_changed",
      "found": true
    },
    {
      "stepName": "Step 3: Submission trigger generates the replenishment order",
      "expectedAction": "decision:create_replenishment_order_on_bill_only",
      "found": true
    },
    {
      "stepName": "Step 6: Bill-only with no lines flagged generates no order",
      "expectedAction": "decision:create_replenishment_order_on_bill_only",
      "found": true
    },
    {
      "stepName": "Step 7: Agency override blocks replenishment for the rep",
      "expectedAction": "organization_settings:bill_only_replenishment_agency_override_changed",
      "found": true
    }
  ],
  "emailAssertions": [],
  "videoPaths": [
    "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/videos/step-07-agency-restore.webm",
    "/home/runner/_work/code/code/validation_test_results/urs-081-bill-only-replenishment/2026-09-29T02-31-00-927Z/videos/step-07-rep-blocked.webm"
  ]
}