{
  "name": "Generate medical reports from emails with Gemini AI & Google Workspace",
  "nodes": [
    {
      "id": "91a19c78-df6d-42b2-85d7-abc7869b8942",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -528,
        96
      ]
    },
    {
      "id": "baa74409-0c1a-4bc9-8f84-a4af654509ff",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -240,
        96
      ]
    },
    {
      "id": "f4b76891-0cbe-4dab-a1f2-f2ce347f6d73",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        656,
        0
      ]
    },
    {
      "id": "f64e9b78-dc5d-4556-8322-1175a33dd062",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        0,
        0
      ]
    },
    {
      "id": "d0efc2af-649e-40b8-8dd9-eeeecdfaf488",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -48,
        288
      ]
    },
    {
      "id": "63c7245b-1c50-45ad-a136-075e92eec522",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        352,
        0
      ]
    },
    {
      "id": "8d11f752-f45c-4b55-b586-d16ad75ae194",
      "name": "Update a document1",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        1216,
        0
      ]
    },
    {
      "id": "ed90c89e-c092-4e07-95ae-a2a229bb994a",
      "name": "Copy file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        960,
        0
      ]
    },
    {
      "id": "472e8004-5605-4275-9975-e2bfe105a517",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2016,
        0
      ]
    },
    {
      "id": "52c9ce22-4874-4d5b-a75f-e620a4c0c6e0",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1504,
        0
      ]
    },
    {
      "id": "6ac43c97-8545-4811-b304-44e053b61071",
      "name": "Code1",
      "type": "n8n-nodes-base.code",
      "position": [
        1760,
        0
      ]
    },
    {
      "id": "6aa03f0e-dff0-4f33-943b-064c499863a9",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -160
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "🔔 *Triggers* the workflow when a new email is received from a specific sender (e.g. a doctor)."
      }
    },
    {
      "id": "14165e9d-eff7-40a6-b035-390de5c430b2",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        -160
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "🛠 *Extracts the raw email content* into a new field called `content` for AI processing."
      }
    },
    {
      "id": "f2adb4f2-1fd2-4e91-99cc-929f3b158dcb",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -176
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "🤖 *Processes the text using AI* to extract structured information like patient name, doctor name, etc."
      }
    },
    {
      "id": "6f55af2f-ac25-4462-be9e-6284fd1fdbf6",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        288,
        -176
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "🧹 *Cleans and parses* the AI response by removing markdown code formatting and turning it into usable JSON."
      }
    },
    {
      "id": "d93463fb-9399-4c51-bec9-26d29bd161b0",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        -176
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "📄 *Adds the extracted data* (patient info, diagnosis, etc.) to a specific Google Sheet row."
      }
    },
    {
      "id": "c8176919-4a09-4330-a481-6de25440845f",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        -176
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "📁 *Makes a copy* of the Google Docs medical report template for the current patient."
      }
    },
    {
      "id": "28dd3b51-feba-4981-8b4b-156f3dedbb07",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1152,
        -176
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "📝 *Replaces placeholders* (like patient name/date) in the copied Google Doc with real data."
      }
    },
    {
      "id": "a966576b-0bfe-4d03-acbe-8475c93c3a9e",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1424,
        -176
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "📤 *Exports the updated Google Doc* as a PDF via Google Drive API."
      }
    },
    {
      "id": "7853e5d4-27e0-4b7e-beed-a85704f5fd4e",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1680,
        -176
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "📛 *Renames the PDF file* using patient name and date, and attaches metadata."
      }
    },
    {
      "id": "f9504b84-ce1a-4dca-8378-fc8bf4183bfa",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1936,
        -176
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": "✉️ *Sends the final PDF* (medical report) to the recipient via Gmail."
      }
    }
  ],
  "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
          }
        ]
      ]
    }
  }
}