{
  "id": "demo-healthcare-assistant-workflow",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "name": "AI Healthcare Assistant - Multi-Agent Demo System",
  "tags": [
    "healthcare",
    "demo",
    "ai-agents",
    "educational",
    "multi-agent"
  ],
  "nodes": [
    {
      "id": "sticky-note-warning",
      "name": "\u26a0\ufe0f DEMO WARNING & SETUP GUIDE",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -800,
        -400
      ],
      "parameters": {
        "width": 863,
        "height": 464,
        "content": "## \u26a0\ufe0f EDUCATIONAL DEMO ONLY \u26a0\ufe0f\n\n**This is a demonstration of n8n multi-agent orchestration patterns.**\n\n### \ud83d\udea8 CRITICAL WARNINGS:\n- **NOT for production medical use**\n- **NOT HIPAA compliant**\n- **Educational purposes only**\n- Use only fictional/test data\n\n### \ud83c\udfaf What This Demonstrates:\n- Advanced multi-agent AI coordination\n- Specialized agent tool integration\n- Memory management across conversations\n- Multi-modal input processing\n- Complex workflow orchestration\n\n### \ud83d\udccb Setup Requirements:\n- OpenAI API credentials\n- WhatsApp Business API access\n- Google Sheets OAuth2 setup\n- PostgreSQL database connection\n\n### \ud83d\udd27 Before Using:\n1. Replace all credential placeholders\n2. Set up Google Sheets database structure\n3. Configure WhatsApp Business webhooks\n4. Test with fictional data only\n\n**For production healthcare systems, use HIPAA-compliant platforms and proper security measures.**"
      },
      "typeVersion": 1
    },
    {
      "id": "sticky-note-architecture",
      "name": "\ud83c\udfd7\ufe0f Architecture Guide",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        -600
      ],
      "parameters": {
        "width": 400,
        "height": 340,
        "content": "## \ud83c\udfd7\ufe0f Architecture Overview\n\n**Main Orchestrator:**\n- Traffic controller for all agents\n- Handles input classification\n- Routes to specialized tools\n\n**Specialized Agents:**\n- \ud83d\udcdd Patient Registration\n- \ud83d\udcc5 Appointment Scheduling  \n- \ud83d\udcca Medical Report Analysis\n- \ud83d\udc8a Prescription Verification\n\n**Integration Points:**\n- WhatsApp Business API\n- Google Sheets Database\n- OpenAI GPT-4 Models\n- PostgreSQL Memory\n\n**Learning Focus:**\nAdvanced n8n patterns for enterprise-grade AI automation"
      },
      "typeVersion": 1
    },
    {
      "id": "sticky-note-processing",
      "name": "\ud83d\udd04 Processing Pipeline",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        -600
      ],
      "parameters": {
        "width": 400,
        "height": 280,
        "content": "## \ud83d\udd04 Multi-Modal Processing\n\n**Input Types Handled:**\n- \ud83d\udcac Text messages \u2192 Direct processing\n- \ud83c\udfb5 Audio \u2192 Transcription \u2192 Response\n- \ud83d\uddbc\ufe0f Images \u2192 Vision analysis\n- \ud83d\udcc4 Documents \u2192 PDF extraction\n\n**Processing Flow:**\n1. Input classification (Switch node)\n2. Media download & processing\n3. Content extraction & analysis\n4. Agent routing & execution\n5. Response generation & delivery\n\n**Key Learning:**\nComplex conditional routing and media processing in n8n workflows"
      },
      "typeVersion": 1
    },
    {
      "id": "40c6fe48-7b5a-4c23-ac14-e19e77fb8e28",
      "name": "Appointment System",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1960,
        -112
      ],
      "parameters": {
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "=You are Medical Appointment Assistant, the main AI agent for managing patient interactions on WhatsApp.\nYour job is to guide the patient through:\n\t1.\tIdentifying themselves\n\t2.\tRegistering if they are new\n\t3.\tScheduling appointments if they are an existing patient\n\t4.\tAnalyzing medical reports when provided\n\t5.\tAnalyzing prescriptions and verifying medicines\nYou must use only the Appointment Scheduler Tool, Register Patient Tool, Report Analyzer Tool, and Prescription Medicine Analyzer Tool to complete these tasks.\n\nCurrent Date & Time: {{ $now }}\n\nResponsibilities in Flow\n\t1.\tGreet the patient politely and professionally. Example:\n\"Hello! Welcome to the Medical Appointment Assistant. I can help you with registration, scheduling, analyzing medical reports, or verifying prescription medicines.\"\n\t2.\tCollect basic info: Full Name + Date of Birth.\n\t3.\tFind patient using the Appointment Scheduler Tool.\n\t4.\tIf found \u2192 Continue to appointment scheduling, report analysis, or prescription verification.\nIf not found \u2192 Offer registration with:\n\"I couldn't find a record for you. Would you like me to register you as a new patient?\"\n\t5.\tIf agreed \u2192 Pass control to Register Patient Tool. Wait until it completes before continuing.\n\t6.\tAfter registration (if requested) \u2192 Continue to appointment scheduling, report analysis, or prescription verification.\n\t7.\tFor appointments \u2192 Pass control to Appointment Scheduler Tool and wait for its response before updating the patient.\n\t8.\tFor report analysis \u2192 When patient sends medical reports, images, or documents, use the Report Analyzer Tool to provide detailed medical analysis and recommendations.\n\t9.\tFor prescription verification \u2192 When patient asks about medicines or uploads prescription/medicine photos, use the Prescription Medicine Analyzer Tool to verify medicines and provide prescription information.\n\t10.\tError handling: If a tool fails or info is missing, ask for the correct details in plain language.\n\t11.\tTone: Professional, concise, and empathetic. Avoid jargon. No assumptions.\n\t12.\tPrivacy: Handle patient data securely; share only as needed for the process.\n\nDocument Classification Intelligence\n\t\u2022\tWhen patient uploads ANY document/image, first analyze the content to determine type:\n\t\t\u25cb\tIf it contains medicine names, dosages, doctor signatures, or prescription format \u2192 Use Prescription Medicine Analyzer Tool\n\t\t\u25cb\tIf it contains lab values, test results, medical measurements, or report format \u2192 Use Report Analyzer Tool\n\t\t\u25cb\tIf unclear, ask patient: \"I see you've uploaded a document. Is this a prescription from your doctor or a medical report/lab results?\"\n\t\u2022\tALWAYS classify documents before routing to specialist tools\n\t\u2022\tHandle both PDF documents and images equally for analysis\n\nReport Analysis Guidelines\n\t\u2022\tWhen patients share medical reports, lab results, X-rays, or other medical documents, automatically use the Report Analyzer Tool\n\t\u2022\tProvide clear, understandable explanations of findings\n\t\u2022\tHighlight any concerning values or abnormalities\n\t\u2022\tSuggest follow-up actions when appropriate\n\t\u2022\tAlways recommend consulting with healthcare providers for medical advice\n\nPrescription Medicine Guidelines\n\t\u2022\tWhen patients ask about medicines, prescriptions, or upload medicine photos, use the Prescription Medicine Analyzer Tool\n\t\u2022\tHelp verify if medicines match prescriptions\n\t\u2022\tProvide detailed prescription information\n\t\u2022\tEnsure patient safety by identifying medicine discrepancies\n\t\u2022\tAlways encourage verification with pharmacists and doctors\n\nConstraints\n\t\u2022\tNo free-text scheduling, registration, report analysis, or prescription verification outside the tools.\n\t\u2022\tNo status updates until the tool response arrives.\n\t\u2022\tNo medical diagnosis - only report analysis, prescription information, and general health guidance.\n\t\u2022\tALWAYS route documents to appropriate specialist tools based on content analysis."
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "33b75de0-3e63-42db-9786-ed2dd7bd9dd5",
      "name": "Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        1376,
        112
      ],
      "parameters": {
        "tableName": "demo_chat_histories",
        "sessionKey": "={{ $('If').item.json.sessionId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 500
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "7ca21910-050e-442e-98b5-2e399f29f1ec",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1248,
        112
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "61add2e7-96cd-4259-a337-69b60fde97a1",
      "name": "WATrigger",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        -544,
        -112
      ],
      "parameters": {
        "options": {},
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "97c88a88-d253-4f76-b3c5-ab15353b333c",
      "name": "PrepareInput",
      "type": "n8n-nodes-base.code",
      "position": [
        576,
        176
      ],
      "parameters": {
        "jsCode": "// Get incoming JSON from previous node\nconst data = items[0].json;\n\n// Initialize defaults\nlet sessionId = null;\nlet chatInput = null;\n\n// Check if it's a \"messages\" type payload with text\nif (Array.isArray(data.messages) && data.messages.length > 0) {\n    const msg = data.messages[0];\n    sessionId = msg.from || null;\n    chatInput = msg.text?.body || null;\n}\n\n// If no messages, maybe it's a status update - extract recipient_id as sessionId\nif (!sessionId && Array.isArray(data.statuses) && data.statuses.length > 0) {\n    sessionId = data.statuses[0].recipient_id || null;\n    chatInput = null; // No text in statuses\n}\n\n// Output result\nreturn [\n  {\n    json: {\n      sessionId,\n      chatInput\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "8d4fa7c5-643c-4778-a800-87e53e4cf399",
      "name": "create_patient",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        1584,
        320
      ],
      "parameters": {
        "columns": {
          "value": {
            "Email": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Email', ``, 'string') }}",
            "Notes": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Notes', ``, 'string') }}",
            "Phone": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Phone', ``, 'string') }}",
            "Gender": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Gender', ``, 'string') }}",
            "Address": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Address', ``, 'string') }}",
            "Full Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Full_Name', ``, 'string') }}",
            "Patient ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Patient_ID', ``, 'string') }}",
            "Date of Birth": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Date_of_Birth', ``, 'string') }}",
            "Insurance Number": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Insurance_Number', ``, 'string') }}",
            "Insurance Provider": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Insurance_Provider', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "Patient ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Patient ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Full Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Full Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date of Birth",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Date of Birth",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Gender",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Gender",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Address",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Insurance Provider",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Insurance Provider",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Insurance Number",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Insurance Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Notes",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1589180996,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit#gid=1589180996",
          "cachedResultName": "Patients"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "Healthcare Demo Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "974011a8-1e55-421d-a8ac-c455998c3f5a",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        1712,
        320
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2af83545-6277-4eeb-808a-6d7652c7e290",
      "name": "get_last_patient_id",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        1840,
        320
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1589180996,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit#gid=1589180996",
          "cachedResultName": "Patients"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "Healthcare Demo Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "6c10f0d4-d611-474d-af75-d7cf3e8a91e7",
      "name": "Memory1",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        1456,
        320
      ],
      "parameters": {
        "tableName": "demo_chat_histories",
        "sessionKey": "={{ $('If').item.json.sessionId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 200
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "3ca96747-cdd2-4d83-81a3-a372db9944d4",
      "name": "OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1328,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "00f712c0-ac42-4208-be4a-73cc9f8f8533",
      "name": "Register Patient Tool",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        1504,
        112
      ],
      "parameters": {
        "text": "={{ $('If').item.json.chatInput }}",
        "options": {
          "systemMessage": "You are Medical Intake Assistant. Your job is to collect and confirm patient details for registration. You can only respond to registration-related queries.\n\nFlow\n\t1.\tCollect in order:\n\t\u2022\tFull Name\n\t\u2022\tDOB\n\t\u2022\tGender (Male/Female/Other)\n\t\u2022\tPhone\n\t\u2022\tEmail\n\t\u2022\tAddress\n\t\u2022\tNotes (medical conditions, first-time visit, etc.)\n\t2.\tValidate & confirm details before saving.\n\t3.\tOn confirmation \u2192 Generate patient ID (using get_last_patient_id), then save via create_patient.\n\t4.\tAfter saving \u2192 Send a clear success message with a summary of stored details.\n\t5.\tGuardrails:\n\t\u2022\tNo medical advice.\n\t\u2022\tPolitely reject irrelevant/offensive content.\n\t\u2022\tEnd session politely if the patient refuses."
        },
        "toolDescription": "Collects and verifies all required patient details, formats them correctly, and saves to the system using the create_patient tool."
      },
      "typeVersion": 2.2
    },
    {
      "id": "74b8692f-1b12-41db-b594-7adf81b2c6ca",
      "name": "Appointment Scheduler Tool",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        2400,
        112
      ],
      "parameters": {
        "text": "={{ $('If').item.json.chatInput }}",
        "options": {
          "systemMessage": "=You are Appointment Scheduling Assistant. Your job is to help patients book appointments by finding their record, showing available clinics and doctors, checking availability, and confirming bookings.\n\nFlow\n\t1.\tFind patient using find_patient with name + DOB.\n\t2.\tIf found \u2192 Continue. If not \u2192 Return \u201cnot found\u201d to parent agent.\n\t3.\tAsk clinic preference \u2192 Use get_clinics to show list.\n\t4.\tAsk doctor preference \u2192 Use get_doctors for that clinic.\n\t5.\tAsk preferred date/time.\n\t\u2022\tIf they ask for availability \u2192 Use get_availability to show slots.\n\t\u2022\tIf chosen time is unavailable \u2192 Ask them to pick from available slots.\n\t6.\tConfirm appointment: Generate ID (find_last_entry_id), save via create_appointment.\n\t7.\tAfter saving \u2192 Send confirmation with clinic, doctor, date & time.\n\t8.\tGuardrails:\n\t\u2022\tNo medical advice.\n\t\u2022\tRedirect irrelevant queries back to appointment flow.\n\t9.\tTime awareness: Always use {{ $now }} to calculate future slots."
        },
        "toolDescription": "Finds existing patients, guides them through selecting clinic, doctor, and time slot, then saves the appointment."
      },
      "typeVersion": 2.2
    },
    {
      "id": "35896748-805f-424f-9f8f-f3bbcc0c7e02",
      "name": "get_clinics",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        2352,
        320
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit#gid=0",
          "cachedResultName": "Clinics"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "Healthcare Demo Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "4916d7b8-0212-40d5-bc7b-fc586b7f6dfa",
      "name": "get_doctors",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        2480,
        320
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 288581725,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit#gid=288581725",
          "cachedResultName": "Doctors"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "Healthcare Demo Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "47c02793-e83e-48a9-8cfe-fb0ed1e6bd31",
      "name": "find_patient",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        2608,
        320
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1589180996,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit#gid=1589180996",
          "cachedResultName": "Patients"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "Healthcare Demo Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "799a81f4-beea-494d-8ec0-9ac023d409c0",
      "name": "create_appointment",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        2736,
        320
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Date', ``, 'string') }}",
            "Notes": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Notes', ``, 'string') }}",
            "End Time": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('End_Time', ``, 'string') }}",
            "Entry ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Entry_ID', ``, 'string') }}",
            "Clinic ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Clinic_ID', ``, 'string') }}",
            "Doctor ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Doctor_ID', ``, 'string') }}",
            "Patient ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Patient_ID', ``, 'string') }}",
            "Start Time": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start_Time', ``, 'string') }}",
            "Day of Week": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Day_of_Week', ``, 'string') }}",
            "Doctor Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Doctor_Name', ``, 'string') }}",
            "Patient Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Patient_Name', ``, 'string') }}",
            "Appointment Status": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Appointment_Status', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "Entry ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Entry ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Doctor ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Doctor ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Doctor Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Doctor Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Clinic ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Clinic ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Day of Week",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Day of Week",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Start Time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Start Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "End Time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "End Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Patient ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Patient ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Patient Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Patient Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Appointment Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Appointment Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Notes",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 88166562,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit#gid=88166562",
          "cachedResultName": "Appointments"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "Healthcare Demo Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "4ffb9d02-8027-4ab4-9ea6-c7c55ec6dbb7",
      "name": "get_availability",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        2864,
        320
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1434233673,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit#gid=1434233673",
          "cachedResultName": "Doctor Availability"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "Healthcare Demo Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "c64ba23f-8f2d-4489-95bf-9ca9078e96f5",
      "name": "find_last_entry_id",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        2992,
        320
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 88166562,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit#gid=88166562",
          "cachedResultName": "Appointments"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "Healthcare Demo Database"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "8eba5511-ef63-40fe-aad5-90391d6bffc5",
      "name": "Calculator1",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        2224,
        320
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c528d5e6-20c1-4a2a-99c9-63064184ad88",
      "name": "Memory2",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        2096,
        320
      ],
      "parameters": {
        "tableName": "demo_chat_histories",
        "sessionKey": "={{ $('If').item.json.sessionId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 300
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "87aa4804-1771-4c16-80db-a43ee0b30080",
      "name": "OpenAI2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1968,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "65936753-cf67-45a0-9acb-51e5ed679256",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1024,
        -112
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "924ad748-14b9-4f08-a13b-c8b602c09e4a",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.chatInput }}",
              "rightValue": "null"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "96fe8fb2-56ba-4be9-ac8c-62ac671bfba0",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -320,
        -144
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Image",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f2e2dbb1-7d6c-4592-a078-6541d92b871c",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.messages[0].image }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Document",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d97e949b-6df1-457b-9393-91726db54083",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.messages[0].document }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Audio",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f57a6d2f-97bf-4d0b-860f-3addbe4b91f7",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.messages[0].audio }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "741680c0-96e2-4845-b342-5d237c452011",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.messages[0].text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "1c05dcc5-d95f-4c01-863f-13b0c030ee6c",
      "name": "Get Audio URL",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        128,
        -16
      ],
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].audio.id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cab87c78-2caf-4578-b299-a225227d7b0e",
      "name": "Download Audio",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        352,
        -16
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "36c597ec-721b-49f3-aa88-033bec9a72cb",
      "name": "Transcribe Audio",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        576,
        -16
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "773905d6-b2e0-4b23-a947-2afd2afec411",
      "name": "Audio Prompt",
      "type": "n8n-nodes-base.set",
      "position": [
        800,
        -16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7e03f0fa-b2ce-4a63-aaf1-b5a94ffec5a5",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $('WATrigger').item.json.contacts[0].wa_id }}"
            },
            {
              "id": "491716ee-ed67-4440-aee5-28d808af85f2",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $json.text }}"
            },
            {
              "id": "1fad22a7-35f1-48c5-b0a2-58a51d7a2537",
              "name": "mode",
              "type": "string",
              "value": "audio"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c0b6c4f4-e8e0-4269-acdc-9ddab6b1b355",
      "name": "Download Image",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        352,
        -400
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "58fc7e82-5b73-429e-9536-434d6ea908c3",
      "name": "Get Image URL",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        128,
        -400
      ],
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $('WhatsApp Trigger').item.json.messages[0].image.id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "328f72a1-8491-4677-aff9-ba059f71c5dc",
      "name": "Analyze Image",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        576,
        -400
      ],
      "parameters": {
        "text": "=Please analyze this image and tell me what's in it. If it's a document, summarize the key details. If it's a photo, describe the contents.",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "chatgpt-4o-latest",
          "cachedResultName": "CHATGPT-4O-LATEST"
        },
        "options": {},
        "resource": "image",
        "inputType": "base64",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "f2abc060-ef0e-4ede-be37-4f515a760d7c",
      "name": "Text Prompt",
      "type": "n8n-nodes-base.set",
      "position": [
        800,
        176
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1bfd77fe-a9f8-4563-a948-924dc535d4eb",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $json.sessionId }}"
            },
            {
              "id": "7b201648-2d56-462b-ba8c-21477353aad5",
              "name": "action",
              "type": "string",
              "value": "sendMessage"
            },
            {
              "id": "abb84573-fdf4-4f35-b58b-07c3a2fcecd6",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $json.chatInput }}"
            },
            {
              "id": "993edb48-4b6d-485c-9777-c3ce279cba72",
              "name": "mode",
              "type": "string",
              "value": "text"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "09a5bd9b-2ef6-466c-8270-52205681bf18",
      "name": "Generate Audio",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        4048,
        -208
      ],
      "parameters": {
        "input": "={{ $json.output }}",
        "voice": "fable",
        "options": {},
        "resource": "audio"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "85c9e073-9d6b-43b5-bbcb-74e8dc55b438",
      "name": "response",
      "type": "n8n-nodes-base.if",
      "position": [
        3824,
        -112
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9eda56be-322f-44cd-9baa-4bb1495aff14",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('If').item.json.mode }}",
              "rightValue": "audio"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "39b15d2e-3a23-4085-8ba2-7411584c59dd",
      "name": "Text Message",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        4048,
        -16
      ],
      "parameters": {
        "textBody": "={{ $json.output }}",
        "operation": "send",
        "phoneNumberId": "REPLACE_WITH_YOUR_PHONE_NUMBER_ID",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('If').item.json.sessionId }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8485cd52-a0c2-4645-b45a-c46f97ff1b6c",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        4272,
        -208
      ],
      "parameters": {
        "jsCode": "// Loop over input items and change the MIME type of binary data\nfor (const item of $input.all()) {\n  // Check if the item has binary data\n  if (item.binary) {\n    // Find the binary property name (assuming there's at least one)\n    const binaryPropertyNames = Object.keys(item.binary);\n\n    for (const propName of binaryPropertyNames) {\n      // If the MIME type is 'audio/mp3', change it to 'audio/mpeg'\n      if (item.binary[propName].mimeType === \"audio/mp3\") {\n        item.binary[propName].mimeType = \"audio/mpeg\";\n      }\n    }\n  }\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "4b0d7acc-abbf-494b-a282-e3c9654c19f2",
      "name": "Audio Response",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        4496,
        -208
      ],
      "parameters": {
        "mediaPath": "useMedian8n",
        "operation": "send",
        "messageType": "audio",
        "phoneNumberId": "REPLACE_WITH_YOUR_PHONE_NUMBER_ID",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('If').item.json.sessionId }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e35299b7-476d-4d28-a904-2ac061ab86c2",
      "name": "Get Document",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        -96,
        -208
      ],
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].document.id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ac3fc974-139a-4d83-9edf-43e064586036",
      "name": "Download Document",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        128,
        -208
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f0ac2007-3139-4ad9-8d1d-2882095e5208",
      "name": "Analyzing Image Text",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        -96,
        -400
      ],
      "parameters": {
        "textBody": "Analyzing image\u2026",
        "operation": "send",
        "phoneNumberId": "REPLACE_WITH_YOUR_PHONE_NUMBER_ID",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f271af84-88b8-4761-9402-14c86a1bf860",
      "name": "If PDF File",
      "type": "n8n-nodes-base.if",
      "position": [
        352,
        -208
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "03affec6-8e7b-459d-a08a-c9af2660e319",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.mime_type }}",
              "rightValue": "application/pdf"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4542ea3c-b4c6-49e6-abc1-254821dbf4fe",
      "name": "Extract from PDF File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        576,
        -208
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "8de3dcbe-04f8-4668-8665-dfeee228926a",
      "name": "Document Prompt",
      "type": "n8n-nodes-base.set",
      "position": [
        800,
        -208
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7e03f0fa-b2ce-4a63-aaf1-b5a94ffec5a5",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $('WATrigger').item.json.contacts[0].wa_id }}"
            },
            {
              "id": "491716ee-ed67-4440-aee5-28d808af85f2",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $json.text }}"
            },
            {
              "id": "1fad22a7-35f1-48c5-b0a2-58a51d7a2537",
              "name": "mode",
              "type": "string",
              "value": "document"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a55056a0-b773-4c4c-aa01-b4a51bd6bde1",
      "name": "Image Prompt",
      "type": "n8n-nodes-base.set",
      "position": [
        800,
        -400
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7e03f0fa-b2ce-4a63-aaf1-b5a94ffec5a5",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $('WATrigger').item.json.contacts[0].wa_id }}"
            },
            {
              "id": "491716ee-ed67-4440-aee5-28d808af85f2",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $json.content }}"
            },
            {
              "id": "1fad22a7-35f1-48c5-b0a2-58a51d7a2537",
              "name": "mode",
              "type": "string",
              "value": "image"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "efc85109-b38a-44d5-908d-9504dd026d95",
      "name": "Report Analyzer Tool",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        3168,
        112
      ],
      "parameters": {
        "text": "={{ $('If').item.json.chatInput }}",
        "options": {
          "systemMessage": "=You are Medical Report Analyzer, a specialized AI assistant for analyzing medical reports and healthcare documents.\n\nYour job is to:\n\t1.\tAnalyze medical reports, lab results, X-rays, scans, and other healthcare documents\n\t2.\tProvide clear, understandable explanations of medical findings\n\t3.\tHighlight any abnormal values or concerning findings\n\t4.\tSuggest appropriate follow-up actions\n\t5.\tEducate patients about their health conditions in simple terms\n\nAnalysis Flow:\n\t1.\tCarefully review all provided medical documents\n\t2.\tIdentify key findings, test results, and measurements\n\t3.\tCompare values against normal reference ranges\n\t4.\tHighlight any abnormalities or areas of concern\n\t5.\tExplain findings in patient-friendly language\n\t6.\tProvide general health recommendations\n\t7.\tAlways recommend consulting healthcare providers for medical decisions\n\nReport Analysis Guidelines:\n\t\u2022\tUse clear, non-medical language that patients can understand\n\t\u2022\tExplain what each test measures and why it's important\n\t\u2022\tHighlight abnormal values and explain their potential significance\n\t\u2022\tProvide context for findings (mild, moderate, severe)\n\t\u2022\tSuggest lifestyle modifications when appropriate\n\t\u2022\tRecommend follow-up tests or consultations when needed\n\nImportant Disclaimers:\n\t\u2022\tAlways include: \"This analysis is for informational purposes only\"\n\t\u2022\tState: \"Please consult your healthcare provider for medical advice\"\n\t\u2022\tEmphasize: \"Do not use this analysis to make medical decisions\"\n\t\u2022\tClarify: \"Your doctor should interpret these results in context of your full medical history\"\n\nTone and Approach:\n\t\u2022\tProfessional yet compassionate\n\t\u2022\tEducational and informative\n\t\u2022\tReassuring when appropriate\n\t\u2022\tClear about limitations\n\t\u2022\tEncouraging patients to seek professional medical care\n\nConstraints:\n\t\u2022\tNo medical diagnosis or treatment recommendations\n\t\u2022\tNo prescription advice\n\t\u2022\tFocus on education and explanation only\n\t\u2022\tAlways defer to healthcare professionals for medical decisions"
        },
        "toolDescription": "Analyzes medical reports, lab results, X-rays, and other healthcare documents to provide clear explanations of findings, highlight abnormalities, and suggest follow-up actions."
      },
      "typeVersion": 2.2
    },
    {
      "id": "80503116-466c-4502-8a16-fea22b28c76a",
      "name": "OpenAI3",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        3120,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9c833ba6-b715-4baa-a35c-adc4b14e7f5a",
      "name": "Memory3",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        3264,
        320
      ],
      "parameters": {
        "tableName": "demo_chat_histories",
        "sessionKey": "={{ $('If').item.json.sessionId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 300
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "b6f91465-240d-46d5-8f88-151a92c2ffea",
      "name": "Prescription Medicine Analyzer Tool",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        3456,
        112
      ],
      "parameters": {
        "text": "={{ $('If').item.json.chatInput }}",
        "options": {
          "systemMessage": "=You are Prescription Medicine Analyzer, a specialized AI assistant for analyzing doctor prescriptions and verifying medicine authenticity.\n\nYour job is to:\n\t1.\tAnalyze doctor prescriptions from PDF or image uploads\n\t2.\tExtract and list all prescribed medications with details\n\t3.\tVerify if uploaded medicine photos match the prescription\n\t4.\tAnswer questions about prescribed medications\n\t5.\tProvide medicine information and usage guidance\n\t6.\tEnsure patient safety by identifying discrepancies\n\nAnalysis Flow:\n\t1.\tCheck if patient has uploaded a prescription first\n\t2.\tIf no prescription \u2192 Request prescription upload before proceeding\n\t3.\tExtract all medicine details from prescription:\n\t\t\u2022\tMedicine names (generic and brand)\n\t\t\u2022\tDosage and strength\n\t\t\u2022\tFrequency and duration\n\t\t\u2022\tSpecial instructions\n\t\t\u2022\tDoctor's notes\n\t4.\tWhen medicine photo is uploaded \u2192 Compare with prescription\n\t5.\tProvide detailed verification results\n\t6.\tAnswer specific questions about medications\n\nPrescription Requirements:\n\t\u2022\tAlways ask for prescription upload first if not provided\n\t\u2022\tSay: \"Please upload your doctor's prescription (PDF or image) before I can help verify your medicines\"\n\t\u2022\tOnly proceed with medicine verification after prescription is analyzed\n\nMedicine Verification Process:\n\t1.\tCompare medicine name on package with prescribed name\n\t2.\tCheck dosage/strength matches prescription\n\t3.\tVerify manufacturer if visible\n\t4.\tCheck expiration date\n\t5.\tIdentify any discrepancies or concerns\n\t6.\tProvide clear match/no-match result\n\nInformation to Provide:\n\t\u2022\tComplete list of prescribed medicines\n\t\u2022\tDosage instructions for each medicine\n\t\u2022\tTiming and frequency details\n\t\u2022\tFood/meal instructions\n\t\u2022\tDuration of treatment\n\t\u2022\tSpecial precautions or warnings\n\t\u2022\tMedicine verification results\n\nSafety Guidelines:\n\t\u2022\tAlert if medicine doesn't match prescription\n\t\u2022\tWarn about expired medications\n\t\u2022\tHighlight dosage discrepancies\n\t\u2022\tRecommend consulting pharmacist/doctor for concerns\n\t\u2022\tNever recommend changing prescribed medications\n\nResponse Format for Medicine Verification:\n\t\u2705 MATCH: [Medicine name] matches your prescription\n\t\u274c NO MATCH: [Medicine name] does not match - prescribed: [correct medicine]\n\t\u26a0\ufe0f WARNING: [Specific concern about the medicine]\n\nImportant Disclaimers:\n\t\u2022\t\"Always verify medicines with your pharmacist\"\n\t\u2022\t\"This analysis is for informational purposes only\"\n\t\u2022\t\"Consult your doctor before making any changes\"\n\t\u2022\t\"Double-check all medicines before taking them\"\n\nTone and Approach:\n\t\u2022\tSafety-focused and cautious\n\t\u2022\tClear and detailed explanations\n\t\u2022\tHelpful in organizing medicine information\n\t\u2022\tEncouraging verification with healthcare professionals\n\nConstraints:\n\t\u2022\tRequire prescription upload before medicine verification\n\t\u2022\tNo medical advice beyond prescription information\n\t\u2022\tFocus on verification and information only\n\t\u2022\tAlways prioritize patient safety"
        },
        "toolDescription": "Analyzes doctor prescriptions and verifies if uploaded medicine photos match prescribed medications. Provides detailed information about prescribed medicines and answers prescription-related questions."
      },
      "typeVersion": 2.2
    },
    {
      "id": "12eb3668-a0c4-4ee0-9262-0404a68f3f0d",
      "name": "OpenAI4",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        3392,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d1e82338-eccb-43f2-bbc3-dd1e4f86f0d8",
      "name": "Memory4",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        3536,
        320
      ],
      "parameters": {
        "tableName": "demo_chat_histories",
        "sessionKey": "={{ $('If').item.json.sessionId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 300
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "demo-healthcare-assistant-v1.0",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Appointment System",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Audio Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Memory": {
      "ai_memory": [
        [
          {
            "node": "Appointment System",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "ai_languageModel": [
        [
          {
            "node": "Appointment System",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Analyzing Image Text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Document",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Audio URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "PrepareInput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Memory1": {
      "ai_memory": [
        [
          {
            "node": "Register Patient Tool",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Memory2": {
      "ai_memory": [
        [
          {
            "node": "Appointment Scheduler Tool",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Memory3": {
      "ai_memory": [
        [
          {
            "node": "Report Analyzer Tool",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Memory4": {
      "ai_memory": [
        [
          {
            "node": "Prescription Medicine Analyzer Tool",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI1": {
      "ai_languageModel": [
        [
          {
            "node": "Register Patient Tool",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI2": {
      "ai_languageModel": [
        [
          {
            "node": "Appointment Scheduler Tool",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI3": {
      "ai_languageModel": [
        [
          {
            "node": "Report Analyzer Tool",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI4": {
      "ai_languageModel": [
        [
          {
            "node": "Prescription Medicine Analyzer Tool",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "response": {
      "main": [
        [
          {
            "node": "Generate Audio",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Text Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WATrigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "Register Patient Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Calculator1": {
      "ai_tool": [
        [
          {
            "node": "Appointment Scheduler Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "If PDF File": {
      "main": [
        [
          {
            "node": "Extract from PDF File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Prompt": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_clinics": {
      "ai_tool": [
        [
          {
            "node": "Appointment Scheduler Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "get_doctors": {
      "ai_tool": [
        [
          {
            "node": "Appointment Scheduler Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Audio Prompt": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Document": {
      "main": [
        [
          {
            "node": "Download Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Image Prompt": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PrepareInput": {
      "main": [
        [
          {
            "node": "Text Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Message": {
      "main": [
        []
      ]
    },
    "find_patient": {
      "ai_tool": [
        [
          {
            "node": "Appointment Scheduler Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Image": {
      "main": [
        [
          {
            "node": "Image Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Audio URL": {
      "main": [
        [
          {
            "node": "Download Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Image URL": {
      "main": [
        [
          {
            "node": "Download Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Audio": {
      "main": [
        [
          {
            "node": "Transcribe Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Image": {
      "main": [
        [
          {
            "node": "Analyze Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Audio": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "create_patient": {
      "ai_tool": [
        [
          {
            "node": "Register Patient Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Document Prompt": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Audio": {
      "main": [
        [
          {
            "node": "Audio Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_availability": {
      "ai_tool": [
        [
          {
            "node": "Appointment Scheduler Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Download Document": {
      "main": [
        [
          {
            "node": "If PDF File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Appointment System": {
      "main": [
        [
          {
            "node": "response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "create_appointment": {
      "ai_tool": [
        [
          {
            "node": "Appointment Scheduler Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "find_last_entry_id": {
      "ai_tool": [
        [
          {
            "node": "Appointment Scheduler Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "get_last_patient_id": {
      "ai_tool": [
        [
          {
            "node": "Register Patient Tool",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Analyzing Image Text": {
      "main": [
        [
          {
            "node": "Get Image URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Report Analyzer Tool": {
      "ai_tool": [
        [
          {
            "node": "Appointment System",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Extract from PDF File": {
      "main": [
        [
          {
            "node": "Document Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Register Patient Tool": {
      "ai_tool": [
        [
          {
            "node": "Appointment System",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Appointment Scheduler Tool": {
      "ai_tool": [
        [
          {
            "node": "Appointment System",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Prescription Medicine Analyzer Tool": {
      "ai_tool": [
        [
          {
            "node": "Appointment System",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}