Skip to main content

Python MS-DRG grouper — assigns Medicare Severity DRG codes from ICD-10 diagnoses and procedures

Project description

drg

Python MS-DRG grouper — assigns Medicare Severity Diagnosis-Related Group codes from ICD-10 diagnoses and procedures.

Implements the CMS MS-DRG algorithm (FY2026 v43.0) as a pure Python package with zero external service dependencies.

Installation

pip install drg

Quick Start

Python API

from drg import MSDRGEngine

engine = MSDRGEngine()

result = engine.group(
    principal_dx="I2109",
    secondary_dxs=["J9601", "E1165"],
    procedures=["02703DZ"],
    age=67,
    sex="M",
)

print(result.drg_code)          # "280"
print(result.description)       # "ACUTE MYOCARDIAL INFARCTION, DISCHARGED ALIVE WITH MCC"
print(result.weight)            # 1.2345
print(result.mdc)               # "05"
print(result.complication_level) # ComplicationLevel.MCC

Command Line

# human-readable output
python -m drg --pdx I2109 --sdx J9601 E1165 --proc 02703DZ --age 67 --sex M

# JSON output
python -m drg --pdx I2109 --json

CLI Flags

Flag Description Default
--pdx Principal ICD-10-CM diagnosis code required
--sdx Secondary ICD-10-CM codes (space-separated) none
--proc ICD-10-PCS procedure codes (space-separated) none
--age Patient age in years 65
--sex Patient sex (M/F/U) M
--discharge-status Discharge status code 01
--json Output full result as JSON false
-V / --version Print version and exit

How It Works

The grouper follows the CMS MS-DRG classification logic:

  1. Pre-MDC check — transplants, ECMO, tracheostomy, and CAR-T therapy (DRGs 001–019)
  2. MDC classification — assigns a Major Diagnostic Category based on the principal diagnosis
  3. Surgical/medical partition — determines whether the encounter is surgical (OR procedure present) or medical
  4. Complication resolution — evaluates secondary diagnoses for CC/MCC status, applying PDX-based exclusions
  5. DRG assignment — selects the final DRG based on MDC, partition, and complication level

API Reference

MSDRGEngine

The main entry point. Data files are lazy-loaded on first call to group().

engine = MSDRGEngine()
result = engine.group(
    principal_dx="I2109",       # ICD-10-CM code (dots optional)
    secondary_dxs=["E1165"],    # secondary ICD-10-CM codes
    procedures=["02703DZ"],     # ICD-10-PCS codes
    age=67,                     # patient age
    sex="M",                    # M/F/U
    discharge_status="01",      # discharge status code
)

GroupingResult

Returned by engine.group(). Key fields:

  • drg_code — MS-DRG code (e.g. "282")
  • description — DRG description
  • mdc — Major Diagnostic Category code (e.g. "05")
  • mdc_description — MDC description
  • weight — DRG relative weight
  • geometric_los — geometric mean length of stay
  • arithmetic_los — arithmetic mean length of stay
  • partitionPartitionType.SURGICAL or PartitionType.MEDICAL
  • complication_levelComplicationLevel.MCC, .CC, or .NONE
  • is_pre_mdc — true for DRGs 001–019
  • principal_diagnosis — echoed Diagnosis object
  • secondary_diagnoses — echoed list of Diagnosis objects
  • procedures — echoed list of Procedure objects
  • encounter — echoed Encounter object
  • has_or_procedure — true if an OR procedure was detected
  • cc_codes_applied — CC codes that contributed to complication level
  • mcc_codes_applied — MCC codes that contributed to complication level

Data Sources

This package bundles public domain and open-source reference data:

  • CMS FY2026 Final Rule — ICD-10-CM codes, CC/MCC lists, CC exclusions, DRG weights Source: cms.gov License: U.S. government public domain

  • Tuva Health — ICD-10-PCS codes, MDC reference, MS-DRG reference Source: github.com/tuva-health/the_tuva_project License: Apache 2.0

Supported Version

  • MS-DRG v43.0 (FY2026 Final Rule)
  • ICD-10-CM/PCS effective October 1, 2025

Limitations

  • Diagnosis-specific DRG families are currently implemented for MDC 04 (respiratory) and MDC 05 (circulatory). Other MDCs fall back to severity-keyword matching against the DRG weights table.
  • MDC 24 (multiple significant trauma) is not yet implemented — it requires multi-body-region injury criteria beyond single-PDX classification.
  • The grouper covers the most common DRG assignment paths. Edge cases in less common MDCs may produce a fallback result.

Development

git clone https://github.com/tl212/drg.git
cd drg
pip install -e ".[dev]"
pytest

License

Apache 2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drg-1.0.0.tar.gz (2.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drg-1.0.0-py3-none-any.whl (2.3 MB view details)

Uploaded Python 3

File details

Details for the file drg-1.0.0.tar.gz.

File metadata

  • Download URL: drg-1.0.0.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for drg-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d9e2dfa827ca2f0958a57e21b7161672adc12322a393d8bd4fe524d9e8e0274f
MD5 eaff5ad498fa15a3b973ff65af077354
BLAKE2b-256 8ce8a4110f08fb49108a02d5cf6b6e4dc7264779bc99d20ca85a96959d047e81

See more details on using hashes here.

Provenance

The following attestation bundles were made for drg-1.0.0.tar.gz:

Publisher: publish.yml on tl212/drg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drg-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: drg-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for drg-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78451e8e9df2707a117a50d54457dd7830ce445fba92a719d46d3fd649863ad3
MD5 83c5683c3b8619b284db913384efe6b1
BLAKE2b-256 8b41b119c5811ffa18930f6d6d379200f25d518a4053da4611dbec9e06f4b893

See more details on using hashes here.

Provenance

The following attestation bundles were made for drg-1.0.0-py3-none-any.whl:

Publisher: publish.yml on tl212/drg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page