本文へスキップ
Skillpedia
分析とスプレッドシート5.8k · #14715

parsing-ccda-documents

できること

このスキルは、エージェントにC-CDAファイルを開く方法を教えます。C-CDAは、医療記録システムからのXMLのエクスポートです。各セクションの読める本文を見つけ、確認や分析ができるようにします。

使う場面

  • ✓患者のカルテがC-CDAまたはCCD形式でエクスポートされ、その中の記録が必要なとき。
  • ✓臨床のXMLファイルから、セクションごとに退院サマリーや病歴の本文がほしいとき。
  • ✓分析の前に、C-CDAの本文を匿名化する必要があるとき。

スキルのリンク

https://github.com/maziyarpanahi/openmed/blob/master/skills/parsing-ccda-documents/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/maziyarpanahi/openmed/blob/master/skills/parsing-ccda-documents/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

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

  1. Confirm it's CDA. is_cda_document(...) checks for a ClinicalDocument root. Reject XML with DOCTYPE/ENTITY declarations (XXE risk) — the adapter does this for you.
  2. Read the header for context: patient, author, effectiveTime, documentType (ClinicalDocument/code LOINC). Treat all header values as PHI.
  3. Walk sections by templateId or section code (LOINC). Map to your section vocabulary.
  4. Flatten narrative <text> with itertext(); 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

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル