{
  "id": "uIcJuMR8Og1FjwMr",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Patient Reminder System",
  "tags": [],
  "nodes": [
    {
      "id": "55e0b6ad-5c28-4c86-a72c-510dd412904a",
      "name": "Trigger: Check Reminder Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -368,
        32
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b7eca472-960e-4d64-b3fe-a91bf89cc0d3",
      "name": "Fetch Patient Records",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -144,
        32
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1672401817,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8/edit#gid=1672401817",
          "cachedResultName": "Patients"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8/edit?usp=drivesdk",
          "cachedResultName": "LinkedIn Profile Monitor"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "4f90a586-e61f-4f50-80e3-694f9ac78f45",
      "name": "Match Reminder Time",
      "type": "n8n-nodes-base.if",
      "position": [
        208,
        32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "81a69983-d594-4699-94f8-6d02c1fd42c0",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json['Reminder Time'] }}",
              "rightValue": "={{ $now.format('HH:mm') }}"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "508b38fb-8446-46e4-ac51-c751322794be",
      "name": "Send Medicine Reminder",
      "type": "n8n-nodes-base.slack",
      "position": [
        448,
        16
      ],
      "parameters": {
        "text": "=Reminder for {{$json.Name}}\n\nTake: {{$json.Medicine}}\n\nReply:\n1. Taken\n2. Not Taken\n3. Feeling Unwell",
        "channel": "YOUR_CHANNEL",
        "attachments": [],
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6c4b5f20-2cc9-449d-9440-e600f5ef35bc",
      "name": "Receive Patient Response",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -400,
        496
      ],
      "parameters": {
        "path": "patient-reply",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 1
    },
    {
      "id": "44f9545d-6d32-4b20-838a-08e0f01be2c9",
      "name": "AI Response Classification",
      "type": "n8n-nodes-base.openAi",
      "position": [
        -224,
        496
      ],
      "parameters": {
        "model": "gpt-4-turbo",
        "prompt": {
          "messages": [
            {
              "role": "system",
              "content": "Classify patient response into JSON"
            },
            {
              "content": "=You are an AI healthcare assistant.\n\nYour task is to analyze a patient's response to a medicine reminder and classify it.\n\nClassify the response into ONE of the following categories:\n1. TAKEN \u2192 Patient confirmed they took the medicine\n2. NOT_TAKEN \u2192 Patient clearly did not take it\n3. LATER \u2192 Patient will take it later / delayed\n4. CONFUSED \u2192 Message is unclear, unrelated or cannot determine intent\n\nPatient Message:\n\"{{ $json.body.message }}\"\n\nAlso consider:\n- If the patient sounds confused, distressed or mentions symptoms (pain, dizziness, emergency, etc.), treat it as CONFUSED.\n- If the patient repeatedly avoids taking medicine or gives risky responses, it may indicate a CRITICAL situation.\n\nReturn output in STRICT JSON format:\n\n{\n  \"classification\": \"TAKEN | NOT_TAKEN | LATER | CONFUSED\",\n  \"is_critical\": true | false,\n  \"reason\": \"short explanation\",\n  \"recommended_action\": \"what system should do next\",\n  \"doctor_alert\": \"message to doctor if critical, otherwise empty string\",\n  \"patient_reply\": \"professional and empathetic reply to patient\"\n}\n\nRules:\n- Return ONLY valid JSON (no extra text)\n- Keep responses short and clear\n- If is_critical = true \u2192 MUST generate doctor_alert\n- patient_reply must always be polite, supportive and professional"
            }
          ]
        },
        "options": {},
        "resource": "chat",
        "requestOptions": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e9eb142e-9f76-44db-99a3-b1558370f64b",
      "name": "Parse & Normalize AI Output",
      "type": "n8n-nodes-base.code",
      "position": [
        -48,
        496
      ],
      "parameters": {
        "jsCode": "const raw = $json.message.content;\n\nlet parsed;\n\ntry {\n  parsed = JSON.parse(raw);\n} catch (e) {\n  parsed = {\n    classification: \"CONFUSED\",\n    is_critical: false,\n    reason: \"Parsing failed\",\n    recommended_action: \"Fallback\",\n    doctor_alert: \"\",\n    patient_reply: \"Sorry, I couldn't understand. Please try again.\"\n  };\n}\n\n// Remove reserved fields like index\nconst { index, ...rest } = $json;\n\n// Return in correct n8n format\nreturn [\n  {\n    json: {\n      ...parsed,\n      ...rest\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "ddcf6329-21d1-49c4-9048-99124d166fcd",
      "name": "Load Patient Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        240,
        496
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1672401817,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8/edit#gid=1672401817",
          "cachedResultName": "Patients"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8/edit?usp=drivesdk",
          "cachedResultName": "LinkedIn Profile Monitor"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "021a86c1-f4f8-4a16-b082-e694603fa9ff",
      "name": "Match Patient by Phone",
      "type": "n8n-nodes-base.if",
      "position": [
        432,
        496
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c4bf4917-afff-492c-b60c-37d2a53576b8",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.Phone.toString() }}",
              "rightValue": "={{ $('Receive Patient Response').item.json.body.phone }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "2d746208-d12b-463e-8457-8b4324862426",
      "name": "Update Missed Count",
      "type": "n8n-nodes-base.code",
      "position": [
        848,
        480
      ],
      "parameters": {
        "jsCode": "let missed = parseInt( $input.first().json.Missed_Count|| 0);\n\n// Increase count only for NOT_TAKEN or LATER\nif ($('Parse & Normalize AI Output').first().json.classification === \"NOT_TAKEN\") {\n  missed += 1;\n}\n\nif ($('Parse & Normalize AI Output').first().json.classification === \"LATER\") {\n  missed += 1;\n}\n\n// Reset if TAKEN\nif ($('Parse & Normalize AI Output').first().json.classification === \"TAKEN\") {\n  missed = 0;\n}\n\n// Attach new value\nreturn [\n  {\n    json: {\n      ...$input.first().json,\n      Missed_Count: missed\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "d6dc2b8a-7364-40aa-8e55-f58220c4bf73",
      "name": "Check Critical Condition",
      "type": "n8n-nodes-base.if",
      "position": [
        1248,
        480
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "2533fe93-8b66-4959-b933-9d31bc943f26",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('Parse & Normalize AI Output').item.json.is_critical }}",
              "rightValue": ""
            },
            {
              "id": "0057c6d1-0970-423b-a061-74340fb1d4c9",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.Missed_Count }}",
              "rightValue": 3
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0295ffec-379c-4b00-9a39-f121682fcc97",
      "name": "Update Critical Status",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1664,
        192
      ],
      "parameters": {
        "columns": {
          "value": {
            "Phone": "={{ $('Receive Patient Response').item.json.body.phone }}",
            "Status": "=CRITICAL",
            "Missed_Count": "={{ $json.Missed_Count }}",
            "Last Response": "={{ $('Parse & Normalize AI Output').item.json.classification }}",
            "Last Patient Message": "={{ $('Receive Patient Response').item.json.body.message }}"
          },
          "schema": [
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Medicine",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Medicine",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Reminder Time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Reminder Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Last Response",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Last Response",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Last Patient Message",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Last Patient Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Missed_Count",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Missed_Count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Phone"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1672401817,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8/edit#gid=1672401817",
          "cachedResultName": "Patients"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8/edit?usp=drivesdk",
          "cachedResultName": "LinkedIn Profile Monitor"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "cd847c40-19d4-432d-8723-03b376982153",
      "name": "Update Patient Record",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1680,
        720
      ],
      "parameters": {
        "columns": {
          "value": {
            "Phone": "={{ $('Receive Patient Response').item.json.body.phone }}",
            "Status": "={{ $('Parse & Normalize AI Output').item.json.classification }}",
            "Missed_Count": "={{ $('Update Missed Count').item.json.Missed_Count }}",
            "Last Response": "={{ $('Parse & Normalize AI Output').item.json.classification }}",
            "Last Patient Message": "={{ $('Receive Patient Response').item.json.body.message }}"
          },
          "schema": [
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Medicine",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Medicine",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Reminder Time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Reminder Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Last Response",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Last Response",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Last Patient Message",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Last Patient Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Missed_Count",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Missed_Count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Phone"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1672401817,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8/edit#gid=1672401817",
          "cachedResultName": "Patients"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1b4XQG0yh1s3ZrnYTsKBlnSMNdlYzQt42zJ8DUneVTS8/edit?usp=drivesdk",
          "cachedResultName": "LinkedIn Profile Monitor"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "433e06c6-2839-4ebe-91b3-e581ba473955",
      "name": "Route Based on Response",
      "type": "n8n-nodes-base.switch",
      "position": [
        1888,
        704
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "269864d9-4640-429f-a729-f99c7e35d01b",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse & Normalize AI Output').item.json.classification }}",
                    "rightValue": "NOT_TAKEN"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "3bbe8ea4-452b-4b9a-a9a7-15b9086006dc",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse & Normalize AI Output').item.json.classification }}",
                    "rightValue": "LATER"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "1f8b3965-ad4d-46e7-a376-5828399bdd56",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse & Normalize AI Output').item.json.classification }}",
                    "rightValue": "TAKEN"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.3
    },
    {
      "id": "97548710-3242-4a3d-a04f-204f32bf29ed",
      "name": "Notify Missed Dose",
      "type": "n8n-nodes-base.slack",
      "position": [
        2144,
        544
      ],
      "parameters": {
        "text": "You missed your medicine. Please take it as soon as possible.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0ALCNTB03G",
          "cachedResultName": "complain"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "f919177d-826a-4284-be9a-58d3b215b268",
      "name": "Reminder for Later",
      "type": "n8n-nodes-base.slack",
      "position": [
        2160,
        720
      ],
      "parameters": {
        "text": "No problem, Please don\u2019t forget to take it soon.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0ALCNTB03G",
          "cachedResultName": "complain"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "48a3050e-6f27-4a27-a8ba-ca50a7f526cb",
      "name": "Acknowledge Compliance",
      "type": "n8n-nodes-base.slack",
      "position": [
        2160,
        912
      ],
      "parameters": {
        "text": "Great! Keep taking your medicine regularly.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0ALCNTB03G",
          "cachedResultName": "complain"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "a0e7ecab-5d47-4e5c-891b-34b573493c8f",
      "name": "Alert Doctor (Critical Case)",
      "type": "n8n-nodes-base.slack",
      "position": [
        1904,
        192
      ],
      "parameters": {
        "text": "=CRITICAL PATIENT ALERT\n\nName: {{ $('Match Patient by Phone').item.json.Name }}\nPhone: {{$json.Phone}}\nMedicine: {{ $('Match Patient by Phone').item.json.Medicine }}\n\nReason:\n{{ $('Parse & Normalize AI Output').item.json.reason }}\n\nAI Alert:\n{{ $('Parse & Normalize AI Output').item.json.doctor_alert }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0ALTQD6L0H",
          "cachedResultName": "feature-addition"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "42dd5c65-3db3-4edf-90dd-ea9d60169f20",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -448,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 416,
        "content": "## Reminder Scheduler & Patient Fetch\nThis section initiates the workflow at regular intervals and retrieves all patient records from the database. It ensures the system continuously checks for upcoming medicine reminders and processes patient data dynamically without manual intervention."
      },
      "typeVersion": 1
    },
    {
      "id": "cd009249-4b25-49a9-a112-4c8b50ed5b75",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 416,
        "content": "## Reminder Time Validation\nThis section verifies whether the current time matches the patient\u2019s scheduled reminder time. If matched, it sends a personalized medicine reminder via Slack, prompting the patient to confirm their action or provide a response."
      },
      "typeVersion": 1
    },
    {
      "id": "0aa13a73-4a5f-4164-a542-00ec1b8c1264",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -448,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 592,
        "height": 400,
        "content": "## Patient Response Intake & AI Processing\nThis section captures patient replies via webhook and uses AI to classify their response. The output is parsed into structured JSON, ensuring consistent data handling for further decision-making and automation."
      },
      "typeVersion": 1
    },
    {
      "id": "eae02ea5-36ba-4f8c-b2b2-f7886afb90f7",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        192,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 400,
        "content": "## Patient Identification & Tracking\nThis section identifies the correct patient by matching the incoming response phone number with stored records. It ensures that all actions, updates and alerts are applied to the correct individual."
      },
      "typeVersion": 1
    },
    {
      "id": "258a6952-c2fa-4af2-967d-94bd0e9bab08",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        736,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 400,
        "content": "## Missed Dose Calculation\nThis section updates the patient\u2019s missed medicine count based on their response. It increments the count for missed or delayed doses and resets it when medicine is taken, helping track adherence over time."
      },
      "typeVersion": 1
    },
    {
      "id": "538523ee-76a1-4157-9f52-78aaef6731e7",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 368,
        "height": 400,
        "content": "## Critical Condition Detection \nThis section evaluates whether the situation is critical based on AI output or missed dose thresholds. It ensures that high-risk cases are immediately flagged for urgent attention and escalation."
      },
      "typeVersion": 1
    },
    {
      "id": "18c0f105-cbf4-41ac-9c8c-6e19e3fa00b5",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1568,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 352,
        "content": "## Data Update & Doctor Alert\nThis section updates the patient\u2019s record with critical status and sends an alert to the doctor via Slack. It ensures immediate visibility of high-risk patients and enables timely medical intervention."
      },
      "typeVersion": 1
    },
    {
      "id": "ec83b811-3640-4d47-9985-e6f84a155388",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1568,
        416
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 688,
        "content": "## Standard Update & Patient Feedback \nThis section updates patient records for non-critical cases and routes responses based on classification. It sends appropriate feedback messages to patients, ensuring engagement and encouraging medication adherence."
      },
      "typeVersion": 1
    },
    {
      "id": "1dd765da-244f-479f-9d7f-41d330174d9f",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -448,
        -688
      ],
      "parameters": {
        "width": 832,
        "height": 464,
        "content": "## How Workflow Works + Setup (Detailed)\nThis workflow automates medicine adherence tracking by combining scheduled reminders, AI-based response analysis and real-time notifications. It starts with a scheduler that periodically checks patient records stored in Google Sheets. When the current time matches a patient\u2019s reminder time, a Slack message is sent prompting them to confirm whether they took their medicine.\n\nWhen a patient responds, the webhook captures the message and sends it to an AI model for classification. The AI determines whether the medicine was taken, missed, delayed or unclear and also identifies potential critical conditions. The response is then parsed and matched to the correct patient using their phone number.\n\nBased on the classification, the system updates the patient\u2019s record, adjusts missed dose counts and evaluates whether escalation is required. If a critical condition is detected or missed doses exceed a threshold, an alert is sent to the doctor. Otherwise, the patient receives a contextual follow-up message.\n\nSetup Steps:\nConnect Google Sheets with patient data\nConfigure Slack API for messaging\nSet up webhook endpoint for responses\nAdd OpenAI API key for classification\nDefine reminder times in sheet\nActivate workflow with schedule trigger"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "841adf09-5677-49d2-af3b-8223fb262472",
  "connections": {
    "Load Patient Data": {
      "main": [
        [
          {
            "node": "Match Patient by Phone",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Match Reminder Time": {
      "main": [
        [
          {
            "node": "Send Medicine Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Missed Count": {
      "main": [
        [
          {
            "node": "Check Critical Condition",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Patient Records": {
      "main": [
        [
          {
            "node": "Match Reminder Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Patient Record": {
      "main": [
        [
          {
            "node": "Route Based on Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Match Patient by Phone": {
      "main": [
        [
          {
            "node": "Update Missed Count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Critical Status": {
      "main": [
        [
          {
            "node": "Alert Doctor (Critical Case)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Based on Response": {
      "main": [
        [
          {
            "node": "Notify Missed Dose",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reminder for Later",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Acknowledge Compliance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Critical Condition": {
      "main": [
        [
          {
            "node": "Update Critical Status",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Patient Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Patient Response": {
      "main": [
        [
          {
            "node": "AI Response Classification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Response Classification": {
      "main": [
        [
          {
            "node": "Parse & Normalize AI Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse & Normalize AI Output": {
      "main": [
        [
          {
            "node": "Load Patient Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert Doctor (Critical Case)": {
      "main": [
        []
      ]
    },
    "Trigger: Check Reminder Schedule": {
      "main": [
        [
          {
            "node": "Fetch Patient Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}