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
- Swap the return values in determine_laterality() (2-line change)
- Update the test comment in test_anatomic_index_db.py that documents the "quirk"
- Update any test assertions that were written to match the wrong behavior
- Rebuild the anatomic locations database
- 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.py — determine_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
Bug
determine_laterality()inpackages/oidm-maintenance/src/oidm_maintenance/anatomic/build.py(line 114)interprets
leftRef/rightReffields backwards.In the source data, these fields are cross-references to sibling variants, not self-descriptions:
rightRefpointing to its rightsibling
leftRefpointing to its left siblingleftRefandrightRefThe current logic:
Should be:
Evidence
Record RID10049_RID5824 in
anatomic_sample.json:rightRef(to "right superior nasal turbinate") but noleftRefA test comment in
test_anatomic_index_db.py:288already acknowledges this: "In sample data, left varianthas 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.lateralityvalues returned byAnatomicLocationIndexFix
packages/anatomic-locations/tests/data/anatomic_test.duckdb:packages/anatomic-locations/tests/conftest.py:61references a build scriptpackages/oidm-maintenance/scripts/build_anatomic_test_fixture.pythat does not exist. The fix should create this script (analogous to the existingbuild_test_fixtures.pyfor findingmodel) so the fixturecan be reproducibly rebuilt with mocked embeddings.
Files
packages/oidm-maintenance/src/oidm_maintenance/anatomic/build.py—determine_laterality()line 114packages/anatomic-locations/tests/test_anatomic_index_db.py— test comment at line 288, possibly test assertionspackages/oidm-maintenance/scripts/build_anatomic_test_fixture.py— create (currently missing)packages/anatomic-locations/tests/data/anatomic_test.duckdb— rebuild after fix