Case study 02
MedRef
AI-assisted diagnosis and specialist referral
- Flutter
- Dart
- Python
- FastAPI
- SQLAlchemy
- TensorFlow / Keras
- scikit-learn
- spaCy
- PostgreSQL
- Docker
Overview
Patients describe symptoms in text or upload a skin or chest image. NLP and CNN models analyse the input, and the app suggests which kind of specialist to see, with nearby options and a saved history.
The Problem
Patients often don’t know which specialist they need. They lose time going through general consultations before they reach the right doctor.
MedRef targets that first step: describe what’s wrong, or photograph it, and get a clear suggestion of which kind of specialist to see.
The Approach
There are two input paths. Text symptoms go through an NLP service and a trained referral classifier. Images go through a two-stage pipeline: locally trained skin and chest CNNs run first, and the Hugging Face Inference API is used as a fallback. Both paths return a structured report that names a specialist, for example a dermatologist or a pulmonologist.
A specialist service then matches by department and distance, and every analysis is saved to the user’s history. A second iteration, MedRef AI, rebuilt the client in Flutter with patient, doctor and admin roles, so doctors can review and claim high-risk cases.
Architecture
- ClientFlutter app for Android, web and desktop. It handles login, symptom input, image upload from camera or gallery, results and history, and detects the right API base URL for emulator, web or physical device.
- APIFastAPI REST service: /auth (JWT), /analyze/text, /analyze/image and /history, with uploaded images served from /uploads.
- ModelsSkin and chest CNNs (Keras .h5) and a scikit-learn referral classifier (.joblib), trained in a Colab notebook and loaded at startup.
- DataSQLAlchemy models for users, referrals and feedback, on SQLite in the first version and PostgreSQL in the MedRef AI rebuild. The backend has a Dockerfile.
Engineering Decisions
Degrade, don’t fail
If the trained model files are missing, the backend falls back to keyword NLP and heuristic image routing, so the app still runs end to end in development and demos.
Local first, cloud as backup
Image analysis tries the local CNNs before calling the Hugging Face Inference API. That keeps routine requests on the server, and it still returns an answer when a local model fails.
Every analysis is persisted
Analyses are saved even for users who aren’t logged in, so every response has an ID. That fixed a class of 500 errors in the results flow.
Roles that mirror a clinic
In MedRef AI, patients, doctors and admins get separate flows. High-risk cases surface to doctors, who can claim them, and admins see system analytics.
My Contribution
- FastAPI backend: auth, analysis endpoints, history and uploads
- NLP and image-analysis services, plus the specialist-matching logic
- Model training notebook and model loading
- Flutter client, including the role-based MedRef AI rebuild
Where It Stands
Built
- Text and image analysis with structured, specialist-tagged reports
- JWT authentication and per-user history
- Specialist matching by department and distance
- Patient, doctor and admin roles in the Flutter rebuild
Next
- Clinical validation. The models haven’t been evaluated in a clinical setting, so their output is guidance, not a diagnosis
MedRef is an academic project. Its suggestions are not medical advice.
Next case study
Gohar Medical Trust HMS