Module reference

pymedtermino

PyMedTermino (Medical Terminologies for Python) is a Python module for easy access to the main medical terminologies in Python, including SNOMED CT, ICD10, MedDRA, UMLS and VCM icons.

PyMedTermino is available under the GNU LGPL licence, and it has been created by Jean-Baptiste Lamy, LIMICS, Paris 13 University, Sorbonne Paris Cité, INSERM UMRS 1142, Paris 6 University 74 rue Marcel Cachin 93017 Bobigny, France

This module includes Pymedtermino’s global parameters, the base classes for terminology-specific modules, and utility classes.

Global parameters

pymedtermino.DATA_DIR = '/home/jiba/src/pymedtermino'

the directory where SQLite3 database files containing terminologies are located. Default : PyMedTermino directory.

pymedtermino.LANGUAGE = 'en'

the default language used for terms, when several translations are available. If the desired language is not available, it defaults to English.

Warning

this parameter must be set BEFORE loading terminologies. Default : “en” (English).

pymedtermino.REMOVE_SUPPRESSED_CONCEPTS = True

if True, concepts tagged as suppressed or depreciated in terminologies are skipped.

pymedtermino.REMOVE_SUPPRESSED_TERMS = True

if True, terms (=translations) tagged as suppressed or depreciated in terminologies are skipped.

pymedtermino.REMOVE_SUPPRESSED_RELATIONS = True

if True, relations tagged as suppressed or depreciated in terminologies are skipped.

General functions

The following function can get any concept from a “terminology:code” string:

pymedtermino.get_concept(full_code)

Return a concept from a ‘full code’ including both terminology name and concept code (for example “icd10:I10”).

Bases classes

This module also defined the Terminology, Concept, Mapping classes that are used as base classes for the various terminologies.

class pymedtermino.Terminology(name)

Base class for all terminologies.

name

name of the terminology

first_levels()

Returns the root concepts in the terminology (=concepts without parents).

search(text)

Searches for concepts whose terms match the given text (free-text search).

Returns:a list of concept.
all_concepts(*args)

Retuns a generator for iterating over all concepts in the terminology.

all_concepts_no_double()

Retuns a generator for iterating over all concepts in the terminology, each concept being iterated only once (for multiaxial terminologies).

get(code)

Retuns the concept of the given code, or None if no such concept.

has_concept(code)

Retuns True if the terminology has a concept of the given code.

concept(code)

Retuns the concept of the given code; raise ValueError if it does not exist. Also available as Terminology[code] (i.e. Terminology.__getitem__).

class pymedtermino.Concept(code, term)

Base class for all concepts, in any terminology.

terminology

the terminology this concept is extracted from.

code = None

the code of the concept

term = None

the preferred term (i.e. label) of the concept

terms

the list of terms for this concept.

parents

the list of parent concepts.

Note

Concept.parents is always a list, even for terminologies with single inheritance (like ICD10). This allows to write terminology-independent code.

children

the list of children concepts.

relations

the list of the available relations for this concept. The available relations depend of the terminology, and is-a relations are not included (use parents and children attributes). Each relation corresponds to an attribute of the concept.

full_code()

Returns the ‘full code’ for this concept, including both terminology name and concept code (for example “icd10:I10”).

get_translation(language)

Returns the preferred term for this concept, in the given language. Not supported by all terminology.

get_translations(language)

Returns all concept’s terms, in the given language. Not supported by all terminology.

is_a(concept)

Returns True if this concept is a child of the given concept (or if both concepts are the same).

__rshift__(destination_terminology)

Maps the concept to the destination_terminology. See PyMedTermino tutorial for more info.

ancestors()

Returns a generator for iterating over all ancestors of this concept.

ancestors_no_double()

Returns a generator for iterating over all ancestors of this concept. Each concept is only yielded once (useful for multiaxial terminologies).

self_and_ancestors()

Returns a generator for iterating over all ancestors of this concept, including the concept itself.

self_and_ancestors_no_double()

Returns a generator for iterating over all ancestors of this concept, including the concept itself. Each concept is only yielded once (useful for multiaxial terminologies).

descendants()

Returns a generator for iterating over all descendants of this concept.

descendants_no_double()

Returns a generator for iterating over all descendants of this concept. Each concept is only yielded once (useful for multiaxial terminologies).

self_and_descendants()

Returns a generator for iterating over all descendants of this concept, including the concept itself.

self_and_descendants_no_double()

Returns a generator for iterating over all descendants of this concept, including the concept itself. Each concept is only yielded once (useful for multiaxial terminologies).

class pymedtermino.Mapping(terminology1, terminology2)

Base class for a mapping between two terminologies.

__call__(concepts)

Maps the given concept(s) using this mapping.

Note

You only need this method if you have several mappings with the same origin and destination terminologies. In other situations, you should rather use concept(s) >> destination_terminology.

terminology1 = None

origin terminology for the mapping

terminology2 = None

destination terminology for the mapping

register()

Registers the mapping as the default mapping between its origin and destination terminologies.

Utility classes

class pymedtermino.Concepts

A set of concepts. The set can contain each concept only once, and it inherits from Python’s set the methods for computing intersection, union, difference, ..., of two sets.

__rshift__(destination_terminology)

Maps the set of concepts to the destination_terminology. See PyMedTermino tutorial for more info.

find(parent_concept)

returns the first concept of the set that is a descendant of parent_concept (including parent_concept itself).

imply(other)

returns true if all concepts in the OTHER set are descendants of (at least) one of the concept in this set.

is_semantic_subset(other)

returns true if all concepts in this set are descendants of (at least) one of the concept in the OTHER set.

keep_most_specific(more_specific_than=None)

keeps only the most specific concepts, i.e. remove all concepts that are more general that another concept in the set.

keep_most_generic(more_generic_than=None)

keeps only the most general concepts, i.e. remove all concepts that are more specific that another concept in the set.

extract(parent_concept)

returns all concepts of the set that are descendant of parent_concept (including parent_concept itself).

subtract(parent_concept)

returns a new set after removing all concepts that are descendant of parent_concept (including parent_concept itself).

subtract_update(parent_concept)

same as func:subtract, but modify the set in place.

lowest_common_ancestors()

returns the lowest common ancestors between this set of concepts.

all_subsets()

returns all the subsets included in this set.

pymedtermino.snomedct

PyMedtermino module for SNOMEDCT.

class pymedtermino.snomedct.SNOMEDCT

The SNOMED CT terminology. See pymedtermino.Terminology for common terminology members; only SNOMED CT-specific members are described here.

CORE_problem_list()

Returns a generator iterating over all SNOMED CT concepts that are included in the CORE problem list.

class pymedtermino.snomedct.Group

A group, grouping several SNOMED CT relation together in the definition of a Concept.

class pymedtermino.snomedct.SNOMEDCTConcept(code)

A SNOMED CT concept. See pymedtermino.Concept for common terminology members; only SNOMED CT-specific members are described here.

is_in_core

True if this concept belongs to the SNOMED CT CORE problem list.

groups

A list of the groups in the concept’s definition. Each group include one or more relations, grouped together.

out_of_group

A special group that includes all relations that do not belongs to a group.

active

True if this concept is still active in SNOMED CT; False if it has been removed.

definition_status
module

Additional attributes are available for relations, and are listed in the relations attribute.

descendant_parts()

Returns the sub-parts of this concept, recursively.

ancestor_parts()

Returns the super-part of this concept, recursively.

associated_clinical_findings()

Return the clinical finding concepts associated to this concept (which is expected to be a anatomical structure, a morphology, etc).

pymedtermino.icd10

PyMedtermino module for ICD10. Currently supports English and (ATIH) French version of ICD10.

class pymedtermino.icd10.ICD10

The ICD10 terminology. See pymedtermino.Terminology for common terminology members; only ICD10-specific members are described here.

pymedtermino.icd10.ATIH_EXTENSION

If set to True, include ATIH extension to ICD10 (available only in French). Defaults to false. Must be set before loading ICD10 concepts.

class pymedtermino.icd10.Text(id, concept, relation, text, text_en, dagger, reference)

A text in an ICD10 definition for a concept (for example, an exclusion, and inclusion, etc).

get_translation(language)

Translates this text in the given language.

class pymedtermino.icd10.ICD10Concept(code)

An ICD10 concept. See pymedtermino.Concept for common terminology members; only ICD10-specific members are described here.

dagger
star
morbidity
mortality1
mortality2
mortality3
mortality4
atih_extension

True if the concept is an ATIH extension.

pmsi_restriction

Restriction of use of this concept for PMSI coding in France.

Additional attributes can be available, and are listed in the relations attribute.

pymedtermino.meddra

PyMedtermino module for MedDRA.

Several concepts can share the same code in MedDRA. For example, a preferred term (PT) and a low-level term (LLT) can have the same code and label. In order to distinguish them, PyMedTermino does not use directly the MedDRA codes, but associates the term’s level with the code to obtain a unique code, for example “SOC_10019805” or “PT_10069435”.

class pymedtermino.meddra.MEDDRA

The MedDRA terminology. See pymedtermino.Terminology for common terminology members; only MedDRA-specific members are described here.

first_levels()

Returns the root concepts in MedDRA (=the SOC), in international order.

get_by_meddra_code(meddra_code)

Returns a list of MedDRA concepts corresponding to the given MedDRA numeric code (e.g. 10073496).

class pymedtermino.meddra.MEDDRAConcept(code)

A MedDRA concept. See pymedtermino.Concept for common terminology members; only MedDRA-specific members are described here.

Additional attributes are available for relations, and are listed in the relations attribute.

meddra_code

The original numeric MedDRA code.

meddra_type

The type of MedDRA term (SOC, HLGT, HLT, PT or LLT).

abbrev

The abbreviated name associated to a SOC (only available for SOC).

international_order

The international order associated to a SOC (only available for SOC).

primary_soc

The primary SOC associated to a PT (only available for PT).

pymedtermino.cdf

PyMedtermino module for CDF (Thériaque French drug database).

class pymedtermino.cdf.CDF

The CDF terminology. See pymedtermino.Terminology for common terminology members; only CDF-specific members are described here.

A CDF to ICD10 mapping (from Thériaque) is also provided.

pymedtermino.cdf.connect_to_theriaque_db(host='', port='', user='theriaque', password='', db_name='theriaque', encoding='latin1')

Connects to a Thériaque PostgreSQL database. This function must be called before using CDF. Default values should be OK for a local Theriaque installation with PostgresQL.

class pymedtermino.cdf.CDFConcept(code)

A CDF concept. See pymedtermino.Concept for common terminology members; only CDF-specific members are described here.

Additional attributes are available for relations, and are listed in the relations attribute.

cdf_numero

The original CDF “numero” code.

cdf_code

The original CDF “code”.

pymedtermino.umls

PyMedtermino module for UMLS.

class pymedtermino.umls.UMLS_CUI

The UMLS CUI terminology (concepts). See pymedtermino.Terminology for common terminology members; only UMLS-specific members are described here.

class pymedtermino.umls.UMLS_AUI

The UMLS AUI terminology (atoms). See pymedtermino.Terminology for common terminology members; only UMLS-specific members are described here.

extract_terminology(original_terminology_name, has_int_code=0)

Extract a terminology from UMLS.

Parameters:
  • original_terminology_name – the name of the terminology in UMLS (see UMLS docs).
  • has_int_code – True if the source terminology uses integer code (in this case, PyMedtermino will accept both integer and string as code).
Returns:

a new terminology, that uses the source codes (and not UMLS AUI codes).

class pymedtermino.umls.UMLS_SRC

The UMLS SRC terminology (source terminology). See pymedtermino.Terminology for common terminology members; only UMLS-specific members are described here.

pymedtermino.umls.connect_to_umls_db(host, user, password, db_name='umls', encoding='latin1')

Connects to an UMLS MySQL database. This function must be called before using UMLS.

class pymedtermino.umls.UMLSConcept(code)

A UMLS concept. See pymedtermino.Concept for common terminology members; only UMLS-specific members are described here.

original_terminologies

The name of the terminology this concept comes from.

definitions

The concept’s definitions (if available); in a dict mapping original terminology names to the definition in these terminologies.

attributes
active

True if this concept is still active in UMLS; False if it has been removed / suppressed.

Additional attributes are available for relations, and are listed in the relations attribute.

pymedtermino.vcm

PyMedtermino module for VCM icons.

class pymedtermino.vcm.VCM

The VCM icons terminology. See pymedtermino.Terminology for common terminology members; only VCM-specific members are described here.

class pymedtermino.vcm.VCM_CONCEPT

The VCM medical concept terminology. It is used to describe the medical concept represented by VCM icons. See pymedtermino.Terminology for common terminology members; only VCM-specific members are described here.

class pymedtermino.vcm.VCM_CONCEPT_MONOAXIAL

A mono-axial (=single inheritance) version of pymedtermino.vcm.VCM_CONCEPT. All anatomical structures have been associated to a single parents. See pymedtermino.Terminology for common terminology members; only VCM-specific members are described here.

class pymedtermino.vcm.VCM_LEXICON

The VCM lexicon terminology. It describes the colors, shapes and pictograms used by VCM icons. See pymedtermino.Terminology for common terminology members; only VCM-specific members are described here.

class pymedtermino.vcm.VCMLexiconConcept(code)

A VCM lexicon concept. See pymedtermino.Concept for common terminology members; only VCM-specific members are described here.

VCM lexicon defines “graphical is a” relation in addition to standard “is a”. A concept A is considered as “graphically being” a concept B if (and only if) the pictogram associated to A include the pictogram associated to B.

category

The category of lexicon (0: central color, 1: modifier, etc).

graphical_parents

The list of concepts that are graphically more general than this one.

graphical_children

The list of concepts that are graphically more specific than this one.

abstract

True if this concept is a lexicon category, rather than a concrete color, shape or pictogram.

empty

True if this concept is an ‘empty’ lexicon, such as “no pictogram”.

priority

The priority of this lexicon concept, for icon sorting.

second_priority

The second priority of this lexicon concept, for icon sorting. Only used (non-zero) for some transverse modifiers ; these modifiers use a different priority if they are used along with a central pictogram or not.

Additional attributes can be available, listed in the relations attribute.

is_graphically_a(concept)

Same as pymedtermino.Concept.is_a() but using “graphically is a” relation rather than standard “is a”.

graphical_ancestors()

Same as pymedtermino.Concept.ancestors() but using “graphically is a” relation rather than standard “is a”.

graphical_descendants()

Same as pymedtermino.Concept.descendants() but using “graphically is a” relation rather than standard “is a”.

self_and_graphical_ancestors()

Same as pymedtermino.Concept.self_and_ancestors() but using “graphically is a” relation rather than standard “is a”.

self_and_graphical_ancestors_no_double()

Same as pymedtermino.Concept.self_and_ancestors_no_double() but using “graphically is a” relation rather than standard “is a”.

self_and_graphical_descendants()

Same as pymedtermino.Concept.self_and_descendants() but using “graphically is a” relation rather than standard “is a”.

self_and_graphical_descendants_no_double()

Same as pymedtermino.Concept.self_and_descendants_no_double() but using “graphically is a” relation rather than standard “is a”.

graphical_ancestors_no_double(already=None)

Same as pymedtermino.Concept.ancestors_no_double() but using “graphically is a” relation rather than standard “is a”.

graphical_descendants_no_double(already=None)

Same as pymedtermino.Concept.descendants_no_double() but using “graphically is a” relation rather than standard “is a”.

class pymedtermino.vcm.VCMIcon(code)

A VCM icon (=a concept in the VCM terminology). See pymedtermino.Concept for common terminology members; only VCM-specific members are described here.

lexs

The list of lexicon concept in this icon.

physio
patho
etiology
quantitative
process
transverse

All these attributes returns the shape modifier of the corresponding category (or None if no such modifiers).

short_code

The short icon code, compressed.

long_code

The entire icon code, including optional component.

consistent

True if the icon is consistent, according to the VCM ontology.

concepts

The set of VCM medical concepts associated to this icon.

priority

The priority of this icon (for sorting purpose).

derive(central_color=None, modifiers=None, central_pictogram=None, top_right_color=None, top_right_pictogram=None, second_top_right_pictogram=None, shadow=None)

Creates and returns a new VCM icon, using this icon as a string point, and adding the given VCM lexicon concepts.

derive_lexs(lexs)

Creates and returns a new VCM icon, using this icon as a string point, and adding the given VCM lexicon concepts, as a list.

is_graphically_a(concept)

Same as pymedtermino.Concept.is_a() but using “graphically is a” relation rather than standard “is a”.

pymedtermino.vcm.keep_most_graphically_specific_icons(self, on_del=None)

keeps only the most specific icons, i.e. remove all concepts that are more general that another concept in the set, using “graphical is a” relations.

Parameters:
  • self – the list of icons.
  • on_del – an optional callable, called for each icon removed.
Returns:

the new list of icons.

pymedtermino.vcm.keep_most_graphically_generic_icons(self, on_del=None, add_shadow=1)

keeps only the most generic icons, i.e. remove all concepts that are more general that another concept in the set, using “graphical is a” relations.

Parameters:
  • self – the list of icons.
  • on_del – an optional callable, called for each icon removed.
  • add_shadow – if True, automatically adds shadow below icons that are present several times.
Returns:

the new list of icons.

pymedtermino.vcm.generalize_icons(icons, on_del=None, fail_if_too_much_information_is_lost=0)

Generalizes the given list of icons, and returns the lowest common ancestor icon.

Parameters:
  • icons – the list of icons.
  • on_del – an optional callable, called for each icon removed.
  • fail_if_too_much_information_is_lost – if True, returns None when too much information is lost (i.e. central pictogram).
Returns:

the new list of icons.

pymedtermino.vcm.simplify_icons(icons, on_del=None)

Simplifies the given list of icons, and returns a new list. The list is simplified by keeping the lowest common ancestor icons, whenever possible without loosing any central pictograms.

Parameters:
  • icons – the list of icons.
  • on_del – an optional callable, called for each icon removed.
Returns:

the new list of icons.

pymedtermino.vcm.remove_duplicate_icons(icons, on_del=None, add_shadow=1)

Removes dupplicated icons in the given list, and returns a new list.

Parameters:
  • icons – the list of icons.
  • on_del – an optional callable, called for each icon removed.
  • add_shadow – if True, automatically adds shadow below icons that are present several times.
Returns:

the new list of icons.