simple-icd-10-cm 1.2.0__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Stefano Travasci
3
+ Copyright (c) 2021-2025 Stefano Travasci
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: simple_icd_10_cm
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: A simple python library for ICD-10-CM codes
5
5
  Home-page: https://github.com/StefanoTrv/simple_icd_10_CM
6
6
  Author: Stefano Travasci
@@ -12,6 +12,16 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.9
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: keywords
22
+ Dynamic: license-file
23
+ Dynamic: requires-python
24
+ Dynamic: summary
15
25
 
16
26
  # simple_icd_10_cm
17
27
  A simple python library for ICD-10-CM codes
@@ -20,6 +30,7 @@ A simple python library for ICD-10-CM codes
20
30
  * [Release notes](#release-notes)
21
31
  * [Introduction](#introduction)
22
32
  * [Setup](#setup)
33
+ * [Using other ICD-10-CM releases](#using-other-icd-10-cm-releases)
23
34
  * [The format of the codes](#the-format-of-the-codes)
24
35
  * [About the file "Instructional Notations.md"](#about-the-file-instructional-notationsmd)
25
36
  * [Blocks containing only one category](#blocks-containing-only-one-category)
@@ -55,11 +66,19 @@ A simple python library for ICD-10-CM codes
55
66
  * [get_index(code)](#get_indexcode)
56
67
  * [remove_dot(code)](#remove_dotcode)
57
68
  * [add_dot(code)](#add_dotcode)
69
+ * [change_version(all_codes_file_path=None, classification_data_file_path=None)](#change_versionall_codes_file_pathnone-classification_data_file_pathnone)
58
70
  * [Conclusion](#conclusion)
59
71
 
60
72
  ## Release notes
73
+ * **1.3.0**:
74
+ * Users can now use their preferred ICD-10-CM release by providing properly formatted files as inputs
75
+ * The default ICD-10-CM release of the library is now the **April 2025 release**
76
+ * Renamed some internal variables (you should not have been using them anyway!)
77
+ * Dropped Conda support, older versions are still available
78
+ * Added type hints for optional parameters
79
+ * **1.2.0**: Added type hints - thanks to @JosephSBoyle on GitHub
61
80
  * **1.1.2**: Minor fix in get_full_data
62
- * **1.1.1**: Fixed minor error in the release
81
+ * **1.1.1**: Fixed a minor error in the release
63
82
  * **1.1.0**: Fixed a bug that caused many codes not to be included
64
83
  * **1.0.5**: Fixed a minor bug that affected get_nearest_common_ancestor(a,b) when a and b were the same code but written in different formats.
65
84
  * **1.0.4**: Managed to get the built package to read the data files
@@ -67,9 +86,14 @@ A simple python library for ICD-10-CM codes
67
86
 
68
87
  ## Introduction
69
88
  The objective of this library is to provide a simple instrument for dealing with **ICD-10-CM** codes in Python. It provides ways to check whether a code exists, find its ancestors and descendants, see the data associated with it, including its description, and much more.
70
- If you are looking for a library that deals with ICD-10 codes instead of ICD-10-CM codes, you can check the [simple_icd_10 library](https://github.com/StefanoTrv/simple_icd_10), which is based on the 2019 version of ICD-10.
89
+ If you are looking for a library that deals with ICD-10 codes instead of ICD-10-CM codes, you can check the [simple_icd_10 library](https://github.com/StefanoTrv/simple_icd_10), which is based on the 2019 version of ICD-10. If you are interested in the ICD-11 MMS classification, you can check out instead the [simple_icd_11 library](https://github.com/StefanoTrv/simple_icd_11).
90
+ There is also a Java version of this library, [SimpleICD10CM-Java-edition](https://github.com/StefanoTrv/SimpleICD10CM-Java-edition).
71
91
 
72
- The data used in this library was taken from the websites of the CDC and of the CMS. This library currently uses the **January 2021 release of ICD-10-CM**.
92
+ The data used in this library was taken from the [website of the CDC]((https://www.cdc.gov/nchs/icd/icd-10-cm/files.html). This library currently uses the **April 2025 release of ICD-10-CM**. This package can be configured to use other releases of the ICD-10-CM classification, read the section [Using other ICD-10-CM releases](#using-other-icd-10-cm-releases) for more details.
93
+
94
+ If you feel like supporting me, please check out the [Conclusion section](#conclusion).
95
+
96
+ simple_icd_10_cm is licensed under [the MIT License](https://github.com/StefanoTrv/simple_icd_10_cm/blob/master/LICENSE).
73
97
 
74
98
  ## Setup
75
99
  You can install the package with pip, using this command:
@@ -77,22 +101,41 @@ You can install the package with pip, using this command:
77
101
  pip install simple-icd-10-cm
78
102
  ```
79
103
 
80
- You can also install the package with conda, using the following command:
81
- ```bash
82
- conda install -c stefanotrv simple_icd_10_cm
83
- ```
104
+ The distribution files are also available as [releases in the Github repository](https://github.com/StefanoTrv/simple_icd_10_cm/releases).
84
105
 
85
106
  You can also use the "simple_icd_10_cm.py" file, which contains all the source code, in conjunction with the "data" folder, which contains the data used in this library (you can find them in the [GitHub repository](https://github.com/StefanoTrv/simple_icd_10_CM)).
86
107
 
108
+ ### Using other ICD-10-CM releases
109
+ You can use other releases of ICD-10-CM by providing properly formatted data files.
110
+
111
+ The default release is automatically loaded when the package is imported. Therefore, no further setup is required for users who want to use the default release. On the other hand, it is loaded even if the user wants to load a different release, resulting in additional unnecessary overhead. Since most users are expected to use the default release, and to guarantee backward compatibility with earlier versions of the library, this approach was considered the best overall compromise.
112
+
113
+ The function that allows to use different releases is the `change_version` function. It takes two optional arguments `all_codes_file_path` and `classification_data_file_path`, which specify, respectively, the path to the file containing a list of all the codes and the path to the XML file containing the whole structured classification. These files are described in more detail later. If both paths are provided, `change_version` loads the ICD-10-CM release described in those files. If both parameters are left empty, it loads the default release. If one parameter is provided and the other is left empty, `change_version` raises a `ValueError` exception.
114
+ ```python
115
+ # loads the files of another release
116
+ cm.change_version(all_codes_file_path="code-list-January-2021.txt",classification_data_file_path="icd10cm_tabular_2021.xml")
117
+
118
+ # loads the default release
119
+ cm.change_version()
120
+
121
+ # these both raise an exception
122
+ cm.change_version(all_codes_file_path="code-list-January-2021.txt")
123
+ cm.change_version(classification_data_file_path="icd10cm_tabular_2021.xml")
124
+ ```
125
+
126
+ The file specified in `all_codes_file_path` should contain all the unique codes of the desired release. However, it is sufficient that it contains all the seven-characters codes that must be generated programmatically, that is all the valid codes that are not explicitly listed in the XML file (see [About the special seventh character](#about-the-special-seventh-character) for more information). Each line in this file must contain a single code. Codes can be written in the format with or without the dot. In each line, the code may be followed by any text, as long as there is at least one space character immediately after the code. The `icd10cm-codes` text files available from the [CDC's website](https://www.cdc.gov/nchs/icd/icd-10-cm/files.html) can be used for this purpose, without modification.
127
+ The file specified in `classification_data_file_path` is the XML containing the whole classification. This typically corresponds to the `icd10cm-tabular` XML files available from the [CDC's website](https://www.cdc.gov/nchs/icd/icd-10-cm/files.html). If using XML files from another origin, note that, in the official releases, the first two children of the root XML element are not part of the structure of the classification, and are therefore skipped by the library.
128
+ Examples of both file types can be found in the [all-data folder](https://github.com/StefanoTrv/simple_icd_10_CM/tree/master/all-data), which includes data for the current default release and for a previous release.
129
+
87
130
  ## The format of the codes
88
- The codes of subcategories can be written in two different ways: with a dot (for example "I13.1") and with no dot (for example "I131"). The functions in this library can receive as input codes in both these formats. The codes returned by the functions will always be in the format with the dot.
131
+ Subcategories codes can be written in two different ways: with a dot (for example "I13.1") and with no dot (for example "I131"). The functions in this library can receive as input codes in both these formats. The codes returned by the functions will always be in the format with the dot.
89
132
  You can easily change the format of a code by using the [`remove_dot`](#remove_dotcode) and [`add_dot`](#add_dotcode) functions.
90
133
 
91
134
  ## About the file "Instructional Notations.md"
92
- The file [Instructional Notations.md](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) contains the introduction present in the file `icd10cm_tabular_2021.xml` (the file that contains the whole ICD-10-CM classification), copied there in a more accessible and readable format. There you can find an explanation about the meaning of most of the additional fields that can accompany a code.
135
+ The file [Instructional Notations.md](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) contains the introduction present in the file `icd10cm-tabular-April-2025.xml` (the file that contains the whole ICD-10-CM classification), copied there in a more accessible and readable format. There you can find an explanation about the meaning of most of the additional fields that can accompany a code.
93
136
 
94
137
  ## Blocks containing only one category
95
- Unlike ICD-10, ICD-10-CM includes blocks of categories that contain only one (and its subcategories). These blocks are named after the category that they contain, which means that ICD-10-CM contains blocks and categories that have the same exact code. This is a problem: because of this questionable decision, we can't know for sure if the code "B99", for example, refers to the category "B99" or to the block with the same name. This can be seen in the following example, where "B99" is recognized as both a block and a category:
138
+ Unlike ICD-10, ICD-10-CM includes blocks of categories that contain only one category (and its subcategories). These blocks are named after the category that they contain, which means that ICD-10-CM contains blocks and categories that have the same exact code. This is a problem: because of this questionable decision, we can't know for sure if the code "B99", for example, refers to the category "B99" or to the block with the same name. This can be seen in the following example, where "B99" is recognized as both a block and a category:
96
139
  ```python
97
140
  cm.is_block("B99")
98
141
  #True
@@ -115,9 +158,10 @@ cm.is_block("I12") and cm.is_category("I12")
115
158
  ```
116
159
 
117
160
  ## About the special seventh character
118
- The file `icd10cm_tabular_2021.xml`, which is the XML file that contains the whole ICD-10-CM classification, doesn't have an entry for each code generated by adding the "special" seventh character, but it contains rules that explain how to generate these codes in the "sevenChrDef" field (and sometimes in the "sevenChrNote" field too, just to complicate things a little bit...). You can find more about the structure of these particular codes in [Instructional Notations.md](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md).
119
- Due to the lack of a complete entry for these codes, I had to decide how they would be handled in this library. So I decided that their only field would be the description, composed of the description of their parent followed by the description of the meaning of the additional character, with a comma between the two: this description appears in official documents about ICD-10-CM (for example in the file `icd10cm-order-Jan-2021.txt`), so it's not my invention but the actual official format. All the other fields are empty, but the optional argument `search_in_ancestors` of certain functions can be used to automatically retrieve the content of certain fields from the ancestors of the code (see the description of the specific functions in the [Documentation](#documentation) for more details).
120
- If you need to know whether a code has been automatically generated using a rule described in a "sevenChrDef" field, you can use the [`is_extended_subcategory`](#is_extended_subcategorycode) function.
161
+ The file `icd10cm-tabular-April-2025.xml`, which is the XML file that contains the whole ICD-10-CM classification, doesn't have an entry for all the codes generated by adding the "special" seventh character, but it often contains instead rules that explain how to generate these codes in the "sevenChrDef" field (and sometimes in the "sevenChrNote" field too, just to complicate things a little bit...). You can find more about the structure of these particular codes in [Instructional Notations.md](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md).
162
+ Due to the lack of a complete entry for these missing codes, I had to decide how they would be handled in this library. So I decided that their only field would be the description, composed of the description of their parent followed by the description of the meaning of the additional character, with a comma between the two: this description appears in official documents about ICD-10-CM, so it's not my invention but the actual official format. All the other fields are empty, but the optional argument `search_in_ancestors` of certain functions can be used to automatically retrieve the content of certain fields from the ancestors of the code (see the description of the specific functions in the [Documentation](#documentation) for more details).
163
+ Seven-characters codes that have an entry in `icd10cm-tabular-April-2025.xml` are treated like any other code, and their data is taken directly from the file.
164
+ If you need to know whether a code has been automatically generated using a rule described in a "sevenChrDef" field, you can use the [`is_extended_subcategory`](#is_extended_subcategorycode) function. Only the codes generated programmatically are classified as "extended subcategories", the seven-characters codes explicitly listed in the data are classified as "subcategories".
121
165
 
122
166
  ## Documentation
123
167
  Here I list all the functions provided by this library and describe how to use them. If you are interested in a more interactive introduction to simple_icd_10_cm, please take a look at the Jupyter Notebook ["Showcase notebook.ipynb"](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Showcase%20notebook.ipynb); there you can also find more examples.
@@ -175,7 +219,7 @@ cm.is_category("14")
175
219
  #False
176
220
  ```
177
221
  ### is_subcategory(code, include_extended_subcategories=True)
178
- This function takes a string as input and returns True if the string is a valid subcategory in ICD-10-CM, False otherwise. By setting the optional argument `include_extended_subcategories` to False, this function will also return False if the string is a valid subcategory obtained by adding the 7th character to another code (see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) for more information).
222
+ This function takes a string as input and returns True if the string is a valid subcategory in ICD-10-CM, False otherwise. By setting the optional argument `include_extended_subcategories` to False, this function will also return False if the string is a valid subcategory obtained by programmatically adding the 7th character to another code (see [About the special seventh character](#about-the-special-seventh-character) and [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) for more information).
179
223
  ```python
180
224
  cm.is_subcategory("B95.1")
181
225
  #True
@@ -185,14 +229,18 @@ cm.is_subcategory("S12.000G")
185
229
  #True
186
230
  cm.is_subcategory("S12.000G", include_extended_subcategories=False)
187
231
  #False
232
+ cm.is_subcategory("C44.1192", include_extended_subcategories=False)
233
+ #True
188
234
  ```
189
235
  ### is_extended_subcategory(code)
190
- This function takes a string as input and returns True if the string is a valid subcategory in ICD-10-CM obtained by adding the 7th character to another code (see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) for more information), False otherwise.
236
+ This function takes a string as input and returns True if the string is a valid subcategory in ICD-10-CM obtained by programmatically adding the 7th character to another code (see [About the special seventh character](#about-the-special-seventh-character) and [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) for more information), False otherwise.
191
237
  ```python
192
238
  cm.is_extended_subcategory("S12.000G")
193
239
  #True
194
240
  cm.is_extended_subcategory("S12.000")
195
241
  #False
242
+ cm.is_extended_subcategory("C44.1192")
243
+ #False
196
244
  ```
197
245
  ### get_description(code, prioritize_blocks=False)
198
246
  This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing its description, otherwise it raises a ValueError. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
@@ -238,7 +286,7 @@ cm.get_inclusion_term("J37.0")
238
286
  #['Catarrhal laryngitis', 'Hypertrophic laryngitis', 'Sicca laryngitis']
239
287
  ```
240
288
  ### get_seven_chr_note(code, search_in_ancestors=False, prioritize_blocks=False)
241
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing the data of the "sevenChrNote" field of this code, otherwise it raises a ValueError. If this code does not have an "sevenChrNote" field, it returns an empty string. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "sevenChrNote" field but one of its ancestor does, the "sevenChrNote" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
289
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing the data of the "sevenChrNote" field of this code, otherwise it raises a ValueError. If this code does not have a "sevenChrNote" field, it returns an empty string. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "sevenChrNote" field but one of its ancestor does, the "sevenChrNote" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
242
290
  ```python
243
291
  cm.get_seven_chr_note("I82.40")
244
292
  #''
@@ -250,7 +298,7 @@ cm.get_seven_chr_note("R40.241",search_in_ancestors=True)
250
298
  #'The following appropriate 7th character is to be added to subcategory R40.24-:'
251
299
  ```
252
300
  ### get_seven_chr_def(code, search_in_ancestors=False, prioritize_blocks=False)
253
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **dictionary** containing the data of the "sevenChrDef" field of this code, otherwise it raises a ValueError. The dictionary maps the seventh character to a string that contains its meaning. If this code does not have an "sevenChrDef" field, it returns an empty list. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "sevenChrDef" field but one of its ancestor does, the "sevenChrDef" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
301
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **dictionary** containing the data of the "sevenChrDef" field of this code, otherwise it raises a ValueError. The dictionary maps the seventh character to a string that contains its meaning. If this code does not have a "sevenChrDef" field, it returns an empty list. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "sevenChrDef" field but one of its ancestor does, the "sevenChrDef" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
254
302
  ```python
255
303
  cm.get_seven_chr_def("I82.40")
256
304
  #{}
@@ -288,7 +336,7 @@ cm.get_use_additional_code("R65.20",search_in_ancestors=True)
288
336
  # hepatic failure (K72.0-)'
289
337
  ```
290
338
  ### get_code_first(code, search_in_ancestors=False, prioritize_blocks=False)
291
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing the data of the "codeFirst" field of this code, otherwise it raises a ValueError. If this code does not have an "codeFirst" field, it returns an empty string. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "codeFirst" field but one of its ancestor does, the "codeFirst" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
339
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing the data of the "codeFirst" field of this code, otherwise it raises a ValueError. If this code does not have a "codeFirst" field, it returns an empty string. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "codeFirst" field but one of its ancestor does, the "codeFirst" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
292
340
  ```python
293
341
  cm.get_code_first("I82.41")
294
342
  #''
@@ -357,7 +405,7 @@ cm.get_descendants("S14.109S")
357
405
  #[]
358
406
  ```
359
407
  ### is_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
360
- This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns True if the first string is an ancestor of the second string. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and in `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
408
+ This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns True if the first string is an ancestor of the second string. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
361
409
  ```python
362
410
  cm.is_ancestor("18","R01.0")
363
411
  #True
@@ -369,7 +417,7 @@ cm.is_ancestor("B99","B99",prioritize_blocks_a=True)
369
417
  #True
370
418
  ```
371
419
  ### is_descendant(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
372
- This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns True if the first string is a descendant of the second string. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and in `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
420
+ This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns True if the first string is a descendant of the second string. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
373
421
  ```python
374
422
  cm.is_descendant("R01.0","18")
375
423
  #True
@@ -377,7 +425,7 @@ cm.is_descendant("M31","K00-K14")
377
425
  #False
378
426
  ```
379
427
  ### get_nearest_common_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
380
- This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns their nearest common ancestor if it exists, an empty string if it doesn't exist. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and in `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
428
+ This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns their nearest common ancestor if it exists, an empty string if it doesn't exist. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
381
429
  ```python
382
430
  cm.get_nearest_common_ancestor("H28","H25.1")
383
431
  #'H25-H28'
@@ -385,7 +433,7 @@ cm.get_nearest_common_ancestor("K35","E21.0")
385
433
  #''
386
434
  ```
387
435
  ### is_leaf(code, prioritize_blocks=False)
388
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns True if it's a leaf in the ICD-10-CM classification (that is, if it has no children), otherwise it returns False. If the string is not a valid ICD-10-CM code it raises a ValueError. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
436
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns True if it's a leaf in the ICD-10-CM classification (that is, if it has no children), otherwise it returns False. If the string is not a valid ICD-10-CM code, it raises a ValueError. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
389
437
  ```python
390
438
  cm.is_leaf("12")
391
439
  #False
@@ -429,8 +477,11 @@ cm.add_dot("K00-K14")
429
477
  #'K00-K14'
430
478
  ```
431
479
 
480
+ ### change_version(all_codes_file_path=None, classification_data_file_path=None)
481
+ This function can be used to load any ICD-10-CM release provided by the user, or to revert to using the default release for the package. Its usage is explained in the paragraph [Using other ICD-10-CM releases](#using-other-icd-10-cm-releases).
482
+
432
483
  ## Conclusion
433
- This should be everything you need to know about the simple_icd_10_cm library. Please contact me if you find any mistake, bug, missing feature or anything else that could be improved or made easier to comprehend, both in this documentation and in the library itself as well as in the [Showcase notebook](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Showcase%20notebook.ipynb). You can also contact me if you need any help using this library, but I may not be able to help with questions about the ICD-10-CM classification itself. This library currently only support the January 2021 release of ICD-10-CM: let me know if you'd like me to implement the ability to switch between different versions of ICD-10-CM, and also tell me which release or releases you are interested in.
484
+ This should be everything you need to know about the simple_icd_10_cm library. Please contact me if you find any mistake, bug, missing feature or anything else that could be improved or made easier to comprehend, both in this documentation and in the library itself as well as in the [Showcase notebook](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Showcase%20notebook.ipynb). You can also contact me if you need any help using this library, but I may not be able to help with questions about the ICD-10-CM classification itself.
434
485
 
435
486
  If you find this library useful and are feeling generous, consider making a donation using one of the methods listed at the end of this document.
436
487
 
@@ -1,18 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: simple-icd-10-cm
3
- Version: 1.2.0
4
- Summary: A simple python library for ICD-10-CM codes
5
- Home-page: https://github.com/StefanoTrv/simple_icd_10_CM
6
- Author: Stefano Travasci
7
- Author-email: stefanotravasci@gmail.com
8
- Keywords: ICD-10-CM ICD-10 icd 10 CM codes clinical modification
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.9
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
-
16
1
  # simple_icd_10_cm
17
2
  A simple python library for ICD-10-CM codes
18
3
 
@@ -20,6 +5,7 @@ A simple python library for ICD-10-CM codes
20
5
  * [Release notes](#release-notes)
21
6
  * [Introduction](#introduction)
22
7
  * [Setup](#setup)
8
+ * [Using other ICD-10-CM releases](#using-other-icd-10-cm-releases)
23
9
  * [The format of the codes](#the-format-of-the-codes)
24
10
  * [About the file "Instructional Notations.md"](#about-the-file-instructional-notationsmd)
25
11
  * [Blocks containing only one category](#blocks-containing-only-one-category)
@@ -55,11 +41,19 @@ A simple python library for ICD-10-CM codes
55
41
  * [get_index(code)](#get_indexcode)
56
42
  * [remove_dot(code)](#remove_dotcode)
57
43
  * [add_dot(code)](#add_dotcode)
44
+ * [change_version(all_codes_file_path=None, classification_data_file_path=None)](#change_versionall_codes_file_pathnone-classification_data_file_pathnone)
58
45
  * [Conclusion](#conclusion)
59
46
 
60
47
  ## Release notes
48
+ * **1.3.0**:
49
+ * Users can now use their preferred ICD-10-CM release by providing properly formatted files as inputs
50
+ * The default ICD-10-CM release of the library is now the **April 2025 release**
51
+ * Renamed some internal variables (you should not have been using them anyway!)
52
+ * Dropped Conda support, older versions are still available
53
+ * Added type hints for optional parameters
54
+ * **1.2.0**: Added type hints - thanks to @JosephSBoyle on GitHub
61
55
  * **1.1.2**: Minor fix in get_full_data
62
- * **1.1.1**: Fixed minor error in the release
56
+ * **1.1.1**: Fixed a minor error in the release
63
57
  * **1.1.0**: Fixed a bug that caused many codes not to be included
64
58
  * **1.0.5**: Fixed a minor bug that affected get_nearest_common_ancestor(a,b) when a and b were the same code but written in different formats.
65
59
  * **1.0.4**: Managed to get the built package to read the data files
@@ -67,9 +61,14 @@ A simple python library for ICD-10-CM codes
67
61
 
68
62
  ## Introduction
69
63
  The objective of this library is to provide a simple instrument for dealing with **ICD-10-CM** codes in Python. It provides ways to check whether a code exists, find its ancestors and descendants, see the data associated with it, including its description, and much more.
70
- If you are looking for a library that deals with ICD-10 codes instead of ICD-10-CM codes, you can check the [simple_icd_10 library](https://github.com/StefanoTrv/simple_icd_10), which is based on the 2019 version of ICD-10.
64
+ If you are looking for a library that deals with ICD-10 codes instead of ICD-10-CM codes, you can check the [simple_icd_10 library](https://github.com/StefanoTrv/simple_icd_10), which is based on the 2019 version of ICD-10. If you are interested in the ICD-11 MMS classification, you can check out instead the [simple_icd_11 library](https://github.com/StefanoTrv/simple_icd_11).
65
+ There is also a Java version of this library, [SimpleICD10CM-Java-edition](https://github.com/StefanoTrv/SimpleICD10CM-Java-edition).
66
+
67
+ The data used in this library was taken from the [website of the CDC]((https://www.cdc.gov/nchs/icd/icd-10-cm/files.html). This library currently uses the **April 2025 release of ICD-10-CM**. This package can be configured to use other releases of the ICD-10-CM classification, read the section [Using other ICD-10-CM releases](#using-other-icd-10-cm-releases) for more details.
71
68
 
72
- The data used in this library was taken from the websites of the CDC and of the CMS. This library currently uses the **January 2021 release of ICD-10-CM**.
69
+ If you feel like supporting me, please check out the [Conclusion section](#conclusion).
70
+
71
+ simple_icd_10_cm is licensed under [the MIT License](https://github.com/StefanoTrv/simple_icd_10_cm/blob/master/LICENSE).
73
72
 
74
73
  ## Setup
75
74
  You can install the package with pip, using this command:
@@ -77,22 +76,41 @@ You can install the package with pip, using this command:
77
76
  pip install simple-icd-10-cm
78
77
  ```
79
78
 
80
- You can also install the package with conda, using the following command:
81
- ```bash
82
- conda install -c stefanotrv simple_icd_10_cm
83
- ```
79
+ The distribution files are also available as [releases in the Github repository](https://github.com/StefanoTrv/simple_icd_10_cm/releases).
84
80
 
85
81
  You can also use the "simple_icd_10_cm.py" file, which contains all the source code, in conjunction with the "data" folder, which contains the data used in this library (you can find them in the [GitHub repository](https://github.com/StefanoTrv/simple_icd_10_CM)).
86
82
 
83
+ ### Using other ICD-10-CM releases
84
+ You can use other releases of ICD-10-CM by providing properly formatted data files.
85
+
86
+ The default release is automatically loaded when the package is imported. Therefore, no further setup is required for users who want to use the default release. On the other hand, it is loaded even if the user wants to load a different release, resulting in additional unnecessary overhead. Since most users are expected to use the default release, and to guarantee backward compatibility with earlier versions of the library, this approach was considered the best overall compromise.
87
+
88
+ The function that allows to use different releases is the `change_version` function. It takes two optional arguments `all_codes_file_path` and `classification_data_file_path`, which specify, respectively, the path to the file containing a list of all the codes and the path to the XML file containing the whole structured classification. These files are described in more detail later. If both paths are provided, `change_version` loads the ICD-10-CM release described in those files. If both parameters are left empty, it loads the default release. If one parameter is provided and the other is left empty, `change_version` raises a `ValueError` exception.
89
+ ```python
90
+ # loads the files of another release
91
+ cm.change_version(all_codes_file_path="code-list-January-2021.txt",classification_data_file_path="icd10cm_tabular_2021.xml")
92
+
93
+ # loads the default release
94
+ cm.change_version()
95
+
96
+ # these both raise an exception
97
+ cm.change_version(all_codes_file_path="code-list-January-2021.txt")
98
+ cm.change_version(classification_data_file_path="icd10cm_tabular_2021.xml")
99
+ ```
100
+
101
+ The file specified in `all_codes_file_path` should contain all the unique codes of the desired release. However, it is sufficient that it contains all the seven-characters codes that must be generated programmatically, that is all the valid codes that are not explicitly listed in the XML file (see [About the special seventh character](#about-the-special-seventh-character) for more information). Each line in this file must contain a single code. Codes can be written in the format with or without the dot. In each line, the code may be followed by any text, as long as there is at least one space character immediately after the code. The `icd10cm-codes` text files available from the [CDC's website](https://www.cdc.gov/nchs/icd/icd-10-cm/files.html) can be used for this purpose, without modification.
102
+ The file specified in `classification_data_file_path` is the XML containing the whole classification. This typically corresponds to the `icd10cm-tabular` XML files available from the [CDC's website](https://www.cdc.gov/nchs/icd/icd-10-cm/files.html). If using XML files from another origin, note that, in the official releases, the first two children of the root XML element are not part of the structure of the classification, and are therefore skipped by the library.
103
+ Examples of both file types can be found in the [all-data folder](https://github.com/StefanoTrv/simple_icd_10_CM/tree/master/all-data), which includes data for the current default release and for a previous release.
104
+
87
105
  ## The format of the codes
88
- The codes of subcategories can be written in two different ways: with a dot (for example "I13.1") and with no dot (for example "I131"). The functions in this library can receive as input codes in both these formats. The codes returned by the functions will always be in the format with the dot.
106
+ Subcategories codes can be written in two different ways: with a dot (for example "I13.1") and with no dot (for example "I131"). The functions in this library can receive as input codes in both these formats. The codes returned by the functions will always be in the format with the dot.
89
107
  You can easily change the format of a code by using the [`remove_dot`](#remove_dotcode) and [`add_dot`](#add_dotcode) functions.
90
108
 
91
109
  ## About the file "Instructional Notations.md"
92
- The file [Instructional Notations.md](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) contains the introduction present in the file `icd10cm_tabular_2021.xml` (the file that contains the whole ICD-10-CM classification), copied there in a more accessible and readable format. There you can find an explanation about the meaning of most of the additional fields that can accompany a code.
110
+ The file [Instructional Notations.md](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) contains the introduction present in the file `icd10cm-tabular-April-2025.xml` (the file that contains the whole ICD-10-CM classification), copied there in a more accessible and readable format. There you can find an explanation about the meaning of most of the additional fields that can accompany a code.
93
111
 
94
112
  ## Blocks containing only one category
95
- Unlike ICD-10, ICD-10-CM includes blocks of categories that contain only one (and its subcategories). These blocks are named after the category that they contain, which means that ICD-10-CM contains blocks and categories that have the same exact code. This is a problem: because of this questionable decision, we can't know for sure if the code "B99", for example, refers to the category "B99" or to the block with the same name. This can be seen in the following example, where "B99" is recognized as both a block and a category:
113
+ Unlike ICD-10, ICD-10-CM includes blocks of categories that contain only one category (and its subcategories). These blocks are named after the category that they contain, which means that ICD-10-CM contains blocks and categories that have the same exact code. This is a problem: because of this questionable decision, we can't know for sure if the code "B99", for example, refers to the category "B99" or to the block with the same name. This can be seen in the following example, where "B99" is recognized as both a block and a category:
96
114
  ```python
97
115
  cm.is_block("B99")
98
116
  #True
@@ -115,9 +133,10 @@ cm.is_block("I12") and cm.is_category("I12")
115
133
  ```
116
134
 
117
135
  ## About the special seventh character
118
- The file `icd10cm_tabular_2021.xml`, which is the XML file that contains the whole ICD-10-CM classification, doesn't have an entry for each code generated by adding the "special" seventh character, but it contains rules that explain how to generate these codes in the "sevenChrDef" field (and sometimes in the "sevenChrNote" field too, just to complicate things a little bit...). You can find more about the structure of these particular codes in [Instructional Notations.md](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md).
119
- Due to the lack of a complete entry for these codes, I had to decide how they would be handled in this library. So I decided that their only field would be the description, composed of the description of their parent followed by the description of the meaning of the additional character, with a comma between the two: this description appears in official documents about ICD-10-CM (for example in the file `icd10cm-order-Jan-2021.txt`), so it's not my invention but the actual official format. All the other fields are empty, but the optional argument `search_in_ancestors` of certain functions can be used to automatically retrieve the content of certain fields from the ancestors of the code (see the description of the specific functions in the [Documentation](#documentation) for more details).
120
- If you need to know whether a code has been automatically generated using a rule described in a "sevenChrDef" field, you can use the [`is_extended_subcategory`](#is_extended_subcategorycode) function.
136
+ The file `icd10cm-tabular-April-2025.xml`, which is the XML file that contains the whole ICD-10-CM classification, doesn't have an entry for all the codes generated by adding the "special" seventh character, but it often contains instead rules that explain how to generate these codes in the "sevenChrDef" field (and sometimes in the "sevenChrNote" field too, just to complicate things a little bit...). You can find more about the structure of these particular codes in [Instructional Notations.md](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md).
137
+ Due to the lack of a complete entry for these missing codes, I had to decide how they would be handled in this library. So I decided that their only field would be the description, composed of the description of their parent followed by the description of the meaning of the additional character, with a comma between the two: this description appears in official documents about ICD-10-CM, so it's not my invention but the actual official format. All the other fields are empty, but the optional argument `search_in_ancestors` of certain functions can be used to automatically retrieve the content of certain fields from the ancestors of the code (see the description of the specific functions in the [Documentation](#documentation) for more details).
138
+ Seven-characters codes that have an entry in `icd10cm-tabular-April-2025.xml` are treated like any other code, and their data is taken directly from the file.
139
+ If you need to know whether a code has been automatically generated using a rule described in a "sevenChrDef" field, you can use the [`is_extended_subcategory`](#is_extended_subcategorycode) function. Only the codes generated programmatically are classified as "extended subcategories", the seven-characters codes explicitly listed in the data are classified as "subcategories".
121
140
 
122
141
  ## Documentation
123
142
  Here I list all the functions provided by this library and describe how to use them. If you are interested in a more interactive introduction to simple_icd_10_cm, please take a look at the Jupyter Notebook ["Showcase notebook.ipynb"](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Showcase%20notebook.ipynb); there you can also find more examples.
@@ -175,7 +194,7 @@ cm.is_category("14")
175
194
  #False
176
195
  ```
177
196
  ### is_subcategory(code, include_extended_subcategories=True)
178
- This function takes a string as input and returns True if the string is a valid subcategory in ICD-10-CM, False otherwise. By setting the optional argument `include_extended_subcategories` to False, this function will also return False if the string is a valid subcategory obtained by adding the 7th character to another code (see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) for more information).
197
+ This function takes a string as input and returns True if the string is a valid subcategory in ICD-10-CM, False otherwise. By setting the optional argument `include_extended_subcategories` to False, this function will also return False if the string is a valid subcategory obtained by programmatically adding the 7th character to another code (see [About the special seventh character](#about-the-special-seventh-character) and [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) for more information).
179
198
  ```python
180
199
  cm.is_subcategory("B95.1")
181
200
  #True
@@ -185,14 +204,18 @@ cm.is_subcategory("S12.000G")
185
204
  #True
186
205
  cm.is_subcategory("S12.000G", include_extended_subcategories=False)
187
206
  #False
207
+ cm.is_subcategory("C44.1192", include_extended_subcategories=False)
208
+ #True
188
209
  ```
189
210
  ### is_extended_subcategory(code)
190
- This function takes a string as input and returns True if the string is a valid subcategory in ICD-10-CM obtained by adding the 7th character to another code (see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) for more information), False otherwise.
211
+ This function takes a string as input and returns True if the string is a valid subcategory in ICD-10-CM obtained by programmatically adding the 7th character to another code (see [About the special seventh character](#about-the-special-seventh-character) and [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) for more information), False otherwise.
191
212
  ```python
192
213
  cm.is_extended_subcategory("S12.000G")
193
214
  #True
194
215
  cm.is_extended_subcategory("S12.000")
195
216
  #False
217
+ cm.is_extended_subcategory("C44.1192")
218
+ #False
196
219
  ```
197
220
  ### get_description(code, prioritize_blocks=False)
198
221
  This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing its description, otherwise it raises a ValueError. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
@@ -238,7 +261,7 @@ cm.get_inclusion_term("J37.0")
238
261
  #['Catarrhal laryngitis', 'Hypertrophic laryngitis', 'Sicca laryngitis']
239
262
  ```
240
263
  ### get_seven_chr_note(code, search_in_ancestors=False, prioritize_blocks=False)
241
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing the data of the "sevenChrNote" field of this code, otherwise it raises a ValueError. If this code does not have an "sevenChrNote" field, it returns an empty string. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "sevenChrNote" field but one of its ancestor does, the "sevenChrNote" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
264
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing the data of the "sevenChrNote" field of this code, otherwise it raises a ValueError. If this code does not have a "sevenChrNote" field, it returns an empty string. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "sevenChrNote" field but one of its ancestor does, the "sevenChrNote" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
242
265
  ```python
243
266
  cm.get_seven_chr_note("I82.40")
244
267
  #''
@@ -250,7 +273,7 @@ cm.get_seven_chr_note("R40.241",search_in_ancestors=True)
250
273
  #'The following appropriate 7th character is to be added to subcategory R40.24-:'
251
274
  ```
252
275
  ### get_seven_chr_def(code, search_in_ancestors=False, prioritize_blocks=False)
253
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **dictionary** containing the data of the "sevenChrDef" field of this code, otherwise it raises a ValueError. The dictionary maps the seventh character to a string that contains its meaning. If this code does not have an "sevenChrDef" field, it returns an empty list. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "sevenChrDef" field but one of its ancestor does, the "sevenChrDef" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
276
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **dictionary** containing the data of the "sevenChrDef" field of this code, otherwise it raises a ValueError. The dictionary maps the seventh character to a string that contains its meaning. If this code does not have a "sevenChrDef" field, it returns an empty list. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) and [About the special seventh character](#about-the-special-seventh-character) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "sevenChrDef" field but one of its ancestor does, the "sevenChrDef" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
254
277
  ```python
255
278
  cm.get_seven_chr_def("I82.40")
256
279
  #{}
@@ -288,7 +311,7 @@ cm.get_use_additional_code("R65.20",search_in_ancestors=True)
288
311
  # hepatic failure (K72.0-)'
289
312
  ```
290
313
  ### get_code_first(code, search_in_ancestors=False, prioritize_blocks=False)
291
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing the data of the "codeFirst" field of this code, otherwise it raises a ValueError. If this code does not have an "codeFirst" field, it returns an empty string. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "codeFirst" field but one of its ancestor does, the "codeFirst" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
314
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **string** containing the data of the "codeFirst" field of this code, otherwise it raises a ValueError. If this code does not have a "codeFirst" field, it returns an empty string. Please see [Instructional Notations](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Instructional%20Notations.md) if you have doubts about the meaning of this field. When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a "codeFirst" field but one of its ancestor does, the "codeFirst" data of the closer ancestor that contains such a field is returned. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
292
315
  ```python
293
316
  cm.get_code_first("I82.41")
294
317
  #''
@@ -357,7 +380,7 @@ cm.get_descendants("S14.109S")
357
380
  #[]
358
381
  ```
359
382
  ### is_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
360
- This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns True if the first string is an ancestor of the second string. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and in `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
383
+ This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns True if the first string is an ancestor of the second string. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
361
384
  ```python
362
385
  cm.is_ancestor("18","R01.0")
363
386
  #True
@@ -369,7 +392,7 @@ cm.is_ancestor("B99","B99",prioritize_blocks_a=True)
369
392
  #True
370
393
  ```
371
394
  ### is_descendant(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
372
- This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns True if the first string is a descendant of the second string. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and in `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
395
+ This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns True if the first string is a descendant of the second string. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
373
396
  ```python
374
397
  cm.is_descendant("R01.0","18")
375
398
  #True
@@ -377,7 +400,7 @@ cm.is_descendant("M31","K00-K14")
377
400
  #False
378
401
  ```
379
402
  ### get_nearest_common_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
380
- This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns their nearest common ancestor if it exists, an empty string if it doesn't exist. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and in `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
403
+ This function takes two strings as input. If both strings are valid ICD-10-CM codes, it returns their nearest common ancestor if it exists, an empty string if it doesn't exist. If at least one of the strings is not a valid ICD-10-CM code, it raises a ValueError. The optional arguments `prioritize_blocks_a` and `prioritize_blocks_b` refer, respectively, to the codes in `a` and `b`; please see [Blocks containing only one category](#blocks-containing-only-one-category) for the meaning of these optional arguments.
381
404
  ```python
382
405
  cm.get_nearest_common_ancestor("H28","H25.1")
383
406
  #'H25-H28'
@@ -385,7 +408,7 @@ cm.get_nearest_common_ancestor("K35","E21.0")
385
408
  #''
386
409
  ```
387
410
  ### is_leaf(code, prioritize_blocks=False)
388
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns True if it's a leaf in the ICD-10-CM classification (that is, if it has no children), otherwise it returns False. If the string is not a valid ICD-10-CM code it raises a ValueError. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
411
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns True if it's a leaf in the ICD-10-CM classification (that is, if it has no children), otherwise it returns False. If the string is not a valid ICD-10-CM code, it raises a ValueError. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
389
412
  ```python
390
413
  cm.is_leaf("12")
391
414
  #False
@@ -429,8 +452,11 @@ cm.add_dot("K00-K14")
429
452
  #'K00-K14'
430
453
  ```
431
454
 
455
+ ### change_version(all_codes_file_path=None, classification_data_file_path=None)
456
+ This function can be used to load any ICD-10-CM release provided by the user, or to revert to using the default release for the package. Its usage is explained in the paragraph [Using other ICD-10-CM releases](#using-other-icd-10-cm-releases).
457
+
432
458
  ## Conclusion
433
- This should be everything you need to know about the simple_icd_10_cm library. Please contact me if you find any mistake, bug, missing feature or anything else that could be improved or made easier to comprehend, both in this documentation and in the library itself as well as in the [Showcase notebook](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Showcase%20notebook.ipynb). You can also contact me if you need any help using this library, but I may not be able to help with questions about the ICD-10-CM classification itself. This library currently only support the January 2021 release of ICD-10-CM: let me know if you'd like me to implement the ability to switch between different versions of ICD-10-CM, and also tell me which release or releases you are interested in.
459
+ This should be everything you need to know about the simple_icd_10_cm library. Please contact me if you find any mistake, bug, missing feature or anything else that could be improved or made easier to comprehend, both in this documentation and in the library itself as well as in the [Showcase notebook](https://github.com/StefanoTrv/simple_icd_10_CM/blob/master/Showcase%20notebook.ipynb). You can also contact me if you need any help using this library, but I may not be able to help with questions about the ICD-10-CM classification itself.
434
460
 
435
461
  If you find this library useful and are feeling generous, consider making a donation using one of the methods listed at the end of this document.
436
462
 
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="simple_icd_10_cm",
8
- version="1.2.0",
8
+ version="1.3.0",
9
9
  author="Stefano Travasci",
10
10
  author_email="stefanotravasci@gmail.com",
11
11
  description="A simple python library for ICD-10-CM codes",