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:
- Pre-MDC check — transplants, ECMO, tracheostomy, and CAR-T therapy (DRGs 001–019)
- MDC classification — assigns a Major Diagnostic Category based on the principal diagnosis
- Surgical/medical partition — determines whether the encounter is surgical (OR procedure present) or medical
- Complication resolution — evaluates secondary diagnoses for CC/MCC status, applying PDX-based exclusions
- 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 descriptionmdc— Major Diagnostic Category code (e.g."05")mdc_description— MDC descriptionweight— DRG relative weightgeometric_los— geometric mean length of stayarithmetic_los— arithmetic mean length of staypartition—PartitionType.SURGICALorPartitionType.MEDICALcomplication_level—ComplicationLevel.MCC,.CC, or.NONEis_pre_mdc— true for DRGs 001–019principal_diagnosis— echoedDiagnosisobjectsecondary_diagnoses— echoed list ofDiagnosisobjectsprocedures— echoed list ofProcedureobjectsencounter— echoedEncounterobjecthas_or_procedure— true if an OR procedure was detectedcc_codes_applied— CC codes that contributed to complication levelmcc_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9e2dfa827ca2f0958a57e21b7161672adc12322a393d8bd4fe524d9e8e0274f
|
|
| MD5 |
eaff5ad498fa15a3b973ff65af077354
|
|
| BLAKE2b-256 |
8ce8a4110f08fb49108a02d5cf6b6e4dc7264779bc99d20ca85a96959d047e81
|
Provenance
The following attestation bundles were made for drg-1.0.0.tar.gz:
Publisher:
publish.yml on tl212/drg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drg-1.0.0.tar.gz -
Subject digest:
d9e2dfa827ca2f0958a57e21b7161672adc12322a393d8bd4fe524d9e8e0274f - Sigstore transparency entry: 1076807077
- Sigstore integration time:
-
Permalink:
tl212/drg@76a7b601bab7d287783e60ca829d6784ed9832c2 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/tl212
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@76a7b601bab7d287783e60ca829d6784ed9832c2 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78451e8e9df2707a117a50d54457dd7830ce445fba92a719d46d3fd649863ad3
|
|
| MD5 |
83c5683c3b8619b284db913384efe6b1
|
|
| BLAKE2b-256 |
8b41b119c5811ffa18930f6d6d379200f25d518a4053da4611dbec9e06f4b893
|
Provenance
The following attestation bundles were made for drg-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on tl212/drg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drg-1.0.0-py3-none-any.whl -
Subject digest:
78451e8e9df2707a117a50d54457dd7830ce445fba92a719d46d3fd649863ad3 - Sigstore transparency entry: 1076807103
- Sigstore integration time:
-
Permalink:
tl212/drg@76a7b601bab7d287783e60ca829d6784ed9832c2 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/tl212
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@76a7b601bab7d287783e60ca829d6784ed9832c2 -
Trigger Event:
release
-
Statement type: