Run This Ai
EN DE

OpenMed Tutorial: De-Identify Clinical Notes with On-Device PII Redaction

Step-by-step tutorial: install OpenMed, extract drugs and conditions with the Python API, redact PII via the REST service, and scale with batch processing — all on your own hardware.

In this tutorial you'll de-identify a clinical note and extract medical entities with OpenMed — entirely on your own machine. You'll use the Python API, the REST service, and see how real-time PII redaction works.

🚀 Want to deploy OpenMed yourself?

Docker configs, system requirements, and installation guides — all on one page.

View OpenMed Tool Page →

Step 1 — Install

Install the core runtime with the Hugging Face model backend, and optionally the REST service or MLX acceleration for Apple Silicon:

pip install --upgrade "openmed[hf]"
pip install --upgrade "openmed[hf,service]"   # REST API
pip install --upgrade "openmed[mlx]"          # Apple Silicon

Step 2 — Extract clinical entities with Python

OpenMed's analyze_text detects drugs, conditions, and diseases using specialized super-clinical models:

from openmed import analyze_text

result = analyze_text(
  "Patient received 75mg clopidogrel for NSTEMI.",
  model_name="pharma_detection_superclinical",
)
print([(e.label, e.text) for e in result.entities])
# [('DRUG', 'clopidogrel'), ('CONDITION', 'NSTEMI')]

Step 3 — De-identify PII in real time

Start the REST service and use the /pii/deidentify endpoint to redact names, addresses, IDs, and billing data before text leaves your system:

uvicorn openmed.service.app:app --host 0.0.0.0 --port 8080
# GET /health  → 200 OK
# POST /analyze
# POST /pii/extract
# POST /pii/deidentify
OpenMed redacting PII from a clinical discharge document in real time

Step 4 — Scale with batch processing

Process entire cohorts with the BatchProcessor, grouping entities across thousands of notes — ideal for retrospective research on de-identified data:

from openmed import BatchProcessor
p = BatchProcessor(model_name="disease_detection_superclinical")
results = p.process_texts([...])
# 3 notes → 7 entities, e.g. [('DISEASE', 'leukemia')]
OpenMed Scan on iPhone — on-device PII de-identification via OpenMedKit

From a single Python call to a full on-prem REST service, OpenMed gives you HIPAA-friendly NLP without sending a single byte to the cloud.

🚀 Want to deploy OpenMed yourself?

Docker configs, system requirements, and installation guides — all on one page.

View OpenMed Tool Page →
#openmed #healthcare-ai #pii #privacy #tutorial