Knowledge bases
cms_icd.knowledge_base.ICD10KnowledgeBase
ICD10KnowledgeBase(provider: MaterialProvider)
A CMS ICD-10 release with independently lazy CM and PCS views.
Construction records how materials should be found but performs no network
request, download, or parsing. Accessing a view is also cheap; material is
acquired only when tabular, index, or guidelines is accessed.
Examples:
>>> kb = ICD10KnowledgeBase.from_directory(
... ".", fiscal_year=2026, release_date=date(2025, 10, 1)
... )
>>> repr(kb)
'ICD10KnowledgeBase(...loaded=[])'
Source code in src/cms_icd/knowledge_base.py
from_cms
classmethod
from_cms(fiscal_year: int | None = None, *, year: int | None = None, release_date: date | None = None, cache_dir: str | Path | None = None, fallback: str | None = None, offline: bool = False) -> Self
Create a lazy selector for an exact CMS fiscal-year snapshot.
year is accepted as a compatibility alias for fiscal_year.
Materials unchanged in the requested revision are inherited from the
latest earlier revision in the same fiscal year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fiscal_year
|
int | None
|
CMS fiscal year. |
None
|
year
|
int | None
|
Compatibility alias for |
None
|
release_date
|
date | None
|
Effective date of the requested revision. Defaults to October 1 preceding the fiscal year. |
None
|
cache_dir
|
str | Path | None
|
Persistent artifact cache directory. |
None
|
fallback
|
str | None
|
Set to |
None
|
offline
|
bool
|
Require the catalog and artifacts to already be cached. |
False
|
Source code in src/cms_icd/knowledge_base.py
for_date
classmethod
for_date(service_date: date, *, cache_dir: str | Path | None = None, fallback: str | None = None, offline: bool = False) -> Self
Create a lazy selector for materials applicable on a coding date.
Use the discharge date for inpatient ICD-10-CM and ICD-10-PCS. Use the encounter or date of service for other ICD-10-CM coding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_date
|
date
|
Date that controls coding for the record. |
required |
cache_dir
|
str | Path | None
|
Persistent artifact cache directory. |
None
|
fallback
|
str | None
|
Set to |
None
|
offline
|
bool
|
Require the catalog and artifacts to already be cached. |
False
|
Source code in src/cms_icd/knowledge_base.py
from_directory
classmethod
Create an offline knowledge base from CMS-format files.
Source code in src/cms_icd/knowledge_base.py
load_all
__repr__
Return a representation without acquiring any material.
Source code in src/cms_icd/knowledge_base.py
cms_icd.knowledge_base.ICD10CMKnowledgeBase
ICD10CMKnowledgeBase(provider: MaterialProvider | None, *, tabular: TabularStore | None = None, index: IndexStore | None = None, guidelines: GuidelineStore | None = None)
Lazy structured access to ICD-10-CM materials.
Instances are normally obtained from :attr:ICD10KnowledgeBase.cm.
Examples:
>>> from cms_icd.models import Code, Node
>>> from cms_icd.stores import IndexStore, TabularStore
>>> root = Node("cm", "cm", children_ids=("I10",))
>>> code = Code("I10", "I10", "Essential hypertension", parent_id="cm")
>>> tabular = TabularStore({"cm": root, "I10": code}, {"I10": "I10"}, ("cm",))
>>> cm = ICD10CMKnowledgeBase.from_stores(tabular=tabular)
>>> cm["I10"].description
'Essential hypertension'
>>> cm.get_all_tabular_parents("I10")[0].id
'cm'
Source code in src/cms_icd/knowledge_base.py
from_stores
classmethod
from_stores(*, tabular: TabularStore | None = None, index: IndexStore | None = None, guidelines: GuidelineStore | None = None) -> Self
Construct a CM view from prebuilt stores for custom sources or tests.
Source code in src/cms_icd/knowledge_base.py
get_chapter_guidelines
get_chapter_guidelines(codes: list[str]) -> Guideline
Render chapter-specific CM guidelines for a list of codes.
Source code in src/cms_icd/knowledge_base.py
cms_icd.knowledge_base.ICD10PCSKnowledgeBase
ICD10PCSKnowledgeBase(provider: MaterialProvider | None, *, tabular: TabularStore | None = None, index: IndexStore | None = None, guidelines: GuidelineStore | None = None)
Lazy structured access to ICD-10-PCS materials.
Source code in src/cms_icd/knowledge_base.py
from_stores
classmethod
from_stores(*, tabular: TabularStore | None = None, index: IndexStore | None = None, guidelines: GuidelineStore | None = None) -> Self
Construct a PCS view from prebuilt stores for custom sources or tests.