simple-icd-10-cm 1.1.2__py3-none-any.whl → 1.3.0__py3-none-any.whl

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,451 +1,498 @@
1
- Metadata-Version: 2.1
2
- Name: simple-icd-10-cm
3
- Version: 1.1.2
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
- License: UNKNOWN
9
- Keywords: ICD-10-CM ICD-10 icd 10 CM codes clinical modification
10
- Platform: UNKNOWN
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3
15
- Description-Content-Type: text/markdown
16
- License-File: LICENSE
17
-
18
- # simple_icd_10_cm
19
- A simple python library for ICD-10-CM codes
20
-
21
- ## Index
22
- * [Release notes](#release-notes)
23
- * [Introduction](#introduction)
24
- * [Setup](#setup)
25
- * [The format of the codes](#the-format-of-the-codes)
26
- * [About the file "Instructional Notations.md"](#about-the-file-instructional-notationsmd)
27
- * [Blocks containing only one category](#blocks-containing-only-one-category)
28
- * [About the special seventh character](#about-the-special-seventh-character)
29
- * [Documentation](#documentation)
30
- * [is_valid_item(code)](#is_valid_itemcode)
31
- * [is_category_or_subcategory(code)](#is_category_or_subcategorycode)
32
- * [is_chapter_or_block(code)](#is_chapter_or_blockcode)
33
- * [is_chapter(code)](#is_chaptercode)
34
- * [is_block(code)](#is_blockcode)
35
- * [is_category(code)](#is_categorycode)
36
- * [is_subcategory(code, include_extended_subcategories=True)](#is_subcategorycode-include_extended_subcategoriestrue)
37
- * [is_extended_subcategory(code)](#is_extended_subcategorycode)
38
- * [get_description(code, prioritize_blocks=False)](#get_descriptioncode-prioritize_blocksfalse)
39
- * [get_excludes1(code, prioritize_blocks=False)](#get_excludes1code-prioritize_blocksfalse)
40
- * [get_excludes2(code, prioritize_blocks=False)](#get_excludes2code-prioritize_blocksfalse)
41
- * [get_includes(code, prioritize_blocks=False)](#get_includescode-prioritize_blocksfalse)
42
- * [get_inclusion_term(code, prioritize_blocks=False)](#get_inclusion_termcode-prioritize_blocksfalse)
43
- * [get_seven_chr_note(code, search_in_ancestors=False, prioritize_blocks=False)](#get_seven_chr_notecode-search_in_ancestorsfalse-prioritize_blocksfalse)
44
- * [get_seven_chr_def(code, search_in_ancestors=False, prioritize_blocks=False)](#get_seven_chr_defcode-search_in_ancestorsfalse-prioritize_blocksfalse)
45
- * [get_use_additional_code(code, search_in_ancestors=False, prioritize_blocks=False)](#get_use_additional_codecode-search_in_ancestorsfalse-prioritize_blocksfalse)
46
- * [get_code_first(code, search_in_ancestors=False, prioritize_blocks=False)](#get_code_firstcode-search_in_ancestorsfalse-prioritize_blocksfalse)
47
- * [get_full_data(code, search_in_ancestors=False, prioritize_blocks=False)](#get_full_datacode-search_in_ancestorsfalse-prioritize_blocksfalse)
48
- * [get_parent(code, prioritize_blocks=False)](#get_parentcode-prioritize_blocksfalse)
49
- * [get_children(code, prioritize_blocks=False)](#get_childrencode-prioritize_blocksfalse)
50
- * [get_ancestors(code, prioritize_blocks=False)](#get_ancestorscode-prioritize_blocksfalse)
51
- * [get_descendants(code, prioritize_blocks=False)](#get_descendantscode-prioritize_blocksfalse)
52
- * [is_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)](#is_ancestora-b-prioritize_blocks_afalse-prioritize_blocks_bfalse)
53
- * [is_descendant(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)](#is_descendanta-b-prioritize_blocks_afalse-prioritize_blocks_bfalse)
54
- * [get_nearest_common_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)](#get_nearest_common_ancestora-b-prioritize_blocks_afalse-prioritize_blocks_bfalse)
55
- * [is_leaf(code, prioritize_blocks=False)](#is_leafcode-prioritize_blocksfalse)
56
- * [get_all_codes(with_dots=True)](#get_all_codeswith_dotstrue)
57
- * [get_index(code)](#get_indexcode)
58
- * [remove_dot(code)](#remove_dotcode)
59
- * [add_dot(code)](#add_dotcode)
60
- * [Conclusion](#conclusion)
61
-
62
- ## Release notes
63
- * **1.1.2**: Minor fix in get_full_data
64
- * **1.1.1**: Fixed minor error in the release
65
- * **1.1.0**: Fixed a bug that caused many codes not to be included
66
- * **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.
67
- * **1.0.4**: Managed to get the built package to read the data files
68
- * **1.0.0**: Initial release
69
-
70
- ## Introduction
71
- 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.
72
- 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.
73
-
74
- 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**.
75
-
76
- ## Setup
77
- You can install the package with pip, using this command:
78
- ```bash
79
- pip install simple-icd-10-cm
80
- ```
81
-
82
- You can also install the package with conda, using the following command:
83
- ```bash
84
- conda install -c stefanotrv simple_icd_10_cm
85
- ```
86
-
87
- 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)).
88
-
89
- ## The format of the codes
90
- 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.
91
- You can easily change the format of a code by using the [`remove_dot`](#remove_dotcode) and [`add_dot`](#add_dotcode) functions.
92
-
93
- ## About the file "Instructional Notations.md"
94
- 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.
95
-
96
- ## Blocks containing only one category
97
- 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:
98
- ```python
99
- cm.is_block("B99")
100
- #True
101
- cm.is_category("B99")
102
- #True
103
- ```
104
- To solve this ambiguity, I've introduced in most functions the optional argument `prioritize_blocks`. This optional argument has an effect only when the string passed as input could be the name of a category or of its parent block: when this ambiguity is not present, the value of this argument won't have any impact on the computation. When `prioritize_blocks` is False, which is the default value, the ambiguous code will be interpreted as the category, when it's set to True the same code will be interpreted as being the block. The following code shows an example of this in action:
105
- ```python
106
- cm.get_children("B99")
107
- #['B99.8', 'B99.9']
108
- cm.get_children("B99",prioritize_blocks=True)
109
- #['B99']
110
- ```
111
- If you want to know if a specific code is ambiguous, it's pretty simple: you just have to check if it's at the same time a block and a category, as in the following examples:
112
- ```python
113
- cm.is_block("B10") and cm.is_category("B10")
114
- #True
115
- cm.is_block("I12") and cm.is_category("I12")
116
- #False
117
- ```
118
-
119
- ## About the special seventh character
120
- 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).
121
- 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).
122
- 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.
123
-
124
- ## Documentation
125
- 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.
126
-
127
- Here I suppose we have imported the library as follows:
128
- ```python
129
- import simple_icd_10_cm as cm
130
- ```
131
- ### is_valid_item(code)
132
- This function takes a string as input and returns True if the string is a valid chapter, block, category or subcategory in ICD-10-CM, False otherwise.
133
- ```python
134
- cm.is_valid_item("cat")
135
- #False
136
- cm.is_valid_item("B99")
137
- #True
138
- ```
139
- ### is_category_or_subcategory(code)
140
- This function takes a string as input and returns True if the string is a valid category or subcategory in ICD-10-CM, False otherwise.
141
- ```python
142
- cm.is_category_or_subcategory("A00-B99")
143
- #False
144
- cm.is_category_or_subcategory("B99")
145
- #True
146
- ```
147
- ### is_chapter_or_block(code)
148
- This function takes a string as input and returns True if the string is a valid chapter or block in ICD-10-CM, False otherwise.
149
- ```python
150
- cm.is_chapter_or_block("L80-L99")
151
- #True
152
- cm.is_chapter_or_block("L99")
153
- #False
154
- ```
155
- ### is_chapter(code)
156
- This function takes a string as input and returns True if the string is a valid chapter in ICD-10-CM, False otherwise.
157
- ```python
158
- cm.is_chapter("12")
159
- #True
160
- cm.is_chapter("B99")
161
- #False
162
- ```
163
- ### is_block(code)
164
- This function takes a string as input and returns True if the string is a valid block in ICD-10-CM, False otherwise.
165
- ```python
166
- cm.is_block("L80-L99")
167
- #True
168
- cm.is_block("L99")
169
- #False
170
- ```
171
- ### is_category(code)
172
- This function takes a string as input and returns True if the string is a valid category in ICD-10-CM, False otherwise.
173
- ```python
174
- cm.is_category("B99")
175
- #True
176
- cm.is_category("14")
177
- #False
178
- ```
179
- ### is_subcategory(code, include_extended_subcategories=True)
180
- 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).
181
- ```python
182
- cm.is_subcategory("B95.1")
183
- #True
184
- cm.is_subcategory("B99")
185
- #False
186
- cm.is_subcategory("S12.000G")
187
- #True
188
- cm.is_subcategory("S12.000G", include_extended_subcategories=False)
189
- #False
190
- ```
191
- ### is_extended_subcategory(code)
192
- 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.
193
- ```python
194
- cm.is_extended_subcategory("S12.000G")
195
- #True
196
- cm.is_extended_subcategory("S12.000")
197
- #False
198
- ```
199
- ### get_description(code, prioritize_blocks=False)
200
- 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).
201
- ```python
202
- cm.get_description("12")
203
- #'Diseases of the skin and subcutaneous tissue (L00-L99)'
204
- cm.get_description("I70.501")
205
- #'Unspecified atherosclerosis of nonautologous biological bypass graft(s) of the extremities, right leg'
206
- ```
207
- ### get_excludes1(code, prioritize_blocks=False)
208
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **list of strings** containing the data of the "excludes1" field of this code, otherwise it raises a ValueError. If this code does not have an "excludes1" field, it returns an empty list. 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. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
209
- ```python
210
- cm.get_excludes1("12")
211
- #[]
212
- cm.get_excludes1("I82.40")
213
- #['acute embolism and thrombosis of unspecified deep veins of distal lower extremity (I82.4Z-)',
214
- # 'acute embolism and thrombosis of unspecified deep veins of proximal lower extremity (I82.4Y-)']
215
- ```
216
- ### get_excludes2(code, prioritize_blocks=False)
217
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **list of strings** containing the data of the "excludes2" field of this code, otherwise it raises a ValueError. If this code does not have an "excludes2" field, it returns an empty list. 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. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
218
- ```python
219
- cm.get_excludes2("I82.40")
220
- #[]
221
- cm.get_excludes2("J34.81")
222
- #['gastrointestinal mucositis (ulcerative) (K92.81)',
223
- # 'mucositis (ulcerative) of vagina and vulva (N76.81)',
224
- # 'oral mucositis (ulcerative) (K12.3-)']
225
- ```
226
- ### get_includes(code, prioritize_blocks=False)
227
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **list of strings** containing the data of the "includes" field of this code, otherwise it raises a ValueError. If this code does not have an "includes" field, it returns an empty list. 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. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
228
- ```python
229
- cm.get_includes("I82.40")
230
- #[]
231
- cm.get_includes("J36")
232
- #['abscess of tonsil', 'peritonsillar cellulitis', 'quinsy']
233
- ```
234
- ### get_inclusion_term(code, prioritize_blocks=False)
235
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **list of strings** containing the data of the "inclusionTerm" field of this code, otherwise it raises a ValueError. If this code does not have an "inclusionTerm" field, it returns an empty list. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
236
- ```python
237
- cm.get_inclusion_term("A23")
238
- #[]
239
- cm.get_inclusion_term("J37.0")
240
- #['Catarrhal laryngitis', 'Hypertrophic laryngitis', 'Sicca laryngitis']
241
- ```
242
- ### get_seven_chr_note(code, search_in_ancestors=False, prioritize_blocks=False)
243
- 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).
244
- ```python
245
- cm.get_seven_chr_note("I82.40")
246
- #''
247
- cm.get_seven_chr_note("M48.4")
248
- #'The appropriate 7th character is to be added to each code from subcategory M48.4:'
249
- cm.get_seven_chr_note("R40.241")
250
- #''
251
- cm.get_seven_chr_note("R40.241",search_in_ancestors=True)
252
- #'The following appropriate 7th character is to be added to subcategory R40.24-:'
253
- ```
254
- ### get_seven_chr_def(code, search_in_ancestors=False, prioritize_blocks=False)
255
- 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).
256
- ```python
257
- cm.get_seven_chr_def("I82.40")
258
- #{}
259
- cm.get_seven_chr_def("M48.4")
260
- #{'A': 'initial encounter for fracture',
261
- # 'D': 'subsequent encounter for fracture with routine healing',
262
- # 'G': 'subsequent encounter for fracture with delayed healing',
263
- # 'S': 'sequela of fracture'}
264
- cm.get_seven_chr_def("R40.241")
265
- #{}
266
- cm.get_seven_chr_def("R40.241",search_in_ancestors=True)
267
- #{'0': 'unspecified time',
268
- # '1': 'in the field [EMT or ambulance]',
269
- # '2': 'at arrival to emergency department',
270
- # '3': 'at hospital admission',
271
- # '4': '24 hours or more after hospital admission'}
272
- ```
273
- ### get_use_additional_code(code, search_in_ancestors=False, prioritize_blocks=False)
274
- 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 "useAdditionalCode" field of this code, otherwise it raises a ValueError. If this code does not have an "useAdditionalCode" 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 "useAdditionalCode" field but one of its ancestor does, the "useAdditionalCode" 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).
275
- ```python
276
- cm.get_use_additional_code("I82.41")
277
- #''
278
- cm.get_use_additional_code("R50.2")
279
- #'code for adverse effect, if applicable, to identify drug (T36-T50 with fifth or sixth character 5)'
280
- cm.get_use_additional_code("R65.20")
281
- #''
282
- cm.get_use_additional_code("R65.20",search_in_ancestors=True)
283
- #'code to identify specific acute organ dysfunction, such as:
284
- # acute kidney failure (N17.-)
285
- # acute respiratory failure (J96.0-)
286
- # critical illness myopathy (G72.81)
287
- # critical illness polyneuropathy (G62.81)
288
- # disseminated intravascular coagulopathy [DIC] (D65)
289
- # encephalopathy (metabolic) (septic) (G93.41)
290
- # hepatic failure (K72.0-)'
291
- ```
292
- ### get_code_first(code, search_in_ancestors=False, prioritize_blocks=False)
293
- 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).
294
- ```python
295
- cm.get_code_first("I82.41")
296
- #''
297
- cm.get_code_first("R68.13")
298
- #'confirmed diagnosis, if known'
299
- cm.get_code_first("S04.01")
300
- #''
301
- cm.get_code_first("S04.01",search_in_ancestors=True)
302
- #'any associated intracranial injury (S06.-)'
303
- ```
304
- ### get_full_data(code, search_in_ancestors=False, prioritize_blocks=False)
305
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a string containing all the available data of the code, otherwise it raises a ValueError. The empty fields are omitted from the string, except for the list of children (see second example below). When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a certain field but one of its ancestor does, the data of the closer ancestor that contains such a field is returned: see the previous functions to know which are the fields that are influenced by this argument and which are not. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
306
- ```python
307
- cm.get_full_data("I82.41")
308
- #'Name:
309
- # I82.41
310
- # Description:
311
- # Acute embolism and thrombosis of femoral vein
312
- # Parent:
313
- # I82.4
314
- # inclusion term:
315
- # Acute embolism and thrombosis of common femoral vein
316
- # Acute embolism and thrombosis of deep femoral vein
317
- # Children:
318
- # I82.411, I82.412, I82.413, I82.419'
319
- cm.get_full_data("C8401")
320
- #'Name:
321
- # C84.01
322
- # Description:
323
- # Mycosis fungoides, lymph nodes of head, face, and neck
324
- # Parent:
325
- # C84.0
326
- # Children:
327
- # None'
328
- ```
329
- ### get_parent(code, prioritize_blocks=False)
330
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a string containing its parent, otherwise it raises a ValueError. If the code doesn't have a parent (that is, if it's a chapter), it returns an empty string. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
331
- ```python
332
- cm.get_parent("I70.501")
333
- #'I70.50'
334
- cm.get_parent("12")
335
- #''
336
- ```
337
- ### get_children(code, prioritize_blocks=False)
338
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a list of strings containing its children, otherwise it raises a ValueError. If the code doesn't have children, it returns an empty list. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
339
- ```python
340
- cm.get_children("12")
341
- #['L00-L08', 'L10-L14', 'L20-L30', 'L40-L45', 'L49-L54', 'L55-L59', 'L60-L75', 'L76', 'L80-L99']
342
- cm.get_children("I70.501")
343
- #[]
344
- ```
345
- ### get_ancestors(code, prioritize_blocks=False)
346
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a list containing all its ancestors in the ICD-10-CM classification, otherwise it raises a ValueError. The results are ordered from its parent to its most distant ancestor. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
347
- ```python
348
- cm.get_ancestors("S14.109S")
349
- #['S14.109', 'S14.10', 'S14.1', 'S14', 'S10-S19', '19']
350
- cm.get_ancestors("7")
351
- #[]
352
- ```
353
- ### get_descendants(code, prioritize_blocks=False)
354
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a list containing all its descendants in the ICD-10-CM classification, otherwise it raises a ValueError. The returned codes are ordered as in a pre-order depth-first traversal of the tree containing the ICD-10-CM classification. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
355
- ```python
356
- cm.get_descendants("G93")
357
- #['G93.0', 'G93.1', 'G93.2', 'G93.3', 'G93.4', 'G93.40', 'G93.41', 'G93.49', 'G93.5', 'G93.6', 'G93.7', 'G93.8', 'G93.81', 'G93.82', 'G93.89', 'G93.9']
358
- cm.get_descendants("S14.109S")
359
- #[]
360
- ```
361
- ### is_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
362
- 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.
363
- ```python
364
- cm.is_ancestor("18","R01.0")
365
- #True
366
- cm.is_ancestor("K00-K14","M31")
367
- #False
368
- cm.is_ancestor("B99","B99")
369
- #False
370
- cm.is_ancestor("B99","B99",prioritize_blocks_a=True)
371
- #True
372
- ```
373
- ### is_descendant(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
374
- 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.
375
- ```python
376
- cm.is_descendant("R01.0","18")
377
- #True
378
- cm.is_descendant("M31","K00-K14")
379
- #False
380
- ```
381
- ### get_nearest_common_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
382
- 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.
383
- ```python
384
- cm.get_nearest_common_ancestor("H28","H25.1")
385
- #'H25-H28'
386
- cm.get_nearest_common_ancestor("K35","E21.0")
387
- #''
388
- ```
389
- ### is_leaf(code, prioritize_blocks=False)
390
- 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).
391
- ```python
392
- cm.is_leaf("12")
393
- #False
394
- cm.is_leaf("I70.501")
395
- #True
396
- ```
397
- ### get_all_codes(with_dots=True)
398
- This function returns the list of all items in the ICD-10-CM classification. If the optional boolean argument `with_dots` is set to False, the subcategories in the list will not have a dot in them, otherwise the subcategories will have a dot in them. The codes that represent both a block and a category (for example "B99") appear only once in this list.
399
- ```python
400
- cm.get_all_codes()
401
- #['1', 'A00-A09', 'A00', 'A00.0', 'A00.1', 'A00.9', 'A01', 'A01.0', ...
402
- cm.get_all_codes(False)
403
- #['1', 'A00-A09', 'A00', 'A000', 'A001', 'A009', 'A01', 'A010', ...
404
- ```
405
- ### get_index(code)
406
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns its index in the list returned by `get_all_codes`, otherwise it raises a ValueError.
407
- ```python
408
- cm.get_index("P00")
409
- #27735
410
- cm.get_all_codes(True)[27735]
411
- #"P00"
412
- ```
413
- ### remove_dot(code)
414
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns the same code in the notation without the dot, otherwise it raises a ValueError.
415
- ```python
416
- cm.remove_dot("C84.Z0")
417
- #'C84Z0'
418
- cm.remove_dot("C84Z0")
419
- #'C84Z0'
420
- cm.remove_dot("K00-K14")
421
- #'K00-K14'
422
- ```
423
- ### add_dot(code)
424
- This function takes a string as input. If the string is a valid ICD-10-CM code, it returns the same code in the notation with the dot, otherwise it raises a ValueError.
425
- ```python
426
- cm.add_dot("C84Z0")
427
- #'C84.Z0'
428
- cm.add_dot("C84.Z0")
429
- #'C84.Z0'
430
- cm.add_dot("K00-K14")
431
- #'K00-K14'
432
- ```
433
-
434
- ## Conclusion
435
- 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.
436
-
437
- 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.
438
-
439
- *Stefano Travasci*
440
-
441
- ---
442
-
443
- Paypal: [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/donate?hosted_button_id=9HMMFAZE248VN)
444
-
445
- Curecoin: BKxCWuWzsqtLzAvAjtpsHpJ7LqFHPubqft
446
-
447
- Bitcoin: bc1qjtnvzzgpsxz397l03vhrw8l30vl2p7fepmn5yy
448
-
449
- <sub>*let me know if your favorite donation method is not in this list*</sub>
450
-
451
-
1
+ Metadata-Version: 2.4
2
+ Name: simple_icd_10_cm
3
+ Version: 1.3.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
+ 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
25
+
26
+ # simple_icd_10_cm
27
+ A simple python library for ICD-10-CM codes
28
+
29
+ ## Index
30
+ * [Release notes](#release-notes)
31
+ * [Introduction](#introduction)
32
+ * [Setup](#setup)
33
+ * [Using other ICD-10-CM releases](#using-other-icd-10-cm-releases)
34
+ * [The format of the codes](#the-format-of-the-codes)
35
+ * [About the file "Instructional Notations.md"](#about-the-file-instructional-notationsmd)
36
+ * [Blocks containing only one category](#blocks-containing-only-one-category)
37
+ * [About the special seventh character](#about-the-special-seventh-character)
38
+ * [Documentation](#documentation)
39
+ * [is_valid_item(code)](#is_valid_itemcode)
40
+ * [is_category_or_subcategory(code)](#is_category_or_subcategorycode)
41
+ * [is_chapter_or_block(code)](#is_chapter_or_blockcode)
42
+ * [is_chapter(code)](#is_chaptercode)
43
+ * [is_block(code)](#is_blockcode)
44
+ * [is_category(code)](#is_categorycode)
45
+ * [is_subcategory(code, include_extended_subcategories=True)](#is_subcategorycode-include_extended_subcategoriestrue)
46
+ * [is_extended_subcategory(code)](#is_extended_subcategorycode)
47
+ * [get_description(code, prioritize_blocks=False)](#get_descriptioncode-prioritize_blocksfalse)
48
+ * [get_excludes1(code, prioritize_blocks=False)](#get_excludes1code-prioritize_blocksfalse)
49
+ * [get_excludes2(code, prioritize_blocks=False)](#get_excludes2code-prioritize_blocksfalse)
50
+ * [get_includes(code, prioritize_blocks=False)](#get_includescode-prioritize_blocksfalse)
51
+ * [get_inclusion_term(code, prioritize_blocks=False)](#get_inclusion_termcode-prioritize_blocksfalse)
52
+ * [get_seven_chr_note(code, search_in_ancestors=False, prioritize_blocks=False)](#get_seven_chr_notecode-search_in_ancestorsfalse-prioritize_blocksfalse)
53
+ * [get_seven_chr_def(code, search_in_ancestors=False, prioritize_blocks=False)](#get_seven_chr_defcode-search_in_ancestorsfalse-prioritize_blocksfalse)
54
+ * [get_use_additional_code(code, search_in_ancestors=False, prioritize_blocks=False)](#get_use_additional_codecode-search_in_ancestorsfalse-prioritize_blocksfalse)
55
+ * [get_code_first(code, search_in_ancestors=False, prioritize_blocks=False)](#get_code_firstcode-search_in_ancestorsfalse-prioritize_blocksfalse)
56
+ * [get_full_data(code, search_in_ancestors=False, prioritize_blocks=False)](#get_full_datacode-search_in_ancestorsfalse-prioritize_blocksfalse)
57
+ * [get_parent(code, prioritize_blocks=False)](#get_parentcode-prioritize_blocksfalse)
58
+ * [get_children(code, prioritize_blocks=False)](#get_childrencode-prioritize_blocksfalse)
59
+ * [get_ancestors(code, prioritize_blocks=False)](#get_ancestorscode-prioritize_blocksfalse)
60
+ * [get_descendants(code, prioritize_blocks=False)](#get_descendantscode-prioritize_blocksfalse)
61
+ * [is_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)](#is_ancestora-b-prioritize_blocks_afalse-prioritize_blocks_bfalse)
62
+ * [is_descendant(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)](#is_descendanta-b-prioritize_blocks_afalse-prioritize_blocks_bfalse)
63
+ * [get_nearest_common_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)](#get_nearest_common_ancestora-b-prioritize_blocks_afalse-prioritize_blocks_bfalse)
64
+ * [is_leaf(code, prioritize_blocks=False)](#is_leafcode-prioritize_blocksfalse)
65
+ * [get_all_codes(with_dots=True)](#get_all_codeswith_dotstrue)
66
+ * [get_index(code)](#get_indexcode)
67
+ * [remove_dot(code)](#remove_dotcode)
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)
70
+ * [Conclusion](#conclusion)
71
+
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
80
+ * **1.1.2**: Minor fix in get_full_data
81
+ * **1.1.1**: Fixed a minor error in the release
82
+ * **1.1.0**: Fixed a bug that caused many codes not to be included
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.
84
+ * **1.0.4**: Managed to get the built package to read the data files
85
+ * **1.0.0**: Initial release
86
+
87
+ ## Introduction
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.
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).
91
+
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).
97
+
98
+ ## Setup
99
+ You can install the package with pip, using this command:
100
+ ```bash
101
+ pip install simple-icd-10-cm
102
+ ```
103
+
104
+ The distribution files are also available as [releases in the Github repository](https://github.com/StefanoTrv/simple_icd_10_cm/releases).
105
+
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)).
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
+
130
+ ## The format of the codes
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.
132
+ You can easily change the format of a code by using the [`remove_dot`](#remove_dotcode) and [`add_dot`](#add_dotcode) functions.
133
+
134
+ ## About the file "Instructional Notations.md"
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.
136
+
137
+ ## Blocks containing only one 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:
139
+ ```python
140
+ cm.is_block("B99")
141
+ #True
142
+ cm.is_category("B99")
143
+ #True
144
+ ```
145
+ To solve this ambiguity, I've introduced in most functions the optional argument `prioritize_blocks`. This optional argument has an effect only when the string passed as input could be the name of a category or of its parent block: when this ambiguity is not present, the value of this argument won't have any impact on the computation. When `prioritize_blocks` is False, which is the default value, the ambiguous code will be interpreted as the category, when it's set to True the same code will be interpreted as being the block. The following code shows an example of this in action:
146
+ ```python
147
+ cm.get_children("B99")
148
+ #['B99.8', 'B99.9']
149
+ cm.get_children("B99",prioritize_blocks=True)
150
+ #['B99']
151
+ ```
152
+ If you want to know if a specific code is ambiguous, it's pretty simple: you just have to check if it's at the same time a block and a category, as in the following examples:
153
+ ```python
154
+ cm.is_block("B10") and cm.is_category("B10")
155
+ #True
156
+ cm.is_block("I12") and cm.is_category("I12")
157
+ #False
158
+ ```
159
+
160
+ ## About the special seventh character
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".
165
+
166
+ ## Documentation
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.
168
+
169
+ Here I suppose we have imported the library as follows:
170
+ ```python
171
+ import simple_icd_10_cm as cm
172
+ ```
173
+ ### is_valid_item(code)
174
+ This function takes a string as input and returns True if the string is a valid chapter, block, category or subcategory in ICD-10-CM, False otherwise.
175
+ ```python
176
+ cm.is_valid_item("cat")
177
+ #False
178
+ cm.is_valid_item("B99")
179
+ #True
180
+ ```
181
+ ### is_category_or_subcategory(code)
182
+ This function takes a string as input and returns True if the string is a valid category or subcategory in ICD-10-CM, False otherwise.
183
+ ```python
184
+ cm.is_category_or_subcategory("A00-B99")
185
+ #False
186
+ cm.is_category_or_subcategory("B99")
187
+ #True
188
+ ```
189
+ ### is_chapter_or_block(code)
190
+ This function takes a string as input and returns True if the string is a valid chapter or block in ICD-10-CM, False otherwise.
191
+ ```python
192
+ cm.is_chapter_or_block("L80-L99")
193
+ #True
194
+ cm.is_chapter_or_block("L99")
195
+ #False
196
+ ```
197
+ ### is_chapter(code)
198
+ This function takes a string as input and returns True if the string is a valid chapter in ICD-10-CM, False otherwise.
199
+ ```python
200
+ cm.is_chapter("12")
201
+ #True
202
+ cm.is_chapter("B99")
203
+ #False
204
+ ```
205
+ ### is_block(code)
206
+ This function takes a string as input and returns True if the string is a valid block in ICD-10-CM, False otherwise.
207
+ ```python
208
+ cm.is_block("L80-L99")
209
+ #True
210
+ cm.is_block("L99")
211
+ #False
212
+ ```
213
+ ### is_category(code)
214
+ This function takes a string as input and returns True if the string is a valid category in ICD-10-CM, False otherwise.
215
+ ```python
216
+ cm.is_category("B99")
217
+ #True
218
+ cm.is_category("14")
219
+ #False
220
+ ```
221
+ ### is_subcategory(code, include_extended_subcategories=True)
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).
223
+ ```python
224
+ cm.is_subcategory("B95.1")
225
+ #True
226
+ cm.is_subcategory("B99")
227
+ #False
228
+ cm.is_subcategory("S12.000G")
229
+ #True
230
+ cm.is_subcategory("S12.000G", include_extended_subcategories=False)
231
+ #False
232
+ cm.is_subcategory("C44.1192", include_extended_subcategories=False)
233
+ #True
234
+ ```
235
+ ### is_extended_subcategory(code)
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.
237
+ ```python
238
+ cm.is_extended_subcategory("S12.000G")
239
+ #True
240
+ cm.is_extended_subcategory("S12.000")
241
+ #False
242
+ cm.is_extended_subcategory("C44.1192")
243
+ #False
244
+ ```
245
+ ### get_description(code, prioritize_blocks=False)
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).
247
+ ```python
248
+ cm.get_description("12")
249
+ #'Diseases of the skin and subcutaneous tissue (L00-L99)'
250
+ cm.get_description("I70.501")
251
+ #'Unspecified atherosclerosis of nonautologous biological bypass graft(s) of the extremities, right leg'
252
+ ```
253
+ ### get_excludes1(code, prioritize_blocks=False)
254
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **list of strings** containing the data of the "excludes1" field of this code, otherwise it raises a ValueError. If this code does not have an "excludes1" field, it returns an empty list. 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. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
255
+ ```python
256
+ cm.get_excludes1("12")
257
+ #[]
258
+ cm.get_excludes1("I82.40")
259
+ #['acute embolism and thrombosis of unspecified deep veins of distal lower extremity (I82.4Z-)',
260
+ # 'acute embolism and thrombosis of unspecified deep veins of proximal lower extremity (I82.4Y-)']
261
+ ```
262
+ ### get_excludes2(code, prioritize_blocks=False)
263
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **list of strings** containing the data of the "excludes2" field of this code, otherwise it raises a ValueError. If this code does not have an "excludes2" field, it returns an empty list. 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. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
264
+ ```python
265
+ cm.get_excludes2("I82.40")
266
+ #[]
267
+ cm.get_excludes2("J34.81")
268
+ #['gastrointestinal mucositis (ulcerative) (K92.81)',
269
+ # 'mucositis (ulcerative) of vagina and vulva (N76.81)',
270
+ # 'oral mucositis (ulcerative) (K12.3-)']
271
+ ```
272
+ ### get_includes(code, prioritize_blocks=False)
273
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **list of strings** containing the data of the "includes" field of this code, otherwise it raises a ValueError. If this code does not have an "includes" field, it returns an empty list. 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. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
274
+ ```python
275
+ cm.get_includes("I82.40")
276
+ #[]
277
+ cm.get_includes("J36")
278
+ #['abscess of tonsil', 'peritonsillar cellulitis', 'quinsy']
279
+ ```
280
+ ### get_inclusion_term(code, prioritize_blocks=False)
281
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a **list of strings** containing the data of the "inclusionTerm" field of this code, otherwise it raises a ValueError. If this code does not have an "inclusionTerm" field, it returns an empty list. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
282
+ ```python
283
+ cm.get_inclusion_term("A23")
284
+ #[]
285
+ cm.get_inclusion_term("J37.0")
286
+ #['Catarrhal laryngitis', 'Hypertrophic laryngitis', 'Sicca laryngitis']
287
+ ```
288
+ ### get_seven_chr_note(code, search_in_ancestors=False, prioritize_blocks=False)
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).
290
+ ```python
291
+ cm.get_seven_chr_note("I82.40")
292
+ #''
293
+ cm.get_seven_chr_note("M48.4")
294
+ #'The appropriate 7th character is to be added to each code from subcategory M48.4:'
295
+ cm.get_seven_chr_note("R40.241")
296
+ #''
297
+ cm.get_seven_chr_note("R40.241",search_in_ancestors=True)
298
+ #'The following appropriate 7th character is to be added to subcategory R40.24-:'
299
+ ```
300
+ ### get_seven_chr_def(code, search_in_ancestors=False, prioritize_blocks=False)
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).
302
+ ```python
303
+ cm.get_seven_chr_def("I82.40")
304
+ #{}
305
+ cm.get_seven_chr_def("M48.4")
306
+ #{'A': 'initial encounter for fracture',
307
+ # 'D': 'subsequent encounter for fracture with routine healing',
308
+ # 'G': 'subsequent encounter for fracture with delayed healing',
309
+ # 'S': 'sequela of fracture'}
310
+ cm.get_seven_chr_def("R40.241")
311
+ #{}
312
+ cm.get_seven_chr_def("R40.241",search_in_ancestors=True)
313
+ #{'0': 'unspecified time',
314
+ # '1': 'in the field [EMT or ambulance]',
315
+ # '2': 'at arrival to emergency department',
316
+ # '3': 'at hospital admission',
317
+ # '4': '24 hours or more after hospital admission'}
318
+ ```
319
+ ### get_use_additional_code(code, search_in_ancestors=False, prioritize_blocks=False)
320
+ 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 "useAdditionalCode" field of this code, otherwise it raises a ValueError. If this code does not have an "useAdditionalCode" 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 "useAdditionalCode" field but one of its ancestor does, the "useAdditionalCode" 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).
321
+ ```python
322
+ cm.get_use_additional_code("I82.41")
323
+ #''
324
+ cm.get_use_additional_code("R50.2")
325
+ #'code for adverse effect, if applicable, to identify drug (T36-T50 with fifth or sixth character 5)'
326
+ cm.get_use_additional_code("R65.20")
327
+ #''
328
+ cm.get_use_additional_code("R65.20",search_in_ancestors=True)
329
+ #'code to identify specific acute organ dysfunction, such as:
330
+ # acute kidney failure (N17.-)
331
+ # acute respiratory failure (J96.0-)
332
+ # critical illness myopathy (G72.81)
333
+ # critical illness polyneuropathy (G62.81)
334
+ # disseminated intravascular coagulopathy [DIC] (D65)
335
+ # encephalopathy (metabolic) (septic) (G93.41)
336
+ # hepatic failure (K72.0-)'
337
+ ```
338
+ ### get_code_first(code, search_in_ancestors=False, prioritize_blocks=False)
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).
340
+ ```python
341
+ cm.get_code_first("I82.41")
342
+ #''
343
+ cm.get_code_first("R68.13")
344
+ #'confirmed diagnosis, if known'
345
+ cm.get_code_first("S04.01")
346
+ #''
347
+ cm.get_code_first("S04.01",search_in_ancestors=True)
348
+ #'any associated intracranial injury (S06.-)'
349
+ ```
350
+ ### get_full_data(code, search_in_ancestors=False, prioritize_blocks=False)
351
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a string containing all the available data of the code, otherwise it raises a ValueError. The empty fields are omitted from the string, except for the list of children (see second example below). When the optional argument `search_in_ancestors` is set to True, if the given code doesn't have a certain field but one of its ancestor does, the data of the closer ancestor that contains such a field is returned: see the previous functions to know which are the fields that are influenced by this argument and which are not. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
352
+ ```python
353
+ cm.get_full_data("I82.41")
354
+ #'Name:
355
+ # I82.41
356
+ # Description:
357
+ # Acute embolism and thrombosis of femoral vein
358
+ # Parent:
359
+ # I82.4
360
+ # inclusion term:
361
+ # Acute embolism and thrombosis of common femoral vein
362
+ # Acute embolism and thrombosis of deep femoral vein
363
+ # Children:
364
+ # I82.411, I82.412, I82.413, I82.419'
365
+ cm.get_full_data("C8401")
366
+ #'Name:
367
+ # C84.01
368
+ # Description:
369
+ # Mycosis fungoides, lymph nodes of head, face, and neck
370
+ # Parent:
371
+ # C84.0
372
+ # Children:
373
+ # None'
374
+ ```
375
+ ### get_parent(code, prioritize_blocks=False)
376
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a string containing its parent, otherwise it raises a ValueError. If the code doesn't have a parent (that is, if it's a chapter), it returns an empty string. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
377
+ ```python
378
+ cm.get_parent("I70.501")
379
+ #'I70.50'
380
+ cm.get_parent("12")
381
+ #''
382
+ ```
383
+ ### get_children(code, prioritize_blocks=False)
384
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a list of strings containing its children, otherwise it raises a ValueError. If the code doesn't have children, it returns an empty list. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
385
+ ```python
386
+ cm.get_children("12")
387
+ #['L00-L08', 'L10-L14', 'L20-L30', 'L40-L45', 'L49-L54', 'L55-L59', 'L60-L75', 'L76', 'L80-L99']
388
+ cm.get_children("I70.501")
389
+ #[]
390
+ ```
391
+ ### get_ancestors(code, prioritize_blocks=False)
392
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a list containing all its ancestors in the ICD-10-CM classification, otherwise it raises a ValueError. The results are ordered from its parent to its most distant ancestor. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
393
+ ```python
394
+ cm.get_ancestors("S14.109S")
395
+ #['S14.109', 'S14.10', 'S14.1', 'S14', 'S10-S19', '19']
396
+ cm.get_ancestors("7")
397
+ #[]
398
+ ```
399
+ ### get_descendants(code, prioritize_blocks=False)
400
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns a list containing all its descendants in the ICD-10-CM classification, otherwise it raises a ValueError. The returned codes are ordered as in a pre-order depth-first traversal of the tree containing the ICD-10-CM classification. For the meaning of the optional argument `prioritize_blocks`, please see [Blocks containing only one category](#blocks-containing-only-one-category).
401
+ ```python
402
+ cm.get_descendants("G93")
403
+ #['G93.0', 'G93.1', 'G93.2', 'G93.3', 'G93.4', 'G93.40', 'G93.41', 'G93.49', 'G93.5', 'G93.6', 'G93.7', 'G93.8', 'G93.81', 'G93.82', 'G93.89', 'G93.9']
404
+ cm.get_descendants("S14.109S")
405
+ #[]
406
+ ```
407
+ ### is_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
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.
409
+ ```python
410
+ cm.is_ancestor("18","R01.0")
411
+ #True
412
+ cm.is_ancestor("K00-K14","M31")
413
+ #False
414
+ cm.is_ancestor("B99","B99")
415
+ #False
416
+ cm.is_ancestor("B99","B99",prioritize_blocks_a=True)
417
+ #True
418
+ ```
419
+ ### is_descendant(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
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.
421
+ ```python
422
+ cm.is_descendant("R01.0","18")
423
+ #True
424
+ cm.is_descendant("M31","K00-K14")
425
+ #False
426
+ ```
427
+ ### get_nearest_common_ancestor(a, b, prioritize_blocks_a=False, prioritize_blocks_b=False)
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.
429
+ ```python
430
+ cm.get_nearest_common_ancestor("H28","H25.1")
431
+ #'H25-H28'
432
+ cm.get_nearest_common_ancestor("K35","E21.0")
433
+ #''
434
+ ```
435
+ ### is_leaf(code, prioritize_blocks=False)
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).
437
+ ```python
438
+ cm.is_leaf("12")
439
+ #False
440
+ cm.is_leaf("I70.501")
441
+ #True
442
+ ```
443
+ ### get_all_codes(with_dots=True)
444
+ This function returns the list of all items in the ICD-10-CM classification. If the optional boolean argument `with_dots` is set to False, the subcategories in the list will not have a dot in them, otherwise the subcategories will have a dot in them. The codes that represent both a block and a category (for example "B99") appear only once in this list.
445
+ ```python
446
+ cm.get_all_codes()
447
+ #['1', 'A00-A09', 'A00', 'A00.0', 'A00.1', 'A00.9', 'A01', 'A01.0', ...
448
+ cm.get_all_codes(False)
449
+ #['1', 'A00-A09', 'A00', 'A000', 'A001', 'A009', 'A01', 'A010', ...
450
+ ```
451
+ ### get_index(code)
452
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns its index in the list returned by `get_all_codes`, otherwise it raises a ValueError.
453
+ ```python
454
+ cm.get_index("P00")
455
+ #27735
456
+ cm.get_all_codes(True)[27735]
457
+ #"P00"
458
+ ```
459
+ ### remove_dot(code)
460
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns the same code in the notation without the dot, otherwise it raises a ValueError.
461
+ ```python
462
+ cm.remove_dot("C84.Z0")
463
+ #'C84Z0'
464
+ cm.remove_dot("C84Z0")
465
+ #'C84Z0'
466
+ cm.remove_dot("K00-K14")
467
+ #'K00-K14'
468
+ ```
469
+ ### add_dot(code)
470
+ This function takes a string as input. If the string is a valid ICD-10-CM code, it returns the same code in the notation with the dot, otherwise it raises a ValueError.
471
+ ```python
472
+ cm.add_dot("C84Z0")
473
+ #'C84.Z0'
474
+ cm.add_dot("C84.Z0")
475
+ #'C84.Z0'
476
+ cm.add_dot("K00-K14")
477
+ #'K00-K14'
478
+ ```
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
+
483
+ ## Conclusion
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.
485
+
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.
487
+
488
+ *Stefano Travasci*
489
+
490
+ ---
491
+
492
+ Paypal: [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/donate?hosted_button_id=9HMMFAZE248VN)
493
+
494
+ Curecoin: BKxCWuWzsqtLzAvAjtpsHpJ7LqFHPubqft
495
+
496
+ Bitcoin: bc1qjtnvzzgpsxz397l03vhrw8l30vl2p7fepmn5yy
497
+
498
+ <sub>*let me know if your favorite donation method is not in this list*</sub>