pydrugsdatabase


Namepydrugsdatabase JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://gitlab.com/marcnealer/pydrugsdatabase
SummaryDownloads the FDA drugs database along with the NDC codes active ingredients and drug classes
upload_time2024-06-20 06:50:19
maintainerNone
docs_urlNone
authorMarc Nealer
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyDrugsDatabase

PyDrugsDatabase downloads the FDA drugs database so that it can be used locally. The database is also
indexed allowing for obtaining drugs by generic name, active ingredients and drug classes

## Tutorials

### Installation

To Install PyDrugDatabase from PyPI,

```shell
pip install pydrusgdatabase
```

### Loading the Database

To create and load the database, from the latest data, from the fda,

```python
import pathlib
from pydrugsdatabase.drugs_load import DrugsLoad

DrugsLoad(pathlib.Path("/path/to/save/db")).load_from_fda()
```
This will download, extract format and save the records, plus create a series of indexes to access the
records faster.


### Reading the Database

```python
import pathlib
from pydrugsdatabase.drugs_database import DrugsDatabase

drugs_db = DrugsDatabase(pathlib.Path("/path/to/db/"))
```

#### Obtaining records by Product or Package NDC

```python
rec = drugs_db.get_by_package_ndc("4444-333")
```

A single TinyDB Document object is returned. This is a modified Dictionary

!!! Note
    Records are stored by product NDC numbers. not package. The first two sets of number
    represent the product NDC id, and the last is used for the exact packaging. Drug details
    are the same for all packages (including dose), except for the size of the 
    package (number of doses)

#### Obtaining Records by Medication Class

Each Drug has multiple medication classes, representing different aspects
of the given drug, such as chemical class, main usage, chemical route used etc.
Some medications that have multiple active ingredients will have classes assigned
for each of the active ingredients used.

```python
recs = drugs_db.get_by_class("ssri")
```

A list of TinyDB Documents are returned

#### Obtaining Records By generic Name

```python
recs = drugs_db.get_by_generic_name("paracetamol")
```
A list of TinyDB Document objects is returned

#### Obtaining Records By Ingredient

The database holds lists of the active ingredients in a given medication, which
can be multiple, for example Adderall.

```python
recs = drugs_db.get_by_ingredient("paracetamol")
```

Returns a list of TinyDB Documents


#### Get all Generic Names

```python
names = drugs_db.get_all_generic_names()
```
returns a list of strings

#### get All Medication Classes

```python
class_names = drugs_db.get_all_medication_classes()
```

#### Get All Ingredients

```python
ingredients = drugs_db.get_all_ingredients()
```

returns a list of strings

### Accessing the Database directly

The Database and the indexes can be accessed directly. They
are all TinyDB instances

* obj.db: The main DB
* obj.ndc_index: Two layered index for the NDC product Id
* obj.generic_name_index:  Index of Generic names
* obj.medication_class_index: Index of Medication classes
* obj.ingredient_index: index of the Active ingredients

## Reference

Records in the database are stored in the following format.

* package_ndc: List of strings
* product_ndc: string
* generic_name: string (lowercase)
* brand_name: string (lowercase)
* active_ingredients: list of strings (lowercase)
* pharm_class: list of strings (lowercase)
* pharm_class_epc: list of strings (lowercase)
* pharm_class_cs: list of strings (lowercase)
* pharm_class_moa: list of strings (lowercase)
* pharm_class_pe: list of strings (lowercase)

There is also a calculated field called all_classes() that returns all class fields in one (no duplicates)


## Concepts

The FDA drugs database comes in a large json file format, with a lot of additional data. I have stripped away the 
majority of it, leaving the main classification elements, brand name, generic name, ingredients and medication classes.
the data is pulled and ran through a pydantic model to ensure standards before being saved.

The data is saved in tinyDB, thus no need to have a database server in place, just run the download and start
accessing the data


            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/marcnealer/pydrugsdatabase",
    "name": "pydrugsdatabase",
    "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/99/b7/9205a08afa4d060ab199e3f726dd599756a8b85e3267ab90c2a4e20c3fb4/pydrugsdatabase-0.1.0.tar.gz",
    "platform": null,
    "description": "# pyDrugsDatabase\n\nPyDrugsDatabase downloads the FDA drugs database so that it can be used locally. The database is also\nindexed allowing for obtaining drugs by generic name, active ingredients and drug classes\n\n## Tutorials\n\n### Installation\n\nTo Install PyDrugDatabase from PyPI,\n\n```shell\npip install pydrusgdatabase\n```\n\n### Loading the Database\n\nTo create and load the database, from the latest data, from the fda,\n\n```python\nimport pathlib\nfrom pydrugsdatabase.drugs_load import DrugsLoad\n\nDrugsLoad(pathlib.Path(\"/path/to/save/db\")).load_from_fda()\n```\nThis will download, extract format and save the records, plus create a series of indexes to access the\nrecords faster.\n\n\n### Reading the Database\n\n```python\nimport pathlib\nfrom pydrugsdatabase.drugs_database import DrugsDatabase\n\ndrugs_db = DrugsDatabase(pathlib.Path(\"/path/to/db/\"))\n```\n\n#### Obtaining records by Product or Package NDC\n\n```python\nrec = drugs_db.get_by_package_ndc(\"4444-333\")\n```\n\nA single TinyDB Document object is returned. This is a modified Dictionary\n\n!!! Note\n    Records are stored by product NDC numbers. not package. The first two sets of number\n    represent the product NDC id, and the last is used for the exact packaging. Drug details\n    are the same for all packages (including dose), except for the size of the \n    package (number of doses)\n\n#### Obtaining Records by Medication Class\n\nEach Drug has multiple medication classes, representing different aspects\nof the given drug, such as chemical class, main usage, chemical route used etc.\nSome medications that have multiple active ingredients will have classes assigned\nfor each of the active ingredients used.\n\n```python\nrecs = drugs_db.get_by_class(\"ssri\")\n```\n\nA list of TinyDB Documents are returned\n\n#### Obtaining Records By generic Name\n\n```python\nrecs = drugs_db.get_by_generic_name(\"paracetamol\")\n```\nA list of TinyDB Document objects is returned\n\n#### Obtaining Records By Ingredient\n\nThe database holds lists of the active ingredients in a given medication, which\ncan be multiple, for example Adderall.\n\n```python\nrecs = drugs_db.get_by_ingredient(\"paracetamol\")\n```\n\nReturns a list of TinyDB Documents\n\n\n#### Get all Generic Names\n\n```python\nnames = drugs_db.get_all_generic_names()\n```\nreturns a list of strings\n\n#### get All Medication Classes\n\n```python\nclass_names = drugs_db.get_all_medication_classes()\n```\n\n#### Get All Ingredients\n\n```python\ningredients = drugs_db.get_all_ingredients()\n```\n\nreturns a list of strings\n\n### Accessing the Database directly\n\nThe Database and the indexes can be accessed directly. They\nare all TinyDB instances\n\n* obj.db: The main DB\n* obj.ndc_index: Two layered index for the NDC product Id\n* obj.generic_name_index:  Index of Generic names\n* obj.medication_class_index: Index of Medication classes\n* obj.ingredient_index: index of the Active ingredients\n\n## Reference\n\nRecords in the database are stored in the following format.\n\n* package_ndc: List of strings\n* product_ndc: string\n* generic_name: string (lowercase)\n* brand_name: string (lowercase)\n* active_ingredients: list of strings (lowercase)\n* pharm_class: list of strings (lowercase)\n* pharm_class_epc: list of strings (lowercase)\n* pharm_class_cs: list of strings (lowercase)\n* pharm_class_moa: list of strings (lowercase)\n* pharm_class_pe: list of strings (lowercase)\n\nThere is also a calculated field called all_classes() that returns all class fields in one (no duplicates)\n\n\n## Concepts\n\nThe FDA drugs database comes in a large json file format, with a lot of additional data. I have stripped away the \nmajority of it, leaving the main classification elements, brand name, generic name, ingredients and medication classes.\nthe data is pulled and ran through a pydantic model to ensure standards before being saved.\n\nThe data is saved in tinyDB, thus no need to have a database server in place, just run the download and start\naccessing the data\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Downloads the FDA drugs database along with the NDC codes active ingredients and drug classes",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://gitlab.com/marcnealer/pydrugsdatabase"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "99b79205a08afa4d060ab199e3f726dd599756a8b85e3267ab90c2a4e20c3fb4",
                "md5": "db8255ff1c76c12dbf585e86fa7a40bb",
                "sha256": "77ef9b43dd08a8c57ca283e3c75cf10c45808fcbc1971eab0ba83644e893d3fb"
            },
            "downloads": -1,
            "filename": "pydrugsdatabase-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "db8255ff1c76c12dbf585e86fa7a40bb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5915,
            "upload_time": "2024-06-20T06:50:19",
            "upload_time_iso_8601": "2024-06-20T06:50:19.871785Z",
            "url": "https://files.pythonhosted.org/packages/99/b7/9205a08afa4d060ab199e3f726dd599756a8b85e3267ab90c2a4e20c3fb4/pydrugsdatabase-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-20 06:50:19",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "marcnealer",
    "gitlab_project": "pydrugsdatabase",
    "lcname": "pydrugsdatabase"
}
        
Elapsed time: 0.45776s