Skip to content

OM-334 Add lab reference range flag helper#560

Open
Ispagiytiy wants to merge 3 commits into
maziyarpanahi:masterfrom
Ispagiytiy:feat/OM-334-lab-values
Open

OM-334 Add lab reference range flag helper#560
Ispagiytiy wants to merge 3 commits into
maziyarpanahi:masterfrom
Ispagiytiy:feat/OM-334-lab-values

Conversation

@Ispagiytiy

Copy link
Copy Markdown

Pull Request

Description

Adds deterministic lab reference range parsing and abnormal flag derivation helpers for numeric lab ranges, with focused unit tests and a changelog entry.

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 parse_reference_range() for numeric lab reference range strings such as 135-145, 0.5 - 1.2, <5, and >10.
  • Added derive_abnormal_flag() to return low, normal, high, critical, or unknown from a value, parsed reference range, and optional explicit flag.
  • Normalized explicit H and L flags to high and low before numeric range comparison.
  • Added unit tests for range parsing, one-sided ranges, explicit flag precedence, low/normal derivation, non-numeric values, and invalid range inputs.

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

Documentation

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

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

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 #524

Screenshots/Examples

N/A - no UI changes. Covered by unit tests in tests/unit/clinical/test_lab_values.py.

@maziyarpanahi maziyarpanahi added feature New capability good first issue Good for newcomers help wanted Extra attention is needed P2 Medium roadmap-v2 OpenMed V2 roadmap backlog labels Jun 22, 2026

@maziyarpanahi maziyarpanahi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Ispagiytiy. I reviewed this against #524 / OM-334 and added one maintainer follow-up merge commit: Merge master into lab values helper.

What I changed:

  • resolved the CHANGELOG.md conflict against current master while preserving the lab-values entry;
  • kept the already-merged cardiology label-map changes from master in the PR branch;
  • added the advisory disclaimer that derived lab flags are heuristic and not a substitute for source lab flagging or clinical review;
  • made value parsing stricter so arbitrary strings with embedded numbers return unknown rather than guessing;
  • added normal/critical explicit-flag aliases and broader tests for decimal ranges, one-sided inclusive bounds, explicit flags, and unparseable parsed ranges.

Verification on the current PR checkout:

  • PYTHONPATH=/private/tmp/openmed-pr-560 /Users/maziyar/Developer/openmed/.venv/bin/python -m pytest tests/unit/clinical/test_lab_values.py tests/unit/ner/test_label_map_consistency.py -q -> 73 passed
  • /Users/maziyar/Developer/openmed/.venv/bin/ruff check openmed/clinical/lab_values.py tests/unit/clinical/test_lab_values.py openmed/core/model_registry.py tests/unit/ner/test_label_map_consistency.py CHANGELOG.md -> passed
  • /Users/maziyar/Developer/openmed/.venv/bin/ruff format --check openmed/clinical/lab_values.py tests/unit/clinical/test_lab_values.py openmed/core/model_registry.py tests/unit/ner/test_label_map_consistency.py -> passed

I also copied the labels from #524 onto the PR. The branch is mergeable with no conflicts; GitHub has not attached hosted checks to the new head commit yet, so I verified the touched behavior locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New capability good first issue Good for newcomers help wanted Extra attention is needed P2 Medium roadmap-v2 OpenMed V2 roadmap backlog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a lab reference-range parser and abnormal-flag derivation helper

2 participants