pruijia123/blood-cell-detection-fhir
Blood Cell Detection System with FHIR Integration
Overview
This project is a blood cell detection web app built for the CS6440 Final Project. It uses RF-DETR to detect:
- Platelets
- RBC (Red Blood Cells)
- WBC (White Blood Cells)
The app combines image-based blood cell detection with a FHIR workflow. It supports:
- lab-connected image retrieval through FHIR
- manual patient image upload
- result upload to FHIR as
Observationresources and aDiagnosticReport - CSV export for analysis results
Current Workflow
The app has three main sections:
1. Lab FHIR Workflow
This is the main workflow.
- The lab is represented as the FHIR
OrganizationCS6440 Demo Hematology Lab - The user enters first name, last name, and birth date
- The app looks for the patient record in FHIR
- If lab images already exist, the user can load recent FHIR
Mediaimages - The user selects one image, runs detection, and uploads the result back to FHIR
If the patient does not already have lab images in the organization, the app does not store their manual upload into the lab organization. Instead, the user is directed to the manual upload workflow.
2. Patient Upload & FHIR Record
This section is for patients who want to upload their own images manually.
- Upload multiple blood smear images
- Run detection across the uploaded set
- View annotated results and aggregate counts
- Export the detection results to CSV
- Upload the aggregated result to the patient’s FHIR record
This workflow updates the patient record, but it does not treat the uploaded images as lab-owned images under the demo organization.
3. Analysis & CSV Export
This section is a standalone analysis tool.
- Upload multiple images
- Run detection
- View aggregate counts and per-image results
- Receive a preliminary educational medical assessment
- Export the results to CSV
FHIR Design
The main FHIR resources used in this project are:
In the current demo:
- the lab is a backend-managed mock organization
- patient records are created or reused through the web app
- recent lab images are retrieved from FHIR
Media - model outputs are uploaded as
Observationresources plus oneDiagnosticReport
Mock Testing Data
The app automatically initializes a documented mock catalog at startup:
- Organization:
CS6440 Demo Hematology Lab - Mock patients:
10 - Each mock patient has a unique set of dataset images
- Each patient has between
3and10images
See MOCK_PATIENTS.md for the full mock patient list and image assignments.
Project Structure
FinalProject/
├── web_demo.py
├── blood_cell_detection.py
├── train_blood_cell.py
├── fhir_integration.py
├── mock_patient_catalog.py
├── MOCK_PATIENTS.md
├── checkpoint_best_total.pth
├── environment.yml
├── README.md
└── Dataset/Setup
Conda
conda env create -f environment.yml
conda activate blood-cell-detectionPip
pip install rfdetr gradio supervision pillow numpy pandasPretrained Checkpoint
Place the downloaded file in the project root as:
checkpoint_best_total.pthRun
Train the model
python train_blood_cell.pyLaunch the app
python web_demo.pyOpen:
http://127.0.0.1:7860Quick Demo Steps
Lab-connected workflow
- Open
Lab FHIR Workflow - Enter first name, last name, and birth date in
MM/DD/YYYY - Click
Find or Create My Lab Record - If recent lab images exist, click
Load Recent Lab Images - Select an image
- Click
Analyse Selected Lab Image and Upload Result
Manual patient workflow
- Open
Patient Upload & FHIR Record - Upload one or more images
- Click
Analyse Uploaded Images - Review the results
- Upload the aggregated result to the patient FHIR record
Key Files
- web_demo.py: Gradio UI and workflow logic
- blood_cell_detection.py: model inference and annotation
- train_blood_cell.py: dataset preparation and model training
- fhir_integration.py: FHIR create/search/upload logic
- mock_patient_catalog.py: 10-patient mock catalog definition
- MOCK_PATIENTS.md: mock patient reference
Notes
- Birth date input in the UI uses
MM/DD/YYYY - CSV exports are saved to the current user’s
Downloadsfolder - The medical assessment is for educational use only and is not a diagnosis
Disclaimer
This project is for educational and research purposes only. It is not a medical device and does not provide a clinical diagnosis.
