# FHIR Terminology Encoder
This is a [scikit-learn](https://scikit-learn.org/) compatible encoder that uses
a FHIR terminology server to encode ontological features.
It currently supports subsumption relationships and properties.
You supply a scope in the form of a FHIR ValueSet URI, and a FHIR terminology
endpoint.
The result is a multi-hot encoded vector delivered as a sparse matrix, suitable
for input into most models and estimators.
## Installation
```bash
pip install fhir-tx-encoder
```
## Usage
```python
from fhir_tx_encoder import FhirTerminologyEncoder
import numpy as np
encoder = FhirTerminologyEncoder(
scope="http://snomed.info/sct?fhir_vs=ecl/(%3E%3E%20363346000)",
tx_url="http://localhost:8080/fhir",
)
result = encoder.fit_transform(np.array([["399981008", "363346000"]]))
print(f"result.shape: {result.shape}")
print(f"result:\n{result.toarray()}")
```
Which would output:
```
Expanding value set: http://snomed.info/sct?fhir_vs=ecl/(%3E%3E%20363346000)
Expanding (6 items, offset 0, total 6)
Expansion complete
Generating one-hot encoding... (6, 6)
Creating index... 6 items
Applying transitive closure
Batch 1 of 1, 6 items... 15 pairs added
Encoding complete: (6, 6)
encoder.codes_: ['404684003', '64572001', '363346000', '399981008', '55342001', '138875005']
encoder.displays_: ['Clinical finding', 'Disease', 'Malignant neoplastic disease', 'Neoplasm and/or hamartoma', 'Neoplastic disease', 'SNOMED CT Concept']
result.shape: (2, 6)
result:
[[1. 1. 0. 1. 0. 1.]
[1. 1. 1. 1. 1. 1.]]
```
## Important note
This software is currently in alpha. It is not yet ready for production use.
Copyright © 2023, Commonwealth Scientific and Industrial Research Organisation
(CSIRO) ABN 41 687 119 230. Licensed under
the [Apache License, version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
Raw data
{
"_id": null,
"home_page": "",
"name": "fhir-tx-encoder",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Australian e-Health Research Centre, CSIRO",
"author_email": "ontoserver-support@csiro.au",
"download_url": "https://files.pythonhosted.org/packages/13/1c/2f7fea276a24321e50e15b950dc702b4b4548582da0b0b99abad7e33f677/fhir_tx_encoder-1.0.1.tar.gz",
"platform": null,
"description": "# FHIR Terminology Encoder\n\nThis is a [scikit-learn](https://scikit-learn.org/) compatible encoder that uses \na FHIR terminology server to encode ontological features.\n\nIt currently supports subsumption relationships and properties.\n\nYou supply a scope in the form of a FHIR ValueSet URI, and a FHIR terminology\nendpoint.\n\nThe result is a multi-hot encoded vector delivered as a sparse matrix, suitable\nfor input into most models and estimators.\n\n## Installation\n\n```bash\npip install fhir-tx-encoder\n```\n\n## Usage\n\n```python\nfrom fhir_tx_encoder import FhirTerminologyEncoder\nimport numpy as np\n\nencoder = FhirTerminologyEncoder(\n scope=\"http://snomed.info/sct?fhir_vs=ecl/(%3E%3E%20363346000)\",\n tx_url=\"http://localhost:8080/fhir\",\n)\n\nresult = encoder.fit_transform(np.array([[\"399981008\", \"363346000\"]]))\nprint(f\"result.shape: {result.shape}\")\nprint(f\"result:\\n{result.toarray()}\")\n```\n\nWhich would output:\n\n```\nExpanding value set: http://snomed.info/sct?fhir_vs=ecl/(%3E%3E%20363346000)\nExpanding (6 items, offset 0, total 6)\nExpansion complete\nGenerating one-hot encoding... (6, 6)\nCreating index... 6 items\nApplying transitive closure\nBatch 1 of 1, 6 items... 15 pairs added\nEncoding complete: (6, 6)\nencoder.codes_: ['404684003', '64572001', '363346000', '399981008', '55342001', '138875005']\nencoder.displays_: ['Clinical finding', 'Disease', 'Malignant neoplastic disease', 'Neoplasm and/or hamartoma', 'Neoplastic disease', 'SNOMED CT Concept']\nresult.shape: (2, 6)\nresult:\n[[1. 1. 0. 1. 0. 1.]\n [1. 1. 1. 1. 1. 1.]]\n```\n\n## Important note\n\nThis software is currently in alpha. It is not yet ready for production use.\n\nCopyright \u00a9 2023, Commonwealth Scientific and Industrial Research Organisation \n(CSIRO) ABN 41 687 119 230. Licensed under\nthe [Apache License, version 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Tools for encoding FHIR terminology concepts for machine learning",
"version": "1.0.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "dc7443f0464b9b08fe416f5ff63ee2ebe29bab46add6ff1de59c5e72f4d6f22a",
"md5": "409f344cd5988fb18c976b08acefd1b8",
"sha256": "6982c0e51648184ed73a2039eee214dea6de47505a426bc2d4d53cd88dc2feef"
},
"downloads": -1,
"filename": "fhir_tx_encoder-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "409f344cd5988fb18c976b08acefd1b8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 11989,
"upload_time": "2023-10-26T13:10:37",
"upload_time_iso_8601": "2023-10-26T13:10:37.035582Z",
"url": "https://files.pythonhosted.org/packages/dc/74/43f0464b9b08fe416f5ff63ee2ebe29bab46add6ff1de59c5e72f4d6f22a/fhir_tx_encoder-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "131c2f7fea276a24321e50e15b950dc702b4b4548582da0b0b99abad7e33f677",
"md5": "945efe51a59a1b27756dc2ae0e6b69c6",
"sha256": "2154c09663c87efe80724808811f9ffcee3673439cdd568279d0d4d3d9fccf72"
},
"downloads": -1,
"filename": "fhir_tx_encoder-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "945efe51a59a1b27756dc2ae0e6b69c6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9872,
"upload_time": "2023-10-26T13:10:38",
"upload_time_iso_8601": "2023-10-26T13:10:38.237347Z",
"url": "https://files.pythonhosted.org/packages/13/1c/2f7fea276a24321e50e15b950dc702b4b4548582da0b0b99abad7e33f677/fhir_tx_encoder-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-26 13:10:38",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "fhir-tx-encoder"
}