{
  "id": "port11DiagnosticIntake",
  "name": "Portfolio 11A - Diagnostic Intake and Module Routing",
  "active": false,
  "nodes": [
    {
      "parameters": { "httpMethod": "POST", "path": "portfolio-diagnostic-intake", "responseMode": "responseNode", "options": {} },
      "webhookId": "d1110000-0000-4000-8000-000000000098",
      "id": "d1110000-0000-4000-8000-000000000001", "name": "Fillout Intake Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [-1000, 0]
    },
    {
      "parameters": { "jsCode": "const i=$json.body??$json; const required=['providerEventId','caseKey','organizationKey','organizationName','initiatorToken','requiredParticipants','answers','submittedAt']; const missing=required.filter(k=>i[k]===undefined||i[k]===null||i[k]===''); if(missing.length)return[{json:{valid:false,error:`Missing intake fields: ${missing.join(', ')}`}}]; const a=i.answers||{}; const modules=a.recent_change==='merger'?['architecture','alignment','culture']:(a.diagnostic_goal==='alignment'&&a.market_complexity==='high'?['alignment','portfolio']:(a.diagnostic_goal==='positioning'&&Number(a.brand_maturity)<=2?['foundation','positioning']:['foundation','alignment'])); return[{json:{valid:true,providerEventId:String(i.providerEventId),caseKey:String(i.caseKey),organizationKey:String(i.organizationKey),organizationName:String(i.organizationName),initiatorToken:String(i.initiatorToken),requiredParticipants:Number(i.requiredParticipants),submittedAt:String(i.submittedAt),answers:a,modules,idempotencyKey:`diagnostic:intake:${i.providerEventId}`}}];" },
      "id": "d1110000-0000-4000-8000-000000000002", "name": "Normalize and Route Intake", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [-780, 0]
    },
    {
      "parameters": { "conditions": { "options": { "caseSensitive": true, "typeValidation": "strict", "version": 2 }, "conditions": [{ "id": "d1110000-0000-4000-8000-000000000003", "leftValue": "={{ $json.valid }}", "rightValue": true, "operator": { "type": "boolean", "operation": "true", "singleValue": true } }], "combinator": "and" }, "options": {} },
      "id": "d1110000-0000-4000-8000-000000000004", "name": "Valid Intake?", "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [-560, 0]
    },
    {
      "parameters": { "method": "POST", "url": "http://127.0.0.1:8787/diagnostic/intake", "sendBody": true, "contentType": "raw", "rawContentType": "application/json", "body": "={{ JSON.stringify($json) }}", "options": { "timeout": 10000 } },
      "id": "d1110000-0000-4000-8000-000000000005", "name": "Upsert Case and Modules", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [-320, -100], "onError": "continueRegularOutput", "retryOnFail": true, "maxTries": 3, "waitBetweenTries": 1000
    },
    {
      "parameters": { "conditions": { "options": { "caseSensitive": true, "typeValidation": "strict", "version": 2 }, "conditions": [{ "id": "d1110000-0000-4000-8000-000000000006", "leftValue": "={{ Boolean($json.caseId) }}", "rightValue": true, "operator": { "type": "boolean", "operation": "true", "singleValue": true } }], "combinator": "and" }, "options": {} },
      "id": "d1110000-0000-4000-8000-000000000007", "name": "Case Stored?", "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [-80, -100]
    },
    {
      "parameters": { "method": "POST", "url": "http://127.0.0.1:8787/diagnostic/logs", "sendBody": true, "contentType": "raw", "rawContentType": "application/json", "body": "={{ JSON.stringify({correlationId:$json.providerEventId,workflowKey:'diagnostic-intake',severity:'info',eventType:'intake-stored',caseKey:$json.caseKey}) }}", "options": { "timeout": 10000 } },
      "id": "d1110000-0000-4000-8000-000000000008", "name": "Write Intake Log", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [160, -180]
    },
    {
      "parameters": { "respondWith": "json", "responseBody": "={{ JSON.stringify({ok:true,status:'intake-stored',case:$('Upsert Case and Modules').item.json,logId:$json.logId}) }}", "options": { "responseCode": 200 } },
      "id": "d1110000-0000-4000-8000-000000000009", "name": "Return Intake Success", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.4, "position": [400, -180]
    },
    {
      "parameters": { "respondWith": "json", "responseBody": "={{ JSON.stringify({ok:false,status:'invalid-intake',error:$json.error}) }}", "options": { "responseCode": 400 } },
      "id": "d1110000-0000-4000-8000-000000000010", "name": "Return Invalid Intake", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.4, "position": [-320, 180]
    },
    {
      "parameters": { "method": "POST", "url": "http://127.0.0.1:8787/diagnostic/admin-alerts", "sendBody": true, "contentType": "raw", "rawContentType": "application/json", "body": "={{ JSON.stringify({correlationId:$('Normalize and Route Intake').item.json.providerEventId,workflowKey:'diagnostic-intake',error:'Intake persistence failed after retries'}) }}", "options": { "timeout": 10000 } },
      "id": "d1110000-0000-4000-8000-000000000011", "name": "Escalate Intake Failure", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [160, 40]
    },
    {
      "parameters": { "respondWith": "json", "responseBody": "={{ JSON.stringify({ok:false,status:'intake-service-unavailable',retryable:true,adminAlertId:$json.alertId}) }}", "options": { "responseCode": 503 } },
      "id": "d1110000-0000-4000-8000-000000000012", "name": "Return Intake Failure", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.4, "position": [400, 40]
    }
  ],
  "connections": {
    "Fillout Intake Webhook": { "main": [[{ "node": "Normalize and Route Intake", "type": "main", "index": 0 }]] },
    "Normalize and Route Intake": { "main": [[{ "node": "Valid Intake?", "type": "main", "index": 0 }]] },
    "Valid Intake?": { "main": [[{ "node": "Upsert Case and Modules", "type": "main", "index": 0 }], [{ "node": "Return Invalid Intake", "type": "main", "index": 0 }]] },
    "Upsert Case and Modules": { "main": [[{ "node": "Case Stored?", "type": "main", "index": 0 }]] },
    "Case Stored?": { "main": [[{ "node": "Write Intake Log", "type": "main", "index": 0 }], [{ "node": "Escalate Intake Failure", "type": "main", "index": 0 }]] },
    "Write Intake Log": { "main": [[{ "node": "Return Intake Success", "type": "main", "index": 0 }]] },
    "Escalate Intake Failure": { "main": [[{ "node": "Return Intake Failure", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }, "pinData": {}, "versionId": "d1110000-0000-4000-8000-000000000099", "meta": { "templateCredsSetupCompleted": true }, "tags": []
}
