Quick overview
This workflow combines a Telegram doctor bot, OpenAI, Google Sheets, Gmail, Slack, and a webhook to summarize PDF reports, generate and email discharge summaries, analyze lab values, report bed availability, send daily patient follow-ups, and post error alerts.
How it works
- Runs every day at 9:00 AM to read patient records from Google Sheets, filter those due for follow-up today with a Pending status, send each patient a Telegram check-in, and mark the follow-up as Sent.
- Triggers when a doctor sends a Telegram message and routes it based on whether it includes a document or a supported command.
- If a PDF is attached, downloads it from Telegram, extracts the text, uses OpenAI (gpt-4o-mini) to create a short clinical summary, logs the result to a Google Sheets Reports tab, and replies to the doctor on Telegram.
- If the message starts with "/discharge PATIENTID", extracts the patient ID, looks up the patient in the Google Sheets Patients tab, uses OpenAI (gpt-4o-mini) to generate a discharge summary, saves it back to Google Sheets, emails it to the patient via Gmail, and confirms completion on Telegram.
- If the message starts with "/labs", sends the provided lab values to OpenAI (gpt-4o-mini) for out-of-range flagging and plain-language explanations, then returns the analysis on Telegram.
- If the message starts with "/beds", reads ward capacity from the Google Sheets Beds tab, formats a ward-by-ward availability summary, and sends it to the doctor on Telegram.
- Receives bed-count updates via an HTTP POST webhook and updates the corresponding ward row in the Google Sheets Beds tab.
- Posts a Slack alert with execution details whenever the workflow encounters an error.
Setup
- Create credentials for Telegram Bot API, OpenAI, Google Sheets OAuth2, Gmail OAuth2, and Slack OAuth2, then connect them to the corresponding nodes.
- Create a Google Sheets spreadsheet with tabs named Patients, Reports, and Beds, and ensure the column names match those referenced in the workflow (for example, Patient ID, Follow-up Date, Follow-up Status, Telegram Chat ID, and ward bed fields).
- Replace YOUR_GOOGLE_SHEET_ID in every Google Sheets node with your spreadsheet ID.
- Update the Slack channel selection by replacing YOUR_SLACK_CHANNEL_ID with your target alerts channel.
- Copy the Webhook - Update Bed Count URL and configure your hospital management system to POST JSON with wardName and occupiedBeds to that endpoint.
- Ensure each patient row includes a valid Telegram Chat ID and Email so follow-ups and discharge emails reach the right recipients.