{
  "id": "fiiQwBVbCBkZ1MvC",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI Prescription Processing & Pharmacy Order Management System",
  "tags": [],
  "nodes": [
    {
      "id": "04f374c0-38ee-4ec6-b9da-fc67912b2786",
      "name": "\ud83d\udccc Overview \u2013 How This Workflow Works",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2608,
        592
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "7f3c2e57-c9d9-472a-9d4a-69d8d1d490a2",
      "name": "Section \u2013 Message Intake & Routing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1712,
        1216
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "0aa24eb4-5cdb-4ac1-8faa-f30152d21290",
      "name": "Section \u2013 Prescription OCR & Inventory Lookup",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        928
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "bed782f7-4d82-421d-b34b-fc25a02e9a87",
      "name": "Section \u2013 Order Build & Summary",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        928
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "134befcd-9df2-485d-8108-8e6e95273e85",
      "name": "Section \u2013 Status, Refill & Confirm Commands",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -848,
        1424
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "44a223d3-6094-4ba2-8300-67a06ab55057",
      "name": "Section \u2013 Delivery Status Updates",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        2208
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "a122dd2d-5346-4eaf-ac44-85cff74ad987",
      "name": "Section \u2013 Scheduled Refill Reminders",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1440,
        2560
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "be4d4525-5884-4150-825e-a8792bad79d8",
      "name": "\ud83d\udd11 Credentials & Security",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        2704
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "94bea7c5-926b-494e-8e50-ccf846137a21",
      "name": "Telegram Message Received",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1616,
        1440
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "cd584731-761e-44b8-afa2-1ecbf44ca153",
      "name": "Normalize Incoming Message",
      "type": "n8n-nodes-base.code",
      "position": [
        -1376,
        1440
      ],
      "parameters": {},
      "typeVersion": 2
    },
    {
      "id": "625ed286-6661-4abb-8956-572fe419b9aa",
      "name": "Route By Message Type",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1136,
        1408
      ],
      "parameters": {},
      "typeVersion": 3
    },
    {
      "id": "66bac893-bc4b-4c13-9334-4def03554861",
      "name": "Telegram - Download Photo",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -816,
        1168
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "62a1002d-59ae-4195-bf4c-3105d1f64228",
      "name": "Analyze an image",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        -432,
        1168
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "cf8dc6dd-2bb6-4507-8f27-3a3f34209941",
      "name": "Parse OCR Result",
      "type": "n8n-nodes-base.code",
      "position": [
        -96,
        1168
      ],
      "parameters": {},
      "typeVersion": 2
    },
    {
      "id": "7f9310ce-a447-4f2d-9e65-5602f6e74231",
      "name": "Split Out Medicines",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        144,
        1168
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "66128212-9f71-4443-8159-8a1ad50ac45b",
      "name": "Lookup Medicine In Inventory",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        384,
        1168
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "2adf6893-e139-4ae5-8f84-7e350d26a88c",
      "name": "Check Stock Available",
      "type": "n8n-nodes-base.if",
      "position": [
        656,
        1168
      ],
      "parameters": {},
      "typeVersion": 2
    },
    {
      "id": "b0548c56-9d1c-4852-ab3c-023000f54a19",
      "name": "Update Inventory Stock",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        880,
        1056
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "fe327609-f2bb-4ddd-a569-074b3f84d3bf",
      "name": "Aggregate Order Lines",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1152,
        1184
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "de8679bc-67c9-40e7-82b5-43161028dfad",
      "name": "Build Order Summary",
      "type": "n8n-nodes-base.code",
      "position": [
        1392,
        1184
      ],
      "parameters": {},
      "typeVersion": 2
    },
    {
      "id": "abd3cd2d-b3dd-40f9-9c0b-c66476e40dac",
      "name": "Create Order Record",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1632,
        1184
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "4b85f238-b9e6-4a4a-b7cf-64dfa5f453e5",
      "name": "Telegram - Send Order Summary",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1872,
        1184
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "b41f4e33-b027-4432-a525-d5c30ed4d8ef",
      "name": "Get Latest Order (Status)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -752,
        1536
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "f2622038-57ec-497f-9418-e6cfaa49fb6a",
      "name": "Telegram - Send Delivery Status",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -512,
        1536
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "ea6bca81-08fb-43dc-9205-052af473e219",
      "name": "Get Last Order (Refill)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -768,
        1744
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "eac6d80f-60e0-44ce-9434-4ec0191fb47c",
      "name": "Build Refill Order",
      "type": "n8n-nodes-base.code",
      "position": [
        -528,
        1744
      ],
      "parameters": {},
      "typeVersion": 2
    },
    {
      "id": "73763f9b-2c6a-4743-86b7-5ced90543176",
      "name": "Get Pending Order (Confirm)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -784,
        1952
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "d07a97b7-6398-44a1-af54-0a6f0904b2a9",
      "name": "Update Order Status To Confirmed",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -544,
        1952
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "a9811bcb-bbc1-4ba2-8513-22af77872396",
      "name": "Telegram - Send Order Confirmed",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -304,
        1952
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "26598c9a-e628-4176-a260-9a390b15ebad",
      "name": "Delivery Status Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1216,
        2336
      ],
      "parameters": {},
      "typeVersion": 2
    },
    {
      "id": "7498b876-aadb-4e87-96aa-be250a72a7ea",
      "name": "Update Order Delivery Status",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -976,
        2336
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "b632ff13-d603-4e8a-8a9f-b861767750e6",
      "name": "Telegram - Send Delivery Update",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -736,
        2336
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "0bdcef60-29ab-4117-a433-548f3b8544f4",
      "name": "Daily Refill Check",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1392,
        2736
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "5318d4e4-26d3-4bb7-854d-9bdd0cd1af1f",
      "name": "Get Orders Due For Refill",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1152,
        2736
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "15116ebe-e7de-401c-9560-e6f3ab54a68d",
      "name": "Filter Due Today Or Earlier",
      "type": "n8n-nodes-base.filter",
      "position": [
        -912,
        2736
      ],
      "parameters": {},
      "typeVersion": 2
    },
    {
      "id": "2d1edc42-1d01-4758-bd1a-9519b735f790",
      "name": "Loop Over Due Refills",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -672,
        2736
      ],
      "parameters": {},
      "typeVersion": 3
    },
    {
      "id": "280a9add-d440-41fe-8ab7-ee6ba11e5a97",
      "name": "Telegram - Send Refill Reminder",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -416,
        2864
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "6ba69206-53bf-477f-a130-651ae2b44d78",
      "name": "Mark Reminder Sent",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -176,
        2864
      ],
      "parameters": {},
      "typeVersion": 4.5
    },
    {
      "id": "796ee51b-2332-446e-8e57-b17a5968570e",
      "name": "Section \u2013 Error Handling",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2032,
        2592
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "3cc3c40f-24bf-45a3-b825-b2ab01d7c224",
      "name": "On Workflow Error",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        -1952,
        2768
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "919cf759-2921-418c-be9f-db9700ecd681",
      "name": "Slack \u2013 Post Workflow Error Alert",
      "type": "n8n-nodes-base.slack",
      "position": [
        -1696,
        2768
      ],
      "parameters": {},
      "typeVersion": 2.3
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "e70695c4-2874-4885-bde7-f8fc6eb89fb1",
  "connections": {
    "Analyze an image": {
      "main": [
        [
          {
            "node": "Parse OCR Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse OCR Result": {
      "main": [
        [
          {
            "node": "Split Out Medicines",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On Workflow Error": {
      "main": [
        [
          {
            "node": "Slack \u2013 Post Workflow Error Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Refill Order": {
      "main": [
        [
          {
            "node": "Create Order Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Refill Check": {
      "main": [
        [
          {
            "node": "Get Orders Due For Refill",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark Reminder Sent": {
      "main": [
        [
          {
            "node": "Loop Over Due Refills",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Order Summary": {
      "main": [
        [
          {
            "node": "Create Order Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Order Record": {
      "main": [
        [
          {
            "node": "Telegram - Send Order Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Medicines": {
      "main": [
        [
          {
            "node": "Lookup Medicine In Inventory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Order Lines": {
      "main": [
        [
          {
            "node": "Build Order Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Stock Available": {
      "main": [
        [
          {
            "node": "Update Inventory Stock",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Aggregate Order Lines",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Due Refills": {
      "main": [
        [],
        [
          {
            "node": "Telegram - Send Refill Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route By Message Type": {
      "main": [
        [
          {
            "node": "Telegram - Download Photo",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Last Order (Refill)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Latest Order (Status)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Pending Order (Confirm)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Inventory Stock": {
      "main": [
        [
          {
            "node": "Aggregate Order Lines",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delivery Status Webhook": {
      "main": [
        [
          {
            "node": "Update Order Delivery Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Last Order (Refill)": {
      "main": [
        [
          {
            "node": "Build Refill Order",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Latest Order (Status)": {
      "main": [
        [
          {
            "node": "Telegram - Send Delivery Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Orders Due For Refill": {
      "main": [
        [
          {
            "node": "Filter Due Today Or Earlier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram - Download Photo": {
      "main": [
        [
          {
            "node": "Analyze an image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Message Received": {
      "main": [
        [
          {
            "node": "Normalize Incoming Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Incoming Message": {
      "main": [
        [
          {
            "node": "Route By Message Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Due Today Or Earlier": {
      "main": [
        [
          {
            "node": "Loop Over Due Refills",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Pending Order (Confirm)": {
      "main": [
        [
          {
            "node": "Update Order Status To Confirmed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lookup Medicine In Inventory": {
      "main": [
        [
          {
            "node": "Check Stock Available",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Order Delivery Status": {
      "main": [
        [
          {
            "node": "Telegram - Send Delivery Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram - Send Refill Reminder": {
      "main": [
        [
          {
            "node": "Mark Reminder Sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Order Status To Confirmed": {
      "main": [
        [
          {
            "node": "Telegram - Send Order Confirmed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}