CoolFace
Apppublic

pruijia123/blood-cell-detection-fhir

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

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 Observation resources and a DiagnosticReport
  • —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 Organization CS6440 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 Media images
  • —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:

ResourcePurpose
OrganizationThe lab or clinic
PatientThe patient record
MediaStored blood smear image
ObservationPlatelet, RBC, and WBC counts
DiagnosticReportSummary of the detection result

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 Observation resources plus one DiagnosticReport

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 3 and 10 images

See MOCK_PATIENTS.md for the full mock patient list and image assignments.

Project Structure

text
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

bash
conda env create -f environment.yml
conda activate blood-cell-detection

Pip

bash
pip install rfdetr gradio supervision pillow numpy pandas

Pretrained Checkpoint

Place the downloaded file in the project root as:

text
checkpoint_best_total.pth

Run

Train the model

bash
python train_blood_cell.py

Launch the app

bash
python web_demo.py

Open:

text
http://127.0.0.1:7860

Quick Demo Steps

Lab-connected workflow

  1. 1.Open Lab FHIR Workflow
  2. 2.Enter first name, last name, and birth date in MM/DD/YYYY
  3. 3.Click Find or Create My Lab Record
  4. 4.If recent lab images exist, click Load Recent Lab Images
  5. 5.Select an image
  6. 6.Click Analyse Selected Lab Image and Upload Result

Manual patient workflow

  1. 1.Open Patient Upload & FHIR Record
  2. 2.Upload one or more images
  3. 3.Click Analyse Uploaded Images
  4. 4.Review the results
  5. 5.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 Downloads folder
  • —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.