{
  "name": "Smart Patient Care Automation",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "appointment-request",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "pc1a2b3c-1111-2222-3333-444455556666",
      "name": "Appointment Request Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4",
          "mode": "id"
        },
        "messages": {
          "values": [
            {
              "content": "=Analyze this patient appointment request and perform medical triage:\n\nPatient Name: {{ $json.patient_name }}\nAge: {{ $json.age }}\nSymptoms: {{ $json.symptoms }}\nRequested Specialty: {{ $json.specialty }}\nPreferred Date: {{ $json.preferred_date }}\n\nReturn JSON with:\n- urgency_level (emergency/urgent/normal)\n- priority_score (1-10)\n- recommended_specialty (string)\n- estimated_consultation_time (minutes)\n- pre_visit_questions (array of 3-5 questions to ask before visit)\n- risk_factors (array of identified risk factors)\n- triage_notes (brief medical notes)\n\nReturn only valid JSON."
            }
          ]
        },
        "options": {
          "temperature": 0.3
        }
      },
      "id": "pc2b3c4d-2222-3333-4444-555566667777",
      "name": "AI Medical Triage",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.3,
      "position": [
        480,
        300
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "calendarId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_CALENDAR_ID",
          "mode": "id"
        },
        "timeMin": "={{ $now.toISO() }}",
        "timeMax": "={{ $now.plus({days: 7}).toISO() }}",
        "options": {}
      },
      "id": "pc3c4d5e-3333-4444-5555-666677778888",
      "name": "Check Calendar Availability",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1,
      "position": [
        710,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Find best available slot and prepare appointment data\nconst triageResult = JSON.parse($('AI Medical Triage').first().json.message.content);\nconst calendarEvents = $('Check Calendar Availability').all().map(item => item.json);\nconst patientData = $('Appointment Request Webhook').first().json;\n\n// Find next available slot (simplified logic)\nconst now = new Date();\nlet appointmentTime;\n\nif (triageResult.urgency_level === 'emergency') {\n  appointmentTime = new Date(now.getTime() + 2 * 60 * 60 * 1000); // 2 hours from now\n} else if (triageResult.urgency_level === 'urgent') {\n  appointmentTime = new Date(now.getTime() + 24 * 60 * 60 * 1000); // 24 hours from now\n} else {\n  appointmentTime = new Date(now.getTime() + 48 * 60 * 60 * 1000); // 48 hours from now\n}\n\n// Generate appointment ID\nconst appointmentId = 'APT-' + Date.now();\n\nreturn [{\n  json: {\n    appointment_id: appointmentId,\n    patient_name: patientData.patient_name,\n    patient_email: patientData.email,\n    patient_phone: patientData.phone,\n    age: patientData.age,\n    symptoms: patientData.symptoms,\n    specialty: triageResult.recommended_specialty,\n    urgency_level: triageResult.urgency_level,\n    priority_score: triageResult.priority_score,\n    appointment_time: appointmentTime.toISOString(),\n    estimated_duration: triageResult.estimated_consultation_time,\n    pre_visit_questions: triageResult.pre_visit_questions,\n    risk_factors: triageResult.risk_factors,\n    triage_notes: triageResult.triage_notes,\n    status: 'scheduled',\n    created_at: $now.toISO()\n  }\n}];"
      },
      "id": "pc4d5e6f-4444-5555-6666-777788889999",
      "name": "Schedule Appointment",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        940,
        300
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Appointments",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "appointment_id": "={{ $json.appointment_id }}",
            "patient_name": "={{ $json.patient_name }}",
            "patient_email": "={{ $json.patient_email }}",
            "patient_phone": "={{ $json.patient_phone }}",
            "age": "={{ $json.age }}",
            "symptoms": "={{ $json.symptoms }}",
            "specialty": "={{ $json.specialty }}",
            "urgency_level": "={{ $json.urgency_level }}",
            "priority_score": "={{ $json.priority_score }}",
            "appointment_time": "={{ $json.appointment_time }}",
            "estimated_duration": "={{ $json.estimated_duration }}",
            "status": "={{ $json.status }}",
            "created_at": "={{ $json.created_at }}"
          },
          "schema": []
        },
        "options": {}
      },
      "id": "pc5e6f7a-5555-6666-7777-888899990000",
      "name": "Save Appointment to Database",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1170,
        300
      ]
    },
    {
      "parameters": {
        "calendarId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_CALENDAR_ID",
          "mode": "id"
        },
        "start": "={{ $json.appointment_time }}",
        "end": "={{ new Date(new Date($json.appointment_time).getTime() + $json.estimated_duration * 60000).toISOString() }}",
        "summary": "=Appointment: {{ $json.patient_name }} - {{ $json.specialty }}",
        "description": "=Patient: {{ $json.patient_name }}\nAge: {{ $json.age }}\nSymptoms: {{ $json.symptoms }}\nUrgency: {{ $json.urgency_level }}\nPriority Score: {{ $json.priority_score }}\n\nTriage Notes:\n{{ $json.triage_notes }}\n\nRisk Factors:\n{{ $json.risk_factors.join(', ') }}",
        "options": {}
      },
      "id": "pc6f7a8b-6666-7777-8888-999900001111",
      "name": "Create Calendar Event",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1,
      "position": [
        1400,
        300
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $('Appointment Request Webhook').first().json.telegram_chat_id || 'YOUR_TELEGRAM_CHAT_ID' }}",
        "text": "=\u2705 \u0646\u0648\u0628\u062a \u0634\u0645\u0627 \u0628\u0627 \u0645\u0648\u0641\u0642\u06cc\u062a \u0631\u0632\u0631\u0648 \u0634\u062f!\n\n\ud83d\udc64 \u0628\u06cc\u0645\u0627\u0631: {{ $json.patient_name }}\n\ud83c\udfe5 \u062a\u062e\u0635\u0635: {{ $json.specialty }}\n \u062a\u0627\u0631\u06cc\u062e \u0648 \u0633\u0627\u0639\u062a: {{ new Date($json.appointment_time).toLocaleString('fa-IR') }}\n\u23f1\ufe0f \u0645\u062f\u062a \u0648\u06cc\u0632\u06cc\u062a: {{ $json.estimated_duration }} \u062f\u0642\u06cc\u0642\u0647\n\ud83c\udd94 \u06a9\u062f \u0646\u0648\u0628\u062a: {{ $json.appointment_id }}\n\n\ufe0f \u0633\u0637\u062d \u0641\u0648\u0631\u06cc\u062a: {{ $json.urgency_level === 'emergency' ? '\u0627\u0648\u0631\u0698\u0627\u0646\u0633\u06cc' : $json.urgency_level === 'urgent' ? '\u0641\u0648\u0631\u06cc' : '\u0639\u0627\u062f\u06cc' }}\n\n\ud83d\udccb \u0633\u0648\u0627\u0644\u0627\u062a \u067e\u06cc\u0634 \u0627\u0632 \u0648\u06cc\u0632\u06cc\u062a:\n{{ $json.pre_visit_questions.map((q, i) => `${i+1}. ${q}`).join('\\n') }}\n\n\u0644\u0637\u0641\u0627\u064b \u0628\u0647 \u0627\u06cc\u0646 \u0633\u0648\u0627\u0644\u0627\u062a \u0642\u0628\u0644 \u0627\u0632 \u0648\u06cc\u0632\u06cc\u062a \u067e\u0627\u0633\u062e \u062f\u0647\u06cc\u062f.\n\n\u0628\u0627 \u0627\u062d\u062a\u0631\u0627\u0645\u060c\n\u0633\u06cc\u0633\u062a\u0645 \u0646\u0648\u0628\u062a\u200c\u062f\u0647\u06cc \u0647\u0648\u0634\u0645\u0646\u062f",
        "additionalFields": {}
      },
      "id": "pc7a8b9c-7777-8888-9999-000011112222",
      "name": "Send Appointment Confirmation",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        1630,
        300
      ]
    },
    {
      "parameters": {
        "amount": 24,
        "unit": "hours"
      },
      "id": "pc8b9c0d-8888-9999-0000-111122223333",
      "name": "Wait 24 Hours",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1860,
        300
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $('Appointment Request Webhook').first().json.telegram_chat_id || 'YOUR_TELEGRAM_CHAT_ID' }}",
        "text": "=\ud83d\udd14 \u06cc\u0627\u062f\u0622\u0648\u0631\u06cc \u0646\u0648\u0628\u062a\n\n\ud83d\udc64 \u0628\u06cc\u0645\u0627\u0631: {{ $json.patient_name }}\n\ud83c\udfe5 \u062a\u062e\u0635\u0635: {{ $json.specialty }}\n\ud83d\udcc5 \u0646\u0648\u0628\u062a \u0634\u0645\u0627: {{ new Date($json.appointment_time).toLocaleString('fa-IR') }}\n\ud83c\udd94 \u06a9\u062f \u0646\u0648\u0628\u062a: {{ $json.appointment_id }}\n\n \u0646\u0648\u0628\u062a \u0634\u0645\u0627 \u06f2\u06f4 \u0633\u0627\u0639\u062a \u062f\u06cc\u06af\u0631 \u0627\u0633\u062a.\n\n\u0644\u0637\u0641\u0627\u064b \u0633\u0648\u0627\u0644\u0627\u062a \u067e\u06cc\u0634 \u0627\u0632 \u0648\u06cc\u0632\u06cc\u062a \u0631\u0627 \u067e\u0627\u0633\u062e \u062f\u0647\u06cc\u062f \u0648 \u0645\u062f\u0627\u0631\u06a9 \u067e\u0632\u0634\u06a9\u06cc \u062e\u0648\u062f \u0631\u0627 \u0647\u0645\u0631\u0627\u0647 \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u06cc\u062f.\n\n\u062f\u0631 \u0635\u0648\u0631\u062a \u0646\u06cc\u0627\u0632 \u0628\u0647 \u06a9\u0646\u0633\u0644\u06cc\u060c \u0644\u0637\u0641\u0627\u064b \u0627\u0632 \u06f2 \u0633\u0627\u0639\u062a \u0642\u0628\u0644 \u0627\u0637\u0644\u0627\u0639 \u062f\u0647\u06cc\u062f.",
        "additionalFields": {}
      },
      "id": "pc9c0d1e-9999-0000-1111-222233334444",
      "name": "Send 24h Reminder",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        2090,
        300
      ]
    },
    {
      "parameters": {
        "amount": 22,
        "unit": "hours"
      },
      "id": "pc0d1e2f-0000-1111-2222-333344445555",
      "name": "Wait 22 Hours",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        2320,
        300
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $('Appointment Request Webhook').first().json.telegram_chat_id || 'YOUR_TELEGRAM_CHAT_ID' }}",
        "text": "=\u23f0 \u06cc\u0627\u062f\u0622\u0648\u0631\u06cc \u0641\u0648\u0631\u06cc\n\n\ud83d\udc64 \u0628\u06cc\u0645\u0627\u0631: {{ $json.patient_name }}\n\ud83c\udfe5 \u062a\u062e\u0635\u0635: {{ $json.specialty }}\n\ud83d\udcc5 \u0646\u0648\u0628\u062a \u0634\u0645\u0627: {{ new Date($json.appointment_time).toLocaleString('fa-IR') }}\n\n\u26a1 \u0646\u0648\u0628\u062a \u0634\u0645\u0627 \u06f2 \u0633\u0627\u0639\u062a \u062f\u06cc\u06af\u0631 \u0627\u0633\u062a!\n\n\u0644\u0637\u0641\u0627\u064b \u06f1\u06f5 \u062f\u0642\u06cc\u0642\u0647 \u0642\u0628\u0644 \u0627\u0632 \u0646\u0648\u0628\u062a \u062f\u0631 \u06a9\u0644\u06cc\u0646\u06cc\u06a9 \u062d\u0627\u0636\u0631 \u0628\u0627\u0634\u06cc\u062f.\n\n\ud83d\udccd \u0622\u062f\u0631\u0633 \u06a9\u0644\u06cc\u0646\u06cc\u06a9: [\u0622\u062f\u0631\u0633 \u06a9\u0644\u06cc\u0646\u06cc\u06a9]\n\ud83d\udcde \u062a\u0644\u0641\u0646: [\u0634\u0645\u0627\u0631\u0647 \u062a\u0644\u0641\u0646]",
        "additionalFields": {}
      },
      "id": "pc1e2f3a-1111-2222-3333-444455556666",
      "name": "Send 2h Reminder",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        2550,
        300
      ]
    },
    {
      "parameters": {
        "amount": 48,
        "unit": "hours"
      },
      "id": "pc2f3a4b-2222-3333-4444-555566667777",
      "name": "Wait 48 Hours Post-Visit",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        2780,
        300
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $('Appointment Request Webhook').first().json.telegram_chat_id || 'YOUR_TELEGRAM_CHAT_ID' }}",
        "text": "= \u067e\u06cc\u06af\u06cc\u0631\u06cc \u067e\u0633 \u0627\u0632 \u0648\u06cc\u0632\u06cc\u062a\n\n \u0628\u06cc\u0645\u0627\u0631: {{ $json.patient_name }}\n \u06a9\u062f \u0646\u0648\u0628\u062a: {{ $json.appointment_id }}\n\n\u0627\u0645\u06cc\u062f\u0648\u0627\u0631\u06cc\u0645 \u062d\u0627\u0644\u062a\u0627\u0646 \u0628\u0647\u062a\u0631 \u0634\u062f\u0647 \u0628\u0627\u0634\u062f. \u0644\u0637\u0641\u0627\u064b \u0628\u0647 \u0633\u0648\u0627\u0644\u0627\u062a \u0632\u06cc\u0631 \u067e\u0627\u0633\u062e \u062f\u0647\u06cc\u062f:\n\n1\ufe0f\u20e3 \u0622\u06cc\u0627 \u0639\u0644\u0627\u0626\u0645 \u0634\u0645\u0627 \u0628\u0647\u0628\u0648\u062f \u06cc\u0627\u0641\u062a\u0647 \u0627\u0633\u062a\u061f (\u0628\u0644\u0647/\u062e\u06cc\u0631/\u062a\u0627 \u062d\u062f\u06cc)\n2\ufe0f\u20e3 \u0622\u06cc\u0627 \u0639\u0648\u0627\u0631\u0636 \u062c\u0627\u0646\u0628\u06cc \u062c\u062f\u06cc\u062f\u06cc \u062a\u062c\u0631\u0628\u0647 \u06a9\u0631\u062f\u0647\u200c\u0627\u06cc\u062f\u061f (\u062a\u0648\u0636\u06cc\u062d \u062f\u0647\u06cc\u062f)\n3\ufe0f\u20e3 \u0622\u06cc\u0627 \u062f\u0627\u0631\u0648\u0647\u0627\u06cc \u062a\u062c\u0648\u06cc\u0632 \u0634\u062f\u0647 \u0631\u0627 \u0645\u0635\u0631\u0641 \u06a9\u0631\u062f\u0647\u200c\u0627\u06cc\u062f\u061f (\u0628\u0644\u0647/\u062e\u06cc\u0631)\n4\ufe0f\u20e3 \u0622\u06cc\u0627 \u0646\u06cc\u0627\u0632 \u0628\u0647 \u0648\u06cc\u0632\u06cc\u062a \u0645\u062c\u062f\u062f \u062f\u0627\u0631\u06cc\u062f\u061f (\u0628\u0644\u0647/\u062e\u06cc\u0631)\n\n\u067e\u0627\u0633\u062e \u062e\u0648\u062f \u0631\u0627 \u0627\u0631\u0633\u0627\u0644 \u06a9\u0646\u06cc\u062f.",
        "additionalFields": {}
      },
      "id": "pc3a4b5c-3333-4444-5555-666677778888",
      "name": "Send Follow-up Questionnaire",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        3010,
        300
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "follow-up-response",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "pc4b5c6d-4444-5555-6666-777788889999",
      "name": "Follow-up Response Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        3240,
        300
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4",
          "mode": "id"
        },
        "messages": {
          "values": [
            {
              "content": "=Analyze this patient follow-up response:\n\nPatient: {{ $json.patient_name }}\nAppointment ID: {{ $json.appointment_id }}\nFollow-up Response: {{ $json.follow_up_response }}\n\nDetermine:\n- symptom_improvement (improved/same/worsened)\n- has_adverse_effects (true/false)\n- needs_follow_up_visit (true/false)\n- requires_immediate_attention (true/false)\n- risk_level (low/medium/high)\n- doctor_alert_needed (true/false)\n- summary (brief medical summary)\n- recommended_actions (array of actions)\n\nReturn only valid JSON."
            }
          ]
        },
        "options": {
          "temperature": 0.2
        }
      },
      "id": "pc5c6d7e-5555-6666-7777-888899990000",
      "name": "AI Analyze Follow-up",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.3,
      "position": [
        3470,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ JSON.parse($json.message.content).doctor_alert_needed }}",
              "value2": true
            }
          ]
        }
      },
      "id": "pc6d7e8f-6666-7777-8888-999900001111",
      "name": "Check if Doctor Alert Needed",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        3700,
        300
      ]
    },
    {
      "parameters": {
        "chatId": "YOUR_DOCTOR_TELEGRAM_CHAT_ID",
        "text": "=\ud83d\udea8 \u0647\u0634\u062f\u0627\u0631 \u067e\u0632\u0634\u06a9\u06cc - \u0646\u06cc\u0627\u0632 \u0628\u0647 \u062a\u0648\u062c\u0647 \u0641\u0648\u0631\u06cc\n\n\ud83d\udc64 \u0628\u06cc\u0645\u0627\u0631: {{ $('Follow-up Response Webhook').first().json.patient_name }}\n\ud83c\udd94 \u06a9\u062f \u0646\u0648\u0628\u062a: {{ $('Follow-up Response Webhook').first().json.appointment_id }}\n\n\u26a0\ufe0f \u0633\u0637\u062d \u0631\u06cc\u0633\u06a9: {{ JSON.parse($('AI Analyze Follow-up').first().json.message.content).risk_level }}\n\n \u062e\u0644\u0627\u0635\u0647:\n{{ JSON.parse($('AI Analyze Follow-up').first().json.message.content).summary }}\n\n\ud83c\udfaf \u0627\u0642\u062f\u0627\u0645\u0627\u062a \u062a\u0648\u0635\u06cc\u0647 \u0634\u062f\u0647:\n{{ JSON.parse($('AI Analyze Follow-up').first().json.message.content).recommended_actions.join('\\n- ') }}\n\n\u0644\u0637\u0641\u0627\u064b \u062f\u0631 \u0627\u0633\u0631\u0639 \u0648\u0642\u062a \u0628\u0627 \u0628\u06cc\u0645\u0627\u0631 \u062a\u0645\u0627\u0633 \u0628\u06af\u06cc\u0631\u06cc\u062f.",
        "additionalFields": {}
      },
      "id": "pc7e8f9a-7777-8888-9999-000011112222",
      "name": "Alert Doctor",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        3930,
        200
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $('Follow-up Response Webhook').first().json.telegram_chat_id || 'YOUR_TELEGRAM_CHAT_ID' }}",
        "text": "=\u2705 \u067e\u06cc\u06af\u06cc\u0631\u06cc \u0634\u0645\u0627 \u062b\u0628\u062a \u0634\u062f\n\n\ud83d\udc64 \u0628\u06cc\u0645\u0627\u0631: {{ $json.patient_name }}\n\n \u0648\u0636\u0639\u06cc\u062a: {{ JSON.parse($('AI Analyze Follow-up').first().json.message.content).symptom_improvement === 'improved' ? '\u0628\u0647\u0628\u0648\u062f \u06cc\u0627\u0641\u062a\u0647' : JSON.parse($('AI Analyze Follow-up').first().json.message.content).symptom_improvement === 'same' ? '\u0628\u062f\u0648\u0646 \u062a\u063a\u06cc\u06cc\u0631' : '\u0646\u06cc\u0627\u0632 \u0628\u0647 \u0628\u0631\u0631\u0633\u06cc' }}\n\n{{ JSON.parse($('AI Analyze Follow-up').first().json.message.content).needs_follow_up_visit ? '\ud83d\udd04 \u0648\u06cc\u0632\u06cc\u062a \u0645\u062c\u062f\u062f \u062a\u0648\u0635\u06cc\u0647 \u0645\u06cc\u200c\u0634\u0648\u062f. \u0628\u0647 \u0632\u0648\u062f\u06cc \u0628\u0627 \u0634\u0645\u0627 \u062a\u0645\u0627\u0633 \u06af\u0631\u0641\u062a\u0647 \u062e\u0648\u0627\u0647\u062f \u0634\u062f.' : '\u2705 \u0646\u06cc\u0627\u0632\u06cc \u0628\u0647 \u0648\u06cc\u0632\u06cc\u062a \u0645\u062c\u062f\u062f \u0646\u06cc\u0633\u062a.' }}\n\n\u0628\u0627 \u0622\u0631\u0632\u0648\u06cc \u0633\u0644\u0627\u0645\u062a\u06cc\u060c\n\u062a\u06cc\u0645 \u067e\u0632\u0634\u06a9\u06cc",
        "additionalFields": {}
      },
      "id": "pc8f9a0b-8888-9999-0000-111122223333",
      "name": "Send Patient Follow-up Response",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        3930,
        400
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "FollowUpLog",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "appointment_id": "={{ $('Follow-up Response Webhook').first().json.appointment_id }}",
            "patient_name": "={{ $('Follow-up Response Webhook').first().json.patient_name }}",
            "follow_up_response": "={{ $('Follow-up Response Webhook').first().json.follow_up_response }}",
            "symptom_improvement": "={{ JSON.parse($('AI Analyze Follow-up').first().json.message.content).symptom_improvement }}",
            "risk_level": "={{ JSON.parse($('AI Analyze Follow-up').first().json.message.content).risk_level }}",
            "doctor_alert_needed": "={{ JSON.parse($('AI Analyze Follow-up').first().json.message.content).doctor_alert_needed }}",
            "needs_follow_up_visit": "={{ JSON.parse($('AI Analyze Follow-up').first().json.message.content).needs_follow_up_visit }}",
            "processed_at": "={{ $now.toISO() }}"
          },
          "schema": []
        },
        "options": {}
      },
      "id": "pc9a0b1c-9999-0000-1111-222233334444",
      "name": "Log Follow-up to Database",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        4160,
        300
      ]
    }
  ],
  "connections": {
    "Appointment Request Webhook": {
      "main": [
        [
          {
            "node": "AI Medical Triage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Medical Triage": {
      "main": [
        [
          {
            "node": "Check Calendar Availability",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Calendar Availability": {
      "main": [
        [
          {
            "node": "Schedule Appointment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Appointment": {
      "main": [
        [
          {
            "node": "Save Appointment to Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Appointment to Database": {
      "main": [
        [
          {
            "node": "Create Calendar Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Calendar Event": {
      "main": [
        [
          {
            "node": "Send Appointment Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Appointment Confirmation": {
      "main": [
        [
          {
            "node": "Wait 24 Hours",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 24 Hours": {
      "main": [
        [
          {
            "node": "Send 24h Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send 24h Reminder": {
      "main": [
        [
          {
            "node": "Wait 22 Hours",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 22 Hours": {
      "main": [
        [
          {
            "node": "Send 2h Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send 2h Reminder": {
      "main": [
        [
          {
            "node": "Wait 48 Hours Post-Visit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 48 Hours Post-Visit": {
      "main": [
        [
          {
            "node": "Send Follow-up Questionnaire",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Follow-up Questionnaire": {
      "main": [
        [
          {
            "node": "Follow-up Response Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Follow-up Response Webhook": {
      "main": [
        [
          {
            "node": "AI Analyze Follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Analyze Follow-up": {
      "main": [
        [
          {
            "node": "Check if Doctor Alert Needed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Doctor Alert Needed": {
      "main": [
        [
          {
            "node": "Alert Doctor",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Patient Follow-up Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert Doctor": {
      "main": [
        [
          {
            "node": "Log Follow-up to Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Patient Follow-up Response": {
      "main": [
        [
          {
            "node": "Log Follow-up to Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}