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.
text mined with clinical NLP.
content tree contains the dictated report.
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 |
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.
pydicom.dcmread (use stop_before_pixels=Truefor header-only/metadata work — faster, avoids loading pixels).
ContentSequence nests CONTAINER, TEXT,CODE, NUM, PNAME nodes; concatenate TEXT.TextValue (and relevantCODE/NUM measurements) in document order to reconstruct the report.
tags (ImageComments, *Description) that frequently leak PHI. Report tag
presence — never echo the values into logs.
profile (PS3.15 Annex E / Basic Application Level Confidentiality). OpenMed
de-identifies the narrative; header scrubbing is a separate DICOM step.
openmed.deidentify → openmed.analyze_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.
StudyInstanceUID/SeriesInstanceUID asrejoin keys; these are not identifiers but should be re-mapped consistently if
the profile requires UID remapping.
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.
(gggg,eeee) odd-group private tags can hide PHI;PS3.15 requires removing or whitelisting them — don't trust unknown tags.
StudyDate, shift allrelated dates by the same offset to preserve temporal relationships.
NUM (measurements),CODE (coded findings), PNAME (person names, PHI!) need different handling;
don't dump PNAME into NLP text.
SpecificCharacterSet (0008,0005); non-Latinpatient names need correct decoding before de-id.
copies, never overwrite originals.
https://www.dicomstandard.org/current
https://dicom.nema.org/medical/dicom/current/output/html/part15.html#chapter_E
https://dicom.nema.org/medical/dicom/current/output/html/part03.html
https://dicom.nema.org/medical/dicom/current/output/html/part16.html