Skip to main content

Safe OCR pipeline for healthcare images with PII masking and NHS number validation.

Project description

health-safe-ocr

Safe OCR pipeline for healthcare images with PII masking, NHS number validation, confidence scoring, and human review flags.

health-safe-ocr helps developers extract text from healthcare images before sending content to an LLM, RAG pipeline, vector database, logs, audit system, or internal API.

Installation

pip install health-safe-ocr

For local development:

python -m venv .venv
.venv\Scripts\activate
pip install -e ".[dev]"

On macOS or Linux:

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

Tesseract OCR Requirement

This package uses pytesseract, which requires the Tesseract OCR system binary to be installed separately.

Windows:

winget install UB-Mannheim.TesseractOCR

macOS:

brew install tesseract

Linux:

sudo apt install tesseract-ocr

Python Usage

from health_safe_ocr import HealthSafeOCR

ocr = HealthSafeOCR()
result = ocr.extract(
    "patient_letter.jpg",
    mask_sensitive=True,
)

print(result.text)
print(result.masked_text)
print(result.confidence)
print(result.requires_human_review)
print(result.entities)

Example result:

OcrResult(
    text="Patient Sachin Tiwari NHS No 485 777 3456",
    masked_text="Patient Sachin Tiwari NHS No [NHS_NUMBER]",
    confidence=0.88,
    requires_human_review=False,
    entities=["NHS_NUMBER"],
    engine="tesseract",
)

CLI Usage

Extract plain text:

health-safe-ocr patient_letter.jpg

Extract and mask PII:

health-safe-ocr patient_letter.jpg --mask-pii

Return JSON:

health-safe-ocr patient_letter.jpg --mask-pii --json

Example JSON output:

{
  "text": "Patient Sachin Tiwari DOB 12/05/1990 NHS No 943 476 5919",
  "masked_text": "Patient Sachin Tiwari [DOB] NHS No [NHS_NUMBER]",
  "confidence": 0.88,
  "requires_human_review": false,
  "entities": ["DOB", "NHS_NUMBER"],
  "engine": "tesseract"
}

Supported PII Masking

Version 0.1.0 supports regex-based masking for:

  • Email addresses
  • UK phone numbers
  • Valid NHS numbers
  • Dates of birth
  • UK postcodes
  • National Insurance numbers
  • Patient IDs

Safety Note

This package does not provide diagnosis, clinical advice or treatment recommendations. It only extracts text from images and masks sensitive information.

Always review OCR output before using it in clinical, operational, audit, or production AI systems. OCR confidence scores and regex masking can miss sensitive data.

Local Checks

Run tests:

pytest

Run the CLI locally:

health-safe-ocr examples/sample.jpg --mask-pii --json

Build package distributions:

python -m build

Upload to TestPyPI:

python -m twine upload --repository testpypi dist/*

Upload to PyPI:

python -m twine upload dist/*

Roadmap

0.1.0

  • Image OCR
  • PII masking
  • NHS number validation
  • CLI
  • JSON output
  • PyPI release

0.2.0

  • PDF support
  • Scanned PDF page extraction
  • Better image preprocessing

0.3.0

  • PaddleOCR engine option
  • Better OCR accuracy
  • Multilingual support

0.4.0

  • Microsoft Presidio integration
  • Advanced entity detection
  • Name and address masking

0.5.0

  • Azure Document Intelligence provider
  • Cloud OCR fallback

1.0.0

  • Stable API
  • Full docs
  • Production examples
  • FastAPI integration
  • RAG-safe pipeline
  • Audit report output

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

health_safe_ocr-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

health_safe_ocr-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file health_safe_ocr-0.1.0.tar.gz.

File metadata

  • Download URL: health_safe_ocr-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for health_safe_ocr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 22b2e58be0b182d9e2798a570681bc370e4391f21ef0bb8de6e216dbcb4ae115
MD5 2963ae4166b9348834acfb189bafd0ac
BLAKE2b-256 403aaf6ee31fcc373785807a72d38d7f4f01c412727b94358d9a1d35e9f0334c

See more details on using hashes here.

File details

Details for the file health_safe_ocr-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for health_safe_ocr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8000a5007d3522332c2270acfc71fa503a32c0219ee94f779851d6f7dbcdf0a9
MD5 4dd49679c0219936e1773b5587a69dc3
BLAKE2b-256 07547335816323c505cfcf073901cf66dff05e65751409b13590ad2cb5e26545

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page