{
  "ursId": "URS-005",
  "title": "Prevent Uncertified Reps from Creating Orders",
  "timestamp": "2026-09-29T02:31:01.775Z",
  "durationMs": 90091,
  "config": {
    "inboxUrl": "http://localhost:39399",
    "dbHost": "localhost",
    "dbPort": 41629,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Uncertified rep blocked",
      "status": "pass",
      "description": "Step 1: Uncertified rep blocked",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-01-ryan-logged-in.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-01-order-blocked.png"
      ],
      "explanation": "Proves the system correctly prevents a representative who has not completed the manufacturer's required certification from creating orders. Rana Reyes is in pending certification, so the bill-only order creation form displays a \"Certification required\" notice with a link to complete the certification, and the gated manufacturer is absent from the manufacturer picker. The same block appears on both the /billing/new and /orders/requests/new routes, confirming the enforcement is applied consistently across order entry points.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-09-29T02:31:08.730Z",
      "finishedAt": "2026-09-29T02:31:14.483Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/videos/step-01-uncertified-blocked.webm"
    },
    {
      "name": "Step 1: Trunk order requests allowed while pending",
      "status": "pass",
      "description": "Step 1: Trunk order requests allowed while pending",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-01-order-request-trunk-allowed.png"
      ],
      "startedAt": "2026-09-29T02:31:19.966Z",
      "finishedAt": "2026-09-29T02:31:19.966Z"
    },
    {
      "name": "Step 2: Certified rep control",
      "status": "pass",
      "description": "Step 2: Certified rep control",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-02-bob-logged-in.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-02-order-form-accessible.png"
      ],
      "explanation": "Control condition confirming that the blocking behavior is targeted at uncertified reps only. Blair Bennett, whose representation relationship is active, can access the order creation form without any certification notice. The form auto-advances to Step 2 with Vantis pre-selected. This eliminates the possibility that the block in Step 1 is a general UI defect.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-09-29T02:31:25.740Z",
      "finishedAt": "2026-09-29T02:31:32.205Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/videos/step-02-certified-control.webm"
    },
    {
      "name": "Step 3: Rep completes certification",
      "status": "pass",
      "description": "Step 3: Rep completes certification",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-03-identity-verified.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-03-doc-acknowledged.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-03-quiz-answers.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-03-signature.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-03-completed.png"
      ],
      "explanation": "Rana 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 the order gate.",
      "expectedAuditActions": [
        "certification:completed"
      ],
      "startedAt": "2026-09-29T02:31:44.403Z",
      "finishedAt": "2026-09-29T02:31:55.853Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/videos/step-03-rep-certification.webm"
    },
    {
      "name": "Step 4: Certified order creation",
      "status": "pass",
      "description": "Step 4: Certified order creation",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-04-ryan-logged-in-certified.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-04-form-accessible.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-04-account-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-04-devices-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-04-documents.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-04-review.png",
        "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/step-04-order-submitted.png"
      ],
      "explanation": "Validates that the now-certified representative can create and submit a bill-only order without restriction. Rana logs in after completing the certification, accesses /billing/new without any certification notice, selects an account, adds a product with lot number, and successfully submits the order. The system redirects to /billing, confirming the gate is lifted immediately on certification completion.",
      "expectedEmailTemplates": [
        "New Bill-Only Order"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.direct_po_import_on_create"
      ],
      "startedAt": "2026-09-29T02:32:00.426Z",
      "finishedAt": "2026-09-29T02:32:30.289Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/videos/step-04-certified-order.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 active flag should remain true and unaffected by Rana's approval flow"
    },
    {
      "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": "01a0eb01-2461-72de-a98d-202156dbbd38",
          "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:31:55.713Z"
        }
      ],
      "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:31:55.723Z",
          "signature_ref": "01a0eb01-244b-70e8-9963-4952b5bf708e"
        }
      ],
      "assertion": "Exactly one certification record should exist for Rana, on the current version, with a completion timestamp and a signature reference"
    },
    {
      "name": "Billing 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": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
          "order_number": "BO-1",
          "status": "submitted",
          "created_at": "2026-09-29T02:32:26.491Z",
          "created_by_user_id": "28c9d0e1-f2a3-4567-2345-678901234567"
        }
      ],
      "assertion": "At least one billing order should have been created by Rana after being certified"
    },
    {
      "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": "01a0eb01-2463-7069-9cbf-6cf121250d28",
          "event_type": "organization_representation",
          "action": "status_change",
          "created_at": "2026-09-29T02:31:55.713Z",
          "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": "01a0eb01-2469-7de8-b2ae-b2979caaec1a",
          "event_type": "decision",
          "action": "certifications.complete_certification.mark_relationship_certified",
          "created_at": "2026-09-29T02:31:55.713Z",
          "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-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z",
  "auditStartTime": "2026-09-29T02:31:00.048Z",
  "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-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/emails/2026-09-29T02-31-41-375Z-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-005-uncertified-rep-orders/2026-09-29T02-31-01-774Z/screenshots/emails/2026-09-29T02-32-29-054Z-New_Bill-Only_Order_-_9_28_2026_-_Vantis_BO-1.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-09-29T02:31:06.603Z",
      "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:31:23.940Z",
      "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:36.377Z",
      "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:31:40.738Z",
      "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": "01a0eb00-ea64-7719-8e9b-e116ce70acd9",
      "payload": {
        "expiresAt": "2026-10-13T02:31:40.899Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:40.738Z",
      "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": "01a0eb00-ea64-7719-8e9b-e116ce70acd9",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_phone_channel",
        "performed": false,
        "entityType": "certification_signing_challenge"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:41.464Z",
      "eventType": "transactional_email",
      "action": "certification_signing_code",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-ea64-7719-8e9b-e116ce70acd9",
      "secondaryObjectId": null,
      "payload": {
        "to": "rana.reyes@corvetasurgical.com",
        "s3Path": "email-audit/a1b2c3d4-e5f6-7890-abcd-ef1234567890/01a0eb00-ec56-7c8a-97ba-a7f1f45e374e/",
        "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:31:44.312Z",
      "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": "01a0eb00-ea64-7719-8e9b-e116ce70acd9",
      "payload": {
        "signingWindowExpiresAt": "2026-09-29T06:31:44.316Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:51.662Z",
      "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:31:55.713Z",
      "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": "01a0eb01-244b-70e8-9963-49514e13bfe6",
      "secondaryObjectId": "01a0eb01-246d-71af-a685-d5da18aa74d2",
      "payload": {
        "reason": "quiz_backed_completion",
        "performed": true,
        "entityType": "certification_record"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:55.713Z",
      "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": "01a0eb00-ea64-7719-8e9b-e116ce70acd9",
      "payload": {
        "signatureId": "01a0eb01-244b-70e8-9963-4952b5bf708e"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:55.713Z",
      "eventType": "certification",
      "action": "completed",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-244b-70e8-9963-49514e13bfe6",
      "secondaryObjectId": "ce000100-0000-4000-8000-000000000001",
      "payload": {
        "repUserId": "28c9d0e1-f2a3-4567-2345-678901234567",
        "versionNumber": 2
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:55.713Z",
      "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:31:55.713Z",
      "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": "01a0eb01-244b-70e8-9963-49514e13bfe6",
      "payload": {
        "reason": "relationship_pending_certification",
        "performed": true,
        "entityType": "organization_representation_relationship"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:55.758Z",
      "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:31:56.225Z",
      "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": "01a0eb01-246d-71af-a685-d5da18aa74d2",
      "secondaryObjectId": "95d6e7f8-a9b0-1234-9012-345678901234",
      "payload": null,
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:56.235Z",
      "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": "01a0eb01-2471-742e-9c95-f78d31cb017a",
      "secondaryObjectId": "01a0eb01-244b-70e8-9963-49514e13bfe6",
      "payload": {
        "relationshipId": "95d6e7f8-a9b0-1234-9012-345678901234"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:58.863Z",
      "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:32:12.285Z",
      "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:32:26.491Z",
      "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": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
      "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:26.491Z",
      "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:32:26.491Z",
      "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:32:26.491Z",
      "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": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
      "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:26.491Z",
      "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:32:26.491Z",
      "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": "01a0eb01-9ced-7f15-9d8b-dbde3f953072",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-20T02:32:26.596Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.491Z",
      "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": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.491Z",
      "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": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.491Z",
      "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": "01a0eb01-9ce5-735d-9aba-1bcae783afa6",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-06T02:32:26.596Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.491Z",
      "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": "01a0eb01-9cea-7cda-a04e-d84a932b0ac7",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-13T02:32:26.596Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:26.491Z",
      "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": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
      "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:28.575Z",
      "eventType": "decision",
      "action": "bill_only.notifications.cc_incident_recipients",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
      "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:29.075Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb01-9cc1-7f8c-a57c-d51d8d4d62f9",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "rana.reyes@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eb01-a686-7e6c-8415-a8a4e669f29a/",
        "subject": "New Bill-Only Order - 9/28/2026 - Vantis BO-1",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    }
  ],
  "auditQuery": "SELECT\n    ae.created_at,\n    ae.event_type,\n    ae.action,\n    ae.user_id,\n    u.email AS user_email,\n    ae.organization_id,\n    o.name AS organization_name,\n    ae.object_id,\n    ae.secondary_object_id,\n    ae.payload,\n    ae.route,\n    ae.trace_id\n  FROM audit_events ae\n  LEFT JOIN users u ON u.id = ae.user_id\n  LEFT JOIN organizations o ON o.id = ae.organization_id\n  WHERE ae.created_at >= $1\n    AND ae.organization_id = ANY($2::uuid[])\n  ORDER BY ae.created_at ASC",
  "auditAssertions": [
    {
      "stepName": "Step 1: Uncertified rep blocked",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 2: Certified rep control",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 3: Rep completes certification",
      "expectedAction": "certification:completed",
      "found": true
    },
    {
      "stepName": "Step 4: Certified order creation",
      "expectedAction": "decision:bill_only_order.direct_po_import_on_create",
      "found": true
    }
  ],
  "emailAssertions": [
    {
      "stepName": "Step 4: Certified order creation",
      "expectedTemplate": "New Bill-Only Order",
      "found": true
    }
  ]
}