agentleFS
aks129aks129/HealthClawGuardrails/skills/healthex-export/SKILL.md

healthex-export

Skill33 starsChanged 4 months agoMITView on GitHub

HealthClaw HealthEx Export (healthclaw.io) — automated personal health record export from the local HealthClaw FHIR store. Use when: (1) The patient wants to export all their health data from the HealthClaw local store as a portable FHIR bundle, (2) Migrating health data to a new tenant or archive, (3) Creating a de-identified snapshot for sharing with a provider or second opinion, (4) Pre-screening records for Curatr quality issues before a full evaluation, (5) Automating the HealthEx → local FHIR store ingestion pipeline.

The file

Files
SKILL.md

HealthClaw HealthEx Export

scripts/export_healthex.py automates the full pipeline from local HealthClaw FHIR store → de-identified, Curatr-pre-tagged FHIR R4 transaction Bundle.

Replaces the manual Claude session pull for personal health data export.

Quick Start

# Basic export — all clinical resource types for a tenant
python scripts/export_healthex.py --tenant-id my-tenant

# Export + immediately import into a second tenant
python scripts/export_healthex.py \
    --tenant-id my-tenant \
    --import \
    --import-tenant my-archive-tenant \
    --step-up-secret $STEP_UP_SECRET

# Preview what would be exported (no file written)
python scripts/export_healthex.py --tenant-id my-tenant --dry-run

# Export specific resource types
python scripts/export_healthex.py \
    --tenant-id my-tenant \
    --types Condition Observation AllergyIntolerance Immunization MedicationRequest

Output

Bundle written to exports/healthex-<YYYY-MM-DD>.json by default. Override with --output /path/to/file.json.

Format: FHIR R4 transaction Bundle ("type": "transaction") with PUT entries, ready for POST /Bundle/$ingest-context or direct use with import_healthex.py.

Resource Types Exported (default)

TypeNotes
PatientDe-identified: name/address/telecom removed, EHR identifiers stripped
ConditionFull — diagnoses, clinical/verification status, onset/abatement
ObservationFull — labs, vitals, social history (smoking, BMI, etc.)
AllergyIntoleranceFull
ImmunizationFull
MedicationRequestFull
ProcedureFull
DiagnosticReportFull
CarePlanFull
CoverageFull
EncounterFull

Pass --types <ResourceType> ... to limit to a subset.

De-identification

Applied automatically (skip with --no-deidentify).

Removed from Patient:

  • name — full name
  • address — street, city, state, zip
  • telecom — phone, email
  • photo — base64 images
  • contact — emergency contacts
  • OID-namespaced identifiers (EHR-internal MRNs, Epic IDs, CEID, EID, EMPI, etc.)

Preserved:

  • birthDate — full date (patient-controlled export; use $deidentify for the de-identification preview, which strips it — that endpoint is not a legal Safe Harbor determination either)
  • gender
  • communication — language preferences
  • A synthetic urn:healthclaw:patient/<uuid> identifier is injected

Other resource types are exported as-is — they contain clinical observations and codes, not patient demographics.

For the conservative de-identification preview (birthDate truncated to year), call POST /r6/fhir/Patient/:id/$deidentify before export, or use the phi-redaction skill after import.

Curatr Pre-Tags

Applied automatically (skip with --no-pretag).

Scans the export bundle for known data quality patterns and injects FHIR extensions — without modifying stored resources. The tags exist only in the exported bundle and serve as hints for a subsequent Curatr evaluation.

Tag codeTriggerAction recommended
smoking_contradictionLOINC 72166-2 observations with conflicting SNOMED codes (e.g. "Never smoked" + "Ex-smoker" in same tenant)Run curatr_apply_fix with patient attestation
h_flag_titerObservation with interpretation.code of H/HH/HU, or valueString starting with "H"Clinical review; consider flagging for provider
missing_resultObservation with no value[x] elementVerify whether result is pending, cancelled, or truly missing

Pre-tags are FHIR extensions at: https://healthclaw.example.org/fhir/StructureDefinition/curatr-pretag

Each extension carries a valueCodeableConcept with the tag code and display text.

Reading Pre-Tags After Import

# Find all observations with Curatr pre-tags
curl -s "http://localhost:5000/r6/fhir/Observation?_count=200" \
  -H "X-Tenant-ID: my-archive-tenant" \
  | python3 -c "
import json, sys
b = json.load(sys.stdin)
url = 'https://healthclaw.example.org/fhir/StructureDefinition/curatr-pretag'
for e in b.get('entry', []):
    r = e['resource']
    tags = [
        ext['valueCodeableConcept']['coding'][0]['code']
        for ext in r.get('extension', [])
        if ext.get('url') == url
    ]
    if tags:
        print(r['id'][:40], tags)
"

Full Pipeline: HealthEx → Local FHIR Store

The complete automated flow replaces the previous manual Claude session pull:

1. Patient data arrives via Fasten Connect webhook → ingested to tenant T
2. export_healthex.py --tenant-id T --import --import-tenant T-archive
   ├── Fetches all resources via REST API (paginated)
   ├── Strips EHR identifiers + PII (de-identification)
   ├── Pre-tags Curatr issue patterns
   └── POSTs bundle to /Bundle/$ingest-context for tenant T-archive
3. AI agent (MCP) queries T-archive for Curatr evaluation
4. curatr_apply_fix applied for patient-approved corrections
5. AuditEvent trail shows full chain: ingest → redact → evaluate → fix

Arguments Reference

FlagDefaultDescription
--tenant-iddesktop-demoSource tenant to export from
--base-urlhttp://localhost:5000/r6/fhirHealthClaw FHIR base URL
--typesFull clinical setSpace-separated list of FHIR resource types
--outputexports/healthex-<date>.jsonOutput bundle file path
--importoffRun import_healthex.py after export
--import-tenantsame as --tenant-idTenant to import the bundle into
--step-up-secret$STEP_UP_SECRET envHMAC secret (required with --import)
--no-deidentifyoffSkip de-identification
--no-pretagoffSkip Curatr pre-tagging
--dry-runoffPrint counts only, do not write file

Related Scripts

ScriptPurpose
scripts/import_healthex.pyImport a FHIR bundle into HealthClaw with step-up auth
scripts/convert_fasten.pyConvert Fasten Health export format to FHIR transaction Bundle

Related Skills

  • fhir-r6-guardrails — Stack setup and MCP tool reference
  • curatr — Evaluate and fix data quality issues in exported records
  • phi-redaction — conservative de-identification preview (stricter than patient-controlled)
  • fasten-connect — Patient-authorized EHR ingestion (upstream of this export)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.