{
  "id": "port11DiagnosticAssessment",
  "name": "Portfolio 11B - Diagnostic Assessment Mapping",
  "active": false,
  "nodes": [
    { "parameters": { "httpMethod": "POST", "path": "portfolio-diagnostic-assessment", "responseMode": "responseNode", "options": {} }, "webhookId": "d1120000-0000-4000-8000-000000000098", "id": "d1120000-0000-4000-8000-000000000001", "name": "Fillout Assessment Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [-1000, 0] },
    { "parameters": { "jsCode": "const i=$json.body??$json; const required=['providerEventId','caseKey','participantToken','answers','submittedAt']; const missing=required.filter(k=>i[k]===undefined||i[k]===null||i[k]===''); if(missing.length)return[{json:{valid:false,error:`Missing assessment fields: ${missing.join(', ')}`}}]; if(typeof i.answers!=='object'||Array.isArray(i.answers)||!Object.keys(i.answers).length)return[{json:{valid:false,error:'Assessment answers must be a non-empty object'}}]; const answers=Object.entries(i.answers).map(([questionKey,value])=>({questionKey,normalizedValue:Number.isFinite(Number(value))?Number(value):String(value)})); return[{json:{valid:true,providerEventId:String(i.providerEventId),caseKey:String(i.caseKey),participantToken:String(i.participantToken),submittedAt:String(i.submittedAt),answers,idempotencyKey:`diagnostic:assessment:${i.providerEventId}`}}];" }, "id": "d1120000-0000-4000-8000-000000000002", "name": "Normalize Assessment Rows", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [-780, 0] },
    { "parameters": { "conditions": { "options": { "caseSensitive": true, "typeValidation": "strict", "version": 2 }, "conditions": [{ "id": "d1120000-0000-4000-8000-000000000003", "leftValue": "={{ $json.valid }}", "rightValue": true, "operator": { "type": "boolean", "operation": "true", "singleValue": true } }], "combinator": "and" }, "options": {} }, "id": "d1120000-0000-4000-8000-000000000004", "name": "Valid Assessment?", "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [-560, 0] },
    { "parameters": { "method": "POST", "url": "http://127.0.0.1:8787/diagnostic/assessment", "sendBody": true, "contentType": "raw", "rawContentType": "application/json", "body": "={{ JSON.stringify($json) }}", "options": { "timeout": 10000 } }, "id": "d1120000-0000-4000-8000-000000000005", "name": "Store Submission and Answers", "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": "d1120000-0000-4000-8000-000000000006", "leftValue": "={{ Boolean($json.submissionId) }}", "rightValue": true, "operator": { "type": "boolean", "operation": "true", "singleValue": true } }], "combinator": "and" }, "options": {} }, "id": "d1120000-0000-4000-8000-000000000007", "name": "Submission 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-assessment',severity:'info',eventType:'assessment-stored',caseKey:$json.caseKey}) }}", "options": { "timeout": 10000 } }, "id": "d1120000-0000-4000-8000-000000000008", "name": "Write Assessment Log", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [160, -180] },
    { "parameters": { "respondWith": "json", "responseBody": "={{ JSON.stringify({ok:true,status:'assessment-stored',submission:$('Store Submission and Answers').item.json,logId:$json.logId}) }}", "options": { "responseCode": 200 } }, "id": "d1120000-0000-4000-8000-000000000009", "name": "Return Assessment Success", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.4, "position": [400, -180] },
    { "parameters": { "respondWith": "json", "responseBody": "={{ JSON.stringify({ok:false,status:'invalid-assessment',error:$json.error}) }}", "options": { "responseCode": 400 } }, "id": "d1120000-0000-4000-8000-000000000010", "name": "Return Invalid Assessment", "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 Assessment Rows').item.json.providerEventId,workflowKey:'diagnostic-assessment',error:'Assessment persistence failed after retries'}) }}", "options": { "timeout": 10000 } }, "id": "d1120000-0000-4000-8000-000000000011", "name": "Escalate Assessment Failure", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [160, 40] },
    { "parameters": { "respondWith": "json", "responseBody": "={{ JSON.stringify({ok:false,status:'assessment-service-unavailable',retryable:true,adminAlertId:$json.alertId}) }}", "options": { "responseCode": 503 } }, "id": "d1120000-0000-4000-8000-000000000012", "name": "Return Assessment Failure", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.4, "position": [400, 40] }
  ],
  "connections": {
    "Fillout Assessment Webhook": { "main": [[{ "node": "Normalize Assessment Rows", "type": "main", "index": 0 }]] },
    "Normalize Assessment Rows": { "main": [[{ "node": "Valid Assessment?", "type": "main", "index": 0 }]] },
    "Valid Assessment?": { "main": [[{ "node": "Store Submission and Answers", "type": "main", "index": 0 }], [{ "node": "Return Invalid Assessment", "type": "main", "index": 0 }]] },
    "Store Submission and Answers": { "main": [[{ "node": "Submission Stored?", "type": "main", "index": 0 }]] },
    "Submission Stored?": { "main": [[{ "node": "Write Assessment Log", "type": "main", "index": 0 }], [{ "node": "Escalate Assessment Failure", "type": "main", "index": 0 }]] },
    "Write Assessment Log": { "main": [[{ "node": "Return Assessment Success", "type": "main", "index": 0 }]] },
    "Escalate Assessment Failure": { "main": [[{ "node": "Return Assessment Failure", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }, "pinData": {}, "versionId": "d1120000-0000-4000-8000-000000000099", "meta": { "templateCredsSetupCompleted": true }, "tags": []
}
