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.1.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.1-py3-none-any.whl (2.2 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: icdmap-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6c52e81ea331a08eaf3ca37f28cd6b1ae2483ab2438738182be7e9b2c88d44e2
MD5 efc6028ceb76f7262d46c49619d97fc0
BLAKE2b-256 03d5fc89f6f57db201d82ae14d1146d85dffb36a2d200cfa06b85befdfa96a0b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: icdmap-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 968adae24ced5525aa81b27c1a596c268a7087175be04e44eb60b905fd6b0955
MD5 561205ee71ae5224d803756f00af0bd3
BLAKE2b-256 87a7c4f2481fb87f54585c111f793640174622630a33a80ccd7a4e8cd964a05b

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