Skip to main content

fhiratwill.terminology_binder

Nearest-neighbor terminology binding for FHIR at Will. A free-text phrase is embedded with SapBERT and matched by cosine similarity against one or more dictionaries. ICD-10-CM is loaded by default. Codes always come from a catalog row; the model never invents a code.

Alpha software. Binding logic in this package is expected to change.

Install

pip install "fhiratwill.terminology_binder[nn]"

The [nn] extra installs sentence-transformers and torch for the default SapBERT encoder. The base install is enough if you inject your own encoder.

Bind a phrase or a Bundle

from fhiratwill.terminology_binder import Dictionary, TerminologyIndex, bind_bundle

index = TerminologyIndex.load()  # ICD-10-CM by default
result = index.bind("type 2 diabetes")
print(result.coding)
# {'system': 'http://hl7.org/fhir/sid/icd-10-cm', 'code': 'E11.9', 'display': '...'}

bound = await bind_bundle(bundle, index=index)

confidence is not the cosine. It uses the sample standard deviation of the k neighbor scores so a tight pack cannot look sure: min(1, s1 * std / 0.10).

Add your own dictionaries

A dictionary is JSON: either a concept list (pass name and system) or an object that already includes them.

{
  "name": "loinc",
  "system": "http://loinc.org",
  "concepts": [
    {"code": "8867-4", "display": "Heart rate", "aliases": ["pulse"], "leaf": true}
  ]
}
loinc = Dictionary.from_path("loinc.json")
index = TerminologyIndex.load()
index.add_dictionary(loinc)

index = TerminologyIndex.load(loinc)  # ICD-10-CM + LOINC
index = TerminologyIndex.load(loinc, include_default=False)  # LOINC only

First ICD-10-CM embed is cached under %LOCALAPPDATA%/fhiratwill/terminology_binder (or $XDG_CACHE_HOME/fhiratwill/terminology_binder). Override with FHIRATWILL_BINDER_CACHE. Later runs only encode the query.

Development

From the fhirbridge repository root:

python -m pip install -e ".[dev]"
python -m pip install -e "./packages/terminology-binder[nn]"
pytest packages/terminology-binder/tests
python -m build packages/terminology-binder
twine check packages/terminology-binder/dist/*

Tests inject a fake encoder and do not download SapBERT.

License

Apache License 2.0.

Metadata

Release files for fhiratwill.terminology-binder 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fhiratwill.terminology-binder 0.2.0
File Size Uploaded
fhiratwill_terminology_binder-0.2.0.tar.gz 550.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fhiratwill.terminology-binder 0.2.0
File Interpreter ABI Platform
fhiratwill_terminology_binder-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / fhiratwill_terminology_binder-0.2.0.tar.gz

Download URL fhiratwill_terminology_binder-0.2.0.tar.gz
Size 550.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dca1e7ea5ece98a3ea286bc013d2c44de9036fa922d3fa69b8be1e74cd2c8b93
BLAKE2b-256 checksum
How to use checksums
f1d7a437eda682a01f8ecb07e2ab657fbae21c6da0099fcd0ad47c865408c9f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release files / fhiratwill_terminology_binder-0.2.0-py3-none-any.whl

Download URL fhiratwill_terminology_binder-0.2.0-py3-none-any.whl
Size 577.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
849c34ca95070fc2b525a3c7d92f19c4edc39cd102411ab982b24f802e17e634
BLAKE2b-256 checksum
How to use checksums
3b837def9367e5ac561e66497ad94a955f0163671239b00fdc1f47a0c440c34f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page