Agent Skillsmaziyarpanahi/openmed › extracting-dicom-metadata

extracting-dicom-metadata

GitHub

读取DICOM文件头及结构化报告(SR)内容,提取元数据与报告文本,并标记头部中的个人健康信息(PHI)。旨在为OpenMed处理前的影像数据提供去标识化分析和脱敏标签列表。

skills/extracting-dicom-metadata/SKILL.md maziyarpanahi/openmed

Trigger Scenarios

DICOM pydicom DICOM-SR structured report PatientName study metadata PACS radiology report PS3

Install

npx skills add maziyarpanahi/openmed --skill extracting-dicom-metadata -g -y
More Options

Use without installing

npx skills use maziyarpanahi/openmed@extracting-dicom-metadata

指定 Agent (Claude Code)

npx skills add maziyarpanahi/openmed --skill extracting-dicom-metadata -a claude-code -g -y

安装 repo 全部 skill

npx skills add maziyarpanahi/openmed --all -g -y

预览 repo 内 skill

npx skills add maziyarpanahi/openmed --list

SKILL.md

Frontmatter
{
    "name": "extracting-dicom-metadata",
    "license": "Apache-2.0",
    "metadata": {
        "pairs": "before",
        "project": "OpenMed",
        "version": "1.0",
        "category": "data-ingestion"
    },
    "description": "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."
}

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

  1. Read the dataset with pydicom.dcmread (use stop_before_pixels=True for header-only/metadata work — faster, avoids loading pixels).
  2. 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.
  3. 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.
  4. De-identify → analyze the report narrative with OpenMed.
  5. 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.deidentifyopenmed.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

Version History

  • f213557 Current 2026-07-23 00:44

Same Skill Collection

skills/building-with-openmed/SKILL.md
skills/loading-openmed-models/SKILL.md
skills/annotating-variants/SKILL.md
skills/assembling-fhir-bundles/SKILL.md
skills/auditing-deid-leakage/SKILL.md
skills/auditing-deidentification-runs/SKILL.md
skills/auditing-part11-trails/SKILL.md
skills/auditing-safe-harbor-checklist/SKILL.md
skills/auditing-subgroup-fairness/SKILL.md
skills/authoring-model-cards/SKILL.md
skills/batch-processing-clinical-text/SKILL.md
skills/benchmarking-clinical-ner/SKILL.md
skills/bridging-presidio-and-spacy/SKILL.md
skills/building-gold-corpus/SKILL.md
skills/building-patient-timelines/SKILL.md
skills/checking-hipaa-compliance/SKILL.md
skills/choosing-openmed-models/SKILL.md
skills/coding-hcc-risk-adjustment/SKILL.md
skills/coding-icd10/SKILL.md
skills/computing-ecqms/SKILL.md
skills/configuring-privacy-policies/SKILL.md
skills/defining-cohort-phenotypes/SKILL.md
skills/deidentifying-clinical-text/SKILL.md
skills/deidentifying-multilingual-text/SKILL.md
skills/deploying-openmed-mcp/SKILL.md
skills/detecting-pv-signals/SKILL.md
skills/enforcing-nophi-logging/SKILL.md
skills/etl-to-omop-cdm/SKILL.md
skills/evaluating-with-leakage-gates/SKILL.md
skills/exporting-bulk-fhir/SKILL.md
skills/exporting-to-fhir/SKILL.md
skills/extracting-clinical-entities/SKILL.md
skills/extracting-lab-tables/SKILL.md
skills/extracting-pii-entities/SKILL.md
skills/extracting-sdoh/SKILL.md
skills/fetching-fhir-resources/SKILL.md
skills/gating-deid-leakage/SKILL.md
skills/generating-synthea-data/SKILL.md
skills/generating-synthetic-surrogates/SKILL.md
skills/ingesting-clinical-documents/SKILL.md
skills/linking-umls-concepts/SKILL.md
skills/mapping-loinc/SKILL.md
skills/mapping-to-snomed/SKILL.md
skills/mining-pubmed-literature/SKILL.md
skills/normalizing-rxnorm/SKILL.md
skills/parsing-ccda-documents/SKILL.md
skills/parsing-hl7v2-messages/SKILL.md
skills/parsing-lab-values/SKILL.md
skills/parsing-trial-eligibility/SKILL.md

Metadata

Files
0
Version
f213557
Hash
98af8803
Indexed
2026-07-23 00:44

ホーム - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-29 13:12
浙ICP备14020137号-1 $お客様$