Slaiwala commited on
Commit
9deb1ad
·
verified ·
1 Parent(s): 5b489d0

Update spine_coder/spine_coder_core.py

Browse files
Files changed (1) hide show
  1. spine_coder/spine_coder_core.py +36 -1
spine_coder/spine_coder_core.py CHANGED
@@ -99,6 +99,12 @@ def suggest_with_cpt_billing(note: str, payer: str = "Medicare", top_k: int = 10
99
  elif any(l.startswith("T") for l in levels) or _has(t, r"\bthorac"): region = "thoracic"
100
  elif any(l.startswith(("L","S")) for l in levels) or _has(t, r"\blumbar|sacrum"): region = "lumbar"
101
 
 
 
 
 
 
 
102
  # Helper flags
103
  mentions_plate_ant = _has(t, r"\b(anterior (plate|instrument(ation)?)|plate fixed|plating)\b") or _has(t, r"\bplate\b")
104
  mentions_pedicle = _has(t, r"\bpedicle screw|pedicle-screw|pedicle fixation|s2ai\b")
@@ -388,6 +394,30 @@ def suggest_with_cpt_billing(note: str, payer: str = "Medicare", top_k: int = 10
388
  out.sort(key=lambda r: (not r.get("primary", False), -(r.get("score", r.get("confidence",0.0))), _cpt_num(r)))
389
  if isinstance(top_k, int) and top_k > 0: out = out[:top_k]
390
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  return {
392
  "payer": payer,
393
  "region": region,
@@ -395,5 +425,10 @@ def suggest_with_cpt_billing(note: str, payer: str = "Medicare", top_k: int = 10
395
  "interspaces_est": inters,
396
  "span_segments_est": span,
397
  "suggestions": out,
398
- "case_modifiers": case_modifiers
 
 
 
 
 
399
  }
 
99
  elif any(l.startswith("T") for l in levels) or _has(t, r"\bthorac"): region = "thoracic"
100
  elif any(l.startswith(("L","S")) for l in levels) or _has(t, r"\blumbar|sacrum"): region = "lumbar"
101
 
102
+ # Transitional zone override: C7 + T1–T3 → cervicothoracic
103
+ has_c7 = any(l.upper() == "C7" for l in levels) or _has(t, r"\bc7\b")
104
+ has_t1_3 = any(l.upper() in {"T1","T2","T3"} for l in levels) or _has(t, r"\bt[1-3]\b")
105
+ if has_c7 and has_t1_3:
106
+ region = "cervicothoracic"
107
+
108
  # Helper flags
109
  mentions_plate_ant = _has(t, r"\b(anterior (plate|instrument(ation)?)|plate fixed|plating)\b") or _has(t, r"\bplate\b")
110
  mentions_pedicle = _has(t, r"\bpedicle screw|pedicle-screw|pedicle fixation|s2ai\b")
 
394
  out.sort(key=lambda r: (not r.get("primary", False), -(r.get("score", r.get("confidence",0.0))), _cpt_num(r)))
395
  if isinstance(top_k, int) and top_k > 0: out = out[:top_k]
396
 
397
+ # ---------- Tech flags (microscope / navigation / neuromonitoring / fluoro) ----------
398
+ flags_map = {
399
+ "microscope": _has(t, r"\bmicroscope\b|microdissection"),
400
+ "nav": _has(t, r"\bnavigation\b|o-?arm|stealth|mazor|7d|image[- ]?guided"),
401
+ "io_monitor": _has(t, r"\bneuromonitor\w*|ssep|tcem|tcme|emg\b|\bintra[- ]?op(erative)? monitoring\b"),
402
+ "fluoro": _has(t, r"\bfluoro\w*|c[- ]?arm\b|fluoroscop\w*"),
403
+ }
404
+ flags_list = [k for k, v in flags_map.items() if v]
405
+
406
+ # ---------- Case-level laterality (meta) ----------
407
+ # 'Bilateral' should indicate both sides procedurally, NOT just bilateral implants/instrumentation.
408
+ bilateral_procedure_pat = (
409
+ r"\bboth sides\b"
410
+ r"|"
411
+ r"\bbilateral\b(?!\s*(pedicle|screw|screws|rod|rods|instrumentation|hardware))"
412
+ )
413
+ case_laterality = "na"
414
+ if _has(t, bilateral_procedure_pat):
415
+ case_laterality = "bilateral"
416
+ elif _has(t, r"\bleft[- ]sided|\bleft\b"):
417
+ case_laterality = "left"
418
+ elif _has(t, r"\bright[- ]sided|\bright\b"):
419
+ case_laterality = "right"
420
+
421
  return {
422
  "payer": payer,
423
  "region": region,
 
425
  "interspaces_est": inters,
426
  "span_segments_est": span,
427
  "suggestions": out,
428
+ "case_modifiers": case_modifiers,
429
+ "flags": flags_list,
430
+ "flags_map": flags_map,
431
+ "laterality": case_laterality,
432
+ "build": "FINAL-v2.0",
433
+ "mode": "standard",
434
  }