parsing-ccda-documents
它能做什么
这项技能教智能体如何打开 C-CDA 文件,这是病历系统导出的 XML 文件。它会找出每个章节中可阅读的叙述文字,以便进行检查或分析。
适用场景
- ✓当用户拥有 C-CDA 或 CCD 格式的患者病历导出文件,并需要其中的书面记录的时候。
- ✓当用户需要从临床 XML 文件中按章节获取出院小结或既往史文本的时候。
- ✓当用户需要在分析之前,为去标识化准备记录文本的时候。
技能链接
https://github.com/maziyarpanahi/openmed/blob/master/skills/parsing-ccda-documents/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能把我医院导出的 C-CDA 文件中的书面记录,按章节提取出来吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会读取文件的 XML 结构,找出每个章节,并返回其可读文本。编码条目会单独保留。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Parsing C-CDA / CCD Documents for OpenMed
C-CDA (Consolidated Clinical Document Architecture) is the XML document standard
behind Meaningful Use / ONC certification — the CCD, Discharge Summary, History
& Physical, and Consultation Note you get when an EHR "exports a chart". Each
document is a ClinicalDocument with a header (patient, authors, encounter) and
a structuredBody of sections. Every section has two representations: a
human-readable narrative <text> block and machine-readable coded
entries. The narrative is what you feed to clinical NLP. This skill extracts
it and hands it to OpenMed.
When to use
- You receive C-CDA R2.1 / CCD documents (Direct messaging, patient portal export, HIE) and want the free-text section narrative for de-id and NER.
- You need to pair narrative spans with the section they came from (problems, meds, allergies, results, plan, H&P narrative).
- You want XML-safe de-identification that keeps the document parseable.
C-CDA structure in one minute
<ClinicalDocument xmlns="urn:hl7-org:v3">
<recordTarget><patientRole>
<id extension="12345" root="..."/>
<patient><name><given>Jane</given><family>Doe</family></name>
<birthTime value="19700115"/></patient>
</patientRole></recordTarget>
<component><structuredBody>
<component><section>
<templateId root="2.16.840.1.113883.10.20.22.2.5.1"/> <!-- Problems -->
<code code="11450-4" codeSystem="2.16.840.1.113883.6.1"/> <!-- LOINC -->
<title>Problems</title>
<text>Active problems: Type 2 diabetes, hypertension.</text> <!-- narrative -->
<entry>...coded SNOMED/ICD entries...</entry>
</section></component>
</structuredBody></component>
</ClinicalDocument>
Sections are identified by templateId/@root and by section code
(LOINC). The CDA namespace is urn:hl7-org:v3.
Quick start
Extract section narrative by LOINC code, then hand off to OpenMed:
import openmed
from xml.etree import ElementTree as ET
NS = {"hl7": "urn:hl7-org:v3"}
SECTION_LOINC = {
"11450-4": "problems", "10160-0": "medications", "48765-2": "allergies",
"30954-2": "results", "18776-5": "plan", "10164-2": "hpi",
"8648-8": "hospital_course", "11488-4": "consult_note",
}
root = ET.parse("ccd.xml").getroot()
for section in root.findall(".//hl7:section", NS):
code_el = section.find("hl7:code", NS)
loinc = code_el.get("code") if code_el is not None else None
text_el = section.find("hl7:text", NS)
if text_el is None:
continue
narrative = "".join(text_el.itertext()).strip() # flatten narrative block
if not narrative:
continue
deid = openmed.deidentify(narrative, method="replace", policy="hipaa_safe_harbor")
result = openmed.analyze_text(deid.text, output_format="dict")
section_name = SECTION_LOINC.get(loinc, loinc)
# attach (section_name, result) for downstream consumers
"".join(text_el.itertext()) flattens the narrative block (which may contain
<paragraph>, <list>, <table>, <content> markup) into plain text.
XML-aware whole-document de-identification
When you need to redact PHI from the document (header ids, names, addresses, dates) while keeping the CDA XML valid and parseable, use the bundled adapter rather than regexing the raw XML:
from openmed.interop.cda import redact_cda, is_cda_document
if is_cda_document("ccd.xml"):
safe_xml = redact_cda("ccd.xml") # returns redacted XML string
redact_cda applies DEFAULT_PHI_ELEMENT_MAP (patient id hashed, name/address/
telecom null-flavored, birthTime and effectiveTime date-shifted) to header
elements and sweeps section narrative text — operating on text nodes only so
surrounding markup stays intact. Pass text_redactor= to plug an extra
free-text callback (e.g. an openmed.deidentify wrapper), date_shift_days=
for a fixed shift, and keep_year=True to preserve years.
Workflow
- Confirm it's CDA.
is_cda_document(...)checks for aClinicalDocumentroot. Reject XML withDOCTYPE/ENTITYdeclarations (XXE risk) — the adapter does this for you. - Read the header for context: patient, author,
effectiveTime,documentType(ClinicalDocument/codeLOINC). Treat all header values as PHI. - Walk sections by
templateIdor sectioncode(LOINC). Map to your section vocabulary. - Flatten narrative
<text>withitertext(); preserve the secti
常见问题
使用这项技能需要懂 XML 吗?
不需要。智能体会处理文件格式,你只需提供导出的文件。
它适用于哪些类型的文档?
它面向 C-CDA R2.1 文档,例如 CCD、出院小结、病史和体格检查记录,以及会诊记录。
这项技能能替代去标识化吗?
不能。这项技能会指示下一步把章节文本交给 OpenMed 去标识化步骤,两者配合使用。
详情
作者的原始描述
Parses C-CDA / CCD XML clinical documents to extract human-readable section narrative plus coded entries, keyed by section LOINC codes and templateIds. Use before OpenMed processing when ingesting C-CDA R2.1 documents (CCD, Discharge Summary, H&P, Consultation Note) exported from an EHR and you need the narrative section text de-identified and analyzed. Hand section narrative to openmed.deidentify and openmed.analyze_text; XML-aware de-identification that preserves CDA markup is available via openmed.interop.cda. Trigger keywords: C-CDA, CCD, CDA, clinical document, templateId, LOINC section,
repo: maziyarpanahi/openmed
热度
- GitHub 星标
- 5.8k
- 排名
- #14715
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
annotating-variants
5.8k帮你的智能体预测基因变异的作用,把 HGVS 名称转换为基因组位置,并使用免费的公共注释工具添加人群频率。
ask-openmed
5.8k帮你的智能体为临床文本请求选择合适的 OpenMed 工作流程,并在可能涉及患者数据时,先进行隐私检查。
assembling-fhir-bundles
5.8k把多份 FHIR 健康记录打包成一个事务 Bundle,可直接发送给 EHR 系统,并正确链接其中的内部引用。
auditing-deid-leakage
5.8k扫描已去标识化的临床文本,查找残留的标识符,例如社会安全号、银行卡号、电子邮件地址和日期,若仍有残留则阻止发布。