Coding icd10

From maziyarpanahi/openmed · View interactive version

Coding icd10 is an AI agent skill from the GitHub repository maziyarpanahi/openmed. Suggests candidate ICD-10-CM diagnosis codes (and ICD-10-PCS procedure codes) for diagnoses and procedures extracted by OpenMed, with rationale and a human-coder caveat. Use when the user wants to code a problem list, map a diagnosis span to a billable ICD-10-CM code, route a finding to the right ch

How to use this skill

Skill file

Coding OpenMed diagnoses to ICD-10-CM / PCS

Suggest ICD-10-CM diagnosis codes (and ICD-10-PCS for inpatient

procedures) for the diagnosis and procedure spans OpenMed extracts. This is

decision support for a certified coder, not autonomous billing: OpenMed +

this skill narrow the candidate set and explain why; a human validates the

final, billable code.

ICD-10-CM and ICD-10-PCS are public domain. CMS publishes the complete

annual code files, addenda, and indexes for free. (CPT/HCPCS procedure codes are

AMA-licensed and restricted — out of scope here; obtain those separately

under the user's own AMA license.)

When to use

acquired pneumonia") and you want candidate ICD-10-CM codes plus rationale.

(see references/icd10-chapters.md for code ranges).

For clinical-meaning codes use mapping-to-snomed; for HCC/risk capture use

coding-hcc-risk-adjustment; this skill is for the ICD-10 classification.

Quick start (public data + public FHIR lookup)

Two complementary paths, both license-clean:

A) CMS files, loaded locally (public domain; you download once):

# CMS publishes the order/addenda file; load the code->description table.
# Columns: code (no dot), description; you insert the dot for display.
icd10cm = {}                       # "E1122" -> "Type 2 diabetes mellitus with diabetic chronic kidney disease"
with open("icd10cm_order_2025.txt", encoding="latin-1") as fh:
    for line in fh:
        code = line[6:13].strip()
        billable = line[14] == "1"     # '1' = valid billable code
        long_desc = line[77:].strip()
        if billable:
            icd10cm[code] = long_desc

def search_local(term: str, limit: int = 5):
    t = term.lower()
    hits = [(c, d) for c, d in icd10cm.items() if t in d.lower()]
    return sorted(hits, key=lambda cd: len(cd[1]))[:limit]

B) A FHIR terminology server that hosts ICD-10-CM (public servers exist;

e.g. an NLM Clinical Tables endpoint or your own HAPI/Ontoserver):

import requests

# NLM Clinical Tables (public, no key) — ICD-10-CM autocomplete/search:
def search_icd10cm(term: str, count: int = 7):
    r = requests.get(
        "https://clinicaltables.nlm.nih.gov/api/icd10cm/v3/search",
        params={"sf": "code,name", "terms": term, "maxList": count}, timeout=10,
    )
    r.raise_for_status()
    _total, codes, _extra, display = r.json()
    return list(zip(codes, [d[1] for d in display]))   # [(code, name), ...]

print(search_icd10cm("type 2 diabetes nephropathy"))

Workflow

  1. Extract diagnosis/procedure spans with OpenMed (Disease/Pathology models).
  2. Route to a chapter using the span's clinical theme and

references/icd10-chapters.md (e.g. endocrine → E00–E89, circulatory →

I00–I99). This shrinks the search space and catches obvious mis-hits.

  1. Search the code text (local CMS table or the NLM API) for candidates.
  2. Apply ICD-10-CM specificity rules in your rationale: laterality,

acute/chronic, episode of care, "with"/"due to" combination codes, and

"code first / use additional code" notes. Flag where the note lacks the detail

a billable code requires.

  1. Rank candidates; present the top few **with rationale and the missing-

detail caveat**, not a single auto-selected code.

  1. Emit {system: "http://hl7.org/fhir/sid/icd-10-cm", code, display}

marked status: needs-coder-review, with OpenMed source offsets.

Hand-off from OpenMed

openmed.analyze_text(..., output_format="dict") returns entities, each a dict

with text, label, confidence, start, end. Consume Disease/Pathology

spans:

import openmed

note = "Assessment: type 2 diabetes with diabetic nephropathy; CAP."
result = openmed.analyze_text(
    note,
    model_name="disease_detection_superclinical",   # Disease category
    output_format="dict",
)

DX_LABELS = {"DISEASE", "CONDITION", "PATHOLOGY"}
for ent in result["entities"]:
    if ent["label"] in DX_LABELS:
        candidates = search_icd10cm(ent["text"], count=5)
        print(ent["text"], ent["start"], ent["end"],
              f"(conf {ent['confidence']:.2f}) ->", candidates)
        # surface as SUGGESTIONS for a coder — never auto-bill

Keep OpenMed's start/end offsets next to each suggested code so the coder can

jump to the exact supporting text. Store offsets and codes only — never the raw

note in your suggestion log.

Edge cases & gotchas

weight. Output candidates with rationale; a certified coder assigns the final

billable code. Never present a suggestion as an authorized claim.

episode, or "with" detail the note may not state. Prefer flagging "documentation

insufficient for a specific code" over forcing an .9/unspecified code.

diabetes with diabetic CKD). Don't emit two separate codes where one

combination code is required; let the search surface combinations.

change which codes coexist. Carry these as rationale for the coder.

many-to-many and lossy; treat a GEM result as a starting hint, not a billable

mapping.

you loaded and refresh annually; record which version produced a suggestion.

proprietary code maps that require an AMA/other license — those stay

user-supplied and out-of-process.

the de-identified diagnosis string. No PHI over the wire.

Standards & references

https://www.cms.gov/medicare/coding-billing/icd-10-codes/icd-10-cm-cms-hcc

and https://www.cms.gov/medicare/coding-billing/icd-10-codes

https://www.cms.gov/medicare/coding-billing/icd-10-codes/icd-10-pcs

https://clinicaltables.nlm.nih.gov/apidoc/icd10cm/v3/doc.html

https://www.cms.gov/medicare/coding-billing/icd-10-codes/icd-10-cm-pcs-gems-archive

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.