assembling-fhir-bundles
できること
このスキルは、複数のFHIR健康記録を一つのBundleにまとめ、医療機関が一度に受け取れるようにします。電子カルテシステムに渡す臨床データのエクスポートを作る開発者向けです。
使う場面
- ✓EHRに一緒に送る必要があるFHIRリソースの集まりがあるとき。
- ✓集まりの中のリソース同士が参照し合っているとき。たとえば、病態が患者を指す場合です。
- ✓FHIRサーバー向けに、トランザクションのBundleとバッチのBundleのどちらを使うか決めるとき。
スキルのリンク
https://github.com/maziyarpanahi/openmed/blob/master/skills/assembling-fhir-bundles/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“患者、encounter、2つの病態のFHIRリソースがあります。EHRに投稿できる一つのBundleにまとめてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは各リソースに安定した識別子を割り当て、内部の参照を合わせて書き換えます。また、Bundleの種類に応じてサーバーが期待するリクエストの詳細を設定します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Assembling FHIR Bundles
A FHIR server ingests one transaction Bundle, not loose resources, and the
resources inside it must cross-reference each other (Condition.subject →
Patient, Observation.encounter → Encounter, DiagnosticReport.result →
Observation). OpenMed ships a deterministic, mechanical Bundle assembler —
openmed.clinical.exporters.fhir.to_bundle — that wraps the resources you built
in exporting-to-fhir into a valid R4 Bundle and wires up the references.
When to use
Use after you have a list of standalone resources from exporting-to-fhir and
the destination is a FHIR server. Reach for it when the user says "build a
Bundle", "transaction", "POST these resources", or needs internal references
resolved. To check the Bundle against US Core, hand off to validating-us-core.
What OpenMed gives you (verified API)
from openmed.clinical.exporters.fhir import to_bundle, deterministic_fullurl
bundle = to_bundle(
resources, # Sequence[Mapping] each with a resourceType
doc_id="note-2024-03-02-001", # seeds stable urn:uuid fullUrls
bundle_type="transaction", # "transaction" | "batch" | "collection" | ...
)
to_bundle does exactly three things, and never synthesises or validates:
- Deterministic
fullUrl. Each resource gets aurn:uuidseeded bydoc_id+ its index, so the same input always produces byte-identical output (golden-test friendly). You can pre-compute the same urn withdeterministic_fullurl(doc_id, index). - Reference rewriting. Any
{"reference": "ResourceType/id"}whose target is present in the Bundle is repointed at that resource'sfullUrl. References to resources absent from the Bundle (e.g. a Patient removed by de-identification) are left untouched — no dangling internal refs. - Request blocks. For
transaction/batchbundles each entry gets arequestblock ({"method": "POST", "url": "<ResourceType>"}) so the server knows to create it.
It raises ValueError if a resource lacks resourceType, or if two
resources share the same ResourceType/id (duplicate ids would silently corrupt
the reference map).
Quick start
from openmed.clinical.exporters.fhir import to_bundle
from openmed.clinical.exporters.codeable_concept_simple import coding, codeable_concept
condition = {
"resourceType": "Condition", "id": "cond-1",
"clinicalStatus": {"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/condition-clinical",
"code": "active"}]},
"code": codeable_concept(
[coding("snomed", "44054006", "Diabetes mellitus type 2")],
text="type 2 diabetes"),
"subject": {"reference": "Patient/patient-1"}, # internal ref, rewritten
}
medication = {
"resourceType": "MedicationStatement", "id": "med-1", "status": "active",
"medicationCodeableConcept": codeable_concept(
[coding("rxnorm", "860975", "metformin 500 MG Oral Tablet")],
text="metformin 500 mg"),
"subject": {"reference": "Patient/patient-1"},
}
patient = {
"resourceType": "Patient", "id": "patient-1",
"gender": "unknown", # de-identified, synthetic
}
bundle = to_bundle([patient, condition, medication],
doc_id="demo-note", bundle_type="transaction")
Worked: the transaction Bundle
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"fullUrl": "urn:uuid:6f1c...e2",
"resource": { "resourceType": "Patient", "id": "patient-1", "gender": "unknown" },
"request": { "method": "POST", "url": "Patient" }
},
{
"fullUrl": "urn:uuid:9a3b...77",
"resource": {
"resourceType": "Condition", "id": "cond-1",
"subject": { "reference": "urn:uuid:6f1c...e2" }
},
"request": { "method": "POST", "url": "Condition" }
},
{
"fullUrl": "urn:uuid:c0d4...19",
"resource": {
"resourceType": "MedicationStatement", "id": "med-1",
"subject": { "reference": "urn:uuid:6f1c...e2" }
},
"request": { "method": "POST", "url": "MedicationStatement" }
}
]
}
Note Condition.subject and MedicationStatement.subject were rewritten from
"Patient/patient-1" to the Patient entry's fullUrl — that is what makes the
transaction resolvable in a single POST.
Workflow
- Build resources with
exporting-to-fhir; give each a uniqueid. - Put a
よくある質問
BundleをUS Coreの標準と照合しますか?
この手順では行いません。US Coreとの照合は、別の検証スキルに任せます。
どのBundleの種類に対応していますか?
トランザクションとバッチに対応しています。サーバーがエントリをどう処理するかに合わせて選びます。
FHIRリソースを作りますか?
この手順では作りません。別のエクスポートの手順で作られたリソースをまとめます。
詳細
作者による元の説明
Package multiple FHIR R4 resources produced from OpenMed output into a single valid transaction Bundle ready to POST to an EHR, using OpenMed's verified bundle assembler openmed.clinical.exporters.fhir.to_bundle. Covers deterministic urn:uuid fullUrls, automatic in-Bundle reference rewriting, request blocks (method/url) for transaction vs batch, and conditional create. Use after exporting-to-fhir when the user has several Condition/Observation/MedicationStatement resources and wants one transaction Bundle, mentions Bundle, transaction, references, or posting to a FHIR server. Builds on exporti
repo: maziyarpanahi/openmed
人気
- GitHubのスター
- 5.8k
- ランキング
- #14667
- ライセンス
- Apache-2.0
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
annotating-variants
5.8kエージェントが、無料の公開アノテーターを使って、遺伝子バリアントの作用を予測し、HGVS名をゲノム上の位置に変換し、集団の頻度を付与できるよう支援します。
ask-openmed
5.8kエージェントが、臨床テキストの依頼に合ったOpenMedのワークフローを選べるよう支援します。患者データが含まれる可能性がある場合は、必ずプライバシーの確認から始めます。
auditing-deid-leakage
5.8kエージェントが、匿名化済みの臨床テキストに残っている識別子(SSN、カード番号、メール、日付など)をスキャンし、残っていれば公開を止めます。
auditing-deidentification-runs
5.8kエージェントが、匿名化の実行について、何が、なぜ伏せられたかを示す、署名付きで再現可能な記録を作ります。その記録には患者データは含まれません。
似ているスキル
discrawl
394k保存済みのローカルなDiscordメッセージのアーカイブを検索して要約し、その新しさを確認し、ダイレクトメッセージを読めるようエージェントを支援します。
clickhouse-io
280kエージェントがClickHouseデータベースのクエリとスキーマを最適化できるようにします。高性能な分析処理向けのベストプラクティスを適用します。分析クエリが遅すぎるときに使います。
scientific-db-pubmed-database
280kエージェントが生物医学分野の科学論文を検索するのに役立ちます。特定の医療情報が必要な研究に便利です。