building-patient-timelines
What it does
This skill turns clinical events from one or more notes into a time-ordered patient timeline. It is for clinicians and analysts who want a clear history of a patient's care over time.
When to use it
- ✓When you want a patient's diagnoses, medicines and procedures ordered by date from notes.
- ✓When relative time phrases like two days after admission must become actual dates.
- ✓When you need a sorted sequence of dated encounters before exporting or summarizing.
Skill link
https://github.com/maziyarpanahi/openmed/blob/master/skills/building-patient-timelines/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“From these discharge notes, build a timeline of the diagnoses, medicines and procedures, with dates for each event.”
5 new skills a week. 1 minute to read.
How it works
The agent extracts clinical events with their positions in the text, normalizes the dates and resolves relative time expressions, then sorts everything into one sequence.
Technical content (original SKILL.md)
Original text by the author, straight from 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
FAQ
Does it handle notes that mention past history?
Yes. It uses clinical context to separate current events from historical mentions.
Should I remove identifiers first?
Yes, if the notes contain personal details. The skill recommends de-identifying first and keeping identifiers out of logs.
Does it only extract entities?
No. Its goal is an ordered timeline, while plain entity extraction is a separate step.
Details
Original description by the author
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
Popularity
- GitHub stars
- 5.8k
- Ranking position
- #14679
- License
- Apache-2.0
- Updated
- 11/2/2026
Comments
- …
More skills from this repository
annotating-variants
5.8kHelps your agent predict what a genetic variant does, convert HGVS names to genome positions and attach population frequencies, using free public annotators.
ask-openmed
5.8kHelps your agent pick the right OpenMed workflow for a clinical text request, starting with a privacy check whenever patient data may be present.
assembling-fhir-bundles
5.8kPackages several FHIR health records into one transaction Bundle ready to send to an EHR, with the internal references linked correctly.
auditing-deid-leakage
5.8kScans de-identified clinical text for leftover identifiers such as SSNs, card numbers, emails and dates, and blocks release if any remain.
Similar skills
gitcrawl
394kLets your agent search a saved archive of GitHub issues and pull requests, group duplicates, and check their current status on GitHub.
slacrawl
394kLets your agent search and count messages in a local Slack archive, check how fresh that archive is, and refresh it when needed.
goplaces
394kHelps your agent search for places, get their details and reviews, and resolve place names using Google Places, with JSON output for scripts.