Healthcare data interop (validated, de-identified)
Build healthcare-data pipelines and prove the data is well-formed and
stripped of PHI — correctness is gated by scripts that run (FHIR/HL7 validation,
PHI scan, DICOM de-id + verify), not by assertion.
Core principle
Validity and de-identification are measured, not claimed. The loop is:
scan/validate → fix the root cause → re-validate, until the gate is green; then a
human reviews what the automation cannot decide.
Be honest about scope (this is the rule that keeps the skill correct):
- De-identification reduces, but does not eliminate, re-identification risk.
HIPAA gives two paths — Safe Harbor (remove the 18 identifiers) and
Expert Determination (a qualified statistician certifies low risk). GDPR
distinguishes true anonymization (irreversible, out of scope of GDPR) from
pseudonymization (reversible, still personal data). State which you are
doing. →
references/02-deidentification.md
- The scripts handle header/structured PHI only. They do not touch
burned-in pixel PHI in images, and the regex scan does not reliably
catch names or free-text PHI.
- Structural FHIR validation ≠ profile conformance. A green structural run
does not prove US Core / IG conformance; that needs a real validator.
This skill is engineering assistance, not a clinical or regulatory sign-off.
When to use vs. not
- Use for: validating FHIR R4 / HL7 v2 messages; de-identifying DICOM header
PHI; scanning text/JSON for Safe-Harbor identifiers; designing an
ingest→validate→de-id→transform→store pipeline; mapping legacy data to FHIR.
- Not for: clinical decision-making, billing/coding adjudication, or any output
treated as a compliance certification. Not a substitute for a HAPI/Inferno
conformance run or a privacy/legal review.
Inputs to gather first
- Standards & versions — DICOM, HL7 v2.x (which version), and/or FHIR
R4/R5; any profile (US Core, a national profile, IHE actor). →
references/01-standards.md
- De-id basis — HIPAA Safe Harbor vs Expert Determination, or GDPR
anonymization vs pseudonymization; whether dates/UIDs must be
retained. →
references/02-deidentification.md
- Data shape & PHI surface — files vs streams; do images carry burned-in
pixel PHI? Are there free-text fields the regex scan can't clear?
- Pipeline stage — what to build: ingest, validate, de-id, transform/map,
or store. →
references/04-pipeline-patterns.md
Workflow
Load each reference when you reach its step.
Pin the standards & profiles. Confirm DICOM/HL7 v2/FHIR versions and any
profile, and that structural checks ≠ full conformance. → references/01-standards.md
Set up the scripts. They are stdlib-only except DICOM de-id (optional
pydicom). → references/05-running-the-scripts.md
python3 --version # 3.12+
pip install -r scripts/requirements.txt # only needed for DICOM de-id
Validate structure of FHIR and/or HL7 v2 inputs; fix errors; re-run until
exit 0. → references/03-validation-and-conformance.md
python3 scripts/validate_fhir.py path/to/fhir.json --out-dir fhir-report
python3 scripts/validate_hl7v2.py path/to/msg.hl7 --out-dir hl7-report
Scan for PHI before anything leaves a trusted boundary; a non-zero exit
means stop and review. → references/02-deidentification.md
python3 scripts/phi_scan.py path/to/data --out-dir phi-report
De-identify DICOM header PHI and verify by re-reading the output. → references/02-deidentification.md
cp scripts/deid.config.example.json scripts/deid.config.json # optional overrides
python3 scripts/deidentify_dicom.py path/to/dicom --out-dir deid-out \
--config scripts/deid.config.json --verify
Build the pipeline stage by stage (ingest → validate → de-id → transform
→ store), gating each handoff on the checks above. → references/04-pipeline-patterns.md
Complete the human review the automation can't: burned-in pixel PHI,
free-text/name PHI, profile conformance via a real validator, and the
re-identification-risk judgement. → references/02-deidentification.md
What's in this skill
scripts/validate_fhir.py — structural FHIR R4 JSON check (resourceType, required elements, reference shape, coding presence); file or dir; report + exit code. STDLIB only.
scripts/validate_hl7v2.py — pipe-delimited HL7 v2 parser; validates MSH + basic required fields; report + exit code. STDLIB only.
scripts/phi_scan.py — regex scan for the regex-detectable Safe-Harbor identifiers (SSN, phone, email, dates, URLs, IPs, MRN/account, IBAN, ZIP); report + exit code. STDLIB only.
scripts/deidentify_dicom.py — removes/blanks DICOM PS3.15 Basic-Profile PHI tags via pydicom; --verify re-reads and asserts none remain; clean message if pydicom missing.
scripts/deid.config.example.json — tag→action overrides for the DICOM de-id.
scripts/examples/ — valid + invalid samples used by the self-test.
references/01–05 — standards, de-identification, validation/conformance, pipeline patterns, running the scripts.
Definition of done
Guardrails — avoid these mistakes
- Don't claim "de-identified" from a clean PHI scan. State "no structured
Safe-Harbor identifiers detected; free-text and pixel PHI reviewed separately."
Overclaiming is the cardinal error here.
- Don't claim "FHIR conformant" from the structural check. It proves shape,
not profile/value-set/invariant conformance — run a real validator for that.
- Never put real PHI in logs, reports, test fixtures, or prompts. Use
synthetic data; the
examples/ are already synthetic.
- Burned-in pixel PHI is invisible to header de-id — flag images for OCR /
pixel review separately.
- Don't suppress a validation error to go green — fix the data or the
mapping. Configure
deid.config.json for real tag needs, never to skip PHI.
- Pseudonymization is not anonymization — a re-identification key still
exists; treat the output as personal data under GDPR.
- Mind the minimum-necessary principle — only move the PHI a stage actually
needs.
1---2name: healthcare-data-interop3description: Build and validate healthcare-data pipelines and de-identify PHI, gated by checks that actually run — structural FHIR R4 validation, HL7 v2.x parsing, a Safe-Harbor PHI regex scan, and pydicom-based DICOM header de-identification with a re-read verify step. Use when the user works with DICOM, HL7 v2, or FHIR data; needs to ingest/transform/map clinical data; wants to de-identify or anonymize PHI; checks interoperability conformance; or builds a healthcare data pipeline. Triggers: "DICOM", "HL7", "FHIR", "de-identify PHI", "anonymize patient data", "healthcare data pipeline", "interoperability", "Safe Harbor", "US Core", "IHE".4license: MIT5---67# Healthcare data interop (validated, de-identified)89Build healthcare-data pipelines and **prove** the data is well-formed and10stripped of PHI — correctness is gated by scripts that run (FHIR/HL7 validation,11PHI scan, DICOM de-id + verify), not by assertion.1213## Core principle1415**Validity and de-identification are measured, not claimed.** The loop is:16scan/validate → fix the root cause → re-validate, until the gate is green; then a17human reviews what the automation cannot decide.1819**Be honest about scope (this is the rule that keeps the skill correct):**2021- **De-identification reduces, but does not eliminate, re-identification risk.**22 HIPAA gives two paths — **Safe Harbor** (remove the 18 identifiers) and23 **Expert Determination** (a qualified statistician certifies low risk). GDPR24 distinguishes true **anonymization** (irreversible, out of scope of GDPR) from25 **pseudonymization** (reversible, still personal data). State which you are26 doing. → `references/02-deidentification.md`27- The scripts handle **header/structured PHI only**. They do **not** touch28 **burned-in pixel PHI** in images, and the regex scan does **not** reliably29 catch **names or free-text PHI**.30- **Structural FHIR validation ≠ profile conformance.** A green structural run31 does not prove US Core / IG conformance; that needs a real validator.3233This skill is **engineering assistance, not a clinical or regulatory sign-off.**3435## When to use vs. not3637- Use for: validating FHIR R4 / HL7 v2 messages; de-identifying DICOM header38 PHI; scanning text/JSON for Safe-Harbor identifiers; designing an39 ingest→validate→de-id→transform→store pipeline; mapping legacy data to FHIR.40- Not for: clinical decision-making, billing/coding adjudication, or any output41 treated as a compliance certification. Not a substitute for a HAPI/Inferno42 conformance run or a privacy/legal review.4344## Inputs to gather first45461. **Standards & versions** — DICOM, HL7 v2.x (which version), and/or FHIR47 R4/R5; any profile (US Core, a national profile, IHE actor). → `references/01-standards.md`482. **De-id basis** — HIPAA **Safe Harbor** vs **Expert Determination**, or GDPR49 **anonymization** vs **pseudonymization**; whether dates/UIDs must be50 retained. → `references/02-deidentification.md`513. **Data shape & PHI surface** — files vs streams; do images carry **burned-in52 pixel PHI**? Are there free-text fields the regex scan can't clear?534. **Pipeline stage** — what to build: ingest, validate, de-id, transform/map,54 or store. → `references/04-pipeline-patterns.md`5556## Workflow5758Load each reference when you reach its step.59601. **Pin the standards & profiles.** Confirm DICOM/HL7 v2/FHIR versions and any61 profile, and that structural checks ≠ full conformance. → `references/01-standards.md`62632. **Set up the scripts.** They are stdlib-only except DICOM de-id (optional64 `pydicom`). → `references/05-running-the-scripts.md`65 ```bash66 python3 --version # 3.12+67 pip install -r scripts/requirements.txt # only needed for DICOM de-id68 ```69703. **Validate structure** of FHIR and/or HL7 v2 inputs; fix errors; re-run until71 exit 0. → `references/03-validation-and-conformance.md`72 ```bash73 python3 scripts/validate_fhir.py path/to/fhir.json --out-dir fhir-report74 python3 scripts/validate_hl7v2.py path/to/msg.hl7 --out-dir hl7-report75 ```76774. **Scan for PHI** before anything leaves a trusted boundary; a non-zero exit78 means stop and review. → `references/02-deidentification.md`79 ```bash80 python3 scripts/phi_scan.py path/to/data --out-dir phi-report81 ```82835. **De-identify DICOM** header PHI and **verify** by re-reading the output. → `references/02-deidentification.md`84 ```bash85 cp scripts/deid.config.example.json scripts/deid.config.json # optional overrides86 python3 scripts/deidentify_dicom.py path/to/dicom --out-dir deid-out \87 --config scripts/deid.config.json --verify88 ```89906. **Build the pipeline** stage by stage (ingest → validate → de-id → transform91 → store), gating each handoff on the checks above. → `references/04-pipeline-patterns.md`92937. **Complete the human review** the automation can't: burned-in pixel PHI,94 free-text/name PHI, profile conformance via a real validator, and the95 re-identification-risk judgement. → `references/02-deidentification.md`9697## What's in this skill9899- `scripts/validate_fhir.py` — structural FHIR R4 JSON check (resourceType, required elements, reference shape, coding presence); file or dir; report + exit code. STDLIB only.100- `scripts/validate_hl7v2.py` — pipe-delimited HL7 v2 parser; validates MSH + basic required fields; report + exit code. STDLIB only.101- `scripts/phi_scan.py` — regex scan for the regex-detectable Safe-Harbor identifiers (SSN, phone, email, dates, URLs, IPs, MRN/account, IBAN, ZIP); report + exit code. STDLIB only.102- `scripts/deidentify_dicom.py` — removes/blanks DICOM PS3.15 Basic-Profile PHI tags via `pydicom`; `--verify` re-reads and asserts none remain; clean message if pydicom missing.103- `scripts/deid.config.example.json` — tag→action overrides for the DICOM de-id.104- `scripts/examples/` — valid + invalid samples used by the self-test.105- `references/01–05` — standards, de-identification, validation/conformance, pipeline patterns, running the scripts.106107## Definition of done108109- [ ] `validate_fhir.py` exits **0** on all FHIR inputs (errors fixed at the110 source, not suppressed).111- [ ] `validate_hl7v2.py` exits **0**; MSH and required segment fields present.112- [ ] `phi_scan.py` exits **0** on data crossing a trust boundary — **or** every113 finding is reviewed and justified.114- [ ] `deidentify_dicom.py --verify` reports **no residual** configured PHI tags.115- [ ] **Burned-in pixel PHI** and **free-text/name PHI** reviewed by a human116 (the scripts cannot clear these).117- [ ] De-id **basis stated** (Safe Harbor / Expert Determination / GDPR118 anonymization vs pseudonymization) and matches what was actually done.119- [ ] Where conformance is claimed, a **real validator** (HAPI `$validate`,120 Inferno, HL7 conformance profile) was run — not just the structural check.121122## Guardrails — avoid these mistakes123124- **Don't claim "de-identified" from a clean PHI scan.** State "no structured125 Safe-Harbor identifiers detected; free-text and pixel PHI reviewed separately."126 Overclaiming is the cardinal error here.127- **Don't claim "FHIR conformant" from the structural check.** It proves shape,128 not profile/value-set/invariant conformance — run a real validator for that.129- **Never put real PHI in logs, reports, test fixtures, or prompts.** Use130 synthetic data; the `examples/` are already synthetic.131- **Burned-in pixel PHI is invisible to header de-id** — flag images for OCR /132 pixel review separately.133- **Don't suppress a validation error to go green** — fix the data or the134 mapping. Configure `deid.config.json` for real tag needs, never to skip PHI.135- **Pseudonymization is not anonymization** — a re-identification key still136 exists; treat the output as personal data under GDPR.137- **Mind the minimum-necessary principle** — only move the PHI a stage actually138 needs.