Inspiration
I was inspired to build CHATEHR after seeing how modern Electronic Health Records (EHRs), while powerful, have become complex and cumbersome to navigate. Clinicians often spend more time clicking through menus and searching for data than they do interacting with patients. I saw the potential of Large Language Models (LLMs) to revolutionize this interaction. I envisioned CHATEHR: a conversational interface where you simply ask for the information you need, and an intelligent agent finds it for you. My goal was to transform data retrieval from a chore into a natural conversation, unlocking the full potential of structured clinical data.
What it does
CHATEHR is an intelligent chat application that provides a conversational interface for electronic health records. Instead of manually navigating complex EHR software, a clinician can ask questions in plain English like:
- "Show me all diabetic patients over 40 with high blood pressure."
- "What was John Doe's latest HbA1c value?"
- "Compare the average blood pressure readings for patients on Drug A vs. Drug B."
The application uses an AI agent that I built to understand the intent behind these questions. It securely queries the EHR's FHIR API and its own knowledge base via a custom MCP server I developed, returning a concise, synthesized answer with citations from the actual patient data.
How I built it
I built CHATEHR as a full-stack application on a modern, serverless-ready tech stack:
- Frontend: I built a responsive Next.js application with React, styled with Tailwind CSS and shadcn/ui components for a polished, accessible user experience.
- AI Orchestration & Agent Core: This is where the magic happens.
- I used the Vercel AI SDK to handle the streaming chat interface.
- I used LangChain.js
MultiServerMCPClientto create a dynamic connection to my custom MCP server. This client automatically discovers the available FHIR tools at runtime, giving the AI agent a full understanding of its capabilities without any hardcoded definitions. - The agent uses this connection to plan and execute sequences of tool calls based on the user's query.
- The Toolbox (MCP Server): I built a custom Model Context Protocol (MCP) server from the ground up that provides the discovered tools for secure and efficient querying of the FHIR API. The clean separation between the agent and the tool server was a key feature of my architecture.
- Data & Knowledge:
- I used TiDB Cloud as my multi-model database, which acts as the persistent store for conversations, a vector database for RAG, and a cache for FHIR data.
- I used Drizzle ORM to ensure type-safe database interactions.
- APIs & Services: I integrated with standard FHIR APIs for EHR data access and leveraged Moonshot AI's Kimi-K2 for its strong LLM capabilities.
Challenges I ran into
- FHIR Complexity & SMART on FHIR Integration: Different EHR systems implement FHIR and SMART on FHIR with variations. Configuring my MCP server and auth flow to handle these nuances was a significant challenge that required deep research and testing.
- Hallucination Mitigation: Ensuring the AI's responses are 100% grounded in real patient data was my highest priority. I combated hallucination through rigorous Retrieval-Augmented Generation (RAG) and by architecting the system to force the agent to use structured tool calls instead of fabricating answers.
- Agentic Reasoning Latency: The chain of reasoning -> tool call -> execution -> synthesis can be slow. I optimized performance by making my MCP tools highly efficient and implementing strategic caching layers.
- Security & Privacy: Designing a secure architecture to handle Protected Health Information (PHI) was paramount. Correctly implementing the SMART on FHIR standard was complex but essential to ensure patient data privacy and comply with healthcare regulations.
Accomplishments that I'm proud of
- Building a Functional, Secure MCP Server: Creating a production-ready MCP server that securely bridges the gap between a conversational AI and complex FHIR APIs was a significant technical accomplishment that I'm particularly proud of.
- Creating a Truly Useful Agent: I built more than a simple chatbot; I created an AI agent that can autonomously plan and execute a multi-step workflow to answer complex clinical questions.
- Novel Use of TiDB: I successfully leveraged TiDB as a unified operational and vector database, which greatly simplified my architecture and proved to be a powerful pattern.
- Implementing SMART on FHIR: Correctly integrating this industry standard was a major milestone, ensuring my project is secure, compliant, and launch-ready in real clinical environments.
- Tackling a Real-World Problem: I'm proud to have built a solution that addresses a genuine pain point for healthcare professionals and has the potential to improve efficiency and patient care.
What I learned
This project was a deep dive into cutting-edge AI architecture and healthcare interoperability for me. I moved beyond simple prompt engineering and learned how to build reasoning engines. I gained hands-on experience with the FHIR standard, the principles of building effective tools for AI agents (via MCP), and the critical importance of the SMART on FHIR standard for security and launch context. Most importantly, I learned that the key to trustworthy AI in healthcare lies in a strong architecture that prioritizes security, accuracy, and regulatory compliance over pure linguistic fluency.
What's next for CHATEHR
- Advanced Agent Capabilities: I plan to implement more sophisticated agent plans for handling even more complex, multi-faceted questions.
- Enhanced Data Visualization: I want to allow the AI to generate charts and graphs from the data it retrieves to provide more insightful answers.
- EHR System Adaptors: I aim to build a library of connectors for a wider range of major EHR systems and their specific FHIR implementations.
- Clinical Validation: My goal is to partner with medical professionals to rigorously test and validate the accuracy and utility of the system in a real clinical setting.
- Fine-Tuned Models: I'm interested in exploring the development of specialized, fine-tuned LLMs for even more accurate and efficient clinical reasoning.
Built With
- drizzle-orm
- drizzle-orm-apis:-fhir-api
- drizzle-orm-fhir-api
- fastmcp
- fastmcp-radix-ui
- fastmcp-ui/components:-radix-ui
- fhir-api
- javascript
- jose-(jwt)
- langchain
- moonshot-ai-(kimi)
- moonshot-ai-(kimi)-database/orm:-tidb-cloud
- moonshot-ai-(kimi)-tidb-cloud
- next.js
- radix-ui
- react
- react-query
- react-query-deployment:-vercel-(app)
- react-query-vercel
- render
- shadcn/ui
- smart-on-fhir
- smart-on-fhir-auth:-jose-(jwt)-utilities:-zod
- smart-on-fhir-jose-(jwt)-zod
- sql
- sql-frameworks:-next.js
- sql-next.js
- tailwind-css
- tailwind-css-ai/llm:-langchain
- tailwind-css-langchain
- tidb-cloud
- typescript
- vercel
- vercel-ai-sdk
- zod
Log in or sign up for Devpost to join the conversation.