MedCode#
Translating Between Medical Standards#
Healthcare data comes in many different coding systems and standards. PyHealth’s medical code mapping enables:
Cross-system mapping (e.g., ICD9CM → CCSCM, NDC → ATC)
Within-system ontology lookup (e.g., ancestors/descendants in ICD, ATC hierarchy)
Quick Examples#
from pyhealth.medcode import CrossMap, InnerMap
# Cross-system mapping: ICD-9-CM → CCS
icd9_to_ccs = CrossMap.load("ICD9CM", "CCSCM")
print(icd9_to_ccs.map("82101")) # example diagnosis code
# Drug code mapping: NDC → ATC
ndc_to_atc = CrossMap.load("NDC", "ATC")
print(ndc_to_atc.map("00527051210"))
# Within-system lookup: ICD-9-CM
icd9cm = InnerMap.load("ICD9CM")
print(icd9cm.lookup("428.0"))
print(icd9cm.get_ancestors("428.0"))
We provide medical code mapping tools for (i) ontology mapping within one coding system and (ii) mapping the same concept cross different coding systems.
- class pyhealth.medcode.InnerMap(vocabulary, refresh_cache=False)[source]#
Bases:
ABCContains information for a specific medical code system.
InnerMap is a base abstract class for all medical code systems. It will be instantiated as a specific medical code system with InnerMap.load(vocabulary).
Note
This class cannot be instantiated using __init__() (throws an error).
- classmethod load(vocabulary, refresh_cache=False)[source]#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- static standardize(code)[source]#
Standardizes a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- static convert(code, **kwargs)[source]#
Converts a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- class pyhealth.medcode.CrossMap(source_vocabulary, target_vocabulary, refresh_cache=False)[source]#
Bases:
objectContains mapping between two medical code systems.
CrossMap is a base class for all possible mappings. It will be initialized with two specific medical code systems with CrossMap.load(source_vocabulary, target_vocabulary).
- classmethod load(source_vocabulary, target_vocabulary, refresh_cache=False)[source]#
Initializes the mapping between two medical code systems.
- Parameters:
Examples
>>> from pyhealth.medcode import CrossMap >>> mapping = CrossMap("ICD9CM", "CCSCM") >>> mapping.map("428.0") ['108']
>>> mapping = CrossMap.load("NDC", "ATC") >>> mapping.map("00527051210", target_kwargs={"level": 3}) ['A11C']
- map(source_code, source_kwargs=None, target_kwargs=None)[source]#
Maps a source code to a list of target codes.
- Parameters:
source_code (
str) – source code.**source_kwargs (
Optional[Dict]) – additional arguments for the source code. Will be passed to self.s_class.convert(). Default is empty dict.**target_kwargs (
Optional[Dict]) – additional arguments for the target code. Will be passed to self.t_class.convert(). Default is empty dict.
- Return type:
- Returns:
A list of target codes.
Diagnosis codes:#
- class pyhealth.medcode.ICD9CM(**kwargs)[source]#
Bases:
InnerMap9-th International Classification of Diseases, Clinical Modification.
- static convert(code, **kwargs)#
Converts a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- get_ancestors(code)#
Gets the ancestors of the code.
- get_descendants(code)#
Gets the descendants of the code.
- classmethod load(vocabulary, refresh_cache=False)#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- lookup(code, attribute='name')#
Looks up the code.
- stat()#
Prints statistics of the code system.
- class pyhealth.medcode.ICD10CM(**kwargs)[source]#
Bases:
InnerMap10-th International Classification of Diseases, Clinical Modification.
- static convert(code, **kwargs)#
Converts a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- get_ancestors(code)#
Gets the ancestors of the code.
- get_descendants(code)#
Gets the descendants of the code.
- classmethod load(vocabulary, refresh_cache=False)#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- lookup(code, attribute='name')#
Looks up the code.
- stat()#
Prints statistics of the code system.
- class pyhealth.medcode.CCSCM(**kwargs)[source]#
Bases:
InnerMapClassification of Diseases, Clinical Modification.
- static convert(code, **kwargs)#
Converts a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- get_ancestors(code)#
Gets the ancestors of the code.
- get_descendants(code)#
Gets the descendants of the code.
- classmethod load(vocabulary, refresh_cache=False)#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- lookup(code, attribute='name')#
Looks up the code.
- static standardize(code)#
Standardizes a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- stat()#
Prints statistics of the code system.
Procedure codes:#
- class pyhealth.medcode.ICD9PROC(**kwargs)[source]#
Bases:
InnerMap9-th International Classification of Diseases, Procedure.
- static convert(code, **kwargs)#
Converts a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- get_ancestors(code)#
Gets the ancestors of the code.
- get_descendants(code)#
Gets the descendants of the code.
- classmethod load(vocabulary, refresh_cache=False)#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- lookup(code, attribute='name')#
Looks up the code.
- stat()#
Prints statistics of the code system.
- class pyhealth.medcode.ICD10PROC(**kwargs)[source]#
Bases:
InnerMap10-th International Classification of Diseases, Procedure.
- static convert(code, **kwargs)#
Converts a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- get_ancestors(code)#
Gets the ancestors of the code.
- get_descendants(code)#
Gets the descendants of the code.
- classmethod load(vocabulary, refresh_cache=False)#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- lookup(code, attribute='name')#
Looks up the code.
- static standardize(code)#
Standardizes a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- stat()#
Prints statistics of the code system.
- class pyhealth.medcode.CCSPROC(**kwargs)[source]#
Bases:
InnerMapClassification of Diseases, Procedure.
- static convert(code, **kwargs)#
Converts a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- get_ancestors(code)#
Gets the ancestors of the code.
- get_descendants(code)#
Gets the descendants of the code.
- classmethod load(vocabulary, refresh_cache=False)#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- lookup(code, attribute='name')#
Looks up the code.
- static standardize(code)#
Standardizes a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- stat()#
Prints statistics of the code system.
Medication codes:#
- class pyhealth.medcode.NDC(**kwargs)[source]#
Bases:
InnerMapNational Drug Code.
- static convert(code, **kwargs)#
Converts a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- get_ancestors(code)#
Gets the ancestors of the code.
- get_descendants(code)#
Gets the descendants of the code.
- classmethod load(vocabulary, refresh_cache=False)#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- lookup(code, attribute='name')#
Looks up the code.
- static standardize(code)#
Standardizes a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- stat()#
Prints statistics of the code system.
- class pyhealth.medcode.RxNorm(**kwargs)[source]#
Bases:
InnerMapRxNorm.
- static convert(code, **kwargs)#
Converts a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- get_ancestors(code)#
Gets the ancestors of the code.
- get_descendants(code)#
Gets the descendants of the code.
- classmethod load(vocabulary, refresh_cache=False)#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- lookup(code, attribute='name')#
Looks up the code.
- static standardize(code)#
Standardizes a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- stat()#
Prints statistics of the code system.
- class pyhealth.medcode.ATC(**kwargs)[source]#
Bases:
InnerMapAnatomical Therapeutic Chemical.
- get_ancestors(code)#
Gets the ancestors of the code.
- get_descendants(code)#
Gets the descendants of the code.
- classmethod load(vocabulary, refresh_cache=False)#
Initializes a specific medical code system inheriting from InnerMap.
- Parameters:
Examples
>>> from pyhealth.medcode import InnerMap >>> icd9cm = InnerMap.load("ICD9CM") >>> icd9cm.lookup("428.0") 'Congestive heart failure, unspecified' >>> icd9cm.get_ancestors("428.0") ['428', '420-429.99', '390-459.99', '001-999.99']
- lookup(code, attribute='name')#
Looks up the code.
- static standardize(code)#
Standardizes a given code.
Subclass will override this method based on different medical code systems.
- Return type:
- stat()#
Prints statistics of the code system.