Agentic Healthcare Clinical Q&A

A clinical-assistant agent that grounds answers in the patient's chart AND the relevant guideline — never just one or the other. Built on a single SQL session with AGENT_RUN.

All recipes· agents· 12 minutesintermediateen
Instance: localhost:8080

Opens your running SynapCores (Agentic Healthcare Clinical Q&A will be staged for a preview — nothing runs until you click Run). No instance yet? Install free in ~30s.

Share

Objective

Clinicians spend 16+ hours a week on documentation and recurring questions ("this patient's INR is 2.8 — can I start amiodarone safely?"). Generic chatbots are RAG-only and miss the patient's actual state; raw SQL misses the guideline. In this recipe you set up a tiny EHR-shaped database, embed clinical guidelines, and let a care-assistant persona answer questions by combining both sources via SELECT AGENT_RUN(...). PHI never leaves the database boundary.

Requires: SynapCores v1.6.6.9+. For production use, run a HIPAA-eligible LLM endpoint (local Ollama, or a BAA-covered cloud).

Step 1: Create patient + lab + guideline tables

CREATE TABLE IF NOT EXISTS recipe_hc_patients (
  patient_id     INTEGER PRIMARY KEY,
  initials       TEXT,
  dob            DATE,
  active_meds    TEXT,           -- comma-separated for brevity
  comorbidities  TEXT
);

CREATE TABLE IF NOT EXISTS recipe_hc_labs (
  lab_id        INTEGER PRIMARY KEY,
  patient_id    INTEGER,
  test          TEXT,
  value         DOUBLE,
  units         TEXT,
  taken_at      TIMESTAMP
);

CREATE TABLE IF NOT EXISTS recipe_hc_guidelines (
  guideline_id  INTEGER PRIMARY KEY,
  topic         TEXT,
  body          TEXT,
  embedding     VECTOR(384)
);

Step 2: Seed

INSERT INTO recipe_hc_patients VALUES
 (1,'J.D.','1958-03-11','warfarin 5mg, lisinopril 10mg','atrial fibrillation, hypertension'),
 (2,'M.K.','1972-08-22','metformin 1000mg','type 2 diabetes'),
 (3,'L.S.','1945-11-04','warfarin 4mg, atorvastatin 20mg','prior PE, hyperlipidemia');

INSERT INTO recipe_hc_labs VALUES
 (1,1,'INR',2.8,'',         '2026-05-22 09:10:00'),
 (2,1,'eGFR',62,'mL/min',   '2026-05-22 09:10:00'),
 (3,2,'A1C',7.4,'%',        '2026-05-15 11:00:00'),
 (4,3,'INR',3.6,'',         '2026-05-26 08:45:00'),
 (5,3,'Hgb',11.2,'g/dL',    '2026-05-26 08:45:00');

INSERT INTO recipe_hc_guidelines (guideline_id, topic, body) VALUES
 (1,'Warfarin–Amiodarone Interaction','Amiodarone potentiates warfarin via CYP2C9 inhibition, often doubling the INR within 1–3 weeks. When starting amiodarone in a patient on warfarin, reduce the warfarin dose by 30–50 percent and check INR within 5–7 days, then weekly for 4 weeks.'),
 (2,'Warfarin INR Range — AFib','Target INR for non-valvular atrial fibrillation is 2.0–3.0. INR above 3.0 without bleeding: hold one dose and recheck in 24–48 hours; INR above 4.5: consider vitamin K.'),
 (3,'Warfarin INR Range — PE','Target INR for venous thromboembolism prophylaxis post-PE is 2.0–3.0. Same management thresholds as for AFib.'),
 (4,'Metformin and eGFR','Metformin is contraindicated below eGFR 30. Between 30 and 45, use with dose reduction and lactate monitoring. Hold around iodinated contrast.'),
 (5,'A1C Targets — T2DM','For non-frail adults with type 2 diabetes, A1C target is below 7.0 percent. Above 7.0: consider intensification (add second agent, increase metformin dose if eGFR allows, or add GLP-1).');

Step 3: Embed

UPDATE recipe_hc_guidelines SET embedding = EMBED(body);

Step 4: Ground truth — guideline retrieval

SELECT topic, COSINE_SIMILARITY(embedding, EMBED('starting amiodarone for a patient on warfarin')) AS sim
FROM recipe_hc_guidelines ORDER BY sim DESC LIMIT 2;

Expected: Warfarin–Amiodarone Interaction ranks first.

Step 5: Ground truth — patient state

SELECT p.initials, p.active_meds,
       (SELECT value FROM recipe_hc_labs l WHERE l.patient_id = p.patient_id AND l.test='INR' ORDER BY taken_at DESC LIMIT 1) AS latest_inr
FROM recipe_hc_patients p WHERE p.patient_id = 1;

Expected: J.D., warfarin/lisinopril, INR 2.8.

Step 6: Ask the agent a real clinical question

SELECT AGENT_RUN(
  'aidb-assistant',
  'You are a careful clinical-documentation assistant. The clinician is considering starting amiodarone for patient_id 1 in recipe_hc_patients. Use execute_query to look up the patient''s current medications, latest INR, eGFR, and comorbidities. Use rag_search on recipe_hc_guidelines for the relevant interaction guideline. Output: a short summary of patient state, the citation of the applicable guideline, and three specific monitoring actions the clinician should take. Do not invent any clinical facts not present in the data.'
) AS clinical_summary;

Cleanup

DROP TABLE IF EXISTS recipe_hc_patients;
DROP TABLE IF EXISTS recipe_hc_labs;
DROP TABLE IF EXISTS recipe_hc_guidelines;

Use it from your agent

  • REST/SDK: Step 6 in POST /v1/query/execute — the LLM endpoint can be local (Ollama) or HIPAA-eligible cloud. PHI never crosses your network boundary.
  • MCP: same SQL via the query tool on ws://<host>/mcp?token=<jwt>.
  • Why this matters: RAG-only assistants miss patient-specific facts; record-only views miss the medical knowledge. AGENT_RUN lets the model see both in one transaction.

Key Concepts Learned

  • Combining patient-state SQL + guideline RAG in one agent call is the difference between "useful" and "dangerous" in clinical contexts.
  • The data perimeter never moves — only the final LLM call talks to a model, and that model can be local.
  • Every clinical recommendation is traceable to the exact rows and guideline passages that informed it.

Tags

ai-agentagent-runhealthcareclinicalragehrpatient-charthipaa

Run this on your own machine

Install SynapCores Community Edition free, paste the SQL or Cypher above into the bundled web UI, and watch it run.

Download Free CE