Skip to content

Hamju1999/DischargeSimplify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DischargeSimplify (Leap of Faith)

Course Project - Digital Healthcare Informatics Illinois Institute of Technology | Mar 2025 - Apr 2025

Overview

A clinical NLP web application that translates complex hospital discharge instructions into patient-friendly summaries at a 6th-grade reading level, with FHIR Composition output for EHR integration and a multilingual translation layer supporting the full language catalog via pycountry.

My Contribution

This was a team project. My scope covered:

  • Prompt Engineering: Engineered the 8-category structured prompt in prompt_engineer.py enforcing deterministic GPT-4o output at temperature=0.0 into a strict JSON schema with keys: Summary, Instructions, Importance, FollowUpTasks, Medications (ToTake/ToAvoid), Precautions, References, Disclaimer. All JSON keys enforced in English regardless of output language. Every section required non-empty content with explicit constraints on bullet length and deduplication logic.

  • FAISS-Backed RAG Validation Layer: Built validation_layer.py using SentenceTransformer (all-MiniLM-L6-v2) embeddings and IndexFlatL2 similarity search to retrieve top-3 relevant source chunks per bullet, with a strict per-bullet LLM validation pass that accepts or rejects each simplified statement against the original discharge text without rephrasing it.

  • FHIR Composition Conversion: Built fhirconvertion.py using fhir.resources to convert simplified JSON output into a LOINC-coded (11502-2) FHIR Composition resource with structured sections for Summary, Instructions, Importance, FollowUpTasks, Medications, Precautions, References, and Disclaimer - triggered automatically post-simplification for EHR integration.

  • Hybrid Translation System: Engineered two dedicated translation functions in language.py: t() for static UI elements with (text, language) session-state cache keys, and at() for bidirectional chatbot translation with (text, source, target) cache keys - both calling GPT-4o with a literal translation prompt. Language enumeration handled via pycountry across the full language selector.

  • Chatbot Translation Layer: Engineered the bilingual translation integration within the assistant chat flow using at() in language.py - a bidirectional GPT-4o translation function with (text, source, target) session-state cache keys that translates both user queries and assistant responses while preserving the original simplified content integrity.

API Endpoints

Method Endpoint Purpose
POST /simplify Simplify discharge instructions into 8-category JSON
POST /validate LLM-based validation of simplified output against original
POST /to_fhir Convert simplified JSON to FHIR Composition resource
POST /assistant/chat Source-grounded chatbot from simplified instructions
POST /upload Upload discharge document and extract raw text
GET /health Health check

Repository Structure

├── backend/
│   ├── app.py                # FastAPI app - all endpoints
│   ├── prompt_engineer.py    # GPT-4o prompt + simplify/validate logic
│   ├── validation_layer.py   # FAISS RAG validation layer
│   ├── fhirconvertion.py     # FHIR Composition builder
│   ├── language.py           # t() and at() translation functions
│   ├── models.py             # Pydantic + SQLAlchemy data models
│   ├── db.py                 # Database session management
│   ├── utils.py              # File extraction and JSON parsing utilities
│   ├── create_assistant.py   # OpenAI Assistant configuration
│   └── requirements.txt
├── frontend/
│   ├── app.py                # Streamlit frontend
│   ├── language.py           # Translation and language selector
│   └── requirements.txt
└── README.md

Technical Stack

  • Backend: FastAPI, Uvicorn, SQLAlchemy
  • AI: GPT-4o (OpenAI), OpenAI Assistants API
  • NLP: SentenceTransformers (all-MiniLM-L6-v2), FAISS IndexFlatL2
  • Healthcare: fhir.resources, LOINC 11502-2
  • Frontend: Streamlit
  • Other: pycountry, pdfminer.six, ratelimit, python-dotenv

Setup

git clone https://github.com/Hamju1999/DischargeSimplify.git
cd DischargeSimplify
pip install -r backend/requirements.txt

Create .env:

OPENAI_API_KEY=your-api-key
ASSISTANT_ID=your-assistant-id

Run:

uvicorn backend.app:app --reload

Author

Mohammad Hamza Piracha | Data Scientist & Applied AI Engineer | LinkedIn | hamzapiracha@live.com

About

Clinical NLP pipeline that simplifies hospital discharge instructions into patient-friendly summaries using GPT-4o, with FAISS-backed RAG validation, FHIR Composition output (LOINC 11502-2), and multilingual translation via pycountry.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages