
Parsing Lab Values
Parse laboratory values and reference ranges from clinical text and flag results as...
Install
npx skills add maziyarpanahi/openmed --skill parsing-lab-values -g -a claude-code -y- Repository
- maziyarpanahi/openmed5.8k
- Category
- Engineering
- Updated
- 4d ago
- License
- Apache-2.0
- Context cost
- Lightabout 1,442 tokens
- Runs scripts
- No, instructions only
What it does
Parse laboratory values and reference ranges from clinical text and flag results as low, normal, high, or critical with OpenMed. Use when the user needs to interpret lab results, compute abnormal flags, parse reference ranges like \"135-145\" or \"<5\", honor an originating-lab flag (H/L/critical), or turn extracted lab entities into structured high/low/critical signals. Covers openmed.clinical.parse_reference_range, derive_abnormal_flag, ReferenceRange, and AbnormalFlag, with UCUM/LOINC framing. Unit-agnostic, it does not convert units. Pairs after extracting-clinical-entities (lab entities from analyze_text).
Parsing lab values
Lab results in clinical text arrive as a value, a unit, and a reference range
("Sodium 132 mmol/L (135, 145)"). To act on them you need a structured
abnormal flag, is 132 low, normal, high, or critical? OpenMed's
openmed.clinical lab helpers parse the reference range deterministically and
derive the flag, honoring any explicit flag the originating lab already supplied.
The helpers are unit-agnostic by design: they compare numbers within a stated
range and never convert units, so a mmol/L value is never silently compared
against a mg/dL range.
When to use
- After
extracting-clinical-entitiessurfaces lab/measurement entities and you need to classify each as low / normal / high / critical. - The user asks to parse reference ranges, flag abnormal labs, build a flagged
labs table, or interpret values like
<5,>=10,0.5 - 1.2. - You have an originating-lab flag (
H,L,C,HH) and want it honored over a derived comparison.
Quick start
from openmed.clinical import (
parse_reference_range, derive_abnormal_flag, LAB_FLAG_ADVISORY,
)
# Closed range
rng = parse_reference_range("135-145")
# -> {"low": 135.0, "high": 145.0, "low_inclusive": True, "high_inclusive": True}
derive_abnormal_flag(132, rng) # "low"
derive_abnormal_flag(140, "135-145") # "normal" (raw range string accepted)
derive_abnormal_flag(150, "135 to 145") # "high"
# One-sided bounds
derive_abnormal_flag(7, parse_reference_range("<5")) # "high" (above the cap)
derive_abnormal_flag(3, parse_reference_range(">=10")) # "low"
# Honor the lab's own explicit flag (takes precedence over derived comparison)
derive_abnormal_flag(132, "135-145", explicit_flag="C") # "critical"
derive_abnormal_flag(132, "135-145", explicit_flag="HH") # "critical"
