Skip to content

mz-drg

High-performance CMS claim processing tools written in Zig with Python bindings.

License: MIT Zig Python Docs


mz-drg provides open-source reimplementations of two CMS tools:

  • MS-DRG Grouper — assigns Diagnosis Related Groups based on diagnoses, procedures, and demographics
  • Medicare Code Editor (MCE) — validates ICD diagnosis and procedure codes against CMS edit rules

Both are written in Zig, callable from Python, and validated against the CMS reference Java implementations with a 100% match rate on 50,000+ claims.

⚡ Why mz-drg?

The official CMS tools are Java applications. While accurate, they come with practical limitations:

Java (CMS) mz-drg
Startup JVM warmup, seconds Instant
Throughput (Ryzen 5 5600U) ~500 claims/sec ~7,000+ claims/sec
Memory JVM heap overhead Minimal, memory-mapped data
Dependencies JRE 17+, classpath management Single shared library
Python integration JPype bridge (fragile) Native ctypes (simple)
Embedding Requires JVM process C ABI, any language

🚀 Quick example

import msdrg

# MS-DRG grouping
with msdrg.MsdrgGrouper() as g:
    result = g.group({
        "version": 431, "age": 65, "sex": 0, "discharge_status": 1,
        "pdx": {"code": "I5020"}, "sdx": [{"code": "E1165"}], "procedures": []
    })
    print(result["final_drg"])  # 293

# MCE validation
with msdrg.MceEditor() as mce:
    result = mce.edit({
        "discharge_date": 20250101, "age": 65, "sex": 0, "discharge_status": 1,
        "pdx": {"code": "I5020"}, "sdx": [], "procedures": []
    })
    print(result["edit_type"])  # "NONE"

📖 What's next?