Initial Release
FHIR Patient Snapshot Agent is an AI-powered clinical summarisation tool built for the InterSystems AI Agents and FHIR Programming Contest.
The application retrieves structured FHIR resources for a selected patient from an InterSystems IRIS for Health FHIR Server and generates a concise clinical summary.
The project implements a Smart Patient Summary Generator: an AI agent called inside a FHIR interoperability solution.
Idea link: https://community.intersystems.com/post/intersystems-programming-contest-ai-agents-fhir
patient_id.flowchart LR
user["User / CLI"] --> cli["snapshot_demo.py"]
cli --> agent["PatientSnapshotAgent"]
agent --> client["FHIR client"]
client --> iris["InterSystems IRIS for Health\nFHIR R4 Server"]
iris --> resources["Patient, Condition,\nMedicationRequest, AllergyIntolerance,\nObservation, Encounter, CarePlan"]
resources --> normalizer["FHIR normalizer"]
normalizer --> context["PatientSnapshotContext"]
context --> deterministic["Deterministic Markdown renderer"]
context --> prompt["LLM prompt builder"]
prompt --> llm["Nebius Token Factory\nOpenAI-compatible chat completions"]
deterministic --> output["Patient snapshot summary\nwith source resource IDs"]
llm --> output
IRIS for Health is the FHIR interoperability layer in this project. The Python agent does not read local files or query a database directly; it retrieves standards-based FHIR R4 JSON from IRIS and uses those resources as the source of truth for summarisation.
This project is for demonstration purposes only. It does not provide diagnosis, treatment recommendations, or clinical decision-making. All generated summaries must be verified against the source FHIR data.
The LLM prompt explicitly prohibits creating new care plans, monitoring recommendations, medication changes, referrals, and treatment follow-up instructions. Existing FHIR CarePlan resources may be summarised as source data. Potential concerns are framed as neutral source-data checks only.
The Missing Information section is constrained to items identified by the deterministic normalizer, which reduces the risk of the model inventing extra clinical gaps.
The prompt also requests Markdown headings, bullet lists, blank lines between sections, and readable clinical language instead of raw source-context line copying. FHIR resource IDs are kept out of narrative sections and shown in the collapsible source-resource review. The web UI applies compact display cleanup for common LLM Markdown spacing issues across role-specific summaries, including unbulleted lists after subsection labels and empty bullet points.
.env loading without external dependencies1This project is designed to align closely with the InterSystems AI Agents and FHIR Programming Contest goals:
meta-llama/Llama-3.3-70B-Instruct.The current demo uses Patient 1 from the local InterSystems IRIS for Health FHIR Server.
YouTube video demo: https://youtu.be/Hsu10Nnujng
Online demo deployment is supported through render.yaml. For public hosting, set ONLINE_DEMO_MODE=1. In this mode the Streamlit app uses a bundled Patient 1 demo context captured from the local IRIS for Health FHIR Server setup, so the public app does not need access to a local localhost FHIR endpoint or a private LLM API key. The full live FHIR workflow still runs locally against InterSystems IRIS for Health as described below.
Verified resource counts:
Sample generated summary: docs/sample_patient_1_llm_summary.md
The Streamlit UI allows a user to enter a FHIR patient ID, choose the summary audience, generate a deterministic or LLM-backed patient snapshot, and review the source FHIR resources used by the agent.



.
+-- app/
| +-- fhir_client.py
| +-- llm_provider.py
| +-- normalizer.py
| +-- prompt_builder.py
| +-- summary_renderer.py
| +-- snapshot_demo.py
| +-- web_ui.py
+-- tests/
| +-- test_normalizer.py
+-- docs/
| +-- day1_fhir_setup.md
| +-- demo_script.md
| +-- sample_patient_1_llm_summary.md
| +-- screenshots/
| +-- streamlit_ed_summary_top.png
| +-- streamlit_ed_summary_middle.png
| +-- streamlit_ed_summary_bottom.png
+-- .env.example
+-- .gitignore
+-- README.md
+-- render.yaml
+-- requirements.txt
The local FHIR server setup uses the InterSystems community FHIR template as the reference starting point:
https://github.com/intersystems-community/iris-fhir-template
Clone and run that template separately:
git clone https://github.com/intersystems-community/iris-fhir-template.git iris-challenge-ai-agent
cd iris-challenge-ai-agent
docker compose up --build
The project currently expects this FHIR base URL:
http://localhost:32783/fhir/r4
The local InterSystems template exposes the FHIR port through Docker. Check docker ps and use the host port mapped to container port 52773. In our first local run this was 32783.
The local template also requires Basic Auth:
FHIR_USERNAME=_SYSTEM
FHIR_PASSWORD=SYS
Verify the local FHIR API:
curl -i -u _SYSTEM:SYS http://localhost:32783/fhir/r4/metadata
curl -s -u _SYSTEM:SYS http://localhost:32783/fhir/r4/Patient | python3 -m json.tool
curl -s -u _SYSTEM:SYS http://localhost:32783/fhir/r4/Condition | python3 -m json.tool
curl -s -u _SYSTEM:SYS http://localhost:32783/fhir/r4/Observation | python3 -m json.tool
Create a local .env file:
FHIR_BASE_URL=http://localhost:32783/fhir/r4
FHIR_USERNAME=_SYSTEM
FHIR_PASSWORD=SYS
LLM_BASE_URL=https://api.tokenfactory.nebius.com/v1
LLM_MODEL=meta-llama/Llama-3.3-70B-Instruct
LLM_API_KEY=your-nebius-token
Local .env files are loaded automatically and are ignored by Git.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
On Windows PowerShell:
py -m venv .venv
.\.venv\Scripts\Activate.ps1
py -m pip install -r requirements.txt
Run a deterministic patient snapshot:
python -m app.snapshot_demo 1
Generate an LLM-ready prompt:
python -m app.snapshot_demo 1 --format prompt
Generate a role-specific prompt:
python -m app.snapshot_demo 1 --format prompt --audience patient
Generate a summary with Nebius Token Factory or another OpenAI-compatible provider:
python -m app.snapshot_demo 1 --format llm
Supported audiences: clinician, ed_doctor, care_manager, patient, and family_caregiver. Each audience uses a different required section template.
Return only resource counts:
python -m app.snapshot_demo 1 --format counts
Run the Streamlit web UI:
py -m streamlit run app/web_ui.py
Run the Streamlit web UI in public online demo mode:
$env:ONLINE_DEMO_MODE="1"
py -m streamlit run app/web_ui.py
Sample output: docs/sample_patient_1_llm_summary.md
Demo walkthrough: docs/demo_script.md
Run tests:
python -m unittest discover -s tests
Working prototype:
1 verified with 5 conditions, 2 medication requests, 0 allergy records, 88 observations, 14 encounters, and 2 care plans