Skip to content

determine_laterality() assigns left/right backwards in anatomic location build #39

Description

@talkasab

Bug

determine_laterality() in packages/oidm-maintenance/src/oidm_maintenance/anatomic/build.py (line 114)
interprets leftRef/rightRef fields backwards.

In the source data, these fields are cross-references to sibling variants, not self-descriptions:

  • A left-sided structure (e.g., "left superior nasal turbinate") has a rightRef pointing to its right
    sibling
  • A right-sided structure has a leftRef pointing to its left sibling
  • A generic structure has both leftRef and rightRef

The current logic:

if has_left and not has_right:
    return "left"     # WRONG: has leftRef → is RIGHT (points to left sibling)
elif has_right and not has_left:
    return "right"    # WRONG: has rightRef → is LEFT (points to right sibling)

Should be:

if has_left and not has_right:
    return "right"    # has leftRef only → IS right-sided (points to left sibling)
elif has_right and not has_left:
    return "left"     # has rightRef only → IS left-sided (points to right sibling)

Evidence

Record RID10049_RID5824 in anatomic_sample.json:

  • description: "left superior nasal turbinate"
  • Has rightRef (to "right superior nasal turbinate") but no leftRef
  • Current code assigns laterality = "right" — wrong

A test comment in test_anatomic_index_db.py:288 already acknowledges this: "In sample data, left variant
has rightRef but no leftRef, so laterality will be RIGHT, not LEFT. This is a data quirk in the sample." —
it's not a data quirk, it's a bug.

Impact

Every left-sided anatomic location in the database is labeled right, and vice versa. This affects:

  • location.laterality values returned by AnatomicLocationIndex
  • Any query filtering by laterality
  • The anatomic-locations laterality CLI command output

Fix

  1. Swap the return values in determine_laterality() (2-line change)
  2. Update the test comment in test_anatomic_index_db.py that documents the "quirk"
  3. Update any test assertions that were written to match the wrong behavior
  4. Rebuild the anatomic locations database
  5. Rebuild packages/anatomic-locations/tests/data/anatomic_test.duckdb:
    • packages/anatomic-locations/tests/data/anatomic_test.duckdb is a pre-built test fixture committed to the repo. It was built by the same build_anatomic_database() pipeline and has the swapped laterality baked in. After fixing determine_laterality(), this file must be rebuilt.
    • The conftest at packages/anatomic-locations/tests/conftest.py:61 references a build script
      packages/oidm-maintenance/scripts/build_anatomic_test_fixture.py that does not exist. The fix should create this script (analogous to the existing build_test_fixtures.py for findingmodel) so the fixture
      can be reproducibly rebuilt with mocked embeddings.

Files

  • packages/oidm-maintenance/src/oidm_maintenance/anatomic/build.pydetermine_laterality() line 114
  • packages/anatomic-locations/tests/test_anatomic_index_db.py — test comment at line 288, possibly test assertions
  • Published anatomic locations database — needs rebuild and republish
  • packages/oidm-maintenance/scripts/build_anatomic_test_fixture.py — create (currently missing)
  • packages/anatomic-locations/tests/data/anatomic_test.duckdb — rebuild after fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions