Fetches and pages FHIR R4 resources from EHR APIs, decodes base64 attachments, and extracts clinical narrative for OpenMed de-identification and analysis.
Ships in openmed-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
FHIR R4 is the modern EHR API: a RESTful, JSON-or-XML interface over resources
like Patient, Encounter, Condition, Observation, DiagnosticReport,
and DocumentReference. The unstructured clinical text you want for NLP lives
in DocumentReference.content.attachment and
DiagnosticReport.presentedForm — usually base64-encoded PDF, RTF, or
plain text. This skill pulls those resources, pages through results, decodes the
attachments, and hands the narrative to OpenMed.
Bundle.link[next]).Search is GET [base]/[Type]?param=value. Results come back as a
searchset Bundle; the next page is the URL in Bundle.link where
relation == "next". Use _count to size pages, _revinclude to pull related
resources in one round trip, and _since/_lastUpdated for incremental sync.
GET /Patient?identifier=http://hospital.org/mrn|12345
GET /DocumentReference?patient=Patient/abc&category=clinical-note&_count=50
GET /DiagnosticReport?patient=Patient/abc&_revinclude=Observation:related
Page a search, decode attachments, hand narrative to OpenMed:
import base64
import requests
import openmed
BASE = "https://fhir.example.org/r4"
HEADERS = {"Accept": "application/fhir+json", "Authorization": "Bearer <token>"}
def iter_bundle(url, params=None):
"""Yield resources across all pages following Bundle.link[next]."""
while url:
bundle = requests.get(url, params=params, headers=HEADERS, timeout=30).json()
for entry in bundle.get("entry", []):
yield entry.get("resource", {})
params = None # next links are fully-qualified
url = next(
(l["url"] for l in bundle.get("link", []) if l.get("relation") == "next"),
None,
)
def attachment_text(att):
"""Decode a FHIR Attachment to text (handles base64 and inline text/plain)."""
if att.get("data"):
raw = base64.b64decode(att["data"])
if att.get("contentType", "").startswith("text/"):
return raw.decode("utf-8", "replace")
return "" # PDF/RTF: route to OpenMed multimodal/OCR intake instead
return ""
# Pull a patient's clinical notes and analyze each.
for doc in iter_bundle(f"{BASE}/DocumentReference",
{"patient": "Patient/abc",
"category": "clinical-note", "_count": 50}):
for content in doc.get("content", []):
text = attachment_text(content.get("attachment", {}))
if not text.strip():
continue
deid = openmed.deidentify(text, method="replace", policy="hipaa_safe_harbor")
result = openmed.analyze_text(deid.text, output_format="dict")
patient_ref = doc.get("subject", {}).get("reference") # rejoin key
system/DocumentReference.read, system/DiagnosticReport.read).patient, category, type (LOINC),
date, and _count. Prefer server-side filtering over client-side.Bundle.link[next] until exhausted. Never assume one page.DocumentReference.content.attachment and
DiagnosticReport.presentedForm. Decode base64; for PDF/RTF/scanned
content, route bytes to OpenMed's document intake (multimodal/ocr)
rather than decoding as UTF-8.subject.reference (patient) and context.encounter
so downstream consumers can group by patient/encounter — storing hashed,
not raw, identifiers.To OpenMed (client-side): decoded narrative → openmed.deidentify →
openmed.analyze_text. Carry subject.reference as the rejoin key.
Server-side $de-identify: openmed.interop.fhir_operations implements
the FHIR $de-identify operation logic over the OpenMed privacy pipeline:
de_identify_resource(resource, policy=..., method=...)de_identify_bundle(bundle, policy=..., method=...)de_identify(parameters) — accepts/returns a Parameters envelope and
reports modified element paths as an OperationOutcome.
It de-identifies free-text strings, identifier values, and text.div
narrative while never altering codes, references, systems, or temporal
values. Use this to de-identify a whole fetched Bundle before storage:from openmed.interop.fhir_operations import de_identify_bundle
safe_bundle = de_identify_bundle(bundle, policy="hipaa_safe_harbor",
method="replace")
Onward: re-export structured findings with
openmed.clinical.exporters.fhir (to_bundle, to_operation_outcome).
attachment.data is base64; large files use
attachment.url (a separate Binary fetch) instead. Handle both.application/pdf, text/rtf, scanned TIFF — do
not utf-8 decode these; send bytes to OpenMed multimodal/OCR intake.next links; cap page
count and dedupe by resource id._revinclude vs _include. _include pulls referenced resources;
_revinclude pulls resources that reference yours. Mixing them changes
Bundle entry search.mode (match vs include) — filter on it./metadata
CapabilityStatement) and US Core-conformant; field cardinality differs across
FHIR versions.429/Retry-After; batch with _count and back off.presentedForm): https://hl7.org/fhir/R4/diagnosticreport.htmlWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
fhir, ehr-api, clinical-narrative, openmed, base64-decoding, data-ingestion
74 skills in this plugin
/annotating-variantsAnnotates VCF variants and normalizes HGVS nomenclature with public, license-free annotators (Ensembl VEP REST, VEP/SnpEff/ANNOVAR offline) and links variants to gnomAD population frequencies and the clinical context OpenMed extracts. Use when the user wants to predict variant consequences, map HGVS to genomic coordinates, annotate a VCF, attach allele frequencies, or pair variants with phenotype/oncology context. Trigger keywords: VCF, HGVS, variant annotation, VEP, SnpEff, ANNOVAR, consequence, missense, gnomAD, allele frequency, GRCh38, rsID, transcript. Pairs adjacent to OpenMed: combine annotated variants with Genomics/Oncology entities and phenotype from openmed.analyze_text. Tools used are free; restricted clinical databases are user-supplied./ask-openmedChoose the first OpenMed workflow skill for an intake, privacy, extraction, exchange, or verification request using deterministic local routing. Use when a goal is broad, spans several clinical-data stages, or leaves the data-sensitivity status unclear; the privacy gate is selected before downstream work when raw clinical or personal content may be present./assembling-fhir-bundlesPackage 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 exporting-to-fhir; pairs after./openmed-skills:fetching-fhir-resourcesfrom openmed-skills
npx claudepluginhub maziyarpanahi/openmed --plugin openmed-skillsOther plugins' skills for the same job