deidentifying-clinical-text
它能做什么
这项技能在你自己的电脑上去除或隐藏临床记录中的患者标识符,例如姓名、日期和病历号。适合必须共享或分析病历,又不能暴露患者身份的人。
适用场景
- ✓当你需要在共享病历之前,去除其中的患者姓名、日期或病历号的时候。
- ✓当你希望用逼真的虚假值替换标识符,使记录仍然易于阅读的时候。
- ✓当你必须选择去标识化方法,例如遮盖、删除或偏移日期的时候。
技能链接
https://github.com/maziyarpanahi/openmed/blob/master/skills/deidentifying-clinical-text/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在我把这些出院小结分享给研究团队之前,去除其中的患者姓名、日期和电话号码。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会在设备上运行检测以找出标识符,应用所选方法(如遮盖或替换),并返回清理后的文本以及变更清单。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
De-identifying clinical text
openmed.deidentify detects PHI/PII and rewrites the text so it can be shared,
stored, or analyzed without exposing patients. It runs fully on-device after
a one-time model download — no network calls, no telemetry, no raw PHI leaving
the process. This is the single most important OpenMed entry point for privacy
work; everything else (policies, audit, multilingual, date-shifting) layers on
top of it.
When to use this skill
Reach for deidentify when you need to transform text — replace, mask, remove,
hash, or date-shift the identifiers. If you only need to locate PHI spans
without changing the text, use extract_pii (see extracting-pii-entities). To
restore masked text later, use reidentify (see reidentifying-text).
Quick start
import openmed
note = (
"Patient John Doe (MRN 1234567) was seen on 2024-03-02 by Dr. Alice Reed. "
"Contact: john.doe@example.com, 617-555-0142."
)
result = openmed.deidentify(
note,
method="mask", # mask | remove | replace | hash | shift_dates
confidence_threshold=0.7, # safety default; raise to reduce false negatives' impact
policy="hipaa_safe_harbor", # optional bundled profile (see below)
)
print(result.deidentified_text)
# Patient [NAME] (MRN [ID_NUM]) was seen on [DATE] by Dr. [NAME]. ...
for e in result.pii_entities:
# NEVER log e.text / e.original_text — those are raw PHI. Use offsets + label.
print(e.canonical_label, e.start, e.end, round(e.confidence, 3))
deidentify returns a DeidentificationResult with these fields (note the
exact names):
| Field | What it holds |
|---|---|
.deidentified_text |
the rewritten, PHI-safe string (your output) |
.pii_entities |
list[PIIEntity] — each has start, end, canonical_label, confidence, action, surrogate; original_text/text hold raw PHI |
.mapping |
redacted→original dict, only when keep_mapping=True (secret) |
.method |
the method actually applied |
.metadata |
run metadata (model, policy, counts) |
The five methods
method= |
Effect | Reversible? | Use when |
|---|---|---|---|
"mask" |
John Doe → [NAME] |
with keep_mapping=True |
default; clear that redaction happened |
"remove" |
deletes the span entirely | no | minimal-footprint output |
"replace" |
type-matched fake value (John Doe→Mark Lee) |
with keep_mapping=True |
keep notes readable/parseable (see generating-synthetic-surrogates) |
"hash" |
stable hash per value, links repeats | no (one-way) | cohort linkage without revealing identity |
"shift_dates" |
moves dates, preserves intervals | n/a | research needing temporal structure (see shifting-clinical-dates) |
Workflow
- Pick a method and a policy. Start from a bundled
policy=profile (hipaa_safe_harbor,gdpr_pseudonymization,research_limited_dataset, …) so per-label actions are set for you. Seeconfiguring-privacy-policies. - Set
confidence_thresholddeliberately. Default is0.7. For de-id, prefer over-redaction: a missed identifier is a breach, an over-redacted token is just noise. The bundled safety sweep catches structured IDs (SSN, MRN-like, emails) even below threshold. - Run
deidentify. Inspectresult.pii_entitiesby offset and label, not raw text, to confirm coverage. - For stable surrogates, pass
consistent=True, seed=<int>so the same input maps to the same fake value every run (reproducible pipelines). - For reversibility, pass
keep_mapping=Trueand storeresult.mappingin a secured vault — never alongside the de-identified output. - Verify, don't assume. Check residual risk with
audit=True(auditing-deidentification-runs) and the 18-identifier checklist (auditing-safe-harbor-checklist).
Consistent surrogates and reversibility
# Same fake identity for every mention of the same person, reproducibly:
r = openmed.deidentify(note, method="replace", consistent=True, seed=42)
# Reversible de-id (keep the mapping secret and separate from output):
r = openmed.deidentify(note, method="mask", keep_mapping=True)
restored = openmed.reidentify(r.deidentified_text, r.mapping)
assert restored == note
Hand-off to / from OpenMed
- Detect only:
openmed.extract_pii(text)→PredictionResultwith.entities(spans, no rewrite). Use it to preview coverage first. - Restore:
常见问题
文本会离开我的电脑吗?
不会。在一次性下载模型之后,处理在设备上进行,没有任何网络请求。
我之后可以恢复原始文本吗?
某些方法支持还原。再识别技能涵盖如何恢复被遮盖的文本。
有安全设置吗?
有。置信度阈值默认设置为偏向安全,你也可以自行调整。
详情
作者的原始描述
Remove, mask, or replace PHI/PII in clinical free text on-device with OpenMed's deidentify(). Use when the user needs to de-identify medical notes, strip patient identifiers, redact PHI before sharing or analysis, anonymize discharge summaries, or pick a de-id method (mask vs remove vs replace vs hash vs shift_dates). Covers confidence_threshold for safety, consistent+seed for stable surrogates, keep_mapping for reversible de-id, policy= profiles, and the DeidentificationResult fields. Pairs with OpenMed extract_pii (detect spans), reidentify (restore), configuring-privacy-policies, and auditi
repo: maziyarpanahi/openmed
热度
- GitHub 星标
- 5.8k
- 排名
- #14689
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
annotating-variants
5.8k帮你的智能体预测基因变异的作用,把 HGVS 名称转换为基因组位置,并使用免费的公共注释工具添加人群频率。
ask-openmed
5.8k帮你的智能体为临床文本请求选择合适的 OpenMed 工作流程,并在可能涉及患者数据时,先进行隐私检查。
assembling-fhir-bundles
5.8k把多份 FHIR 健康记录打包成一个事务 Bundle,可直接发送给 EHR 系统,并正确链接其中的内部引用。
auditing-deid-leakage
5.8k扫描已去标识化的临床文本,查找残留的标识符,例如社会安全号、银行卡号、电子邮件地址和日期,若仍有残留则阻止发布。