Linking OpenMed entities to UMLS CUIs
Resolve concept spans that OpenMed extracts to UMLS Metathesaurus concepts.
The atom is the CUI (Concept Unique Identifier, e.g. C0011860): one CUI
unifies synonyms from many source vocabularies (SNOMED CT, ICD-10-CM, RxNorm,
MeSH, LOINC), making the CUI the natural hub for cross-vocabulary normalization.
Every concept also carries one or more semantic types (TUIs, e.g. Disease or
Syndrome T047) for type-based filtering.
Hard licensing boundary — read first. The UMLS Metathesaurus is
license-restricted. OpenMed and this skill never bundle, ship, or cache
Metathesaurus content. Concept linking runs out-of-process against the NLM
UTS (UMLS Terminology Services) REST API using the user's own UTS API key.
A free UTS account + API key is required (request at uts.nlm.nih.gov and accept
the UMLS license). The Metathesaurus stays user-supplied: your code holds only
the key (from the environment) and stores only returned CUIs/strings.
When to use
- You need one canonical id across vocabularies — e.g. to unify a SNOMED CT
disorder, an ICD-10 code, and a free-text mention onto a single CUI.
- You want synonym normalization ("MI", "myocardial infarction", "heart
attack" →
C0027051).
- You need semantic-type filtering to keep only, say, Pharmacologic
Substance or Disease or Syndrome entities.
- You are cross-walking codes and need the CUI as the join key before pivoting to
RxNorm (
normalizing-rxnorm) or SNOMED (mapping-to-snomed).
Quick start (user-supplied UTS API key)
The UTS REST API base is https://uts-ws.nlm.nih.gov/rest. Authentication uses
your API key as the apiKey query parameter (the modern, simplest method).
import os, requests
UTS = "https://uts-ws.nlm.nih.gov/rest"
API_KEY = os.environ["UTS_API_KEY"] # USER's own key — never hardcoded
VERSION = "current" # or a fixed release like 2024AB
def search(term: str, sabs: str | None = None, count: int = 10) -> list[dict]:
"""Search the Metathesaurus for a term; optionally restrict source vocabs."""
params = {"string": term, "apiKey": API_KEY, "pageSize": count}
if sabs: # e.g. "SNOMEDCT_US,RXNORM,ICD10CM"
params["sabs"] = sabs
r = requests.get(f"{UTS}/search/{VERSION}", params=params, timeout=15)
r.raise_for_status()
return r.json().get("result", {}).get("results", [])
def concept(cui: str) -> dict:
"""Pull a concept's preferred name and semantic types."""
r = requests.get(f"{UTS}/content/{VERSION}/CUI/{cui}",
params={"apiKey": API_KEY}, timeout=15)
r.raise_for_status()
return r.json().get("result", {})
def crosswalk(cui: str, target_sab: str) -> list[dict]:
"""Atoms of a CUI in a target vocabulary (the cross-walk)."""
r = requests.get(f"{UTS}/content/{VERSION}/CUI/{cui}/atoms",
params={"apiKey": API_KEY, "sabs": target_sab,
"pageSize": 50}, timeout=20)
r.raise_for_status()
return r.json().get("result", [])
hits = search("type 2 diabetes") # -> [{ui: 'C0011860', name: ...}, ...]
sct = crosswalk("C0011860", "SNOMEDCT_US") # CUI -> SNOMED CT codes
Workflow
- Extract spans with OpenMed (Disease, Pharmaceutical, Chemical, Anatomy).
- Search each span via
/search/{version} for candidate CUIs.
- Filter by semantic type (TUI) so a drug span resolves to a substance
concept, not a same-named disease. Pull semantic types from
/content/.../CUI/{cui} and keep only the expected group.
- Rank candidates (exact preferred-name match > synonym match) and combine
with OpenMed's
confidence to choose one CUI.
- Cross-walk the chosen CUI to whatever target you actually store —
SNOMEDCT_US, ICD10CM, RXNORM, MSH — via
/CUI/{cui}/atoms?sabs=.
- Emit the CUI plus the target code(s) and OpenMed source offsets.
Hand-off from OpenMed
openmed.analyze_text(..., output_format="dict") returns entities, each a dict
with text, label, confidence, start, end. Use the label to pick the
semantic-type group you keep:
import openmed
note = "History of myocardial infarction; started on lisinopril."
result = openmed.analyze_text(
note,
model_name="disease_detection_superclinical", # Disease category
output_format="dict",
)
# OpenMed label -> acceptable UMLS semantic-type groups (TUI prefixes)
KEEP_STY = {
"DISEASE": {"Disease or Syndrome", "Sign or Symptom", "Neoplastic Process"},
"DRUG": {"Pharmacologic Substance", "Clinical Drug"},
"CHEM": {"Pharmacologic Substance", "Organic Chemical"},
}
for ent in result["entities"]:
for hit in search(ent["text"], count=5):
cui = hit["ui"]
stys = {s["name"] for s in concept(cui).get("semanticTypes", [])}
if not KEEP_STY.get(ent["label"]) or stys & KEEP_STY[ent["label"]]:
print(ent["text"], ent["start"], ent["end"], "->", cui, hit["name"])
break
Keep OpenMed's start/end offsets beside each CUI for traceability. Store only
CUIs and codes — never the raw note, never a local copy of the Metathesaurus.
Edge cases & gotchas
- Never bundle or cache the Metathesaurus. No vendored MRCONSO, no local
concept dump baked into the package. If you precompute, do it inside the
user's licensed environment, not in distributed OpenMed assets.
- The UTS key is the user's. Read it from the environment/secret store; never
embed it, log it, or commit it. One key, the user's license, their rate limits.
- Semantic-type filtering is essential. Many strings are polysemous across
types ("cold" = symptom vs temperature). Without TUI filtering you will link to
the wrong concept family.
- Version pin for reproducibility.
current drifts at each UMLS release. Pin
a release (e.g. 2024AB) for stable, auditable mappings; record it.
- Source-vocab restriction. Restrict
sabs to the vocabularies you are
licensed for and actually need; this both narrows results and respects per-source
license terms inside UMLS.
- CUI as hub, not endpoint. Downstream systems usually want a target code
(SNOMED/ICD/RxNorm), so resolve to CUI then cross-walk — don't store only the
CUI if your consumers expect billable/clinical codes.
- Offline alternatives are still user-licensed. Tools like MetaMap or
QuickUMLS run locally but require a UMLS download under the user's license;
OpenMed neither ships nor requires those datasets.
- Local-first. OpenMed NER runs on-device; only de-identified concept strings
reach UTS. No PHI over the wire.
Standards & references
1---2name: linking-umls-concepts3description: Links entities extracted by OpenMed to UMLS Metathesaurus CUIs using the USER'S OWN UTS API key, with nothing from the Metathesaurus bundled or cached. Use when the user wants to normalize concepts across vocabularies to a single CUI, resolve synonyms via the UMLS, filter by semantic type, or cross-walk between SNOMED CT, ICD-10, RxNorm and MeSH through their shared CUI. Trigger keywords: UMLS, CUI, Metathesaurus, UTS API key, semantic type, TUI, MetaMap, QuickUMLS, concept normalization, cross-vocabulary. Pairs after OpenMed NER: consume Disease/Pharmaceutical/Chemical/Anatomy entities from openmed.analyze_text and resolve each span to a CUI out-of-process. UMLS is license-restricted — the Metathesaurus is NEVER bundled; every call uses the user's UTS account.4license: Apache-2.05---67# Linking OpenMed entities to UMLS CUIs89Resolve concept spans that OpenMed extracts to **UMLS Metathesaurus** concepts.10The atom is the **CUI** (Concept Unique Identifier, e.g. `C0011860`): one CUI11unifies synonyms from many source vocabularies (SNOMED CT, ICD-10-CM, RxNorm,12MeSH, LOINC), making the CUI the natural hub for cross-vocabulary normalization.13Every concept also carries one or more **semantic types** (TUIs, e.g. *Disease or14Syndrome* `T047`) for type-based filtering.1516> **Hard licensing boundary — read first.** The UMLS Metathesaurus is17> **license-restricted**. OpenMed and this skill **never bundle, ship, or cache**18> Metathesaurus content. Concept linking runs **out-of-process against the NLM19> UTS (UMLS Terminology Services) REST API using the user's own UTS API key**.20> A free UTS account + API key is required (request at uts.nlm.nih.gov and accept21> the UMLS license). The Metathesaurus stays user-supplied: your code holds only22> the key (from the environment) and stores only returned CUIs/strings.2324## When to use2526- You need **one canonical id across vocabularies** — e.g. to unify a SNOMED CT27 disorder, an ICD-10 code, and a free-text mention onto a single CUI.28- You want **synonym normalization** ("MI", "myocardial infarction", "heart29 attack" → `C0027051`).30- You need **semantic-type filtering** to keep only, say, *Pharmacologic31 Substance* or *Disease or Syndrome* entities.32- You are cross-walking codes and need the CUI as the join key before pivoting to33 RxNorm (`normalizing-rxnorm`) or SNOMED (`mapping-to-snomed`).3435## Quick start (user-supplied UTS API key)3637The UTS REST API base is `https://uts-ws.nlm.nih.gov/rest`. Authentication uses38your API key as the `apiKey` query parameter (the modern, simplest method).3940```python41import os, requests4243UTS = "https://uts-ws.nlm.nih.gov/rest"44API_KEY = os.environ["UTS_API_KEY"] # USER's own key — never hardcoded45VERSION = "current" # or a fixed release like 2024AB4647def search(term: str, sabs: str | None = None, count: int = 10) -> list[dict]:48 """Search the Metathesaurus for a term; optionally restrict source vocabs."""49 params = {"string": term, "apiKey": API_KEY, "pageSize": count}50 if sabs: # e.g. "SNOMEDCT_US,RXNORM,ICD10CM"51 params["sabs"] = sabs52 r = requests.get(f"{UTS}/search/{VERSION}", params=params, timeout=15)53 r.raise_for_status()54 return r.json().get("result", {}).get("results", [])5556def concept(cui: str) -> dict:57 """Pull a concept's preferred name and semantic types."""58 r = requests.get(f"{UTS}/content/{VERSION}/CUI/{cui}",59 params={"apiKey": API_KEY}, timeout=15)60 r.raise_for_status()61 return r.json().get("result", {})6263def crosswalk(cui: str, target_sab: str) -> list[dict]:64 """Atoms of a CUI in a target vocabulary (the cross-walk)."""65 r = requests.get(f"{UTS}/content/{VERSION}/CUI/{cui}/atoms",66 params={"apiKey": API_KEY, "sabs": target_sab,67 "pageSize": 50}, timeout=20)68 r.raise_for_status()69 return r.json().get("result", [])7071hits = search("type 2 diabetes") # -> [{ui: 'C0011860', name: ...}, ...]72sct = crosswalk("C0011860", "SNOMEDCT_US") # CUI -> SNOMED CT codes73```7475## Workflow76771. **Extract** spans with OpenMed (Disease, Pharmaceutical, Chemical, Anatomy).782. **Search** each span via `/search/{version}` for candidate CUIs.793. **Filter by semantic type (TUI)** so a drug span resolves to a substance80 concept, not a same-named disease. Pull semantic types from81 `/content/.../CUI/{cui}` and keep only the expected group.824. **Rank** candidates (exact preferred-name match > synonym match) and combine83 with OpenMed's `confidence` to choose one CUI.845. **Cross-walk** the chosen CUI to whatever target you actually store —85 SNOMEDCT_US, ICD10CM, RXNORM, MSH — via `/CUI/{cui}/atoms?sabs=`.866. **Emit** the CUI plus the target code(s) and OpenMed source offsets.8788## Hand-off from OpenMed8990`openmed.analyze_text(..., output_format="dict")` returns `entities`, each a dict91with `text`, `label`, `confidence`, `start`, `end`. Use the label to pick the92semantic-type group you keep:9394```python95import openmed9697note = "History of myocardial infarction; started on lisinopril."98result = openmed.analyze_text(99 note,100 model_name="disease_detection_superclinical", # Disease category101 output_format="dict",102)103104# OpenMed label -> acceptable UMLS semantic-type groups (TUI prefixes)105KEEP_STY = {106 "DISEASE": {"Disease or Syndrome", "Sign or Symptom", "Neoplastic Process"},107 "DRUG": {"Pharmacologic Substance", "Clinical Drug"},108 "CHEM": {"Pharmacologic Substance", "Organic Chemical"},109}110111for ent in result["entities"]:112 for hit in search(ent["text"], count=5):113 cui = hit["ui"]114 stys = {s["name"] for s in concept(cui).get("semanticTypes", [])}115 if not KEEP_STY.get(ent["label"]) or stys & KEEP_STY[ent["label"]]:116 print(ent["text"], ent["start"], ent["end"], "->", cui, hit["name"])117 break118```119120Keep OpenMed's `start`/`end` offsets beside each CUI for traceability. Store only121CUIs and codes — never the raw note, never a local copy of the Metathesaurus.122123## Edge cases & gotchas124125- **Never bundle or cache the Metathesaurus.** No vendored MRCONSO, no local126 concept dump baked into the package. If you precompute, do it inside the127 *user's* licensed environment, not in distributed OpenMed assets.128- **The UTS key is the user's.** Read it from the environment/secret store; never129 embed it, log it, or commit it. One key, the user's license, their rate limits.130- **Semantic-type filtering is essential.** Many strings are polysemous across131 types ("cold" = symptom vs temperature). Without TUI filtering you will link to132 the wrong concept family.133- **Version pin for reproducibility.** `current` drifts at each UMLS release. Pin134 a release (e.g. `2024AB`) for stable, auditable mappings; record it.135- **Source-vocab restriction.** Restrict `sabs` to the vocabularies you are136 licensed for and actually need; this both narrows results and respects per-source137 license terms inside UMLS.138- **CUI as hub, not endpoint.** Downstream systems usually want a target code139 (SNOMED/ICD/RxNorm), so resolve to CUI then cross-walk — don't store only the140 CUI if your consumers expect billable/clinical codes.141- **Offline alternatives are still user-licensed.** Tools like MetaMap or142 QuickUMLS run locally but require a UMLS download under the user's license;143 OpenMed neither ships nor requires those datasets.144- **Local-first.** OpenMed NER runs on-device; only de-identified concept strings145 reach UTS. No PHI over the wire.146147## Standards & references148149- UMLS Metathesaurus: https://www.nlm.nih.gov/research/umls/index.html150- UMLS license & UTS account: https://uts.nlm.nih.gov/uts/151- UTS REST API docs: https://documentation.uts.nlm.nih.gov/rest/home.html152- Semantic Network (types/TUIs): https://www.nlm.nih.gov/research/umls/META3_current_semantic_types.html153- MetaMap: https://lhncbc.nlm.nih.gov/ii/tools/MetaMap.html154- QuickUMLS: https://github.com/Georgetown-IR-Lab/QuickUMLS