Skip to content

GEM API

cms_icd.gems.GEMKnowledgeBase

GEMKnowledgeBase(provider: MaterialProvider, *, correction_providers: tuple[MaterialProvider, ...] = ())

A CMS fiscal-year GEM release with independently lazy CM and PCS views.

Source code in src/cms_icd/gems.py
def __init__(
    self,
    provider: MaterialProvider,
    *,
    correction_providers: tuple[MaterialProvider, ...] = (),
) -> None:
    self._provider = provider
    self._correction_providers = correction_providers
    self._cm: GEMSystemView | None = None
    self._pcs: GEMSystemView | None = None

release property

release: Release

Return the selected CMS GEM release.

cm property

Return the lazy diagnosis GEM view.

pcs property

Return the lazy procedure GEM view.

from_cms classmethod

from_cms(fiscal_year: int, *, cache_dir: str | Path | None = None, offline: bool = False) -> Self

Create a lazy GEM selector for an official CMS fiscal year.

Parameters:

Name Type Description Default
fiscal_year int

Official CMS GEM fiscal year.

required
cache_dir str | Path | None

Persistent artifact cache directory. None uses the platform default cache directory.

None
offline bool

Require the catalog and artifacts to already be cached.

False
Source code in src/cms_icd/gems.py
@classmethod
def from_cms(
    cls,
    fiscal_year: int,
    *,
    cache_dir: str | Path | None = None,
    offline: bool = False,
) -> Self:
    """Create a lazy GEM selector for an official CMS fiscal year.

    Args:
        fiscal_year: Official CMS GEM fiscal year.
        cache_dir: Persistent artifact cache directory. ``None`` uses the
            platform default cache directory.
        offline: Require the catalog and artifacts to already be cached.
    """
    release = Release(fiscal_year, date(fiscal_year - 1, 10, 1))
    return cls(
        CMSProvider(
            release,
            cache_dir=cache_dir,
            offline=offline,
        )
    )

corrected_from_cms classmethod

corrected_from_cms(fiscal_year: int, *, corrections_through_fiscal_year: int = 2018, cache_dir: str | Path | None = None, offline: bool = False) -> Self

Create GEMs using historical vocabulary and later safe corrections.

Each source remains on the requested fiscal year's vocabulary. Later complete row sets are adopted only until that source encounters an introduced or retired source/target code. Corrections are reviewed through FY2018 by default, the last CMS GEM release.

Parameters:

Name Type Description Default
fiscal_year int

Historical vocabulary fiscal year.

required
corrections_through_fiscal_year int

Last GEM release considered for safe corrections.

2018
cache_dir str | Path | None

Persistent artifact cache directory shared by all releases. None uses the platform default cache directory.

None
offline bool

Require the catalog and artifacts to already be cached.

False
Source code in src/cms_icd/gems.py
@classmethod
def corrected_from_cms(
    cls,
    fiscal_year: int,
    *,
    corrections_through_fiscal_year: int = 2018,
    cache_dir: str | Path | None = None,
    offline: bool = False,
) -> Self:
    """Create GEMs using historical vocabulary and later safe corrections.

    Each source remains on the requested fiscal year's vocabulary. Later complete
    row sets are adopted only until that source encounters an introduced or retired
    source/target code. Corrections are reviewed through FY2018 by default, the last
    CMS GEM release.

    Args:
        fiscal_year: Historical vocabulary fiscal year.
        corrections_through_fiscal_year: Last GEM release considered for safe
            corrections.
        cache_dir: Persistent artifact cache directory shared by all releases.
            ``None`` uses the platform default cache directory.
        offline: Require the catalog and artifacts to already be cached.
    """
    if corrections_through_fiscal_year < fiscal_year:
        raise ValueError(
            "corrections_through_fiscal_year must not precede fiscal_year"
        )

    def provider(year: int) -> CMSProvider:
        return CMSProvider(
            Release(year, date(year - 1, 10, 1)),
            cache_dir=cache_dir,
            offline=offline,
        )

    return cls(
        provider(fiscal_year),
        correction_providers=tuple(
            provider(year)
            for year in range(fiscal_year + 1, corrections_through_fiscal_year + 1)
        ),
    )

from_directory classmethod

from_directory(directory: str | Path, *, fiscal_year: int) -> Self

Create a knowledge base from locally supplied CMS-format GEM files.

Source code in src/cms_icd/gems.py
@classmethod
def from_directory(
    cls,
    directory: str | Path,
    *,
    fiscal_year: int,
) -> Self:
    """Create a knowledge base from locally supplied CMS-format GEM files."""
    release = Release(fiscal_year, date(fiscal_year - 1, 10, 1))
    return cls(DirectoryProvider(directory, release))

__repr__

__repr__() -> str

Return a representation without acquiring any GEM material.

Source code in src/cms_icd/gems.py
def __repr__(self) -> str:
    """Return a representation without acquiring any GEM material."""
    loaded = [
        name
        for name, view in (("cm", self._cm), ("pcs", self._pcs))
        if view is not None
    ]
    corrections_through = (
        self._correction_providers[-1].release
        if self._correction_providers
        else None
    )
    return (
        f"GEMKnowledgeBase(release={self.release!r}, "
        f"corrections_through={corrections_through!r}, loaded={loaded!r})"
    )

cms_icd.gems.GEMSystemView

GEMSystemView(provider: MaterialProvider | None, system: str, *, icd9_to_icd10: GEMStore | None = None, icd10_to_icd9: GEMStore | None = None, correction_providers: tuple[MaterialProvider, ...] = ())

Lazy bidirectional GEMs for one ICD-10 system (CM or PCS).

Source code in src/cms_icd/gems.py
def __init__(
    self,
    provider: MaterialProvider | None,
    system: str,
    *,
    icd9_to_icd10: GEMStore | None = None,
    icd10_to_icd9: GEMStore | None = None,
    correction_providers: tuple[MaterialProvider, ...] = (),
) -> None:
    if system not in {"cm", "pcs"}:
        raise ValueError(f"Unsupported GEM system: {system!r}")
    self._provider = provider
    self._correction_providers = correction_providers
    self.system = system
    self._stores = {
        GEMDirection.ICD9_TO_ICD10: icd9_to_icd10,
        GEMDirection.ICD10_TO_ICD9: icd10_to_icd9,
    }
    self._locks = {direction: Lock() for direction in GEMDirection}

release property

release: Release | None

Return release metadata, if this view is provider-backed.

icd9_to_icd10 property

icd9_to_icd10: GEMStore

Return mappings from ICD-9-CM to ICD-10-CM or ICD-10-PCS.

icd10_to_icd9 property

icd10_to_icd9: GEMStore

Return mappings from ICD-10-CM or ICD-10-PCS to ICD-9-CM.

from_stores classmethod

from_stores(system: str, *, icd9_to_icd10: GEMStore | None = None, icd10_to_icd9: GEMStore | None = None) -> Self

Construct a view from prebuilt stores for custom sources or tests.

Source code in src/cms_icd/gems.py
@classmethod
def from_stores(
    cls,
    system: str,
    *,
    icd9_to_icd10: GEMStore | None = None,
    icd10_to_icd9: GEMStore | None = None,
) -> Self:
    """Construct a view from prebuilt stores for custom sources or tests."""
    return cls(
        None,
        system,
        icd9_to_icd10=icd9_to_icd10,
        icd10_to_icd9=icd10_to_icd9,
    )

__repr__

__repr__() -> str

Return a representation without loading mappings.

Source code in src/cms_icd/gems.py
def __repr__(self) -> str:
    """Return a representation without loading mappings."""
    loaded = [
        direction.value
        for direction, store in self._stores.items()
        if store is not None
    ]
    return (
        f"GEMSystemView(system={self.system!r}, release={self.release!r}, "
        f"loaded={loaded!r})"
    )