Skip to main content

Thai DRG Grouper - Multi-version support for Linux/Mac/Windows

Project description

Thai DRG Grouper

🏥 Thai DRG Grouper - Multi-version Thai DRG grouper for Linux/Mac/Windows

PyPI version License: MIT Python 3.8+

📖 เอกสารภาษาไทย (Thai Documentation) | ตัวอย่างการใช้งาน (Examples)

✨ Features

  • Cross-platform - Linux, Mac, Windows
  • Multi-version - Run multiple DRG versions simultaneously
  • Easy updates - Add new versions with one command
  • REST API - FastAPI included
  • CLI - Command-line interface
  • Batch processing - Process multiple cases at once
  • Version comparison - Compare results across versions

📦 Installation

pip install thai-drg-grouper

# With API support
pip install thai-drg-grouper[api]

🚀 Quick Start

Python Library

from thai_drg_grouper import ThaiDRGGrouperManager

# Initialize with versions directory
manager = ThaiDRGGrouperManager('./data/versions')

# Group a case (uses default version)
result = manager.group_latest(
    pdx='S82201D',        # Principal diagnosis
    sdx=['E119', 'I10'],  # Secondary diagnoses
    procedures=['7936'],   # ICD-9-CM procedures
    age=25,
    sex='M',
    los=5
)

print(f"DRG: {result.drg}")      # 08172
print(f"RW: {result.rw}")        # 5.0602
print(f"AdjRW: {result.adjrw}")  # 5.0602

# Group with specific version
result = manager.group('6.3', pdx='J189', los=5)

# Compare across all versions
results = manager.group_all_versions(pdx='S82201D', los=5)
for version, res in results.items():
    print(f"{version}: DRG={res.drg}, RW={res.rw}")

CLI

# List installed versions
thai-drg-grouper list

# Group a case
thai-drg-grouper group --pdx S82201D --sdx E119,I10 --proc 7936 --los 5

# Group with specific version
thai-drg-grouper group --version 6.3 --pdx J189 --los 5

# Compare across versions
thai-drg-grouper compare --pdx S82201D --los 5

# Start API server
thai-drg-grouper serve --port 8000

REST API

# Start server
thai-drg-grouper serve --port 8000

# Or with uvicorn
uvicorn thai_drg_grouper.api:app --port 8000

Endpoints:

Method Endpoint Description
GET / API info
GET /versions List versions
POST /group Group (default version)
POST /group/{version} Group (specific version)
POST /group/compare Compare all versions
POST /group/batch Batch grouping
GET /health Health check

Example:

curl -X POST http://localhost:8000/group \
  -H "Content-Type: application/json" \
  -d '{"pdx": "S82201D", "sdx": ["E119"], "los": 5}'

📁 Version Management

Add Version

# From zip file
thai-drg-grouper add --version 6.4 --source /path/to/TGrp64.zip --set-default

# From folder
thai-drg-grouper add --version 6.4 --source /path/to/TGrp64/

Download from TCMC

# List available versions
thai-drg-grouper download

# Download version
thai-drg-grouper download --version 6.3 --set-default

Directory Structure

data/versions/
├── config.json           # Default settings
├── 6.3/
│   ├── version.json      # Version metadata
│   └── data/
│       ├── c63i10.dbf    # ICD-10 codes
│       ├── c63proc.dbf   # Procedures
│       ├── c63drg.dbf    # DRG definitions
│       └── c63ccex.dbf   # CC exclusions
└── 6.3.4/
    └── ...

🐳 Docker

Using Pre-built Image from GitHub Container Registry

docker pull ghcr.io/aegisx-platform/thai-drg-grouper:latest
docker run -p 8000:8000 ghcr.io/aegisx-platform/thai-drg-grouper:latest

Building Your Own Image

FROM python:3.11-slim

WORKDIR /app
RUN pip install thai-drg-grouper[api]

COPY data/versions ./data/versions

EXPOSE 8000
CMD ["thai-drg-grouper", "serve", "--port", "8000"]
docker build -t thai-drg-grouper .
docker run -p 8000:8000 thai-drg-grouper

📊 Output Fields

Field Description
drg DRG code (5 digits)
drg_name DRG description
mdc Major Diagnostic Category
dc Disease Cluster
rw Relative Weight
rw0d RW for day case
adjrw Adjusted RW (by LOS)
pcl Patient Complexity Level (0-4)
is_surgical Surgical/Medical flag
los_status daycase/normal/long_stay

📋 Adding New Versions

When TCMC releases a new version:

# 1. Download from https://www.tcmc.or.th/tdrg
wget https://www.tcmc.or.th/.../TGrp64.zip

# 2. Add to grouper
thai-drg-grouper add --version 6.4 --source TGrp64.zip --set-default

# 3. Verify
thai-drg-grouper list

⚠️ Disclaimer

  • This is an implementation based on .dbf files, not the official grouper
  • Validate results against official TGrp before production use
  • DRG data from Thai CaseMix Centre (สรท.)

🔗 References

💖 Support This Project

If you find this project helpful, consider buying me a coffee! ☕

Buy Me A Coffee

Your support helps maintain and improve this project!

📄 License

MIT License - See LICENSE for details.

🤝 Contributing

Contributions welcome! Please read CONTRIBUTING.md first.

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

thai_drg_grouper-2.2.0.tar.gz (761.6 kB view details)

Uploaded Source

Built Distribution

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

thai_drg_grouper-2.2.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file thai_drg_grouper-2.2.0.tar.gz.

File metadata

  • Download URL: thai_drg_grouper-2.2.0.tar.gz
  • Upload date:
  • Size: 761.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for thai_drg_grouper-2.2.0.tar.gz
Algorithm Hash digest
SHA256 e6f9c17153064fe3063329bbbf69341edc0fe06482ffcfd6b0390b85d6c6966f
MD5 0a75afe36d4ba409ee4a6b891a0e3ed7
BLAKE2b-256 a91bf1bce26c73ac88158d9f00d50c5756f0234eb30723d2a4ea3ad669e280f5

See more details on using hashes here.

File details

Details for the file thai_drg_grouper-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for thai_drg_grouper-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7decb83e26942939158141248d900322bed5bdfa1648305b778f07f318de824
MD5 54a9500609f61da8fb8bb3d0be1b3fa1
BLAKE2b-256 00dd20b7be3b053a2ea9bf99ef7a1364a021821c54d04feecdf1e55c5dd5595f

See more details on using hashes here.

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