Stores
cms_icd.stores.ReadOnlyStore
cms_icd.stores.TabularStore
TabularStore(values: Mapping[str, Node], code_lookup: Mapping[str, str], roots: Iterable[str])
Read-only ICD tabular hierarchy.
children_ids always contains direct children. Recursive relationships
are requested explicitly.
Examples:
>>> root = Node("cm", "cm", children_ids=("I10",))
>>> code = Code("I10", "I10", "Essential hypertension", parent_id="cm")
>>> store = TabularStore({"cm": root, "I10": code}, {"I10": "I10"}, ("cm",))
>>> [node.id for node in store.parents("I10")]
['cm']
>>> [node.name for node in store.leaves("cm")]
['I10']
Source code in src/cms_icd/stores.py
lookup
property
Map normalized ICD code strings to tabular node identifiers.
by_code
by_code(code: str) -> Node
parents
parents(code_or_id: str) -> tuple[Node, ...]
Return parents from the immediate parent to the root.
Source code in src/cms_icd/stores.py
children
children(code_or_id: str) -> tuple[Node, ...]
descendants
descendants(code_or_id: str) -> tuple[Node, ...]
Return all descendants in deterministic depth-first order.
Source code in src/cms_icd/stores.py
siblings
siblings(code_or_id: str) -> tuple[Node, ...]
Return direct siblings, excluding the requested node.
Source code in src/cms_icd/stores.py
lowest_common_ancestor
lowest_common_ancestor(codes_or_ids: Iterable[str]) -> Node | None
Return the deepest hierarchy node shared by all supplied codes.
The requested nodes themselves participate in the comparison. An empty input has
no common ancestor; unknown codes retain the normal mapping KeyError.
Source code in src/cms_icd/stores.py
cms_icd.stores.IndexStore
Read-only alphabetic-index hierarchy.
Source code in src/cms_icd/stores.py
parents
parents(term_id: str) -> tuple[Term, ...]
Return index parents from immediate parent to main term.
Source code in src/cms_icd/stores.py
children
children(term_id: str) -> tuple[Term, ...]
descendants
descendants(term_id: str) -> tuple[Term, ...]
Return all descendant terms in depth-first order.
Source code in src/cms_icd/stores.py
cms_icd.stores.GuidelineStore
GuidelineStore(values: Mapping[str, Guideline], titles: Mapping[str, str] | None = None, preambles: Mapping[str, str] | None = None)
Hierarchical guideline sections keyed with dotted identifiers.
Examples:
>>> item = Guideline("I_A_1", "I.A.1", "Example", "Body")
>>> titles = {"I": "Section", "I.A": "Conventions"}
>>> store = GuidelineStore({"I.A.1": item}, titles)
>>> store.descendants("I")
('I.A.1',)
>>> store["I.A.1"].content
'Body'
Source code in src/cms_icd/stores.py
titles
property
Return titles for both leaf and non-leaf guideline sections.
preambles
property
Return text appearing before the first child of container sections.
descendants
Return naturally sorted leaf keys below a prefix.
ancestors
Return titled ancestor keys from outermost to innermost.