Repository navigation
Add OMOP vocabulary reader + KEEP condition hierarchy + ICD mapper - #2
Merged
Merged
Conversation
Reads Athena OMOP vocabularies and builds the SNOMED "Disease" hierarchy used by KEEP (depth-limited, all parents kept, orphans re-attached) plus an ICD-9-CM/ICD-10-CM to standard concept mapper that accepts MIMIC's dot-free codes. Adds synthetic-data tests, docs, and an example script that reports the depth ablation and MIMIC-IV coverage as counts only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JrebVyPi1jFyjkAiLbLSC1
This was referenced Nov 14, 2026
- Split omop.py into pyhealth/medcode/omop/ (vocabulary, condition_hierarchy, icd_mapper); public imports unchanged. Tests split to match, sharing tests/core/omop_test_utils.py. - Rename ConditionHierarchy to OMOPConditionHierarchy. - to_triples(direction=...) and new to_knowledge_graph(); rescue edges get their own relation; knowledge graph defaults to parent -> child so GraphProcessor reaches ancestors from a child seed. - Add OMOPVocabularyFormat for non-Athena vocabulary files. - map_frame() and coverage() accept polars LazyFrames. - Docs: KnowledgeGraph/GraphProcessor example; rescue described as an adapter policy. Example script documents task and processor entry points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JrebVyPi1jFyjkAiLbLSC1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
-- SNOMED "Disease" hierarchy KEEP embeds
-- mapping from MIMIC's ICD codes onto it
Changes / Additions
pyhealth/medcode/omop/(new package;from pyhealth.medcode import ...works as before)vocabulary.py:OMOPVocabularyreadsCONCEPT,CONCEPT_RELATIONSHIP, andCONCEPT_ANCESTORfrom an Athena folder (tab-separated, multi-GB; read lazily with polars).OMOPVocabularyFormatoverrides the file format for non-Athena sources.condition_hierarchy.py:OMOPConditionHierarchy, standard SNOMED Condition concepts within N levels of "Disease" (4274025). Default is 5 levels by shortest path, as in KEEP §A.1.1;depth_measure="max"is an option. Every "Is a" parent is kept. Concepts whose only parents are filtered out are attached to their nearest kept ancestor and flaggedrescued(our own policy, not specified by KEEP;connect_orphans=Falseturns it off).retained_ancestors()for roll-up,restrict()for depth ablations without re-reading Athena,save()/load().to_triples(direction=...)andto_knowledge_graph(direction=...)export topyhealth.graph.KnowledgeGraphwith string concept ids; rescue edges get their own relation (rescued_is_a/rescued_subsumes).to_knowledge_graph()defaults to parent → child soGraphProcessorreaches a code's ancestors.icd_mapper.py:ICDToSNOMEDMapper, ICD-9-CM / ICD-10-CM to standard concepts through valid "Maps to" links. Takes MIMIC's dot-free codes.map(),map_frame()(whole diagnoses table),coverage()(counts only); the last two also accept lazy polars tables.pyhealth/medcode/__init__.py: exports the new classes.docs/api/medcode.rst: new "OMOP Vocabularies (Athena)" section, with a runnableKnowledgeGraph/GraphProcessorexample.test_omop_vocabulary.py,test_omop_condition_hierarchy.py,test_omop_icd_mapper.py, sharing a synthetic Athena bundle intests/core/omop_test_utils.py.examples/omop_keep_condition_graph_check.py(new): builds and caches the graph, prints the depth ablation and MIMIC-IV coverage (counts only); its docstring shows the task and processor entry points..gitignore: ignores Athena files andmimiciv/.Testing and validation
restrict()matches a direct build.GraphProcessortests need torch-geometric and are skipped without it. With it: from a child seed, the parent → child graph reaches the ancestors; child → parent returns only the seed. PyHealth's existingKnowledgeGraph/GraphProcessortests still pass.Notes
retained_ancestors()for it.