This workflow corresponds to n8n.io template #6487 — we link there as the canonical source.
This workflow follows the Agent → Gmail recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"id": "iKLz8kl2wKbZDjdk",
"name": "AI Medical Report Generator",
"tags": [],
"nodes": [
{
"id": "91a19c78-df6d-42b2-85d7-abc7869b8942",
"name": "Gmail Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-528,
96
],
"parameters": {
"simple": false,
"filters": {
"sender": "user@example.com"
},
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyHour"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "baa74409-0c1a-4bc9-8f84-a4af654509ff",
"name": "Edit Fields",
"type": "n8n-nodes-base.set",
"notes": "\ud83d\udee0 *Extracts the raw email content* into a new field called `content` for AI processing.",
"position": [
-240,
96
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "d4b7d4b4-3daa-4804-bf99-fadfed1b7bb2",
"name": "content",
"type": "string",
"value": "={{ $json.text }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "f4b76891-0cbe-4dab-a1f2-f2ce347f6d73",
"name": "Append row in sheet",
"type": "n8n-nodes-base.googleSheets",
"position": [
656,
0
],
"parameters": {
"columns": {
"value": {
"Date": "={{ $json.date }}",
"Diagnoses": "={{ $json.diagnosis }}",
"Patient Name": "={{ $json.patient_name }}",
"Doctor's Name": "={{ $json.doctor_name }}",
"Patient Phone Num.": "={{ $json.phone_number }}"
},
"schema": [
{
"id": "Date",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Patient Name",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Patient Name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Patient Phone Num.",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Patient Phone Num.",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Doctor's Name",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Doctor's Name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Diagnoses",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Diagnoses",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Description ",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Description ",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Attachments",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Attachments",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 12488983,
"cachedResultUrl": "https://your-google-sheet-url/d/1EZgjpZ2B1umVImyMItfaHRn7Gi2T-y9etYmUNQZNiRw/edit#gid=12488983",
"cachedResultName": "Sheet2"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1EZgjpZ2B1umVImyMItfaHRn7Gi2T-y9etYmUNQZNiRw",
"cachedResultUrl": "https://your-google-sheet-url/d/1EZgjpZ2B1umVImyMItfaHRn7Gi2T-y9etYmUNQZNiRw/edit?usp=drivesdk",
"cachedResultName": "your-sheet-name"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 4.6
},
{
"id": "f64e9b78-dc5d-4556-8322-1175a33dd062",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
0,
0
],
"parameters": {
"text": "=Extract the following details from the input below and return them in raw JSON format:\n\n- patient_name \n- doctor_name (if not found, return null) \n- diagnosis \n- phone_number (must start with 0111) \n- date (use today\u2019s date in YYYY-MM-DD format)\n\nINPUT:\n{{ $json.content }}\n\nRespond ONLY with JSON like this:\n{\n \"patient_name\": \"john doe\",\n \"doctor_name\": null,\n \"diagnosis\": \"diaria\",\n \"phone_number\": \"0111xxxxxxx\",\n \"date\": \"2025-07-21\"\n}\n",
"options": {},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 2.1
},
{
"id": "d0efc2af-649e-40b8-8dd9-eeeecdfaf488",
"name": "Google Gemini Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"notes": "\u2699\ufe0f *Specifies the AI model* (Gemini) used by the AI Agent for text understanding.",
"position": [
-48,
288
],
"parameters": {
"options": {},
"modelName": "models/gemini-2.0-flash-lite"
},
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "63c7245b-1c50-45ad-a136-075e92eec522",
"name": "Code",
"type": "n8n-nodes-base.code",
"position": [
352,
0
],
"parameters": {
"jsCode": "const rawOutput = $json[\"output\"];\n\n// Remove ```json ... ``` if it exists\nconst cleaned = rawOutput.replace(/```json\\n?|```/g, \"\").trim();\n\nconst parsed = JSON.parse(cleaned);\n\nreturn [\n {\n json: parsed\n }\n];"
},
"typeVersion": 2
},
{
"id": "8d11f752-f45c-4b55-b586-d16ad75ae194",
"name": "Update a document1",
"type": "n8n-nodes-base.googleDocs",
"position": [
1216,
0
],
"parameters": {
"actionsUi": {
"actionFields": [
{
"rows": 2,
"action": "insert",
"object": "table",
"columns": 2
},
{
"text": "{{date}}",
"action": "replaceAll",
"replaceText": "={{ $('Append row in sheet').item.json.Date }}"
},
{
"rows": 3,
"action": "insert",
"object": "table",
"columns": 3
},
{
"text": "{{patient_name}}",
"action": "replaceAll",
"replaceText": "={{ $('Append row in sheet').item.json['Patient Name'] }}"
}
]
},
"operation": "update",
"documentURL": "https://your-google-doc-url/d/1UzqfWelQRYC_i9Q_7snYJ8h67b3-qfLK9YxGiKgl25k/edit?tab=t.0"
},
"credentials": {
"googleDocsOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 2
},
{
"id": "ed90c89e-c092-4e07-95ae-a2a229bb994a",
"name": "Copy file",
"type": "n8n-nodes-base.googleDrive",
"position": [
960,
0
],
"parameters": {
"name": "=your-doc-template-name - {{ $json['Patient Name'] }}",
"fileId": {
"__rl": true,
"mode": "list",
"value": "1UzqfWelQRYC_i9Q_7snYJ8h67b3-qfLK9YxGiKgl25k",
"cachedResultUrl": "https://your-google-doc-url/d/1UzqfWelQRYC_i9Q_7snYJ8h67b3-qfLK9YxGiKgl25k/edit?usp=drivesdk",
"cachedResultName": "your-doc-template-name"
},
"options": {},
"operation": "copy"
},
"credentials": {
"googleDriveOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 3
},
{
"id": "472e8004-5605-4275-9975-e2bfe105a517",
"name": "Send a message",
"type": "n8n-nodes-base.gmail",
"position": [
2016,
0
],
"parameters": {
"sendTo": "user@example.com",
"message": "Please find the your-doc-template-name attached",
"options": {
"attachmentsUi": {
"attachmentsBinary": [
{}
]
}
},
"subject": "=your-doc-template-name - {{ $('Code').item.json.patient_name }}",
"emailType": "text"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "52c9ce22-4874-4d5b-a75f-e620a4c0c6e0",
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"position": [
1504,
0
],
"parameters": {
"url": "=https://www.googleapis.com/drive/v3/files/{{ $node[\"Copy file\"].json[\"id\"] }}/export?mimeType=application/pdf\n",
"options": {},
"sendQuery": true,
"authentication": "predefinedCredentialType",
"queryParameters": {
"parameters": [
{}
]
},
"nodeCredentialType": "googleDriveOAuth2Api"
},
"credentials": {
"googleDriveOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 4.2
},
{
"id": "6ac43c97-8545-4811-b304-44e053b61071",
"name": "Code1",
"type": "n8n-nodes-base.code",
"position": [
1760,
0
],
"parameters": {
"jsCode": "const patientName = $node[\"HTTP Request\"].json.patientName;\nconst dateStr = new Date().toISOString().split('T')[0]; // e.g. \"2025-07-21\"\nitems[0].binary.data.fileName = `${$('Append row in sheet').first().json['Patient Name']}_${dateStr}.pdf`;\nitems[0].binary.data.mimeType = 'application/pdf';\nreturn items;"
},
"typeVersion": 2
},
{
"id": "6aa03f0e-dff0-4f33-943b-064c499863a9",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-560,
-160
],
"parameters": {
"color": 3,
"content": "\ud83d\udd14 *Triggers* the workflow when a new email is received from a specific sender (e.g. a doctor)."
},
"typeVersion": 1
},
{
"id": "14165e9d-eff7-40a6-b035-390de5c430b2",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-304,
-160
],
"parameters": {
"color": 5,
"content": "\ud83d\udee0 *Extracts the raw email content* into a new field called `content` for AI processing."
},
"typeVersion": 1
},
{
"id": "f2adb4f2-1fd2-4e91-99cc-929f3b158dcb",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
-176
],
"parameters": {
"color": 4,
"content": "\ud83e\udd16 *Processes the text using AI* to extract structured information like patient name, doctor name, etc."
},
"typeVersion": 1
},
{
"id": "6f55af2f-ac25-4462-be9e-6284fd1fdbf6",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
288,
-176
],
"parameters": {
"color": 3,
"content": "\ud83e\uddf9 *Cleans and parses* the AI response by removing markdown code formatting and turning it into usable JSON."
},
"typeVersion": 1
},
{
"id": "d93463fb-9399-4c51-bec9-26d29bd161b0",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
576,
-176
],
"parameters": {
"color": 5,
"content": "\ud83d\udcc4 *Adds the extracted data* (patient info, diagnosis, etc.) to a specific Google Sheet row."
},
"typeVersion": 1
},
{
"id": "c8176919-4a09-4330-a481-6de25440845f",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
880,
-176
],
"parameters": {
"color": 3,
"content": "\ud83d\udcc1 *Makes a copy* of the Google Docs medical report template for the current patient."
},
"typeVersion": 1
},
{
"id": "28dd3b51-feba-4981-8b4b-156f3dedbb07",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
1152,
-176
],
"parameters": {
"color": 5,
"content": "\ud83d\udcdd *Replaces placeholders* (like patient name/date) in the copied Google Doc with real data."
},
"typeVersion": 1
},
{
"id": "a966576b-0bfe-4d03-acbe-8475c93c3a9e",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"position": [
1424,
-176
],
"parameters": {
"color": 3,
"content": "\ud83d\udce4 *Exports the updated Google Doc* as a PDF via Google Drive API."
},
"typeVersion": 1
},
{
"id": "7853e5d4-27e0-4b7e-beed-a85704f5fd4e",
"name": "Sticky Note8",
"type": "n8n-nodes-base.stickyNote",
"position": [
1680,
-176
],
"parameters": {
"color": 5,
"content": "\ud83d\udcdb *Renames the PDF file* using patient name and date, and attaches metadata."
},
"typeVersion": 1
},
{
"id": "f9504b84-ce1a-4dca-8378-fc8bf4183bfa",
"name": "Sticky Note9",
"type": "n8n-nodes-base.stickyNote",
"position": [
1936,
-176
],
"parameters": {
"content": "\u2709\ufe0f *Sends the final PDF* (medical report) to the recipient via Gmail."
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "389f4f89-16fb-4cce-8d2e-e4f031b7fdfc",
"connections": {
"Code": {
"main": [
[
{
"node": "Append row in sheet",
"type": "main",
"index": 0
}
]
]
},
"Code1": {
"main": [
[
{
"node": "Send a message",
"type": "main",
"index": 0
}
]
]
},
"AI Agent": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Copy file": {
"main": [
[
{
"node": "Update a document1",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request": {
"main": [
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"Gmail Trigger": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"Update a document1": {
"main": [
[
{
"node": "HTTP Request",
"type": "main",
"index": 0
}
]
]
},
"Append row in sheet": {
"main": [
[
{
"node": "Copy file",
"type": "main",
"index": 0
}
]
]
},
"Google Gemini Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
gmailOAuth2googleDocsOAuth2ApigoogleDriveOAuth2ApigooglePalmApigoogleSheetsOAuth2Api
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This template is designed for healthcare providers, sales reps, and medical tourism companies who need to process diagnosis emails efficiently. It automates the full flow from email to report delivery.
Source: https://n8n.io/workflows/6487/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
> Note: This workflow uses sticky notes extensively to document each logical section of the automation. Sticky notes are mandatory and already included to explain OCR, AI parsing, folder logic, dup
CV → Match → Screen → Decide, all automated
Enterprise-grade resume screening automation built for production environments. This workflow combines intelligent AI analysis with comprehensive error handling to ensure reliable processing of candid
Based on the Google Sheet data, the AI will retrieve the userstories ID's, retrieves the userstory data and the corresponding attachments and creates sprint goals according to the defined system promp
This workflow automates the extraction and processing of invoice data from PDFs stored in a Google Drive folder. It leverages Google Drive, Google Sheets, and Gemini AI to streamline invoice managemen