AutomationFlowsAI & RAG › Predictive Health Monitoring & Alert System with Gpt-4o-mini

Predictive Health Monitoring & Alert System with Gpt-4o-mini

ByCheng Siong Chin @cschin on n8n.io

The system collects real-time wearable health data, normalizes it, and uses AI to analyze trends and risk scores. It detects anomalies by comparing with historical patterns and automatically triggers alerts and follow-up actions when thresholds are exceeded. Configure Webhook

Webhook trigger★★★★☆ complexityAI-powered26 nodesPostgresAgentOpenAI ChatEmail SendTwilioMongoDBHTTP RequestSlack
AI & RAG Trigger: Webhook Nodes: 26 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #10457 — we link there as the canonical source.

This workflow follows the Agent → Emailsend recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "EmWzr179H1gbzeK6",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI-GPT-4o-mini Powered Predictive Health Monitoring & Alert System",
  "tags": [],
  "nodes": [
    {
      "id": "0c2ded10-be6c-49be-b328-57581a01abf4",
      "name": "Webhook - Health Data Input",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -272,
        1216
      ],
      "parameters": {
        "path": "health-data",
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "5d24fe84-e6a7-40bf-a749-6752838cb715",
      "name": "Normalize Health Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -80,
        1216
      ],
      "parameters": {
        "mode": "raw"
      },
      "typeVersion": 2
    },
    {
      "id": "a60b0cae-2d85-4c93-8bdc-b819a44d9f77",
      "name": "Store in Database",
      "type": "n8n-nodes-base.postgres",
      "position": [
        144,
        1024
      ],
      "parameters": {
        "table": "health_records",
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "c3d5aa03-7d91-416c-9720-d0ca8c7504cf",
      "name": "Get Recent History",
      "type": "n8n-nodes-base.postgres",
      "position": [
        144,
        1408
      ],
      "parameters": {
        "query": "SELECT * FROM health_records ORDER BY timestamp DESC LIMIT 30",
        "options": {},
        "operation": "executeQuery"
      },
      "typeVersion": 2
    },
    {
      "id": "a90be109-549c-4cd8-a668-d0354a5c7022",
      "name": "Analyze Health Metrics",
      "type": "n8n-nodes-base.code",
      "position": [
        368,
        1408
      ],
      "parameters": {
        "jsCode": "const currentData = $input.first().json;\nconst historicalData = $input.all().map(item => item.json);\n\n// Calculate averages from last 7 days\nconst last7Days = historicalData.slice(0, 7);\nconst avgHeartRate = last7Days.reduce((sum, d) => sum + parseFloat(d.heart_rate || 0), 0) / last7Days.length;\nconst avgBPSystolic = last7Days.reduce((sum, d) => sum + parseFloat(d.bp_systolic || 0), 0) / last7Days.length;\nconst avgBPDiastolic = last7Days.reduce((sum, d) => sum + parseFloat(d.bp_diastolic || 0), 0) / last7Days.length;\nconst avgSleep = last7Days.reduce((sum, d) => sum + parseFloat(d.sleep_hours || 0), 0) / last7Days.length;\n\n// Health analysis flags\nconst alerts = [];\nlet riskLevel = 'normal';\n\n// Heart rate analysis\nif (currentData.heart_rate > 100 || currentData.heart_rate < 60) {\n  alerts.push(`Heart rate abnormal: ${currentData.heart_rate} bpm`);\n  riskLevel = 'warning';\n}\n\n// Blood pressure analysis\nif (currentData.bp_systolic > 140 || currentData.bp_diastolic > 90) {\n  alerts.push(`High blood pressure: ${currentData.bp_systolic}/${currentData.bp_diastolic}`);\n  riskLevel = 'critical';\n}\nif (currentData.bp_systolic < 90 || currentData.bp_diastolic < 60) {\n  alerts.push(`Low blood pressure: ${currentData.bp_systolic}/${currentData.bp_diastolic}`);\n  riskLevel = 'warning';\n}\n\n// Temperature analysis\nif (currentData.temperature > 38.0) {\n  alerts.push(`Elevated temperature: ${currentData.temperature}\u00b0C`);\n  riskLevel = 'critical';\n}\n\n// Sleep analysis\nif (avgSleep < 6) {\n  alerts.push(`Insufficient sleep average: ${avgSleep.toFixed(1)} hours`);\n  if (riskLevel === 'normal') riskLevel = 'warning';\n}\n\n// Symptoms check\nif (currentData.symptoms && currentData.symptoms !== 'none') {\n  alerts.push(`Reported symptoms: ${currentData.symptoms}`);\n  if (riskLevel === 'normal') riskLevel = 'warning';\n}\n\nconst needsDoctorVisit = riskLevel === 'critical' || alerts.length >= 3;\n\nreturn {\n  currentData,\n  analysis: {\n    alerts,\n    riskLevel,\n    needsDoctorVisit,\n    averages: {\n      heartRate: avgHeartRate.toFixed(1),\n      bloodPressure: `${avgBPSystolic.toFixed(0)}/${avgBPDiastolic.toFixed(0)}`,\n      sleep: avgSleep.toFixed(1)\n    },\n    trend: {\n      heartRateChange: ((currentData.heart_rate - avgHeartRate) / avgHeartRate * 100).toFixed(1),\n      sleepChange: ((currentData.sleep_hours - avgSleep) / avgSleep * 100).toFixed(1)\n    }\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "06be0728-a5de-429e-80c4-162f63e9f050",
      "name": "Check If Doctor Visit Needed",
      "type": "n8n-nodes-base.if",
      "position": [
        1024,
        1216
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "doctor-alert-condition",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.analysis.needsDoctorVisit }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "0055cd07-1fe3-4482-bd1c-49845434ffa7",
      "name": "Generate Health Report",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1232,
        944
      ],
      "parameters": {
        "text": "=You are an advanced medical health advisor AI with access to comprehensive patient data. Generate a detailed, personalized health report.\n\n**PATIENT PROFILE:**\n- Name: {{$json.currentData.patient_name}}\n- Patient ID: {{$json.currentData.patient_id}}\n- Data Confidence: {{$json.currentData.data_confidence}}\n\n**CURRENT VITAL SIGNS:**\n- Health Score: {{$json.healthScore.score}}/100 (Grade: {{$json.healthScore.grade}})\n- Heart Rate: {{$json.currentData.heart_rate}} bpm\n- Blood Pressure: {{$json.currentData.bp_systolic}}/{{$json.currentData.bp_diastolic}} mmHg\n- Temperature: {{$json.currentData.temperature}}\u00b0C\n- Blood Oxygen: {{$json.currentData.blood_oxygen}}%\n- Weight: {{$json.currentData.weight}} kg\n\n**LIFESTYLE METRICS:**\n- Sleep: {{$json.currentData.sleep_hours}} hours\n- Steps: {{$json.currentData.steps_count}}\n- Exercise: {{$json.currentData.exercise_minutes}} minutes\n- Hydration: {{$json.currentData.hydration_ml}} ml\n- Stress Level: {{$json.currentData.stress_level}}/10\n- Mood Rating: {{$json.currentData.mood_rating}}/10\n- Medication Adherence: {{$json.currentData.medication_taken ? 'Yes' : 'No'}}\n\n**7-DAY AVERAGES:**\n- Heart Rate: {{$json.analysis.averages.heartRate}} bpm\n- Blood Pressure: {{$json.analysis.averages.bloodPressure}} mmHg\n- Sleep: {{$json.analysis.averages.sleep}} hours\n\n**WEEKLY COMPARISON:**\n{{$json.weeklyComparison.available ? `- Heart Rate Trend: ${$json.weeklyComparison.heartRateChange}%\n- Sleep Trend: ${$json.weeklyComparison.sleepChange}%\n- Overall Trajectory: ${$json.weeklyComparison.trend}\n- Key Insights: ${$json.weeklyComparison.insights.join('; ')}` : 'Baseline week - no comparison data available'}}\n\n**HEALTH SCORE BREAKDOWN:**\n- Cardiovascular: {{$json.healthScore.breakdown.cardiovascular}}/100\n- Rest Quality: {{$json.healthScore.breakdown.rest}}/100\n- Activity Level: {{$json.healthScore.breakdown.activity}}/100\n- Vital Signs: {{$json.healthScore.breakdown.vitals}}/100\n\n**ACTIVE ALERTS ({{$json.analysis.alerts.length}}):**\n{{$json.analysis.alerts.join('\\n')}}\n\n**RISK ASSESSMENT:**\n- Current Risk Level: {{$json.analysis.riskLevel}}\n- Doctor Visit Needed: {{$json.analysis.needsDoctorVisit ? 'YES - URGENT' : 'NO'}}\n- Recommendation: {{$json.healthScore.recommendation}}\n\n**SYMPTOMS REPORTED:**\n{{$json.currentData.symptoms}}\n\n**VALIDATION NOTES:**\n{{$json.currentData.validation_warnings.length > 0 ? $json.currentData.validation_warnings.join('; ') : 'All readings within expected ranges'}}\n\n---\n\n**REQUIRED REPORT SECTIONS:**\n1. **Executive Health Summary** (2-3 sentences)\n2. **Detailed Metrics Analysis** (explain each concerning reading)\n3. **Week-over-Week Progress Assessment**\n4. **Lifestyle Recommendations** (sleep, exercise, nutrition, stress management)\n5. **Medical Action Plan** (urgency level, specific next steps)\n6. **Preventive Health Strategies** (long-term wellness goals)\n7. **Risk Mitigation Plan** (if applicable)\n8. **Mental Health Considerations** (based on stress/mood data)\n9. **Medication Compliance Assessment**\n10. **Follow-up Timeline** (when to reassess)\n\nProvide evidence-based, compassionate, and actionable guidance. Use clear medical terminology with explanations. Prioritize patient safety and wellbeing.",
        "options": {
          "systemMessage": "You are a health analytics AI assistant specialized in interpreting vital signs and health metrics. Provide evidence-based recommendations while emphasizing the importance of professional medical consultation for serious concerns."
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "ef5be657-a1d3-40c4-b54d-19bae5a8509a",
      "name": "OpenAI GPT-4",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1232,
        1184
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0426db19-e07c-4bcc-b48d-905edf59e74f",
      "name": "Send Health Report Email",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1504,
        1072
      ],
      "parameters": {
        "text": "=\ud83d\udcca *COMPREHENSIVE HEALTH REPORT*\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n*Patient:* {{$('Webhook - Health Data Input').item.json.patient_name}}\n*Report Date:* {{DateTime.now().toFormat('MMMM dd, yyyy - HH:mm')}}\n*Health Score:* {{$('Calculate Health Score').item.json.healthScore.score}}/100 ({{$('Calculate Health Score').item.json.healthScore.grade}})\n*Risk Level:* {{$('Calculate Health Score').item.json.analysis.riskLevel.toUpperCase()}}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n*AI-GENERATED HEALTH ANALYSIS*\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n{{$('Generate Health Report').item.json.output}}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n*PREDICTIVE HEALTH INSIGHTS*\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n{{$('AI Predictive Health Agent').item.json.output}}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n*QUICK REFERENCE - CURRENT VITALS*\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n\ud83d\udc93 Heart Rate: {{$('Webhook - Health Data Input').item.json.heart_rate}} bpm\n\ud83e\ude7a Blood Pressure: {{$('Webhook - Health Data Input').item.json.bp_systolic}}/{{$('Webhook - Health Data Input').item.json.bp_diastolic}} mmHg\n\ud83c\udf21\ufe0f Temperature: {{$('Webhook - Health Data Input').item.json.temperature}}\u00b0C\n\ud83d\ude34 Sleep: {{$('Webhook - Health Data Input').item.json.sleep_hours}} hours\n\ud83d\udeb6 Steps: {{$('Webhook - Health Data Input').item.json.steps_count}}\n\ud83d\udca7 Hydration: {{$('Webhook - Health Data Input').item.json.hydration_ml}} ml\n\ud83c\udfcb\ufe0f Exercise: {{$('Webhook - Health Data Input').item.json.exercise_minutes}} min\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n{{$('Calculate Health Score').item.json.analysis.needsDoctorVisit ? '\u26a0\ufe0f *IMPORTANT:* This report indicates you should schedule a doctor visit. Please take action promptly.' : '\u2705 Your health metrics are being monitored. Continue your current wellness routine.'}}\n\n*Disclaimer:* This is an automated health analysis tool. Always consult with qualified healthcare professionals for medical decisions.\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\nGenerated by AI Health Monitoring System",
        "options": {},
        "subject": "=\ud83c\udfe5 Health Index Update - {{ $('Check If Doctor Visit Needed').item.json.analysis.needsDoctorVisit ? '\u26a0\ufe0f DOCTOR VISIT RECOMMENDED' : '\u2705 Status Normal' }}",
        "toEmail": "={{ $('Webhook - Health Data Input').item.json.email || 'your-email@example.com' }}",
        "fromEmail": "user@example.com"
      },
      "typeVersion": 2
    },
    {
      "id": "1122c278-79e4-40f5-81ca-f0ae59075067",
      "name": "Send Urgent Doctor Alert",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1680,
        1072
      ],
      "parameters": {
        "text": "=\ud83d\udea8 *URGENT HEALTH ALERT - DOCTOR VISIT REQUIRED* \ud83d\udea8\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n*Patient:* {{$('Webhook - Health Data Input').item.json.patient_name}}\n*Alert Time:* {{DateTime.now().toFormat('MMMM dd, yyyy - HH:mm')}}\n*Health Score:* {{$('Calculate Health Score').item.json.healthScore.score}}/100 ({{$('Calculate Health Score').item.json.healthScore.grade}})\n*Risk Level:* {{$('Calculate Health Score').item.json.analysis.riskLevel.toUpperCase()}}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n*CRITICAL ALERTS DETECTED ({{$('Calculate Health Score').item.json.analysis.alerts.length}})*\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n{{$('Calculate Health Score').item.json.analysis.alerts.map((alert, i) => `${i + 1}. ${alert}`).join('\\n')}}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n*IMMEDIATE ACTION REQUIRED*\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n\u2705 NEXT STEPS:\n1. Schedule doctor appointment within {{$('Calculate Health Score').item.json.healthScore.score < 50 ? '24 hours' : '48 hours'}}\n2. Monitor symptoms closely\n3. Keep this report for your physician\n4. If symptoms worsen, seek emergency care immediately\n\n\u2695\ufe0f RECOMMENDATION:\n{{$('Calculate Health Score').item.json.healthScore.recommendation}}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n*CURRENT VITAL SIGNS*\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n\ud83d\udc93 Heart Rate: {{$('Webhook - Health Data Input').item.json.heart_rate}} bpm (7-day avg: {{$('Calculate Health Score').item.json.analysis.averages.heartRate}})\n\ud83e\ude7a Blood Pressure: {{$('Webhook - Health Data Input').item.json.bp_systolic}}/{{$('Webhook - Health Data Input').item.json.bp_diastolic}} mmHg (7-day avg: {{$('Calculate Health Score').item.json.analysis.averages.bloodPressure}})\n\ud83c\udf21\ufe0f Temperature: {{$('Webhook - Health Data Input').item.json.temperature}}\u00b0C\n\ud83e\ude78 Blood Oxygen: {{$('Webhook - Health Data Input').item.json.blood_oxygen}}%\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n\u26a0\ufe0f *DO NOT IGNORE THIS ALERT*\n\nYour health monitoring system has detected metrics requiring medical evaluation. This automated alert is designed to help you take timely action.\n\n\ud83d\udcde Emergency Contact: {{$('Webhook - Health Data Input').item.json.emergency_contact_phone || 'Not provided'}}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n*Disclaimer:* This is an automated health monitoring alert. Always use your judgment and seek emergency services (911) if you feel your situation is life-threatening.\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",
        "options": {},
        "subject": "\ud83d\udea8 URGENT: Doctor Visit Recommended - Health Alert",
        "toEmail": "={{ $('Webhook - Health Data Input').item.json.email || 'your-email@example.com' }}",
        "fromEmail": "user@example.com"
      },
      "typeVersion": 2
    },
    {
      "id": "f68c6a66-b9ec-495f-a518-8b6b03055e45",
      "name": "No Action Needed",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1376,
        1360
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "4a48c63d-7880-4b3e-8eac-6041aab8083b",
      "name": "Emergency Contact SMS Alert",
      "type": "n8n-nodes-base.twilio",
      "position": [
        1024,
        1408
      ],
      "parameters": {
        "to": "={{$json.emergency_contact_phone}}",
        "from": "={{$env.TWILIO_PHONE_NUMBER}}",
        "message": "=\ud83d\udea8 URGENT HEALTH ALERT\n\nPatient: {{$('Webhook - Health Data Input').item.json.patient_name}}\nCritical metrics detected:\n{{$json.analysis.alerts.join('\\n')}}\n\nRisk Level: {{$json.analysis.riskLevel}}\nImmediate medical attention recommended.\n\nView full report: {{$json.reportUrl}}",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "b68af135-b329-4f4c-9622-85313522c5b0",
      "name": "Log to MongoDB Health History",
      "type": "n8n-nodes-base.mongoDb",
      "position": [
        368,
        1024
      ],
      "parameters": {
        "fields": "patient_id,timestamp,metrics,analysis,ai_report,action_taken",
        "options": {},
        "operation": "insert",
        "collection": "health_analytics"
      },
      "typeVersion": 1
    },
    {
      "id": "282eda5f-b9bb-4694-959c-e49129061e85",
      "name": "Calculate Health Score",
      "type": "n8n-nodes-base.code",
      "position": [
        512,
        1232
      ],
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst current = data.currentData;\nconst analysis = data.analysis;\n\n// Weighted health scoring algorithm (0-100)\nlet healthScore = 100;\n\n// Heart rate scoring (-20 to 0)\nconst hrDiff = Math.abs(current.heart_rate - 75);\nif (hrDiff > 25) healthScore -= 20;\nelse if (hrDiff > 15) healthScore -= 10;\nelse if (hrDiff > 5) healthScore -= 5;\n\n// Blood pressure scoring (-25 to 0)\nconst bpSystolic = parseFloat(current.bp_systolic);\nconst bpDiastolic = parseFloat(current.bp_diastolic);\nif (bpSystolic > 140 || bpDiastolic > 90) healthScore -= 25;\nelse if (bpSystolic > 130 || bpDiastolic > 85) healthScore -= 15;\nelse if (bpSystolic < 90 || bpDiastolic < 60) healthScore -= 20;\nelse if (bpSystolic > 120 || bpDiastolic > 80) healthScore -= 8;\n\n// Temperature scoring (-15 to 0)\nconst temp = parseFloat(current.temperature);\nif (temp > 38.5) healthScore -= 15;\nelse if (temp > 37.5) healthScore -= 8;\nelse if (temp < 36.0) healthScore -= 10;\n\n// Sleep scoring (-15 to 0)\nconst sleep = parseFloat(current.sleep_hours);\nif (sleep < 5) healthScore -= 15;\nelse if (sleep < 6) healthScore -= 10;\nelse if (sleep < 7) healthScore -= 5;\nelse if (sleep > 10) healthScore -= 5;\n\n// Activity scoring (-15 to 0)\nconst steps = parseInt(current.steps_count);\nif (steps < 3000) healthScore -= 15;\nelse if (steps < 5000) healthScore -= 10;\nelse if (steps < 7000) healthScore -= 5;\n\n// Symptoms scoring (-10 to 0)\nif (current.symptoms && current.symptoms !== 'none') {\n  const symptomSeverity = (current.symptoms.match(/severe|intense|extreme/i)) ? 10 : 5;\n  healthScore -= symptomSeverity;\n}\n\n// Ensure score stays within 0-100\nhealthScore = Math.max(0, Math.min(100, healthScore));\n\n// Determine health grade\nlet grade, recommendation;\nif (healthScore >= 90) {\n  grade = 'A+ Excellent';\n  recommendation = 'Maintain current healthy lifestyle';\n} else if (healthScore >= 80) {\n  grade = 'A Good';\n  recommendation = 'Minor improvements recommended';\n} else if (healthScore >= 70) {\n  grade = 'B Fair';\n  recommendation = 'Focus on sleep and exercise';\n} else if (healthScore >= 60) {\n  grade = 'C Concerning';\n  recommendation = 'Medical consultation advised within 1 week';\n} else if (healthScore >= 50) {\n  grade = 'D Poor';\n  recommendation = 'Schedule doctor appointment within 48 hours';\n} else {\n  grade = 'F Critical';\n  recommendation = 'URGENT: Seek immediate medical attention';\n}\n\nreturn {\n  ...data,\n  healthScore: {\n    score: healthScore,\n    grade: grade,\n    recommendation: recommendation,\n    breakdown: {\n      cardiovascular: Math.max(0, 100 - (hrDiff * 2) - ((bpSystolic > 140) ? 25 : 0)),\n      rest: Math.max(0, 100 - ((sleep < 7) ? (7 - sleep) * 10 : 0)),\n      activity: Math.max(0, 100 - ((steps < 7000) ? ((7000 - steps) / 70) : 0)),\n      vitals: Math.max(0, 100 - ((temp > 37.5) ? (temp - 37.5) * 20 : 0))\n    },\n    timestamp: new Date().toISOString()\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "4dfe63c1-f787-4aae-af1e-85171df75654",
      "name": "Compare with Previous Week",
      "type": "n8n-nodes-base.code",
      "position": [
        736,
        896
      ],
      "parameters": {
        "jsCode": "const currentData = $input.first().json;\nconst historicalData = $input.all().map(item => item.json);\n\n// Get data from 7 days ago (assuming daily records)\nconst previousWeek = historicalData.slice(7, 14);\nif (previousWeek.length === 0) {\n  return { ...currentData, weeklyComparison: { available: false } };\n}\n\n// Calculate previous week averages\nconst prevAvgHR = previousWeek.reduce((sum, d) => sum + parseFloat(d.heart_rate || 0), 0) / previousWeek.length;\nconst prevAvgBP = previousWeek.reduce((sum, d) => sum + parseFloat(d.bp_systolic || 0), 0) / previousWeek.length;\nconst prevAvgSleep = previousWeek.reduce((sum, d) => sum + parseFloat(d.sleep_hours || 0), 0) / previousWeek.length;\nconst prevAvgSteps = previousWeek.reduce((sum, d) => sum + parseFloat(d.steps_count || 0), 0) / previousWeek.length;\n\n// Current week averages (already in analysis)\nconst currAvgHR = parseFloat(currentData.analysis.averages.heartRate);\nconst currAvgSleep = parseFloat(currentData.analysis.averages.sleep);\n\n// Calculate week-over-week changes\nconst weeklyComparison = {\n  available: true,\n  heartRateChange: ((currAvgHR - prevAvgHR) / prevAvgHR * 100).toFixed(1),\n  sleepChange: ((currAvgSleep - prevAvgSleep) / prevAvgSleep * 100).toFixed(1),\n  trend: (currAvgHR < prevAvgHR && currAvgSleep > prevAvgSleep) ? 'improving' : 'needs attention',\n  insights: []\n};\n\nif (Math.abs(weeklyComparison.heartRateChange) > 10) {\n  weeklyComparison.insights.push(`Significant heart rate change: ${weeklyComparison.heartRateChange}%`);\n}\nif (Math.abs(weeklyComparison.sleepChange) > 15) {\n  weeklyComparison.insights.push(`Notable sleep pattern change: ${weeklyComparison.sleepChange}%`);\n}\n\nreturn { ...currentData, weeklyComparison };"
      },
      "typeVersion": 2
    },
    {
      "id": "717957d5-3bf5-4b29-b387-6380442db2ca",
      "name": "Generate PDF Report",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1008,
        560
      ],
      "parameters": {
        "url": "https://api.pdfmonkey.io/api/v1/documents",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "document[document_template_id]",
              "value": "health_report_template"
            },
            {
              "name": "document[payload][patient_name]",
              "value": "={{$('Webhook - Health Data Input').item.json.patient_name}}"
            },
            {
              "name": "document[payload][health_score]",
              "value": "={{$json.healthScore.score}}"
            },
            {
              "name": "document[payload][analysis]",
              "value": "={{JSON.stringify($json.analysis)}}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{$env.PDFMONKEY_API_KEY}}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "3de482ad-942f-4d19-9077-a272a7092e72",
      "name": "Check Critical Threshold",
      "type": "n8n-nodes-base.if",
      "position": [
        752,
        1392
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "critical-score-check",
              "operator": {
                "type": "number",
                "operation": "smaller"
              },
              "leftValue": "={{$json.healthScore.score}}",
              "rightValue": 50
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "f6d440af-7ddf-4b73-85a1-8bc37d20348b",
      "name": "Slack Alert to Care Team",
      "type": "n8n-nodes-base.slack",
      "position": [
        1024,
        1600
      ],
      "parameters": {
        "text": "=\ud83d\udea8 *CRITICAL HEALTH ALERT*\n\n*Patient:* {{$('Webhook - Health Data Input').item.json.patient_name}}\n*Health Score:* {{$json.healthScore.score}}/100 ({{$json.healthScore.grade}})\n*Risk Level:* {{$json.analysis.riskLevel}}\n\n*Critical Metrics:*\n{{$json.analysis.alerts.map(a => '\u2022 ' + a).join('\\n')}}\n\n*Recommendation:* {{$json.healthScore.recommendation}}\n\n*Action Required:* Immediate follow-up needed",
        "otherOptions": {}
      },
      "typeVersion": 2.2
    },
    {
      "id": "b3823d85-0472-42da-bc44-be434f4245d1",
      "name": "Schedule Follow-up Calendar Event",
      "type": "n8n-nodes-base.googleCalendar",
      "position": [
        1024,
        1760
      ],
      "parameters": {
        "end": "={{DateTime.now().plus({days: 1, hours: 1}).toISO()}}",
        "start": "={{DateTime.now().plus({days: 1}).toISO()}}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "740ab316-db84-44eb-ac4e-0fb5b0f72bf2",
      "name": "OpenAI Health Trends Analysis",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1040,
        976
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "de97eb7e-0a9c-4648-9d73-83edab294d5e",
      "name": "AI Predictive Health Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        960,
        752
      ],
      "parameters": {
        "text": "=You are an advanced predictive health analytics AI. Analyze the following comprehensive health data and provide:\n\n**Current Health Snapshot:**\n- Health Score: {{$json.healthScore.score}}/100 ({{$json.healthScore.grade}})\n- Heart Rate: {{$json.currentData.heart_rate}} bpm\n- Blood Pressure: {{$json.currentData.bp_systolic}}/{{$json.currentData.bp_diastolic}} mmHg\n- Temperature: {{$json.currentData.temperature}}\u00b0C\n- Sleep: {{$json.currentData.sleep_hours}} hours\n- Steps: {{$json.currentData.steps_count}}\n\n**Weekly Trends:**\n{{$json.weeklyComparison.available ? `- Heart Rate Change: ${$json.weeklyComparison.heartRateChange}%\n- Sleep Change: ${$json.weeklyComparison.sleepChange}%\n- Overall Trend: ${$json.weeklyComparison.trend}` : 'Insufficient historical data'}}\n\n**Current Alerts:**\n{{$json.analysis.alerts.join('\\n')}}\n\n**Task:**\n1. Provide a comprehensive health trajectory forecast for the next 30 days\n2. Identify potential health risks based on current trends\n3. Suggest specific lifestyle interventions with expected impact percentages\n4. Recommend optimal timing for preventive medical check-ups\n5. Provide personalized nutrition and exercise recommendations\n6. Assess stress indicators and mental health considerations\n\nBe data-driven, actionable, and include confidence levels for predictions.",
        "options": {
          "systemMessage": "You are a medical AI assistant specializing in predictive health analytics. Use evidence-based reasoning and provide confidence intervals for predictions. Always emphasize that your analysis supplements but does not replace professional medical advice."
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "4d01f55c-c6ca-4ec7-ae13-311f6df60c6a",
      "name": "Store Health Score in Redis Cache",
      "type": "n8n-nodes-base.redis",
      "position": [
        752,
        1568
      ],
      "parameters": {
        "key": "=health_score:{{$('Webhook - Health Data Input').item.json.patient_id || 'default'}}:latest",
        "ttl": 604800,
        "value": "={{JSON.stringify({score: $json.healthScore.score, grade: $json.healthScore.grade, timestamp: $json.healthScore.timestamp})}}",
        "expire": true,
        "operation": "set"
      },
      "typeVersion": 1
    },
    {
      "id": "7927ddba-2f68-4db9-b6bf-4c10fbc161cc",
      "name": "Trigger Wearable Device Sync",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        144,
        1216
      ],
      "parameters": {
        "url": "=https://api.fitbit.com/1/user/{{$('Webhook - Health Data Input').item.json.patient_id}}/activities/sync.json",
        "method": "POST",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "fitbitOAuth2Api"
      },
      "typeVersion": 4.2
    },
    {
      "id": "ea7ffeed-3d45-424a-8a0d-698b690428e8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        496
      ],
      "parameters": {
        "width": 624,
        "height": 480,
        "content": "## How It Works\nThe system collects real-time wearable health data, normalizes it, and uses AI to analyze trends and risk scores. It detects anomalies by comparing with historical patterns and automatically triggers alerts and follow-up actions when thresholds are exceeded.\n\n## Setup Steps\n1. **Configure Webhook Endpoint** - Set up webhook to receive data from wearable devices\n2. **Connect Database** - Initialize storage for health metrics and historical data\n3. **Set Normalization Rules** - Define data standardization parameters for different devices\n4. **Configure AI Model** - Set up health score calculation and risk prediction algorithms\n5. **Define Thresholds** - Establish alert triggers for critical health metrics\n6. **Connect Notification Channels** - Configure email and Slack integrations\n7. **Set Up Reporting** - Create automated report templates and schedules\n8. **Test Workflow** - Run end-to-end tests with sample health data\n\n## Workflow Template\nWebhook \u2192 Store Database \u2192 Normalize Data \u2192 Calculate Health Score \u2192 Analyze Metrics \u2192 Compare Previous \u2192 Check Threshold \u2192 Generate Reports/Alerts \u2192 Email/Slack \u2192 Schedule Follow-up\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9127a23c-4896-4aad-bff6-7f0cd66e8902",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1296,
        496
      ],
      "parameters": {
        "color": 3,
        "width": 432,
        "height": 416,
        "content": "## Prerequisites\nWearable API, patient database, GPT-4 key, email SMTP, optional Slack/Twilio, calendar integration.\n\n## Use Cases\nMonitor glucose for diabetics, track elderly vitals/fall risk, assess corporate wellness, and post-surgery recovery alerts.\n\n## Customization\nAdjust risk algorithms, add metrics, integrate telemedicine.\n\n## Benefits\nEarly intervention reduces readmissions and automates 80% of monitoring tasks.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a42f6415-8235-4a23-89f4-7cab111ef510",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        416,
        496
      ],
      "parameters": {
        "color": 6,
        "width": 480,
        "height": 240,
        "content": "## Workflow Steps\nIngest real-time wearable data via webhook, store and standardize it, and use GPT-4 for trend analysis and risk scoring. Monitor metrics against thresholds, trigger SMS, email, or Slack alerts, generate reports, and schedule follow-ups.\n\n## Setup Instructions\nConfigure webhook, database, GPT-4 API, notifications, calendar integration, and customize alert thresholds.\n\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a7553a5c-8ba9-4b5f-aab2-7a866946fb1f",
  "connections": {
    "OpenAI GPT-4": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Health Report",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Store in Database": {
      "main": [
        [
          {
            "node": "Log to MongoDB Health History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Recent History": {
      "main": [
        [
          {
            "node": "Analyze Health Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Health Data": {
      "main": [
        [
          {
            "node": "Store in Database",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Recent History",
            "type": "main",
            "index": 0
          },
          {
            "node": "Trigger Wearable Device Sync",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Health Metrics": {
      "main": [
        [
          {
            "node": "Check If Doctor Visit Needed",
            "type": "main",
            "index": 0
          },
          {
            "node": "Calculate Health Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Health Score": {
      "main": [
        [
          {
            "node": "Compare with Previous Week",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check Critical Threshold",
            "type": "main",
            "index": 0
          },
          {
            "node": "Store Health Score in Redis Cache",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Health Report": {
      "main": [
        [
          {
            "node": "Send Health Report Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Critical Threshold": {
      "main": [
        [
          {
            "node": "Emergency Contact SMS Alert",
            "type": "main",
            "index": 0
          },
          {
            "node": "Slack Alert to Care Team",
            "type": "main",
            "index": 0
          },
          {
            "node": "Schedule Follow-up Calendar Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Health Report Email": {
      "main": [
        [
          {
            "node": "Send Urgent Doctor Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compare with Previous Week": {
      "main": [
        [
          {
            "node": "Check If Doctor Visit Needed",
            "type": "main",
            "index": 0
          },
          {
            "node": "AI Predictive Health Agent",
            "type": "main",
            "index": 0
          },
          {
            "node": "Generate PDF Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook - Health Data Input": {
      "main": [
        [
          {
            "node": "Normalize Health Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If Doctor Visit Needed": {
      "main": [
        [
          {
            "node": "Generate Health Report",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Action Needed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Health Trends Analysis": {
      "ai_languageModel": [
        [
          {
            "node": "AI Predictive Health Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

The system collects real-time wearable health data, normalizes it, and uses AI to analyze trends and risk scores. It detects anomalies by comparing with historical patterns and automatically triggers alerts and follow-up actions when thresholds are exceeded. Configure Webhook…

Source: https://n8n.io/workflows/10457/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This n8n workflow orchestrates a powerful suite of AI Agents and automations to manage and optimize various aspects of an e-commerce operation, particularly for platforms like Shopify. It leverages La

Google Sheets, HTTP Request, Slack +10
AI & RAG

This workflow transforms natural language queries into research reports through a five-stage AI pipeline. When triggered via webhook (typically from Google Sheets using the companion [](https://gist.g

Redis, Agent, Output Parser Structured +7
AI & RAG

This workflow automates customer feedback processing by analyzing sentiment, identifying key issues, generating personalized responses, and escalating critical cases to support teams when required. De

Redis, Postgres, Agent +7
AI & RAG

This workflow automates veterinary clinic operations and client communications for animal hospitals and veterinary practices managing appointments, inventory, and patient care. It solves the dual chal

HTTP Request, Agent, OpenAI Chat +4
AI & RAG

Automate peer review assignment and grading with AI-powered evaluation. Designed for educators managing collaborative assessments efficiently.

OpenAI Chat, Agent, Output Parser Structured +4