{
  "ursId": "URS-055",
  "title": "Restrict uncertified reps from actions until approved",
  "timestamp": "2026-09-29T02:25:14.883Z",
  "durationMs": 194524,
  "config": {
    "inboxUrl": "http://localhost:44137",
    "dbHost": "localhost",
    "dbPort": 32891,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Bill-only blocked",
      "status": "pass",
      "description": "Step 1: Bill-only blocked",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-01-ryan-dashboard.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-01-billing-blocked.png"
      ],
      "explanation": "A sales rep who has not completed the manufacturer's required certification attempts to create a bill-only order. The form shows a \"Certification required\" notice linking to the certification checklist, and the gated manufacturer is absent from the manufacturer picker — confirming that the certification requirement is enforced before any order can be submitted.",
      "startedAt": "2026-09-29T02:25:25.835Z",
      "finishedAt": "2026-09-29T02:25:31.808Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/videos/step-01-billing-blocked.webm"
    },
    {
      "name": "Step 2: Order request trunk allowed",
      "status": "pass",
      "description": "Step 2: Order request trunk allowed",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-02-order-request-trunk-allowed.png"
      ],
      "startedAt": "2026-09-29T02:25:43.472Z",
      "finishedAt": "2026-09-29T02:25:43.472Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/videos/step-02-order-request-trunk-allowed.webm"
    },
    {
      "name": "Step 3: Certified rep control",
      "status": "pass",
      "description": "Step 3: Certified rep control",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-03-bob-billing-form.png"
      ],
      "explanation": "A certified sales rep navigates through the bill-only form without being blocked. The form heading and step indicator both render, and the certification-required notice is absent — confirming the restriction is applied only to uncertified reps.\n\nBlair's relationship row has `active = true` in the fixtures, which is the column the gating logic (`getAvailableFulfillingOrganizations`) consults. The `status` column in the demo data may read `proposed_pending_onboarding` rather than `active` because the seed set preserves the original onboarding history — but the boolean `active` flag is authoritative for whether the rep may place orders, which is why the DB assertion in this run checks `active = true` for the control case rather than the `status` string.",
      "startedAt": "2026-09-29T02:25:54.588Z",
      "finishedAt": "2026-09-29T02:25:54.588Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/videos/step-03-certified-control.webm"
    },
    {
      "name": "Step 4: Rep completes certification",
      "status": "pass",
      "description": "Step 4: Rep completes certification",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-04-identity-verified.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-04-doc-acknowledged.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-04-quiz-answers.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-04-signature.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-04-completed.png"
      ],
      "explanation": "The gated rep opens the manufacturer's required certification and completes it in the UI: opens and acknowledges the training document (timestamped server-side), passes the knowledge check (graded server-side), and signs. Completion activates the representation relationship (status='active', reason_code='certification_completed') — this is what lifts both order gates.",
      "expectedAuditActions": [
        "certification:completed"
      ],
      "startedAt": "2026-09-29T02:26:47.210Z",
      "finishedAt": "2026-09-29T02:26:58.286Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/videos/step-04-rep-certification.webm"
    },
    {
      "name": "Step 5: Bill-only after certification",
      "status": "pass",
      "description": "Step 5: Bill-only after certification",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-05-billing-form-accessible.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-05-devices-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-05-review.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-05-order-submitted.png"
      ],
      "explanation": "The newly certified rep navigates to the bill-only form and is no longer blocked. The form is accessible and the order is submitted successfully, confirming that certification takes immediate effect.",
      "startedAt": "2026-09-29T02:27:05.940Z",
      "finishedAt": "2026-09-29T02:27:29.775Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/videos/step-05-billing-submitted.webm"
    },
    {
      "name": "Step 6: Order request after certification",
      "status": "pass",
      "description": "Step 6: Order request after certification",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-06-order-request-form-accessible.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-06-order-request-product.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-06-order-request-review.png",
        "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/step-06-order-request-submitted.png"
      ],
      "explanation": "The certified rep navigates to the standard order request form without the approval warning, then submits a consignment order end-to-end. A DB assertion subsequently confirms that a row was persisted to the `order_requests` table — proving the post-certification path is unlocked at the database level, not just the UI level.",
      "startedAt": "2026-09-29T02:28:07.880Z",
      "finishedAt": "2026-09-29T02:28:26.526Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/videos/step-06-order-request-submitted.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Rana relationship now active",
      "query": "SELECT id, status, active, responded_at, responded_by_user_id\n      FROM organization_representation_relationships\n      WHERE id = $1",
      "status": "pass",
      "rows": [
        {
          "id": "95d6e7f8-a9b0-1234-9012-345678901234",
          "status": "active",
          "active": true,
          "responded_at": null,
          "responded_by_user_id": null
        }
      ],
      "assertion": "Rana's representation relationship should be active after certification completion"
    },
    {
      "name": "Blair relationship still active (control)",
      "query": "SELECT id, status, active\n      FROM organization_representation_relationships\n      WHERE id = $1",
      "status": "pass",
      "rows": [
        {
          "id": "84c5d6e7-f8a9-0123-8901-234567890123",
          "status": "proposed_pending_onboarding",
          "active": true
        }
      ],
      "assertion": "Blair's relationship should remain `active = true` (the column the certification gate actually reads) and be unaffected by Rana's approval. The `status` string in this row is informational only and may read `proposed_pending_onboarding` from the seed data."
    },
    {
      "name": "Certification completion status change recorded",
      "query": "SELECT id, to_status, from_status, reason_code, changed_by_user_id, created_at\n      FROM organization_representation_request_status_changes\n      WHERE relationship_id = $1\n        AND created_at > NOW() - INTERVAL '30 minutes'\n      ORDER BY created_at DESC\n      LIMIT 5",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eafc-9a1a-7ced-b964-aee406836e38",
          "to_status": "active",
          "from_status": "pending_certification",
          "reason_code": "certification_completed",
          "changed_by_user_id": "28c9d0e1-f2a3-4567-2345-678901234567",
          "created_at": "2026-09-29T02:26:58.172Z"
        }
      ],
      "assertion": "A status change to 'active' with reason_code 'certification_completed' should be recorded in the history table"
    },
    {
      "name": "Rana's certification record created on completion",
      "query": "SELECT rep_user_id, certification_id, certification_version_id,\n        completed_at, signature_ref\n      FROM certification_records\n      WHERE rep_user_id = $1 AND certification_id = $2",
      "status": "pass",
      "rows": [
        {
          "rep_user_id": "28c9d0e1-f2a3-4567-2345-678901234567",
          "certification_id": "ce000100-0000-4000-8000-000000000001",
          "certification_version_id": "ce000200-0000-4000-8000-000000000002",
          "completed_at": "2026-09-29T02:26:58.181Z",
          "signature_ref": "01a0eafc-9a05-76de-8074-2067c5092048"
        }
      ],
      "assertion": "Exactly one certification record should exist for Rana, on the current version, with a completion timestamp and a signature reference"
    },
    {
      "name": "Bill-only order created by Rana after certification",
      "query": "SELECT bo.id, bo.order_number, bo.status, bo.created_at, bo.created_by_user_id\n      FROM billing_orders bo\n      WHERE bo.created_by_user_id = $1\n        AND bo.created_at > NOW() - INTERVAL '30 minutes'\n      ORDER BY bo.created_at DESC\n      LIMIT 5",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
          "order_number": "BO-1",
          "status": "submitted",
          "created_at": "2026-09-29T02:27:27.320Z",
          "created_by_user_id": "28c9d0e1-f2a3-4567-2345-678901234567"
        }
      ],
      "assertion": "At least one bill-only order should have been created by Rana after being certified"
    },
    {
      "name": "Order request created by Rana after certification",
      "query": "SELECT id, request_number, order_type, status, sales_account_id, notes, created_at\n      FROM order_requests\n      WHERE requested_by_user_id = $1\n        AND notes LIKE $2\n        AND created_at > NOW() - INTERVAL '30 minutes'\n      ORDER BY created_at DESC\n      LIMIT 5",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eafd-eacb-7a28-b19c-2d5dd0fa2596",
          "request_number": "OR-2",
          "order_type": "dropship",
          "status": "submitted",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "notes": "URS-055: post-certification order request",
          "created_at": "2026-09-29T02:28:24.367Z"
        }
      ],
      "assertion": "A standard order request should have been persisted by Rana after certification (Step 6) — tagged with the URS-055 notes marker"
    },
    {
      "name": "Audit trail for certification completion",
      "query": "SELECT ae.id, ae.event_type, ae.action, ae.created_at, ae.user_id, ae.object_id,\n        substring(ae.payload::text, 1, 500) as payload_preview\n      FROM audit_events ae\n      WHERE ae.created_at > NOW() - INTERVAL '30 minutes'\n        AND (ae.object_id = $1 OR ae.object_id = $2)\n      ORDER BY ae.created_at DESC\n      LIMIT 10",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eafc-9a1e-7c54-919b-96deb2953d4d",
          "event_type": "organization_representation",
          "action": "status_change",
          "created_at": "2026-09-29T02:26:58.172Z",
          "user_id": "28c9d0e1-f2a3-4567-2345-678901234567",
          "object_id": "95d6e7f8-a9b0-1234-9012-345678901234",
          "payload_preview": "{\"reason\": \"Certification completed\", \"toStatus\": \"active\", \"fromStatus\": \"pending_certification\", \"reasonCode\": \"certification_completed\", \"requestingOrganizationId\": \"b2c3d4e5-f6a7-8901-bcde-f12345678901\"}"
        },
        {
          "id": "01a0eafc-9a24-7566-a684-5c2d868c37d7",
          "event_type": "decision",
          "action": "certifications.complete_certification.mark_relationship_certified",
          "created_at": "2026-09-29T02:26:58.172Z",
          "user_id": "28c9d0e1-f2a3-4567-2345-678901234567",
          "object_id": "95d6e7f8-a9b0-1234-9012-345678901234",
          "payload_preview": "{\"reason\": \"relationship_pending_certification\", \"performed\": true, \"entityType\": \"organization_representation_relationship\"}"
        }
      ],
      "assertion": "Audit/decision events should exist referencing Rana or his relationship after the certification completion"
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z",
  "auditStartTime": "2026-09-29T02:25:13.558Z",
  "emailEvidence": [
    {
      "subject": "Your signing code for LiraLock Implant System Certification",
      "template": "Your_signing_code_for_LiraLock_Implant_System_Certification",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/emails/2026-09-29T02-26-45-021Z-Your_signing_code_for_LiraLock_Implant_System_Certification.png"
    },
    {
      "subject": "New Bill-Only Order - 9/28/2026 - Vantis BO-1",
      "template": "New_Bill-Only_Order_-_9_28_2026_-_Vantis_BO-1",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-055-uncertified-rep-restrictions/2026-09-29T02-25-14-883Z/screenshots/emails/2026-09-29T02-27-28-658Z-New_Bill-Only_Order_-_9_28_2026_-_Vantis_BO-1.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-09-29T02:25:23.451Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "rana.reyes@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:25:37.015Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "rana.reyes@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:25:48.707Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:26:39.848Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "rana.reyes@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:26:43.775Z",
      "eventType": "certification",
      "action": "signing_code_issued",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "ce000100-0000-4000-8000-000000000001",
      "secondaryObjectId": "01a0eafc-6225-7d53-8233-cb1833f8f9cd",
      "payload": {
        "expiresAt": "2026-10-13T02:26:43.877Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:43.775Z",
      "eventType": "decision",
      "action": "certifications.signing_challenge.send_sms",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-6225-7d53-8233-cb1833f8f9cd",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_phone_channel",
        "performed": false,
        "entityType": "certification_signing_challenge"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:45.072Z",
      "eventType": "transactional_email",
      "action": "certification_signing_code",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-6225-7d53-8233-cb1833f8f9cd",
      "secondaryObjectId": null,
      "payload": {
        "to": "rana.reyes@corvetasurgical.com",
        "s3Path": "email-audit/a1b2c3d4-e5f6-7890-abcd-ef1234567890/01a0eafc-66ab-7433-8bdd-f7769030622c/",
        "subject": "Your signing code for LiraLock Implant System Certification",
        "messageId": "dev-console-log",
        "relatedEntityType": "certification_signing_challenge"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:47.159Z",
      "eventType": "certification",
      "action": "signing_code_verified",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "ce000100-0000-4000-8000-000000000001",
      "secondaryObjectId": "01a0eafc-6225-7d53-8233-cb1833f8f9cd",
      "payload": {
        "signingWindowExpiresAt": "2026-09-29T06:26:47.162Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:54.167Z",
      "eventType": "decision",
      "action": "forms.grade_submission",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "ce000300-0000-4000-8000-000000000002",
      "secondaryObjectId": null,
      "payload": {
        "reason": "all_answers_correct",
        "stepId": "final",
        "performed": true,
        "entityType": "form_definition",
        "gradedCount": 3,
        "incorrectCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:58.172Z",
      "eventType": "certification",
      "action": "signing_code_consumed",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "ce000100-0000-4000-8000-000000000001",
      "secondaryObjectId": "01a0eafc-6225-7d53-8233-cb1833f8f9cd",
      "payload": {
        "signatureId": "01a0eafc-9a05-76de-8074-2067c5092048"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:58.172Z",
      "eventType": "decision",
      "action": "certifications.complete_certification.issue_certificate",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-9a05-76de-8074-2066a386833d",
      "secondaryObjectId": "01a0eafc-9a28-78a1-b912-357c24cfdb65",
      "payload": {
        "reason": "quiz_backed_completion",
        "performed": true,
        "entityType": "certification_record"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:58.172Z",
      "eventType": "decision",
      "action": "certifications.complete_certification.mark_relationship_certified",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "95d6e7f8-a9b0-1234-9012-345678901234",
      "secondaryObjectId": "01a0eafc-9a05-76de-8074-2066a386833d",
      "payload": {
        "reason": "relationship_pending_certification",
        "performed": true,
        "entityType": "organization_representation_relationship"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:58.172Z",
      "eventType": "organization_representation",
      "action": "status_change",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "95d6e7f8-a9b0-1234-9012-345678901234",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Certification completed",
        "toStatus": "active",
        "fromStatus": "pending_certification",
        "reasonCode": "certification_completed",
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:58.172Z",
      "eventType": "certification",
      "action": "completed",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-9a05-76de-8074-2066a386833d",
      "secondaryObjectId": "ce000100-0000-4000-8000-000000000001",
      "payload": {
        "repUserId": "28c9d0e1-f2a3-4567-2345-678901234567",
        "versionNumber": 2
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:58.218Z",
      "eventType": "user_log",
      "action": "rep_relationship_certified",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "reason": "Certification completed",
        "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
        "userName": "Rana Reyes",
        "userEmail": "rana.reyes@corvetasurgical.com",
        "relationshipId": "95d6e7f8-a9b0-1234-9012-345678901234",
        "distributorOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": "/onboarding/[orgshortname]/certification",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:26:59.728Z",
      "eventType": "certification_certificate",
      "action": "issued",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-9a28-78a1-b912-357c24cfdb65",
      "secondaryObjectId": "95d6e7f8-a9b0-1234-9012-345678901234",
      "payload": null,
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:59.919Z",
      "eventType": "certification_completion_record",
      "action": "issued",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-9a2b-708c-9bd8-16e676557758",
      "secondaryObjectId": "01a0eafc-9a05-76de-8074-2066a386833d",
      "payload": {
        "relationshipId": "95d6e7f8-a9b0-1234-9012-345678901234"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:01.248Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "rana.reyes@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:27:13.176Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "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:27:27.320Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:27.320Z",
      "eventType": "decision",
      "action": "bill_only_order.inventory_items_decrement",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "inventory_items_decremented",
        "itemCount": 1,
        "performed": true,
        "entityType": "billing_order",
        "hasCaseToteItems": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:27.320Z",
      "eventType": "decision",
      "action": "bill_only_order.direct_po_import_on_create",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "No uploaded PO documents",
        "performed": false,
        "entityType": "billing_order",
        "fileSourceOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "hasSelectedPurchaseOrderId": false,
        "purchaseOrderDocumentCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:27.320Z",
      "eventType": "billing_order",
      "action": "status_change",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:27.320Z",
      "eventType": "decision",
      "action": "basicErp.deriveSalesOrder",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:27.320Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-0c46-7466-8402-7d347ba2f96e",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-06T02:27:27.428Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:27.320Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-0c4a-7714-b545-9bcd8ac33a5f",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-13T02:27:27.428Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:27.320Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-0c4d-745e-a2e6-2d9ad2b546b9",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-20T02:27:27.428Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:27.320Z",
      "eventType": "decision",
      "action": "bill_only.link_purchase_order",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_purchase_order_selected",
        "performed": false,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:27.320Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "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:27:27.320Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:28.178Z",
      "eventType": "decision",
      "action": "bill_only.notifications.cc_incident_recipients",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
      "secondaryObjectId": null,
      "payload": {
        "reason": "order has no no-charge item with an incident reason",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:28.678Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafd-0c1b-770f-8f1c-80b4c85d3fb2",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "rana.reyes@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eafd-111a-7b72-92dd-474c0ab1a5d9/",
        "subject": "New Bill-Only Order - 9/28/2026 - Vantis BO-1",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:28:03.320Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "rana.reyes@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:28:24.367Z",
      "eventType": "decision",
      "action": "order_request_created",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-eacb-7a28-b19c-2d5dd0fa2596",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Order request OR-2 created (importSource=manual)",
        "priority": "normal",
        "itemCount": 1,
        "orderType": "dropship",
        "performed": true,
        "entityType": "order_request",
        "importSource": "manual",
        "requestNumber": "OR-2",
        "selfFulfilled": false,
        "resolvedLocationId": "6ea3b4c5-d6e7-8901-6789-012345678901",
        "resolvedSalesAccountId": "fea7b8c9-d0e1-2345-0123-456789012345",
        "fulfillingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:28:24.367Z",
      "eventType": "checklist",
      "action": "checklists.create",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafd-ead8-7ebf-ad80-4d4ed7ee4bfc",
      "secondaryObjectId": null,
      "payload": {
        "title": "Order OR-2",
        "source": {
          "type": "order_request",
          "orderRequestId": "01a0eafd-eacb-7a28-b19c-2d5dd0fa2596"
        }
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:28:24.367Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": "dropship",
        "performed": false,
        "entityType": "organization",
        "gatedAction": "order_request",
        "isOwnTrunkDestination": false,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "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 4: Rep completes certification",
      "expectedAction": "certification:completed",
      "found": true
    }
  ],
  "emailAssertions": []
}