The patient care system of a physical therapy clinic, implemented and tested: evaluation and session scheduling, a treatment plan with a dropout alert, home exercises with a reminder, adherence and pain, and a Telegram team desk. The bot never gives clinical advice. Ready to run: ./atende serve on your machine or Docker on your VPS.

The project explained in a few minutes.
The app is in the repository and passes the 98 acceptance tests. It was built by an agent (Codex, on a subscription) from a contract written before the code, a frozen test battery and guardrails that blocked shortcuts; an independent verification then checked the result against a clinic the agent had never seen. The sibling Atende Clínica, which served as the mold, was made the same way and closed 93 of 93 tests.
Scheduling for evaluations, sessions and RPG (postural re-education), no double booking, automatic confirmation and a waitlist. At the center, the treatment plan: planned against completed sessions, with a dropout alert and a re-evaluation alert. Python 3 with the standard library only and SQLite, one clinic per installation. Version 0.7.0.
A 26-section specification (0 to 25), 98 black-box tests, 21 accepted decisions, a map to Raio-X and guardrails that froze the contract. An adversarial validator reviewed the plan first (it found and fixed 9 problems); then the agent implemented it in 7 cycles up to 98 of 98. All of it is still in the repository.
No-shows, patients who do not come back and indicated treatment that never starts are the leaks the system attacks. The system hands eight monthly numbers to the dashboard of Raio-X de Margem, the source of the business rules and of the professional-council guardrail.
It explains an exercise only if the physical therapist prescribed it to that patient. Anything else gets "talk to your physical therapist" and a human attendant. It never gives a diagnosis, medication or clinical advice.
Pain from 7 to 10, or a warning word (numbness, tingling, loss of strength, fever, a fall, swelling and others), opens the human queue at high priority and alerts the team on Telegram. The reply names the physical therapist and 192 (the Brazilian emergency number) and never gives advice.
Health data is sensitive: export and erase also cover the plan, the prescription and the adherence and pain records. A campaign only goes to people who consented and passes the COFFITO 424/2013 guardrail, sourced from the Raio-X research. LGPD (the Brazilian data protection law), COFFITO (the Brazilian physical therapy council) and 192 are Brazilian.
This is the flow of the implemented system. A Python server with no dependencies, SQLite in a data folder and Docker for the VPS. Evolution and Telegram come in only through environment variables; without them the outbox is simulated and no network call goes out.
In the chat or on WhatsApp the patient books, confirms with 1 or 2, asks como faço a ponte? (how do I do the bridge; only if it was prescribed), turns on the reminder with lembrete 19:00 (or sem lembrete to turn it off), replies fiz (did it), nao fiz (did not) or dor 5 (pain 5), gets FAQ answers, asks for an attendant and sends "PARAR" (stop) when they want no more messages.
Notices for new and cancelled bookings, and the commands /agenda, /alertas, /fila, /responder and /encerrar, also as a direct reply to the patient's message.
With a token: schedule, patients, plans, prescriptions, adherence and pain, the exercise library, alerts, FAQ, records, blocked time and the human queue.
A package of sessions per patient: planned, completed and remaining. Two missed sessions in a row (adjustable) become a dropout alert for the team; the patient gets no automatic message, because reaching out again is a human decision. When two sessions remain, a re-evaluation alert. Once the plan is completed, the follow-up is due 30 days after the last session.
The physical therapist prescribes items (sets, repetitions, times a day, days of the week) and the patient receives the text with the link to each exercise. The daily reminder is opt-in: it only turns on when the patient asks, at the time they choose (default 19:00), and only on the prescribed days.
The patient replies fiz, nao fiz or pain from 0 to 10; there is one record per day and the last one wins. Weekly adherence is the days done divided by the days planned, Monday to Sunday, from the start of the prescription until today: 2 done out of 4 planned is 50%. The week's pain is the average of the records.
Each exercise is an SVG animated with CSS only, no script and no SMIL, because the video render can only advance CSS animation. This is the bridge, from the specification's skeleton.
Bridge, hamstring stretch, shoulder rotation with a stick, Codman pendulum, cervical retraction, cat-camel, wall squat, heel raise, side-lying hip abduction, modified plank, bird-dog and ankle mobility.
Each one has a public page /exercicios/<id> (steps, common mistakes, precautions, contraindications and "stop if"). On WhatsApp the patient can get a 4-second MP4 rendered with HyperFrames, an optional local build step (tools/render-exercicios, already written, not run yet); without the MP4, the text with the link goes out instead. The SVG movement has already been checked in a Chromium by the independent verification.
To run the system you only need Python 3. Docker comes in for the VPS deploy; Evolution and Telegram are optional and yours. The exercise MP4 videos are optional and need Node 22 or newer, FFmpeg and Chromium. An agent (Claude Code or Codex) only if you want to rebuild or adapt the system with the same method.
The application uses the standard library only, no dependencies. pytest runs the 98 tests.
# check python3 --version python3 -m pip install pytest
Only to rebuild or adapt the system with the method, on a subscription, no paid API. For the headless loop, clone execucao-longa into ~/projetos.
# check codex --version # or: claude --version
Docker does the build and the VPS deploy. An Evolution instance and a Telegram bot only if you want the channels; credentials live in .env.
# check docker --version
The commands below are the repository's own. The cycle: clone and check the tests, run locally, customize the clinic, deploy to your VPS and get a clinical review. What still depends on you: the real credentials (Evolution/WhatsApp and Telegram), the deploy on your VPS, the clinic's real data, the optional MP4 render and a physical therapist's review.
The system is already in the repository (./atende, src/, web/, Dockerfile). Run the suite to see it for yourself.
git clone https://github.com/inematds/atende-fisioterapia && cd atende-fisioterapia python3 -m pytest -q tests/ | tail -n 1 # 98 passed
The server prints PORTA=8080 and listens only on 127.0.0.1; --porta 0 picks a free port. With no configuration, exemplos/clinica.json is copied into the data folder. The patient chat is at /, the team page at /equipe (token TROQUE-ESTE-TOKEN in the example, "change this token") and each exercise at /exercicios/<id>, for example /exercicios/ponte. Without Evolution and Telegram configured, the output is simulated.
./atende serve --porta 8080 --dados ./dados
Edit dados/clinica.json with your hours, professionals, services, FAQ and exercises, and change the token before real use. The 21 behavior decisions (dropout alert, opt-in reminder, pain threshold and others) are described in docs/DECISOES-ABERTAS.md and were accepted as the default proposals.
less docs/DECISOES-ABERTAS.md $EDITOR dados/clinica.json
The deploy is yours, with your credentials. Copy .env.exemplo, fill in only the integrations you want (Evolution: EVOLUTION_URL, EVOLUTION_API_KEY, EVOLUTION_INSTANCIA, WEBHOOK_SEGREDO; Telegram: TELEGRAM_TOKEN, TELEGRAM_CHAT_ID, TELEGRAM_SEGREDO), create dados/ and backups/ and bring up the compose. The port is bound to 127.0.0.1:8080; put an HTTPS proxy (Nginx or Caddy) in front and set PUBLIC_URL.
cp .env.exemplo .env && chmod 600 .env mkdir -p dados backups && cp exemplos/clinica.json dados/clinica.json docker compose up -d --build && docker compose ps
Then register the Evolution webhook (PUBLIC_URL + /webhook/evolution/<segredo>, event MESSAGES_UPSERT) and the Telegram one (setWebhook with PUBLIC_URL + /webhook/telegram and secret_token). Reminders, confirmations and alerts run through periodic calls to POST /api/tarefas/rodar with X-Token, and the daily backup goes in the crontab with ./atende backup. The full walkthrough is in the README, "VPS deploy" section.
The 12 exercises already work on the web as animated SVGs. To send MP4s on WhatsApp, run tools/render-exercicios once: it is already written but has not been run yet, and it needs network access, Node 22 or newer, FFmpeg and Chromium. It produces web/exercicios/<id>.mp4 (4 s, 720×720, no audio); the MP4 files stay out of Git. On the VPS, set EXERCICIOS_MP4_DIR. Without an MP4, the text with the link goes out.
python3 tools/render-exercicios # or --so ponte, --saida DIR
This is how the system was built: the 21 decisions were answered ("ok em tudo", all fine), the contract was frozen (congelar.sh recorded the hash of tests/, pytest.ini, the specification and the verifiers) and the headless loop from execucao-longa ran Codex (gpt-6-astra, on a subscription) for 7 cycles until 98 passed and LIMITES OK. Finally, the independent verification, which the agent never saw, looked for fixture values copied into the code, brought up a clinic never seen, proved in a Chromium that the SVGs move and ran docker build with a healthcheck: INDEPENDENTE OK, with the MP4 render marked PULADO (skipped) because HyperFrames was not installed.
To adapt it to another clinic or change a rule marked ⚠, edit the specification and the tests, freeze again and run the loop (or /goal in Claude Code, or the Codex TUI, with the prompts in longrun/2026-10-05-fisio-v1/).
bash longrun/2026-10-05-fisio-v1/congelar.sh ~/projetos/execucao-longa/tools/loop-longrun.sh longrun/2026-10-05-fisio-v1 python3 longrun/2026-10-05-fisio-v1/verificar-independente.py # INDEPENDENTE OK
The 12 example exercises (steps, common mistakes, precautions, contraindications and "stop if"), the list of warning words and the pain threshold (dor_alerta: 7) were written as an example, and clinical content belongs to the physical therapist. A physical therapist must review all of it before it reaches a real patient (decisions 10 and 9 in docs/DECISOES-ABERTAS.md). One point is still open: words such as caiu and queda (fell, a fall) match everyday phrases ("a dor caiu bastante", the pain dropped a lot) and open a high-priority queue entry by mistake, a cheap false alarm that the physical therapist decides whether to keep (decision 20).
The system's code (atende, src/, web/, tools/, Dockerfile, docker-compose.yml) and everything that guided the agent while building it and stopped it from pretending it had built it.
Black-box, over HTTP and the command line, in 12 files.
test_integracoes.py 16 test_agenda.py 12 test_conversa.py 10 test_cadastros.py 9 test_campanhas.py 9 test_lembretes.py 8 test_prescricao.py 8 test_exercicios.py 7 test_basico.py 6 test_planos.py 6 test_docker.py 4 test_lgpd_raiox.py 3
docs/ESPECIFICACAO.md, sections 0 to 25: execution, clinica.json, scheduling rules, the HTTP API, a 12-rule conversation, waitlist, confirmation and follow-up, campaigns and the council guardrail, Raio-X, LGPD, records, WhatsApp, Telegram, Docker, treatment plans, the exercise library, prescription and reminders, adherence and pain, team alerts and the MP4 video. Medical records, Pix billing, insurance and claim denials (TISS) and several clinics on one server are explicitly out.
A frozen hash of tests/, pytest.ini, the specification and the verifiers. File scope: the agent could only touch the code and its own records. No API key, no external API in the code and no SMIL or script in the SVGs. verificar-limites.sh checks all of this and prints LIMITES OK.
Level 4, hidden from the agent: it looks for fixture values in the code, brings up a clinic never seen, with every argument explicit, checks the SVG movement and the MP4 when the tools exist, and runs docker build and a healthcheck. Result: INDEPENDENTE OK (MP4 render skipped). Only that way does "98 passed" prove general logic.
Language, channels, the follow-up as a re-evaluation, the dropout alert, the opt-in reminder, adherence logged per day, pain and warning signs, the 12 exercises, CSS-only animation, what the bot explains, the COFFITO guardrail and Raio-X. Only the items marked ⚠ change the contract.
A validator that had not seen the planning checked tests against the specification, redid the arithmetic and tried to get around the guardrails. It found and fixed 9 problems: 3 blocked the run, 4 got in the way and 2 were cosmetic. The full account is in docs/VALIDACAO.md and each fix has a line in FALHAS.md.
No-shows, retention, a treatment plan that never starts and idle hours: docs/MAPA-RAIO-X.md links each leak of the clinica package to a v1 piece or to the reason it stays out. The COFFITO 424/2013 guardrail (price, promotion, free, testimonial, promise of results) is sourced from the Raio-X research. Details in the Raio-X de Margem guide.
LGPD for health data (confirmation, follow-up, prescription and reminder as health care; campaigns only with consent; export and erase), the COFFITO 424/2013 resolution for advertising and 192 for emergencies. Outside Brazil, swap in your local privacy law, professional council and emergency number.
The plan was validated and the system was implemented with the execucao-longa method, like Atende Clínica, which closed 93 of 93. The next step is yours: a pilot in a real clinic.
98 passed and LIMITES OK, on 19/10/2026. Independent verification OK (SVGs in Chromium, docker build and healthcheck).tools/render-exercicios is written and has not been run yet. Run it once, with network access, Node, FFmpeg and Chromium, and copy the files to the VPS if needed.