Updates to Django-SNOMED-CT (6/21)

Chimezie Ogbuji
3 min readJun 21, 2023

I recently made some changes to the django-snomed-ct open source library, a Django model and application for managing and querying the latest release of SNOMED-CT and its ICD-10 mappings. It is a library I use for Home Case Mixer in particular and homecare informatics software development in general. Below are some changes and examples of how they can be used.

In SNOMED-CT, there are two kinds of descriptions: fully specified names and synonyms. The Concept model has a by_fully_specified_name class method, mentioned in the project wiki, which returns a query set of Concepts whose fully specified name matches the query string. The recently added Concept.by_description class method has the same method signature as Concept.by_fully_specified_name. However, it returns a query set of Concepts whose synonyms match the search string.

You can find disorders with the phrase ‘munchausen’ in their fully specified name or synonym. This deprecated name has since been replaced in the DSM-5. Query sets of Concept model instances now have an ids method that returns their SNOMED-CT identifiers. So, using both methods, you can return the identifiers of these disorders that match this search criterion:

Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0]

In [1]: concepts=Concept.by_description('munchausen')
In [2]: pprint(list(concepts.fully_specified_names))
['(Personality: [hysterical] or [unstable (including instability)]) or '
'(personality disorder: [hysterical] or [unstable]) or (Munchausen syndrome)',
'(Personality: [hysterical] or [unstable (including instability)]) or '
'(personality disorder: [hysterical] or [unstable]) or (Munchausen syndrome)',
"Münchausen's syndrome (disorder)",
'Münchausen syndrome by proxy (disorder)',
"Munchausen's by proxy",
"Child affected by Munchausen's by proxy (finding)",
'Cutaneous Munchausen syndrome (disorder)',
'Cutaneous Munchausen syndrome by proxy (disorder)',
'(Personality: [hysterical] or [unstable (including instability)]) or '
'(personality disorder: [hysterical] or [unstable]) or (Munchausen syndrome) '
'(disorder)',
'(Personality: [hysterical] or [unstable (including instability)]) or '
'(personality disorder: [hysterical] or [unstable]) or (Munchausen syndrome) '
'(disorder)',
"Munchausen's by proxy (disorder)",
'Cutaneous Münchhausen syndrome (disorder)',
'Child affected by Münchausen by proxy (finding)',
'Cutaneous Münchhausen syndrome by proxy (disorder)',
'Munchausen syndrome by proxy (disorder)',
"Munchausen's syndrome (disorder)"]
In [3]: pprint(list(concepts.ids))
[154900000,
403586003,
403590001,
21586000,
95637005,
268758001,
401316003,
394514002]

A by_fully_specified_name_and_mapped class method was added to the Concept model. It serves mostly the same function as Concept.by_fully_specified_name (and has the same method signature), except it will only include SNOMED-CT concepts that have mappings to ICD-10. ICD10_MappingQuerySet instances now have a get_icd_codes method, which returns the ICD-10 codes (or code patterns, for mappings to multiple codes) for each item in the query set.

Finally, the ICD10_MappingManager model manager class now has a by_fully_specified_name method, which has the same method signature as Concept.by_fully_specified_name and can be used to return a query set of ICD10 mappings where each of the SNOMED-CT concept mapped has a fully specified name matching the given query string.

Below is a continuation of the example, showing how these methods can be used to find ICD-10 codes for this disorder by their SNOMED-CT fully specified name and get the mapped ICD-10 codes:

In [4]: concepts=Concept.by_fully_specified_name_and_mapped('munchausen')
In [5]: pprint(list(concepts.fully_specified_names))
["Münchausen's syndrome (disorder)",
'Münchausen syndrome by proxy (disorder)',
"Child affected by Munchausen's by proxy (finding)",
'Cutaneous Munchausen syndrome (disorder)',
'Cutaneous Munchausen syndrome by proxy (disorder)',
'Cutaneous Münchhausen syndrome (disorder)',
'Child affected by Münchausen by proxy (finding)',
'Cutaneous Münchhausen syndrome by proxy (disorder)',
'Munchausen syndrome by proxy (disorder)',
"Munchausen's syndrome (disorder)"]

In [6]: pprint(list(concepts.icd10_mappings().get_icd_codes()))
['F68.10', 'F68.A', 'F68.12', 'Y07.9', 'T74.12X?', 'F68.12', 'L98.1']

In [7]: pprint([str(m)
..: for m in ICD10_Mapping.objects.by_fully_specified_name('Munchausen')])
['L98.1 -> 403586003|Cutaneous Munchausen syndrome (disorder)',
'F68.12 -> 403590001|Cutaneous Munchausen syndrome by proxy (disorder)',
"Y07.9 -> 401316003|Child affected by Munchausen's by proxy (finding)",
"T74.12X? -> 401316003|Child affected by Munchausen's by proxy (finding)",
"F68.10 -> 21586000|Munchausen's syndrome (disorder)",
'F68.A -> 95637005|Munchausen syndrome by proxy (disorder)',
'F68.12 -> 95637005|Munchausen syndrome by proxy (disorder)']

--

--

Chimezie Ogbuji

An informatics engineer, data scientist, inventor, and business owner