# Python ICD10
Python-icd10 can be used to download icd10 diagnoses codes from the US CDC website. The data is reformatted and
validated using Pydantic, to ensure all notes and additional information is captured.
Once downloaded, the data can be accessed to locate codes via their descriptions, via their partial code, or
you can pull specific records using the exact icd10 code.
## Installing Python-icd10
To install Python-icd10 from PyPI, run
```shell
pip install python_icd10
```
# Basic Usage
Python-icd10 comes in two main classes. One to download and build the database, and one used to read/extract data
from it.
### Creating/Updating the ICD10 database
```python
import pathlib
from python_icd10.icd10_load import ICD10Load
ICD10Load(pathlib.Path("/path/tp/save/db/")).load_from_cdc()
```
The above code will download the ICD10 codes from the CDC and create the database. The path does not need to exist
before running this command. The code will create directories etc for you, as long as it has access to do so. This class
will examine the CDC website and download the most recent file, based on the year. It will not take any notice of minor
update files though.
### Using the database
```python
import pathlib
from python_icd10.icd10_warehouse import ICD10Warehouse
icd10 = ICD10Warehouse(pathlib.Path("/path/to/the/database/"))
```
This will create an object with access to the database.
A single record can be fetched by find a record by its direct ICD10 code.
```python
record = icd10.get_by_code("M30")
```
It should be noted that the returned value is a TinyDB Document object. This is a child of a Dictionary with some
additions such as obj.doc_id
Finding records via the diagnosis description can be done like this:
```python
records = icd10.search_by_descriptipn("arthritis")
```
The search is case insensitive and will return a list of Document objects
You can also search by partial icd10 code
```python
records = icd10.search_by_code("M30")
```
All ICD10 codes can be returned in a list of strings using:
```python
codes = icd10.get_all_codes()
```
### Directly accessing the database
The TinyDB database is accessable via this object, so you can run custom queries directlt against the database
```python
import pathlib
from tinydb import Query
from python_icd10.icd10_warehouse import ICD10Warehouse
icd10 = ICD10Warehouse(pathlib.Path("/path/to/db/"))
q = Query()
recs = icd10.db.search(q.section_name.matches("*hand*"))
```
See TinyDB for details on creating your own queries.
### Record format
Data from the CDC comes as a multi level XML file with lots of embedded and additional data. Python-icd10 flattens
this and makes it more accessible. Each record is shaped as follows
* name: ICD10 code as a string
* description: Description attached to the code
* inclusion_term: Notes on inclusion terms for the code. List of Strings
* excludes1: Exclusion details(1). List of Strings
* excludes2: Exclusion details(2). List of Strings
* includes: Inclusion notes. List of Strings
* code_first: List of Strings
* additional_codes: List of Strings
* parent: Parent code. String or None
* section_name: string
* section_description: String or None
* chapter: String
A lot of this data, I am unsure of its use, but it's included in the CDC data, so I have included it here
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/marcnealer/python-icd10.git",
"name": "python-icd10",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Marc Nealer",
"author_email": "marcnealer@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ee/4e/8ff17bd69826c1129ecfd9f5ed80f7f454dad089b545c31069b8dfdfd39d/python_icd10-1.0.2.tar.gz",
"platform": null,
"description": "# Python ICD10\n\nPython-icd10 can be used to download icd10 diagnoses codes from the US CDC website. The data is reformatted and\nvalidated using Pydantic, to ensure all notes and additional information is captured. \n\nOnce downloaded, the data can be accessed to locate codes via their descriptions, via their partial code, or\nyou can pull specific records using the exact icd10 code.\n\n## Installing Python-icd10\n\nTo install Python-icd10 from PyPI, run\n```shell\npip install python_icd10\n```\n\n# Basic Usage\n\nPython-icd10 comes in two main classes. One to download and build the database, and one used to read/extract data\nfrom it.\n\n### Creating/Updating the ICD10 database\n\n```python\nimport pathlib\nfrom python_icd10.icd10_load import ICD10Load\n\nICD10Load(pathlib.Path(\"/path/tp/save/db/\")).load_from_cdc()\n```\nThe above code will download the ICD10 codes from the CDC and create the database. The path does not need to exist\nbefore running this command. The code will create directories etc for you, as long as it has access to do so. This class\nwill examine the CDC website and download the most recent file, based on the year. It will not take any notice of minor\nupdate files though.\n\n### Using the database\n\n```python\nimport pathlib\nfrom python_icd10.icd10_warehouse import ICD10Warehouse\n\nicd10 = ICD10Warehouse(pathlib.Path(\"/path/to/the/database/\"))\n```\nThis will create an object with access to the database. \n\n\nA single record can be fetched by find a record by its direct ICD10 code.\n```python\nrecord = icd10.get_by_code(\"M30\")\n```\nIt should be noted that the returned value is a TinyDB Document object. This is a child of a Dictionary with some\nadditions such as obj.doc_id\n\n\nFinding records via the diagnosis description can be done like this:\n```python\nrecords = icd10.search_by_descriptipn(\"arthritis\")\n```\nThe search is case insensitive and will return a list of Document objects\n\n\nYou can also search by partial icd10 code\n```python\nrecords = icd10.search_by_code(\"M30\")\n```\n\nAll ICD10 codes can be returned in a list of strings using:\n```python\ncodes = icd10.get_all_codes()\n```\n\n### Directly accessing the database\n\nThe TinyDB database is accessable via this object, so you can run custom queries directlt against the database\n\n```python\nimport pathlib\nfrom tinydb import Query\nfrom python_icd10.icd10_warehouse import ICD10Warehouse\n\nicd10 = ICD10Warehouse(pathlib.Path(\"/path/to/db/\"))\nq = Query()\n\nrecs = icd10.db.search(q.section_name.matches(\"*hand*\"))\n```\n\nSee TinyDB for details on creating your own queries.\n\n\n### Record format\n\nData from the CDC comes as a multi level XML file with lots of embedded and additional data. Python-icd10 flattens\nthis and makes it more accessible. Each record is shaped as follows\n\n* name: ICD10 code as a string\n* description: Description attached to the code\n* inclusion_term: Notes on inclusion terms for the code. List of Strings\n* excludes1: Exclusion details(1). List of Strings\n* excludes2: Exclusion details(2). List of Strings\n* includes: Inclusion notes. List of Strings\n* code_first: List of Strings\n* additional_codes: List of Strings\n* parent: Parent code. String or None\n* section_name: string\n* section_description: String or None\n* chapter: String\n\nA lot of this data, I am unsure of its use, but it's included in the CDC data, so I have included it here\n\n\n\n\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Downloads ICD10 codes from the CDC and makes them available in a searchable database",
"version": "1.0.2",
"project_urls": {
"Homepage": "https://gitlab.com/marcnealer/python-icd10.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ee4e8ff17bd69826c1129ecfd9f5ed80f7f454dad089b545c31069b8dfdfd39d",
"md5": "b25fbb50e7d237039f7a0624c65d566d",
"sha256": "f437f104e745a8db5167393c32a0f8d5407a6b046b2ed1bfd8724f4f711032b3"
},
"downloads": -1,
"filename": "python_icd10-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "b25fbb50e7d237039f7a0624c65d566d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7319,
"upload_time": "2024-06-20T05:31:43",
"upload_time_iso_8601": "2024-06-20T05:31:43.187580Z",
"url": "https://files.pythonhosted.org/packages/ee/4e/8ff17bd69826c1129ecfd9f5ed80f7f454dad089b545c31069b8dfdfd39d/python_icd10-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-20 05:31:43",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "marcnealer",
"gitlab_project": "python-icd10",
"lcname": "python-icd10"
}