Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“„ Dissertation

This repository contains the complete source code submitted alongside the written dissertation:

πŸ₯ MedAssist β€” Intelligent Medical Assistant

Dashboard

An agentic AI-powered medical assistant built with LangGraph, Retrieval-Augmented Generation and real-time tool-calling for healthcare professionals.

TypeScript React Node.js PostgreSQL LangChain Google Gemini Docker


πŸ“– Overview

MedAssist is a full-stack intelligent medical assistant that allows healthcare professionals to interact with pharmaceutical knowledge through natural language. Instead of searching through textbooks or databases, a clinician can simply ask:

"Can my patient take Azithromycin alongside Atorvastatin?" "What are the contraindications of Amlodipine in elderly patients?" "Generate a dosage card for Sofia Loukisa."

The system understands the intent, queries the right tools, retrieves grounded information from real pharmaceutical PDFs and delivers a structured, cited response β€” all in real time.


✨ Key Features

Feature Description
πŸ’¬ Conversational Interface Natural language chat with real-time token streaming
πŸ” RAG-Powered Queries Answers grounded in uploaded pharmaceutical PDFs, not AI hallucination
⚠️ Drug Interaction Detection Severity-rated DDI checking (mild / moderate / severe / contraindicated)
πŸ“‹ Dosage Card Generation Auto-generated structured medication cards per patient
πŸ‘€ Patient Management Full CRUD for patients, medications, allergies, and medical history
🧠 Agentic Tool-Calling ReAct loop with 10 specialised tools, visible in real time
πŸ”– Bookmarks Save any critical AI response for later reference
πŸ” Secure Auth JWT authentication with bcrypt-hashed passwords

πŸ–₯️ Application Screenshots

Login & Account Creation

Login Create Account


Patient Management

Patients New Patient Patient Card


AI Chat β€” Drug Interactions

Drug Interactions Chat


AI Chat β€” Dosage Card Generation

Dosage Card Chat


Medicine Cards

Medicine Cards Dosage Card PDF


PDF Document Management

PDF Management


Bookmarks

Bookmarks


New Chat Session

New Chat


πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    React 18 Frontend                    β”‚
β”‚         (TypeScript Β· Tailwind CSS Β· Vite)              β”‚
β”‚   Chat UI Β· Patient Dashboard Β· PDF Manager Β· Cards     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ REST + SSE Streaming
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                Express Backend (Node.js)                β”‚
β”‚              JWT Auth Β· Chat Service Β· CRUD             β”‚
β”‚                                                         β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚              LangGraph Agent                    β”‚   β”‚
β”‚   β”‚                                                 β”‚   β”‚
β”‚   β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚   β”‚
β”‚   β”‚   β”‚  Router  │───▢│      toolAgent        β”‚     β”‚   β”‚
β”‚   β”‚   β”‚ (Intent  β”‚    β”‚   (ReAct Loop Γ— 5)    β”‚     β”‚   β”‚
β”‚   β”‚   β”‚Classify) β”‚    β”‚  10 LangChain Tools   β”‚     β”‚   β”‚
β”‚   β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ Drizzle ORM
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              PostgreSQL 16 + pgvector                   β”‚
β”‚    Relational Data         Vector Store (HNSW index)    β”‚
β”‚  Users Β· Patients Β·      768-dim Embeddings             β”‚
β”‚  Medications Β· Chat       Cosine Similarity Search      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚   Google Gemini API β”‚
              β”‚  Flash (LLM) +      β”‚
              β”‚  Embedding-001 (RAG)β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ€– How the AI Works

1. Intent Classification (Router Node)

Every message is first passed through a structured-output Gemini classifier that deterministically routes it to one of five intent categories:

rag_query          β†’ search pharmaceutical PDFs
interaction_check  β†’ check drug-drug interactions  
card_generation    β†’ generate patient dosage card
patient_management β†’ CRUD on patient records
general            β†’ open conversation

2. ReAct Agent Loop (toolAgent Node)

The agent executes a Reason β†’ Act β†’ Observe loop powered by LangGraph's StateGraph:

User Message
     ↓
  [THINK]  "I need to check the interaction between these two drugs"
     ↓
  [ACT]    calls check_interactions("Atorvastatin", "Azithromycin")
     ↓
  [OBSERVE] receives DDI data from pgvector RAG retrieval
     ↓
  [THINK]  "I now have enough context to answer"
     ↓
  [RESPOND] streams severity-rated response to user

3. RAG Pipeline

PDF Upload
   ↓
pdf-parse (text extraction)
   ↓
RecursiveCharacterTextSplitter (chunk: 1000 / overlap: 200)
   ↓
gemini-embedding-001 (768-dimensional vectors)
   ↓
pgvector HNSW index (cosine similarity)
   ↓
Top-5 semantically similar chunks β†’ injected as LLM context

πŸ› οΈ Tech Stack

Layer Technology Purpose
Frontend React 18, TypeScript, Vite, Tailwind CSS SPA with real-time streaming UI
Backend Hono, Node.js 20 LTS, TypeScript Lightweight REST API server
AI Orchestration LangGraph 0.2, LangChain 0.3 Stateful agentic graph execution
LLM Google Gemini Flash Natural language generation + tool-calling
Embeddings Google Gemini Embedding-001 768-dim semantic text vectors
Vector Store PostgreSQL + pgvector (HNSW) Sub-100ms approximate nearest-neighbour search
ORM Drizzle ORM Type-safe SQL with zero code generation
Auth JWT + bcrypt Stateless sessions, hashed passwords
PDF Parsing pdf-parse Text extraction from pharmaceutical documents
Streaming Server-Sent Events (SSE) Real-time token-by-token response delivery
Infrastructure Docker Compose One-command database provisioning

πŸ“Š Evaluation Results

The system was evaluated across 30 novel test queries spanning all intent categories:

Metric Result
🎯 Intent Classification Accuracy 100% (30/30 queries)
πŸ“š RAG Retrieval Quality Score 100% (60/60 weighted points)
πŸ“‹ Dosage Card Consistency 100% (5/5 fully BNF-consistent)
βœ… Unit Tests Passing 15/15
βœ… Integration Tests Passing 7/7

πŸš€ Getting Started

Prerequisites

  • Node.js 20 LTS
  • pnpm (npm install -g pnpm)
  • Docker Desktop
  • Google API Key (Gemini)

Installation

# 1. Clone the repository
git clone https://github.com/SofiaLoukisa/medassist-langgraph-agentic-ai-dissertation.git
cd medassist-langgraph-agentic-ai-dissertation

# 2. Start the database
docker-compose up -d

# 3. Install all dependencies
pnpm install

# 4. Configure environment
cp backend/.env.example backend/.env
# Fill in: DATABASE_URL, GOOGLE_API_KEY, JWT_SECRET

# 5. Run migrations
cd backend && pnpm drizzle-kit migrate

# 6. Start backend (port 3000)
cd backend && pnpm dev

# 7. Start frontend (port 5173)
cd frontend && pnpm dev

Open http://localhost:5173, register an account, upload pharmaceutical PDFs and start chatting.

Environment Variables

DATABASE_URL=postgresql://medassist:medassist_dev@localhost:5432/medassist
GOOGLE_API_KEY=your_google_api_key_here
JWT_SECRET=your_secure_random_secret_here

πŸ“ Project Structure

medassist/
β”œβ”€β”€ assets/                   # Screenshots for README
β”œβ”€β”€ frontend/                 # React SPA
β”‚   └── src/
β”‚       β”œβ”€β”€ pages/            # Route-level components
β”‚       └── components/       # Reusable UI components
β”‚
└── backend/                  # Hono API server
    └── src/
        β”œβ”€β”€ agent/            # LangGraph agent
        β”‚   β”œβ”€β”€ graph.ts      # StateGraph definition
        β”‚   β”œβ”€β”€ state.ts      # AgentState schema
        β”‚   β”œβ”€β”€ nodes/        # router + toolAgent
        β”‚   └── tools/        # 10 LangChain tools
        β”œβ”€β”€ db/               # Drizzle schema + migrations
        β”œβ”€β”€ auth/             # JWT authentication
        β”œβ”€β”€ chat/             # Chat service + SSE streaming
        β”œβ”€β”€ patient/          # Patient CRUD
        β”œβ”€β”€ pdf/              # PDF ingestion pipeline
        └── medicine/         # Dosage card generation

πŸŽ“ Academic Context

  • Institution: University of York Europe Campus, Athens Tech
  • Degree: BSc Computer Science with Honours
  • Module: Individual Project Dissertation
  • Supervisor: Dr. Odysseas Efremidis
  • Academic Year: 2025–2026

Research Questions addressed:

  • RQ1: How effectively can a graph-based agentic architecture produce clinically appropriate pharmaceutical responses?
  • RQ2: How does RAG over user-uploaded documents reduce hallucination compared to ungrounded LLM responses?
  • RQ3: What architectural and safety constraints must be satisfied before clinical deployment?

⚠️ Disclaimer

MedAssist is a research prototype developed for academic purposes. It is not intended for real clinical use without independent validation, regulatory compliance review and integration with authoritative pharmaceutical databases.


πŸ‘€ Author

Sofia Loukisa
Student ID: CSY23106
Stage: 3

About

πŸ₯ Agentic AI medical assistant β€” LangGraph Β· RAG Β· Drug Interaction Detection Β· Patient Management | BSc Dissertation 2025

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages