{
  "ursId": "URS-020",
  "title": "Duplicate Delivered Order Form (DOF / Bill-Only) Detection",
  "timestamp": "2026-04-23T03:37:55.647Z",
  "durationMs": 129068,
  "config": {
    "inboxUrl": "http://localhost:63168",
    "dbHost": "localhost",
    "dbPort": 63169,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Login and open bill-only form",
      "status": "pass",
      "description": "Step 1: Login and open bill-only form",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-01-logged-in.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-01-billing-form-step2.png"
      ],
      "explanation": "Bob Kauffman (StellarTech admin, has billing:create) signs in and opens the bill-only creation wizard. Establishes the user + permission context for every subsequent step.",
      "startedAt": "2026-04-23T03:38:00.887Z",
      "finishedAt": "2026-04-23T03:38:04.462Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/videos/step-01-login.webm"
    },
    {
      "name": "Step 2: Submit reference order",
      "status": "pass",
      "description": "Step 2: Submit reference order",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-02-reference-step2.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-02-reference-review.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-02-reference-submitted.png"
      ],
      "explanation": "Submits a bill-only order with the canonical reference values — BOSS Surgical account, procedure date 2026-04-15, patient PAT-URS020-001 / URS020TestLastName. No warning appears because no prior duplicate exists. This order becomes the match target for Step 3–5 and is persisted with the \"URS-020 validation test\" notes marker.",
      "expectedEmailTemplates": [
        "bill-only"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.enqueue_upload_classification"
      ],
      "startedAt": "2026-04-23T03:38:15.134Z",
      "finishedAt": "2026-04-23T03:38:25.699Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/videos/step-02-reference-order.webm"
    },
    {
      "name": "Step 3: Duplicate warning with both badges",
      "status": "pass",
      "description": "Step 3: Duplicate warning with both badges",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-03-warning-with-both-badges.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-03-duplicate-submitted.png"
      ],
      "explanation": "Re-entering the reference account + procedure date + patient ID + last name triggers \"Possible Duplicate Submission\". Both \"(Same patient ID)\" and \"(Same last name)\" badges render because the match row shares those annotation fields. Clicking \"This is not a duplicate — continue\" unlocks step advancement and the submission then completes end-to-end — proving duplicate detection is a soft block the user can acknowledge and override, and giving the DB a second row that shares the full (account, date, patient ID, last name) key with the reference order.",
      "expectedEmailTemplates": [
        "bill-only"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.enqueue_upload_classification"
      ],
      "startedAt": "2026-04-23T03:38:37.192Z",
      "finishedAt": "2026-04-23T03:38:49.206Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/videos/step-03-duplicate-warning.webm"
    },
    {
      "name": "Step 4: Change date — warning hides",
      "status": "pass",
      "description": "Step 4: Change date — warning hides",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-04-alternate-date-no-warning.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-04-date-restored-warning.png"
      ],
      "explanation": "Switching procedure date from 2026-04-15 to 2026-04-10 dismisses the warning because the primary match key (sales_account_id, procedure_date) no longer matches. Reverting the date brings the warning back — confirms the check is live-driven by form state, not cached server-side.",
      "startedAt": "2026-04-23T03:39:01.090Z",
      "finishedAt": "2026-04-23T03:39:04.455Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/videos/step-04-change-date.webm"
    },
    {
      "name": "Step 5: Clear patient ID — badge hides, warning remains",
      "status": "pass",
      "description": "Step 5: Clear patient ID — badge hides, warning remains",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-05-warning-last-name-only.png"
      ],
      "explanation": "Clearing the patient ID field while leaving account + procedure date intact keeps the \"Possible Duplicate Submission\" warning (primary key still hits) but drops the \"(Same patient ID)\" badge — proving patient_id is only an annotation, not part of the primary match, while last-name match still annotates.",
      "startedAt": "2026-04-23T03:39:18.025Z",
      "finishedAt": "2026-04-23T03:39:18.025Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/videos/step-05-clear-patient-id.webm"
    },
    {
      "name": "Step 6: Different account, same date — no warning",
      "status": "pass",
      "description": "Step 6: Different account, same date — no warning",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-06-different-account-no-warning.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-06-different-account-submitted.png"
      ],
      "explanation": "Submits a bill-only for a DIFFERENT sales account (\"Copley Hospital Account Request\") on the reference procedure date (2026-04-15) with the same patient ID + last name as the reference. No warning appears and the order submits cleanly — proving that changing sales_account_id alone is sufficient to escape detection, even when every other field matches the reference row. This is the symmetric negative counterpart to Step 4: Step 4 proves date-variation escapes detection; Step 6 proves account-variation does too.",
      "expectedEmailTemplates": [
        "bill-only"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.enqueue_upload_classification"
      ],
      "startedAt": "2026-04-23T03:39:30.501Z",
      "finishedAt": "2026-04-23T03:39:38.614Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/videos/step-06-different-account.webm"
    },
    {
      "name": "Step 7: Non-duplicate and verify billing list",
      "status": "pass",
      "description": "Step 7: Non-duplicate and verify billing list",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-07-non-duplicate-step2.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-07-non-duplicate-submitted.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/step-07-billing-list.png"
      ],
      "explanation": "Creates a fourth order with the SAME account + patient but the alternate procedure date (2026-04-10). No warning appears and the order submits without any acknowledgement. The billing list is then asserted to display every URS-020 PO number (reference, acknowledged duplicate, different-account negative, alternate-date non-duplicate) — proving every submission from this run landed in the shared view the next operator would see. (The list itself does not render a row-level duplicate indicator — the warning is a creation-time UX only; see README \"Known Deviations\".)",
      "expectedEmailTemplates": [
        "bill-only"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.enqueue_upload_classification"
      ],
      "startedAt": "2026-04-23T03:39:49.371Z",
      "finishedAt": "2026-04-23T03:39:58.458Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/videos/step-07-non-duplicate.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Four URS-020 billing orders created",
      "query": "SELECT id, order_number, sales_account_id, procedure_date,\n                        patient_id, patient_last_name, po_number, status, notes, created_at\n                 FROM billing_orders\n                 WHERE created_by_user_id = $1\n                   AND notes LIKE $2\n                 ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "019db86a-d7fe-753d-8926-cd3ea0283a46",
          "order_number": "BO-1",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "procedure_date": "2026-02-22T06:00:00.000Z",
          "patient_id": "PAT-URS020-001",
          "patient_last_name": "URS020TestLastName",
          "po_number": "PO-URS020-REF",
          "status": "submitted",
          "notes": "URS-020 validation test — reference order",
          "created_at": "2026-04-23T03:38:22.955Z"
        },
        {
          "id": "019db86b-3d3a-710f-a9a6-6b7d12e367bc",
          "order_number": "BO-2",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "procedure_date": "2026-02-22T06:00:00.000Z",
          "patient_id": "PAT-URS020-001",
          "patient_last_name": "URS020TestLastName",
          "po_number": "PO-URS020-DUP",
          "status": "submitted",
          "notes": "URS-020 validation test — acknowledged duplicate",
          "created_at": "2026-04-23T03:38:48.971Z"
        },
        {
          "id": "019db86b-f54a-78cc-a3a6-1de605efb9d9",
          "order_number": "BO-3",
          "sales_account_id": "1fb8c9d0-e1f2-3456-1234-567890123456",
          "procedure_date": "2026-02-22T06:00:00.000Z",
          "patient_id": "PAT-URS020-001",
          "patient_last_name": "URS020TestLastName",
          "po_number": "PO-URS020-ALTACCT",
          "status": "submitted",
          "notes": "URS-020 validation test — different account negative case",
          "created_at": "2026-04-23T03:39:36.118Z"
        },
        {
          "id": "019db86c-3ed2-76c3-a0ef-7d693cc2e8ca",
          "order_number": "BO-4",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "procedure_date": "2026-02-17T06:00:00.000Z",
          "patient_id": "PAT-URS020-001",
          "patient_last_name": "URS020TestLastName",
          "po_number": "PO-URS020-NONE",
          "status": "submitted",
          "notes": "URS-020 validation test — non-duplicate (alternate procedure date)",
          "created_at": "2026-04-23T03:39:54.931Z"
        }
      ],
      "assertion": "Playwright submitted four bill-only orders — reference, acknowledged duplicate, different-account negative case, and alternate-date non-duplicate — all tagged with the URS-020 marker."
    },
    {
      "name": "Duplicate pair shares account + procedure date",
      "query": "SELECT id, order_number, po_number, patient_id, patient_last_name, created_at\n                 FROM billing_orders\n                 WHERE created_by_user_id = $1\n                   AND notes LIKE $2\n                   AND sales_account_id = $3\n                   AND procedure_date = $4\n                 ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "019db86a-d7fe-753d-8926-cd3ea0283a46",
          "order_number": "BO-1",
          "po_number": "PO-URS020-REF",
          "patient_id": "PAT-URS020-001",
          "patient_last_name": "URS020TestLastName",
          "created_at": "2026-04-23T03:38:22.955Z"
        },
        {
          "id": "019db86b-3d3a-710f-a9a6-6b7d12e367bc",
          "order_number": "BO-2",
          "po_number": "PO-URS020-DUP",
          "patient_id": "PAT-URS020-001",
          "patient_last_name": "URS020TestLastName",
          "created_at": "2026-04-23T03:38:48.971Z"
        }
      ],
      "assertion": "Two URS-020 orders must share the reference sales account and procedure date; that is exactly what `checkDuplicateBillingOrders` uses as its primary key."
    },
    {
      "name": "Alternate-date order: same account, different date (no warning)",
      "query": "SELECT id, order_number, po_number, sales_account_id, procedure_date\n                 FROM billing_orders\n                 WHERE created_by_user_id = $1\n                   AND notes LIKE $2\n                   AND sales_account_id = $3\n                   AND procedure_date = $4",
      "status": "pass",
      "rows": [
        {
          "id": "019db86c-3ed2-76c3-a0ef-7d693cc2e8ca",
          "order_number": "BO-4",
          "po_number": "PO-URS020-NONE",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "procedure_date": "2026-02-17T06:00:00.000Z"
        }
      ],
      "assertion": "A URS-020 order must exist with the reference sales account but the alternate procedure date. The UI rendered no warning at submission time — evidence that changing procedure_date alone is sufficient to escape duplicate detection."
    },
    {
      "name": "Different-account order: other account, same date (no warning)",
      "query": "SELECT id, order_number, po_number, sales_account_id, procedure_date\n                 FROM billing_orders\n                 WHERE created_by_user_id = $1\n                   AND notes LIKE $2\n                   AND sales_account_id = $3\n                   AND procedure_date = $4",
      "status": "pass",
      "rows": [
        {
          "id": "019db86b-f54a-78cc-a3a6-1de605efb9d9",
          "order_number": "BO-3",
          "po_number": "PO-URS020-ALTACCT",
          "sales_account_id": "1fb8c9d0-e1f2-3456-1234-567890123456",
          "procedure_date": "2026-02-22T06:00:00.000Z"
        }
      ],
      "assertion": "A URS-020 order must exist with the alternate sales account (Copley) on the reference procedure date. The UI rendered no warning at submission time — evidence that changing sales_account_id alone is sufficient to escape duplicate detection, proving account is a primary-key element and the detection key is symmetric in account and date."
    },
    {
      "name": "Duplicate pair also matches patient ID and last name",
      "query": "SELECT COUNT(*) AS n\n                 FROM billing_orders\n                 WHERE created_by_user_id = $1\n                   AND notes LIKE $2\n                   AND sales_account_id = $3\n                   AND procedure_date = $4\n                   AND patient_id = $5\n                   AND patient_last_name = $6",
      "status": "pass",
      "rows": [
        {
          "n": "2"
        }
      ],
      "assertion": "Both duplicate-pair orders carry the reference patient ID and patient last name so the warning surfaced both \"(Same patient ID)\" and \"(Same last name)\" badges."
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z",
  "knownDeviations": [
    {
      "summary": "PO number is not a duplicate-detection input",
      "detail": "URS-020 lists PO number as a detection signal, but `checkDuplicateBillingOrders` (in `modules/bill_only/src/services/billing-order-queries.ts`) detects duplicates on `sales_account_id` + `procedure_date` only, scoped to the user's organization. Patient ID and patient last name are used solely to annotate matched rows with the \"(Same patient ID)\" / \"(Same last name)\" badges — not as part of the primary match key. This is intentional: sales reps typically submit bill-onlies before the PO has arrived, so requiring PO in the match would silently disable detection for the common case. The test below exercises the merged behaviour (positive match on account+date, negative match when either differs) rather than the URS wording.",
      "reference": "DF-2598"
    }
  ],
  "auditStartTime": "2026-04-23T03:37:53.715Z",
  "emailEvidence": [
    {
      "subject": "New Bill-Only Order - 2/22/2026 - ZuriMED BO-1",
      "template": "New_Bill-Only_Order_-_2_22_2026_-_ZuriMED_BO-1",
      "screenshotPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/emails/2026-04-23T03-38-24-518Z-New_Bill-Only_Order_-_2_22_2026_-_ZuriMED_BO-1.png"
    },
    {
      "subject": "New Bill-Only Order - 2/22/2026 - ZuriMED BO-2",
      "template": "New_Bill-Only_Order_-_2_22_2026_-_ZuriMED_BO-2",
      "screenshotPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/emails/2026-04-23T03-38-49-090Z-New_Bill-Only_Order_-_2_22_2026_-_ZuriMED_BO-2.png"
    },
    {
      "subject": "New Bill-Only Order - 2/22/2026 - ZuriMED BO-3",
      "template": "New_Bill-Only_Order_-_2_22_2026_-_ZuriMED_BO-3",
      "screenshotPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/emails/2026-04-23T03-39-37-672Z-New_Bill-Only_Order_-_2_22_2026_-_ZuriMED_BO-3.png"
    },
    {
      "subject": "New Bill-Only Order - 2/17/2026 - ZuriMED BO-4",
      "template": "New_Bill-Only_Order_-_2_17_2026_-_ZuriMED_BO-4",
      "screenshotPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-020-duplicate-dof-detection/2026-04-23T03-37-55-645Z/screenshots/emails/2026-04-23T03-39-56-222Z-New_Bill-Only_Order_-_2_17_2026_-_ZuriMED_BO-4.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-04-23T03:37:58.241Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:38:05.661Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:38:22.955Z",
      "eventType": "decision",
      "action": "bill_only_order.enqueue_upload_classification",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019db86a-d7fe-753d-8926-cd3ea0283a46",
      "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-04-23T03:38:24.537Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019db86a-d7fe-753d-8926-cd3ea0283a46",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "bob.kauffman@stellartech.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/019db86a-dd8b-75f4-896b-cd4eac382790/",
        "subject": "New Bill-Only Order - 2/22/2026 - ZuriMED BO-1",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-04-23T03:38:27.111Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:38:48.971Z",
      "eventType": "decision",
      "action": "bill_only_order.enqueue_upload_classification",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019db86b-3d3a-710f-a9a6-6b7d12e367bc",
      "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-04-23T03:38:49.139Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019db86b-3d3a-710f-a9a6-6b7d12e367bc",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "bob.kauffman@stellartech.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/019db86b-3d93-78d6-b886-d5c9f2357119/",
        "subject": "New Bill-Only Order - 2/22/2026 - ZuriMED BO-2",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-04-23T03:38:50.551Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:39:05.774Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:39:22.673Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:39:36.118Z",
      "eventType": "decision",
      "action": "bill_only_order.enqueue_upload_classification",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019db86b-f54a-78cc-a3a6-1de605efb9d9",
      "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-04-23T03:39:37.682Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019db86b-f54a-78cc-a3a6-1de605efb9d9",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "bob.kauffman@stellartech.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/019db86b-fb4b-7a93-8377-0986a227ab79/",
        "subject": "New Bill-Only Order - 2/22/2026 - ZuriMED BO-3",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-04-23T03:39:39.784Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:39:54.931Z",
      "eventType": "decision",
      "action": "bill_only_order.enqueue_upload_classification",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019db86c-3ed2-76c3-a0ef-7d693cc2e8ca",
      "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-04-23T03:39:56.237Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019db86c-3ed2-76c3-a0ef-7d693cc2e8ca",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "bob.kauffman@stellartech.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/019db86c-43c3-7b45-a5db-2b75318e1d3f/",
        "subject": "New Bill-Only Order - 2/17/2026 - ZuriMED BO-4",
        "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 2: Submit reference order",
      "expectedAction": "decision:bill_only_order.enqueue_upload_classification",
      "found": true
    },
    {
      "stepName": "Step 3: Duplicate warning with both badges",
      "expectedAction": "decision:bill_only_order.enqueue_upload_classification",
      "found": true
    },
    {
      "stepName": "Step 6: Different account, same date — no warning",
      "expectedAction": "decision:bill_only_order.enqueue_upload_classification",
      "found": true
    },
    {
      "stepName": "Step 7: Non-duplicate and verify billing list",
      "expectedAction": "decision:bill_only_order.enqueue_upload_classification",
      "found": true
    }
  ],
  "emailAssertions": [
    {
      "stepName": "Step 2: Submit reference order",
      "expectedTemplate": "bill-only",
      "found": true
    },
    {
      "stepName": "Step 3: Duplicate warning with both badges",
      "expectedTemplate": "bill-only",
      "found": true
    },
    {
      "stepName": "Step 6: Different account, same date — no warning",
      "expectedTemplate": "bill-only",
      "found": true
    },
    {
      "stepName": "Step 7: Non-duplicate and verify billing list",
      "expectedTemplate": "bill-only",
      "found": true
    }
  ]
}