shifting-clinical-dates
它能做什么
这项技能教智能体如何隐藏医学文本中的真实日历日期,同时保留事件之间的时间间隔。适合需要在日期被隐藏后仍然使用间隔(例如距再次入院的天数)的研究人员。
适用场景
- ✓当研究人员需要在日期被隐藏后,仍然保留事件之间的时间间隔,例如距再次入院的天数的时候。
- ✓当用户需要按患者分别偏移日期,使每个人使用同一个偏移量的时候。
- ✓当用户需要将 89 岁以上的年龄设为上限,并把日期缩减到安全港方法所允许的程度的时候。
技能链接
https://github.com/maziyarpanahi/openmed/blob/master/skills/shifting-clinical-dates/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“能否隐藏我的患者记录中的真实日期,同时保留每次就诊之间的天数?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会为每位患者选定一个偏移量,并将其加到该记录的每个日期上。真实日期会丢失,但日期之间的间隔保持不变。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Shifting clinical dates
HIPAA Safe Harbor forbids keeping dates more specific than the year. But naively
deleting dates destroys the temporal structure research depends on — time to
event, length of stay, intervals between visits. Date shifting is the
compromise: move every date by a single random offset so the absolute dates
become meaningless while the intervals between them are preserved exactly.
OpenMed does this on-device with deidentify(method="shift_dates", ...).
When to use this skill
Use it when downstream analysis needs temporal relationships (survival curves,
sepsis-to-antibiotic time, readmission gaps) but the calendar dates must be
de-identified. If you can throw dates away entirely, plain method="mask" is
simpler — reach for shifting only when intervals matter.
Quick start
import openmed
note = (
"Admitted 2024-03-02, started antibiotics 2024-03-04, discharged 2024-03-09. "
"Follow-up scheduled 2024-04-02."
)
# Shift every date by the SAME offset -> intervals preserved, dates obscured.
result = openmed.deidentify(
note,
method="shift_dates",
consistent=True, # one stable offset for this run
seed=20240519, # reproducible per-patient offset (use a per-patient key)
keep_year=False, # do NOT retain the year (Safe Harbor: year-only is the max)
)
print(result.deidentified_text)
# Admit -> antibiotics is still 2 days; admit -> discharge still 7 days; etc.
How interval preservation works
All dates in the document are moved by one offset (auto-selected as a random
non-zero value in roughly ±1 year, or fixed with date_shift_days=). Because
the offset is identical for every date, the difference between any two dates is
unchanged:
real: Mar 2 ──2d──▶ Mar 4 ──5d──▶ Mar 9
shifted: Jul 18 ──2d──▶ Jul 20 ──5d──▶ Jul 25 (offset = +138 days, intervals intact)
That is why survival time, length of stay, and visit gaps survive de-identification while the actual calendar is destroyed.
Per-patient consistent offsets
Each patient should get their own offset, and that offset should be
stable across documents and reproducible across runs. Derive a per-patient
seed (e.g. from a secret keyed hash of the patient ID — never the raw MRN) and
pass it as seed=:
def patient_offset_seed(patient_key: str) -> int:
import hashlib, hmac
# keyed so the mapping from patient -> offset is itself a secret
digest = hmac.new(b"<vault-secret>", patient_key.encode(), hashlib.sha256).digest()
return int.from_bytes(digest[:8], "big")
for doc in patient_documents:
openmed.deidentify(
doc, method="shift_dates",
consistent=True, seed=patient_offset_seed(patient_id),
keep_year=False,
)
Same patient → same offset everywhere (their notes stay internally consistent); different patients → different offsets (cross-patient dates cannot be aligned).
Workflow
- Decide the offset policy. Per-patient is standard for clinical research.
Use
consistent=True+ a per-patientseed. Use a fixeddate_shift_days=only when a deterministic, externally-managed offset is required. - Set
keep_year=Falsefor Safe Harbor. (keep_year=Trueretains the year, which is permissible only if dates aren't tied to an individual's care.) - Cap ages over 89 separately. Date shifting moves dates; it does not
aggregate ages. Safe Harbor requires ages >89 and any date implying age >89
to collapse to a single "90+" — handle
AGEspans explicitly (auditing-safe-harbor-checklist). - Keep names/IDs handled too.
shift_datesonly touches dates. Run a normal redaction pass (or a policy) forPERSON,ID_NUM, etc. - Verify intervals are preserved and no calendar leaked via
audit=True.
Hand-off to / from OpenMed
- Core de-id:
deidentifying-clinical-text— combine date shifting with apolicy=so names/IDs are redacted in the same pipeline. - Safe Harbor checklist:
auditing-safe-harbor-checklist— the date rule and the age-90 cap are categories C in the 18. - Audit:
auditing-deidentification-runsrecords the method and per-span actions (offsets/hashes, not raw dates). - Other surfaces: MCP
openmed_deidentify/ RESTPOST /pii/deidentifyaccept the same method and parameters.
Edge cases & gotchas
- Offset 0 is forbidden. An auto-selected offset is always non-zero — a zero shift would si
常见问题
什么情况下直接去除更简单?
这项技能说明,如果日期并不重要,简单的遮盖方法比偏移更容易。
为什么要按患者使用不同的偏移量?
这样既能隐藏真实日期,又能保持每位患者时间线的一致性。
偏移量可以重复生成吗?
可以。这项技能设置了固定种子,使同一患者每次都获得相同的偏移量。
详情
作者的原始描述
Apply consistent per-patient date shifting in OpenMed that preserves intervals between events while satisfying HIPAA Safe Harbor's date rule. Use when the user needs to de-identify dates but keep temporal structure for research, shift all dates by the same offset per patient, preserve days-between-events for survival or longitudinal analysis, cap ages over 89, or strip everything but the year. Covers deidentify(method=\"shift_dates\", date_shift_days=..., keep_year=...) and per-patient reproducible offsets via consistent=True, seed=.... Pairs with OpenMed deidentifying-clinical-text and auditi
repo: maziyarpanahi/openmed
热度
- GitHub 星标
- 5.8k
- 排名
- #14735
- 许可证
- 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扫描已去标识化的临床文本,查找残留的标识符,例如社会安全号、银行卡号、电子邮件地址和日期,若仍有残留则阻止发布。