Extracting DICOM Metadata & Report Text for OpenMed
DICOM (Digital Imaging and Communications in Medicine) files carry far more than
pixels: a header of tagged attributes (patient, study, series, equipment)
and, for DICOM-SR (Structured Reports), a content tree holding the actual
radiology/cardiology report text. Two jobs sit here: pull the report narrative
for NLP, and flag the PHI in the header so it gets scrubbed. This skill does
both, then hands narrative to OpenMed. Header tags are read with pydicom
(external, MIT-licensed); de-identification of the extracted text is OpenMed's.
When to use
- You ingest DICOM from PACS/VNA or a research archive and want the SR report
text mined with clinical NLP.
- You must enumerate PHI-bearing header tags before sharing/exporting images.
- You have DICOM-SR objects (e.g. radiology measurements + impression) whose
content tree contains the dictated report.
DICOM headers in one minute
Every attribute has a tag (gggg,eeee) (group, element), a VR (value
representation, e.g. PN person name, DA date, UI UID), and a value. PHI
clusters in well-known tags:
| Tag |
Name |
VR |
Notes |
| (0010,0010) |
PatientName |
PN |
direct identifier |
| (0010,0020) |
PatientID |
LO |
MRN |
| (0010,0030) |
PatientBirthDate |
DA |
DOB |
| (0010,1040) |
PatientAddress |
LO |
address |
| (0008,0090) |
ReferringPhysicianName |
PN |
provider |
| (0008,0020/0030) |
StudyDate / StudyTime |
DA/TM |
dates |
| (0008,0050) |
AccessionNumber |
SH |
order id |
| (0008,103E) |
SeriesDescription |
LO |
free text — may leak PHI |
| (0020,4000) |
ImageComments |
LT |
free text — may leak PHI |
| (0040,A730) |
ContentSequence |
SQ |
DICOM-SR report tree |
Quick start
Read the header, pull SR report text, flag PHI tags, hand off to OpenMed:
import pydicom
import openmed
ds = pydicom.dcmread("study.dcm")
# 1) Enumerate PHI-bearing header tags (report, do not log values).
PHI_TAGS = [
(0x0010, 0x0010), (0x0010, 0x0020), (0x0010, 0x0030), (0x0010, 0x1040),
(0x0008, 0x0090), (0x0008, 0x0050), (0x0008, 0x0020), (0x0008, 0x0030),
]
present_phi = [hex_pair for hex_pair in PHI_TAGS if hex_pair in ds]
# 2) Extract report text from a DICOM-SR content tree (recursively).
def sr_text(dataset):
chunks = []
for item in dataset.get("ContentSequence", []):
vt = item.get("ValueType")
if vt == "TEXT" and "TextValue" in item:
chunks.append(item.TextValue)
if "ContentSequence" in item: # nested CONTAINER
chunks.append(sr_text(item))
return "\n".join(c for c in chunks if c)
report = sr_text(ds)
# Some modalities stash narrative in free-text header tags too:
for tag in ("ImageComments", "SeriesDescription", "StudyDescription"):
if tag in ds and isinstance(ds.get(tag), str):
report += "\n" + ds.get(tag)
# 3) De-identify the narrative, then run NER.
if report.strip():
deid = openmed.deidentify(report, method="replace", policy="hipaa_safe_harbor")
result = openmed.analyze_text(deid.text, output_format="dict")
pydicom reads tags by keyword (ds.PatientName) or by (group, element).
DICOM-SR text lives in the recursive ContentSequence content tree.
Workflow
- Read the dataset with
pydicom.dcmread (use stop_before_pixels=True
for header-only/metadata work — faster, avoids loading pixels).
- Walk the SR content tree.
ContentSequence nests CONTAINER, TEXT,
CODE, NUM, PNAME nodes; concatenate TEXT.TextValue (and relevant
CODE/NUM measurements) in document order to reconstruct the report.
- Inventory PHI tags. Flag the standard identifier tags and free-text
tags (
ImageComments, *Description) that frequently leak PHI. Report tag
presence — never echo the values into logs.
- De-identify → analyze the report narrative with OpenMed.
- Scrub the header before any image export using a DICOM de-identification
profile (PS3.15 Annex E / Basic Application Level Confidentiality). OpenMed
de-identifies the narrative; header scrubbing is a separate DICOM step.
Hand-off to / from OpenMed
- To OpenMed: SR report text (and free-text header tags) →
openmed.deidentify → openmed.analyze_text.
- Header de-id is out of scope for OpenMed — OpenMed handles the text
narrative; use a DICOM-native de-identifier (pydicom + PS3.15 profile, or a
PACS de-id node) to scrub
(0010,xxxx) and burned-in-pixel PHI. This skill's
job is to flag those tags so they aren't missed.
- Re-link by UID, not PHI. Carry
StudyInstanceUID/SeriesInstanceUID as
rejoin keys; these are not identifiers but should be re-mapped consistently if
the profile requires UID remapping.
Edge cases & gotchas
- Pixel-burned PHI. Ultrasound and secondary-capture images often burn name/
MRN/date into the pixels — header scrubbing alone is insufficient; flag
modalities (US, SC, XC) for pixel review/OCR. OpenMed's multimodal/OCR intake
can read burned-in text for redaction screening.
- Private tags. Vendor
(gggg,eeee) odd-group private tags can hide PHI;
PS3.15 requires removing or whitelisting them — don't trust unknown tags.
- Date shifting must be consistent. If you date-shift
StudyDate, shift all
related dates by the same offset to preserve temporal relationships.
- SR value types. Not all SR content is narrative —
NUM (measurements),
CODE (coded findings), PNAME (person names, PHI!) need different handling;
don't dump PNAME into NLP text.
- Character sets. Honor
SpecificCharacterSet (0008,0005); non-Latin
patient names need correct decoding before de-id.
- Read-only intake. Treat source DICOM as immutable; write de-identified
copies, never overwrite originals.
Standards & references
1---2name: extracting-dicom-metadata3description: Reads DICOM file headers and DICOM-SR (Structured Report) content to pull study/series metadata and embedded report text, and flags PHI carried in header tags. Use before OpenMed processing when ingesting imaging data (CT/MR/CR/US, radiology SR) and you need the report narrative de-identified and analyzed, plus a list of header tags that must be scrubbed. Hand SR/report text to openmed.deidentify and openmed.analyze_text; use pydicom to read tags. Trigger keywords: DICOM, pydicom, DICOM-SR, structured report, PatientName, study metadata, PACS, radiology report, PS3.4license: Apache-2.05---67# Extracting DICOM Metadata & Report Text for OpenMed89DICOM (Digital Imaging and Communications in Medicine) files carry far more than10pixels: a **header** of tagged attributes (patient, study, series, equipment)11and, for **DICOM-SR (Structured Reports)**, a content tree holding the actual12radiology/cardiology *report text*. Two jobs sit here: pull the report narrative13for NLP, and **flag the PHI in the header** so it gets scrubbed. This skill does14both, then hands narrative to OpenMed. Header tags are read with `pydicom`15(external, MIT-licensed); de-identification of the extracted text is OpenMed's.1617## When to use1819- You ingest DICOM from PACS/VNA or a research archive and want the SR report20 text mined with clinical NLP.21- You must enumerate PHI-bearing header tags before sharing/exporting images.22- You have DICOM-SR objects (e.g. radiology measurements + impression) whose23 content tree contains the dictated report.2425## DICOM headers in one minute2627Every attribute has a **tag** `(gggg,eeee)` (group, element), a **VR** (value28representation, e.g. `PN` person name, `DA` date, `UI` UID), and a value. PHI29clusters in well-known tags:3031| Tag | Name | VR | Notes |32| --- | --- | --- | --- |33| (0010,0010) | PatientName | PN | direct identifier |34| (0010,0020) | PatientID | LO | MRN |35| (0010,0030) | PatientBirthDate | DA | DOB |36| (0010,1040) | PatientAddress | LO | address |37| (0008,0090) | ReferringPhysicianName | PN | provider |38| (0008,0020/0030) | StudyDate / StudyTime | DA/TM | dates |39| (0008,0050) | AccessionNumber | SH | order id |40| (0008,103E) | SeriesDescription | LO | free text — may leak PHI |41| (0020,4000) | ImageComments | LT | free text — may leak PHI |42| (0040,A730) | ContentSequence | SQ | DICOM-SR report tree |4344## Quick start4546Read the header, pull SR report text, flag PHI tags, hand off to OpenMed:4748```python49import pydicom50import openmed5152ds = pydicom.dcmread("study.dcm")5354# 1) Enumerate PHI-bearing header tags (report, do not log values).55PHI_TAGS = [56 (0x0010, 0x0010), (0x0010, 0x0020), (0x0010, 0x0030), (0x0010, 0x1040),57 (0x0008, 0x0090), (0x0008, 0x0050), (0x0008, 0x0020), (0x0008, 0x0030),58]59present_phi = [hex_pair for hex_pair in PHI_TAGS if hex_pair in ds]6061# 2) Extract report text from a DICOM-SR content tree (recursively).62def sr_text(dataset):63 chunks = []64 for item in dataset.get("ContentSequence", []):65 vt = item.get("ValueType")66 if vt == "TEXT" and "TextValue" in item:67 chunks.append(item.TextValue)68 if "ContentSequence" in item: # nested CONTAINER69 chunks.append(sr_text(item))70 return "\n".join(c for c in chunks if c)7172report = sr_text(ds)73# Some modalities stash narrative in free-text header tags too:74for tag in ("ImageComments", "SeriesDescription", "StudyDescription"):75 if tag in ds and isinstance(ds.get(tag), str):76 report += "\n" + ds.get(tag)7778# 3) De-identify the narrative, then run NER.79if report.strip():80 deid = openmed.deidentify(report, method="replace", policy="hipaa_safe_harbor")81 result = openmed.analyze_text(deid.text, output_format="dict")82```8384`pydicom` reads tags by keyword (`ds.PatientName`) or by `(group, element)`.85DICOM-SR text lives in the recursive `ContentSequence` content tree.8687## Workflow88891. **Read the dataset** with `pydicom.dcmread` (use `stop_before_pixels=True`90 for header-only/metadata work — faster, avoids loading pixels).912. **Walk the SR content tree.** `ContentSequence` nests `CONTAINER`, `TEXT`,92 `CODE`, `NUM`, `PNAME` nodes; concatenate `TEXT.TextValue` (and relevant93 `CODE`/`NUM` measurements) in document order to reconstruct the report.943. **Inventory PHI tags.** Flag the standard identifier tags *and* free-text95 tags (`ImageComments`, `*Description`) that frequently leak PHI. Report tag96 presence — never echo the values into logs.974. **De-identify → analyze** the report narrative with OpenMed.985. **Scrub the header** before any image export using a DICOM de-identification99 profile (PS3.15 Annex E / Basic Application Level Confidentiality). OpenMed100 de-identifies the *narrative*; header scrubbing is a separate DICOM step.101102## Hand-off to / from OpenMed103104- **To OpenMed:** SR report text (and free-text header tags) →105 `openmed.deidentify` → `openmed.analyze_text`.106- **Header de-id is out of scope for OpenMed** — OpenMed handles the *text*107 narrative; use a DICOM-native de-identifier (pydicom + PS3.15 profile, or a108 PACS de-id node) to scrub `(0010,xxxx)` and burned-in-pixel PHI. This skill's109 job is to flag those tags so they aren't missed.110- **Re-link by UID, not PHI.** Carry `StudyInstanceUID`/`SeriesInstanceUID` as111 rejoin keys; these are not identifiers but should be re-mapped consistently if112 the profile requires UID remapping.113114## Edge cases & gotchas115116- **Pixel-burned PHI.** Ultrasound and secondary-capture images often burn name/117 MRN/date into the *pixels* — header scrubbing alone is insufficient; flag118 modalities (US, SC, XC) for pixel review/OCR. OpenMed's multimodal/OCR intake119 can read burned-in text for redaction screening.120- **Private tags.** Vendor `(gggg,eeee)` odd-group private tags can hide PHI;121 PS3.15 requires removing or whitelisting them — don't trust unknown tags.122- **Date shifting must be consistent.** If you date-shift `StudyDate`, shift all123 related dates by the same offset to preserve temporal relationships.124- **SR value types.** Not all SR content is narrative — `NUM` (measurements),125 `CODE` (coded findings), `PNAME` (person names, PHI!) need different handling;126 don't dump `PNAME` into NLP text.127- **Character sets.** Honor `SpecificCharacterSet (0008,0005)`; non-Latin128 patient names need correct decoding before de-id.129- **Read-only intake.** Treat source DICOM as immutable; write de-identified130 copies, never overwrite originals.131132## Standards & references133134- DICOM standard (PS3.x), Part 6 Data Dictionary (tags):135 https://www.dicomstandard.org/current136- PS3.15 Annex E — Attribute Confidentiality Profiles (de-identification):137 https://dicom.nema.org/medical/dicom/current/output/html/part15.html#chapter_E138- DICOM-SR (PS3.3 Structured Reporting; PS3.16 templates):139 https://dicom.nema.org/medical/dicom/current/output/html/part03.html140- pydicom documentation: https://pydicom.github.io/141- DICOM PS3.16 TID 2000 (Basic Diagnostic Imaging Report):142 https://dicom.nema.org/medical/dicom/current/output/html/part16.html