{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "fc08a16b-26b6-4346-9ad4-788da0e8c6af",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        0
      ],
      "parameters": {
        "width": 560,
        "height": 928,
        "content": "## VLM Run Medical Assistant: Automated X-Ray Analysis  \n\n### Overview  \nThe **VLM Run Medical Assistant** uses VLM Run to automatically analyze X-ray images, detect abnormalities and generate diagnostic insights. It integrates directly into **n8n** workflows using **OpenAI-compatible API endpoints**, ensuring smooth setup and automation.  \n\n### How it works  \n- The workflow starts with a **file upload form**, where medical staff or users can submit **X-ray images**.\n- The uploaded file is passed to **VLM Run (model: `vlmrun-orion-1:auto`)**, which performs medical image interpretation and highlights potential disease areas.  \n- A **Code node** extracts the resulting image URL from the model\u2019s output.    \n- The workflow then automatically:  \n  - Sends results to the **doctor\u2019s email** for review.  \n  - Sends the same analysis and image to **Telegram** for instant notification.  \n  - Uploads patient data and reports to **Google Drive** for secure storage.  \n\n### Requirements  \n- **VLM Run API credentials** used to call the `vlmrun-orion-1:auto` model for X-ray analysis and generate disease-marked images.  \n\n- **Gmail OAuth2 credentials** required to automatically email the diagnostic report to medical personnel.  \n\n- **Telegram Bot credentials** used to send analysis results and annotated images directly to a Telegram chat.  \n\n- **Google Drive OAuth2 credentials** needed to upload the patient\u2019s report and annotated X-ray file."
      },
      "typeVersion": 1
    },
    {
      "id": "1e07426a-8d21-48a4-84fb-c09561489107",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        432
      ],
      "parameters": {
        "color": 4,
        "width": 480,
        "height": 496,
        "content": "## Send to Gmail & Telegram  \n\n### How it works  \n- The **Set node** provides two key fields:  \n  - `Description`: The disease diagnosis or \u201cNormal\u201d report from the model output.  \n  - `Output_Image`: The annotated image URL generated by VLM Run.  \n- The **Gmail node** sends a detailed message containing both text and output image to the configured medical email address.  \n- The **Convert to File node** transforms the description into a file format suitable for sharing.  \n- The **Telegram node** sends the annotated X-ray and analysis summary as a document to the target chat or channel.  \n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "993f85be-0090-4639-8594-c9ce5245907f",
      "name": "Upload X-Ray Image",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -160,
        768
      ],
      "parameters": {
        "options": {},
        "formTitle": "Upload your data to test RAG",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "data",
              "requiredField": true
            }
          ]
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "16fc2ea9-ebf7-4ebf-96a6-88e8e1a52ab8",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        432
      ],
      "parameters": {
        "color": 6,
        "width": 400,
        "height": 496,
        "content": "## Upload to Google Drive  \n\n## How it works  \n- The drive node uploads report to a designated Drive folder (e.g., `test_data`).  \n- Each uploaded record can include both the **X-ray report** and the **annotated image**, enabling centralized storage for medical teams.  \n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f948a0cd-07bf-4b1f-9eb4-589974b23a3d",
      "name": "Convert to Report",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        1200,
        944
      ],
      "parameters": {
        "options": {},
        "operation": "toText",
        "sourceProperty": "="
      },
      "typeVersion": 1.1
    },
    {
      "id": "2e744214-3bb1-4eef-9925-609dfa7a9417",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        400,
        960
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "f01d95b4-4459-4765-8a13-7c7ecb48e560",
      "name": "Analyze X-Ray",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        128,
        768
      ],
      "parameters": {
        "text": "You are an expert in X-ray analysis and disease detection. Analyze the given X-ray, mark the affected area and give a disease description only if the patient has a disease, else analyze as a normal X-ray.. Give new detected image.",
        "modelId": {
          "__rl": true,
          "mode": "id",
          "value": "vlmrun-orion-1:auto"
        },
        "options": {
          "detail": "high"
        },
        "resource": "image",
        "simplify": false,
        "inputType": "base64",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "205c8790-3b92-48fd-9acf-5c952bcc8a28",
      "name": "Send Details",
      "type": "n8n-nodes-base.gmail",
      "position": [
        624,
        784
      ],
      "parameters": {
        "sendTo": "mehediahamed@iut-dhaka.edu",
        "message": "Here is the Patient X Ray Analysis report-",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {},
              {}
            ]
          }
        },
        "subject": "Patient X Ray Analysis"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "b715ea5a-6d2e-453d-8789-434b5f4c0b0e",
      "name": "Send Details1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        896,
        784
      ],
      "parameters": {
        "chatId": "1872183963",
        "operation": "sendDocument",
        "binaryData": true,
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f16181fa-f52e-4416-ab86-08104ac30e01",
      "name": "Upload Report",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1200,
        784
      ],
      "parameters": {
        "name": "Patient Info",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive",
          "cachedResultName": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1S6baavqJn98MjUlbB6KtmARCWuWEekIZ",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1S6baavqJn98MjUlbB6KtmARCWuWEekIZ",
          "cachedResultName": "test_data"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "1a2fc9f9-f68f-46e6-915a-b229df345ce4",
      "name": "Set Key",
      "type": "n8n-nodes-base.set",
      "position": [
        896,
        944
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "960e54b4-bf69-4154-9862-2a530709cf3d",
              "name": "Description",
              "type": "string",
              "value": "={{ $json.choices[0].message.content }}"
            },
            {
              "id": "71c9e67c-d02a-4cc2-9e72-930b03e83523",
              "name": "Output_Image",
              "type": "string",
              "value": "={{ $json.storageLink }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "12f48efe-5caf-4a95-b607-5ff4692060c0",
      "name": "Get Image Artifact",
      "type": "@vlm-run/n8n-nodes-vlmrun.vlmRun",
      "position": [
        384,
        768
      ],
      "parameters": {
        "objectId": "={{ $json.choices[0].message.content.match(/img_[a-zA-Z0-9]+/) ? $json.choices[0].message.content.match(/img_[a-zA-Z0-9]+/)[0] : '' }}",
        "operation": "artifacts",
        "sessionId": "={{ $json.session_id }}"
      },
      "credentials": {
        "vlmRunApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Send Details",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Details1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Upload Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Key": {
      "main": [
        [
          {
            "node": "Convert to Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze X-Ray": {
      "main": [
        [
          {
            "node": "Set Key",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Image Artifact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to Report": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Image Artifact": {
      "main": [
        [
          {
            "node": "Send Details",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Upload X-Ray Image": {
      "main": [
        [
          {
            "node": "Analyze X-Ray",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}