Skip to content

Add HL7 v2 narrative extraction with source provenance#1776

Open
maziyarpanahi wants to merge 1 commit into
masterfrom
feature/om-504-hl7v2-to-narrative-extractor
Open

Add HL7 v2 narrative extraction with source provenance#1776
maziyarpanahi wants to merge 1 commit into
masterfrom
feature/om-504-hl7v2-to-narrative-extractor

Conversation

@maziyarpanahi

Copy link
Copy Markdown
Owner

Description

Adds de-identified narrative extraction for common HL7 v2 ADT, ORU, and ORM messages. The extractor reuses the existing segment-aware parser and structured redactor, renders stable flat or sectioned text, passes the complete narrative through the privacy pipeline, and preserves final-text offsets back to source segment occurrences and fields.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test addition/improvement

Changes Made

  • Added extract_hl7v2_narrative with deterministic flat and sectioned modes for common message, patient, encounter, order, observation, result, and note fields.
  • Added PHI-safe field provenance with final narrative offsets, segment indices and occurrences, field positions, section ranges, and lookup helpers.
  • Added synthetic ADT/ORU coverage and a usage guide linked from the existing HL7 v2 documentation and docs navigation.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this change with different models/inputs

Validation completed:

  • .venv/bin/python -m pytest tests/ -q — 5,205 passed, 46 skipped
  • Focused HL7 v2 tests — 14 passed
  • make format
  • make lint
  • make format-check
  • make type-check
  • make docs-build
  • Scoped pre-commit hooks

Documentation

  • I have updated the documentation accordingly
  • I have added docstrings to new functions/classes
  • I have updated the CHANGELOG.md

A changelog update is not needed for this focused roadmap feature PR.

Code Quality

  • I ran make format, make lint, and make format-check
  • For Swift/OpenMedKit changes, I ran make format-swift and make lint-swift
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

No Swift/OpenMedKit files are changed.

Dependencies

  • I have not added any new dependencies
  • OR I have added new dependencies and they are justified because: ____

Checklist

  • I have read the contributing guidelines
  • My commits have clear, descriptive messages
  • I have squashed/organized my commits appropriately

Related Issues

Closes #861

Screenshots/Examples

Not applicable. This change adds a Python interoperability API, offset provenance contract, tests, and documentation without a UI surface.

@maziyarpanahi maziyarpanahi added roadmap-v2 OpenMed V2 roadmap backlog feature New capability P3 Strategic labels Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New capability P3 Strategic roadmap-v2 OpenMed V2 roadmap backlog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an HL7 v2 to narrative extractor over interop.hl7v2

1 participant