Skip to main content

Offline ICD-9 and ICD-10 code mapping using SQLite

Project description

ICDMap

A command-line and Python library for converting ICD codes using an offline SQLite database.

Features

  • ✅ Offline lookup via included icd_mapping.db and death_cause_mapping.db
  • ✅ CLI and Python API support
  • ✅ Structured JSON output with Chinese/English descriptions and mapping code
  • ✅ Supports ICD-9 → ICD-10 and ICD-10 → ICD-9
  • ✅ Auto-detect or manual specification of code type
  • ✅ Supports cause-of-death mapping by ICD code or Cause code

Usage

1. CLI

# Single code (auto-detect type)
icdmap 250.00

# Force as ICD-9 input
icdmap 250.00 --source icd9

# Force as ICD-10 input
icdmap I10 --source icd10

# Batch from CSV with column 'ICD9_CODE'
icdmap --csv input.csv -o output.json

# Batch with manual source type
icdmap --csv input.csv --source icd9 -o output.json

# Death cause mapping by ICD-9
icdmap 410 --mode death --source icd9

# Death cause mapping by CSV
icdmap --csv death.csv --mode death -o death_output.json

2. Python API

from icdmap import ICDConverter, DeathCauseMapper

# ICD mapping
mapper = ICDConverter()
mapper.convert("250.00")
mapper.convert(["250.00", "I10"])

# Death cause mapping
death_mapper = DeathCauseMapper()
death_mapper.convert("41401", source="icd9")
death_mapper.convert(["41071", "431"], source="icd9")

3. Batch Mapping with Pandas (and tqdm progress)

import pandas as pd
from icdmap import ICDConverter, DeathCauseMapper

# 建立範例資料(模擬 ICD-9 code)
df = pd.DataFrame({
    "ICD9_CODE": ["250.00", "41401", "0389", "431", "41071"]
})

# ICD mapping
icd_mapper = ICDConverter()
icd_results = icd_mapper.convert(df["ICD9_CODE"])

def get_icd_field(code, field):
    return icd_results[code][0][field] if icd_results[code] else pd.NA

df["ICD-10"] = df["ICD9_CODE"].map(lambda x: get_icd_field(x, "ICD-10"))
df["ICD-10 English"] = df["ICD9_CODE"].map(lambda x: get_icd_field(x, "ICD-10 English"))
df["ICD-9 English"] = df["ICD9_CODE"].map(lambda x: get_icd_field(x, "ICD-9 English"))

# Death cause mapping
death_mapper = DeathCauseMapper()
death_results = death_mapper.convert(df["ICD9_CODE"], source="icd9")

def get_death_field(code, field):
    return death_results[code][0][field] if death_results[code] else "Other causes"

df["CAUSE_CN"] = df["ICD9_CODE"].map(lambda x: get_death_field(x, "Cause_Chinese"))
df["CAUSE_EN"] = df["ICD9_CODE"].map(lambda x: get_death_field(x, "Cause_English"))

LICENSE

MIT License

Copyright (c) 2025

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

icdmap-0.1.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.

icdmap-0.1.0-py3-none-any.whl (2.2 MB view details)

Uploaded Python 3

File details

Details for the file icdmap-0.1.0.tar.gz.

File metadata

  • Download URL: icdmap-0.1.0.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for icdmap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 df917539ecce906c6f0e2851071060186e42f80641475de19688f554e1b58a9b
MD5 82310e5915982c3d7935ccee7f9b40b9
BLAKE2b-256 6ce297044e683b5179cb0ebe698f58baba23af6391b92bc6df9870e147d9c0a4

See more details on using hashes here.

File details

Details for the file icdmap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: icdmap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for icdmap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6fbcbdddd3e0b69de1ca474b866d4cd1034b9aa9976204ba8782aaf541d2bbf3
MD5 fd5ed3fb6cb8b0029b8e758ae98eaebb
BLAKE2b-256 6789c727bb90e9c5c4f448d64fdb029a4fa5746cb1b90e2c0b6b0c9e41fa24f4

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