building-patient-timelines
它能做什么
这项技能把一份或多份记录中的临床事件整理为按时间排序的患者时间线。适合希望清楚了解患者长期诊疗历史的临床医生和分析人员。
适用场景
- ✓当你希望从记录中按日期整理出患者的诊断、用药和手术的时候。
- ✓当“入院两天后”这类相对时间表达需要转换为实际日期的时候。
- ✓当你在导出或总结之前,需要一个按日期排序的就诊序列的时候。
技能链接
https://github.com/maziyarpanahi/openmed/blob/master/skills/building-patient-timelines/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请根据这些出院记录,整理出诊断、用药和手术的时间线,并为每个事件标注日期。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会提取带有文本位置的临床事件,标准化日期并解析相对时间表达,然后把所有内容排成一个序列。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Building patient timelines
A patient timeline is a chronologically ordered list of clinical events —
diagnoses, medications, procedures, encounters — each carrying a normalized
date. OpenMed gives you the events (via analyze_text) and the clinical
temporality of each mention (current vs. historical, see
resolving-clinical-context); this skill turns those into a sorted timeline.
Everything runs on-device — de-identify first if the source notes contain
PHI, and keep raw identifiers out of logs.
When to use this skill
After you have extracted entities from one or more notes and want them ordered
in time: a longitudinal history, a "course of illness" view, a feed for a
summary card, or a pre-step before FHIR export. If you only need to extract
entities, use extracting-clinical-entities. If you need negation/temporality
on a single mention, use resolving-clinical-context.
Quick start
import datetime as dt
import openmed
note = (
"Discharge summary, 2024-03-12. Patient admitted 2024-03-08 with chest pain. "
"History of type 2 diabetes diagnosed in 2019. Started on metformin two days "
"after admission. Cardiac catheterization performed yesterday."
)
# 1) Extract clinical events (entities carry char offsets: start/end)
result = openmed.analyze_text(note, output_format="dict")
events = result["entities"] # each: {text, label, confidence, start, end}
# 2) Normalize the temporal frame: an explicit document/anchor date drives
# resolution of relative expressions ("two days after", "yesterday").
anchor = dt.date(2024, 3, 12) # parsed from the note header or document metadata
analyze_text returns {text, entities, model_name, timestamp, ...}; each
entity is {text, label, confidence, start, end}. Use start/end to locate
each event in the source and to find the nearest date expression.
Workflow
- De-identify if needed. If notes carry PHI, run
openmed.deidentify(...)first, or keep the timeline keyed by stable internal IDs — never log raw names/MRNs. - Extract events.
openmed.analyze_text(note)for conditions, drugs, procedures; pick the model that matches your target entities (choosing-openmed-models). - Resolve temporality. For each event, use
resolving-clinical-contextto tag itcurrent/historical/hypotheticaland to drop negated or family-history mentions that should not appear on the patient's own line. - Normalize dates. Map each event to a date:
- Absolute (
2024-03-08,March 2019) → parse directly. Record the granularity (day / month / year) — a year-only event sorts to a coarse bucket, not a fakeJan 1. - Relative (
two days after admission,yesterday,on POD 2) → resolve against an anchor: the document date, admission date, or a prior event's date. Without an anchor, relative expressions are unresolvable — flag them, don't guess.
- Absolute (
- Build event records. One record per event:
(date, granularity, label, surface_text, char_span, temporality, confidence, source_note_id). - Sort and de-duplicate. Sort by
(date, granularity); merge repeated mentions of the same event across notes (same label + overlapping date). - Emit. A sorted list for a UI, or FHIR resources (see hand-off).
Worked example: events → sorted timeline
def to_timeline(events, *, anchor, note_id):
"""events: list of {text,label,start,end,confidence}. anchor: date.
Returns sorted [(date, granularity, label, text, confidence)]."""
timeline = []
for e in events:
date, gran = resolve_event_date(e, note=note, anchor=anchor) # your resolver
if date is None:
continue # undated/unresolvable: route to an "undated" bucket, don't drop silently
timeline.append((date, gran, e["label"], e["text"], e["confidence"]))
# year-only ('Y') sorts before month ('M') before day ('D') on ties
order = {"Y": 0, "M": 1, "D": 2}
return sorted(timeline, key=lambda r: (r[0], order[r[1]]))
# resolve_event_date handles: ISO dates, "March 2019" (gran='M'),
# "yesterday"/"two days after admission" (relative to anchor/admission), POD-n, etc.
Hand-off to / from OpenMed
- From OpenMed:
analyze_textentities (extracting-clinical-entities) andclinicalcontext tags (resolving-clinical-context) are the inputs. Rundeidentifyupstream when notes carry PHI. - To OpenMed / interop: f
常见问题
它会处理提到既往史的记录吗?
会。它利用临床语境,区分当前事件与历史提及。
我应该先去除标识符吗?
如果记录中包含个人信息,应该先去除。这项技能建议先做去标识化,并且不要把标识符写入日志。
它只提取实体吗?
不是。它的目标是生成有序的时间线,而单纯的实体提取是另一个步骤。
详情
作者的原始描述
Assemble a chronological patient timeline from OpenMed-extracted clinical events, normalizing dates and resolving relative time expressions on-device. Use when the user wants to build a patient timeline, order events from clinical notes, reconstruct a longitudinal history, plot a course of illness, or turn analyze_text/deidentify output into a sorted sequence of dated encounters, diagnoses, medications, and procedures. Covers temporal normalization (absolute and relative), event modeling toward FHIR Encounter/Condition.onsetDateTime, anchoring to a document/admission date, and handling undated
repo: maziyarpanahi/openmed
热度
- GitHub 星标
- 5.8k
- 排名
- #14679
- 许可证
- 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扫描已去标识化的临床文本,查找残留的标识符,例如社会安全号、银行卡号、电子邮件地址和日期,若仍有残留则阻止发布。