返回资讯中心
外部精选
软件工程
#开发者实时流

开发者自建可本地运行的药物相互作用API,替代NLM已停服接口

来源标题:I rebuilt NLM's retired drug interaction API

开发者推出自托管药物相互作用API localddi,输出格式与2024年1月2日停服的NLM RxNav Drug Interaction API一致,原有集成可直接改指向自建服务器。该项目从DDInter 2.0导入数据,代码采用MIT许可,但数据仅限非商业用途。作者强调其未经临床验证,不可用于治疗决策。

Hacker News 最新shubhamjoshipro2026/11/16 · 今天29 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

A drug-drug interaction API you run yourself. Send RxCUIs or drug names, get back the interactions listed in the data you imported. It serves the same JSON shape as the NLM RxNav Drug Interaction API that was discontinued on 2 January 2024, so an integration that broke that day can point at your own server instead.

Not for clinical use. localddi is not a medical device and has not been clinically validated by anyone. The data is a third-party research database that can be incomplete, outdated or wrong, and localddi's matching of drug names can also be wrong. A response with no interactions does not mean a combination is safe. Do not use it to make treatment decisions.

The code is MIT. The default data is not. localddi import downloads interaction data from DDInter 2.0, which is licensed CC BY-NC-SA 4.0: non-commercial use only. No interaction data is stored in this repository. For commercial use you need DDInter's permission or your own licensed data (--csv). Details: docs/data-and-licensing.md.

You need Docker. Building and starting takes about a minute. The import is limited by NLM's download server: the 75 MB RxNorm file took me about ten minutes on the day I tested, and the import itself a few seconds. If you only want to see the API respond, use --demo (below) which needs no download at all.

git clone https://github.com/shubhamjoshipromail-svg/localddi cd localddi docker compose up -d --build docker compose run --rm api localddi import

The import shows DDInter's licence terms and asks you to accept them (or pass --accept-ddinter-license). It then downloads RxNorm and DDInter, builds a SQLite database in a Docker volume, and prints what it matched. The running server picks the database up immediately.

curl "http://localhost:8080/v1/interactions?drugs=warfarin,aspirin"

{ "disclaimer": "localddi is NOT a medical device and is NOT clinically validated. ...", "summary": { "drugs_resolved": 2, "drugs_unresolved": 0, "pairs_checked": 1, "interactions_found": 1, "highest_severity": "major", "by_severity": {"major": 1}, "complete": true }, "drugs": [ {"input": "warfarin", "input_type": "name", "resolved": true, "rxcui": "11289", "name": "warfarin", "tty": "IN", "match": "exact", "reason": null, "ingredients": [{"rxcui": "11289", "name": "warfarin"}], "suggestions": []}, {"input": "aspirin", "input_type": "name", "resolved": true, "rxcui": "1191", "name": "aspirin", "tty": "IN", "match": "exact", "reason": null, "ingredients": [{"rxcui": "1191", "name": "aspirin"}], "suggestions": []} ], "interactions": [ { "severity": "major", "source": "DDInter", "description": null, "management": null, "drug_a": {"input": "warfarin", "rxcui": "11289", "name": "warfarin", "source_id": "DDInter1951", "source_name": "Warfarin"}, "drug_b": {"input": "aspirin", "rxcui": "1191", "name": "aspirin", "source_id": "DDInter20", "source_name": "Acetylsalicylic acid"} } ], "sources": [ {"name": "DDInter", "version": "2.0", "url": "https://ddinter2.scbdd.com/", "license": "CC BY-NC-SA 4.0", "license_url": "https://creativecommons.org/licenses/by-nc-sa/4.0/", "attribution": "Interaction data from DDInter 2.0 ...", "interactions": 176817} ] }

That is real output from an import run on 15 November 2026 (RxNorm release of 2 November 2026); your counts may differ as the upstream data changes.

The same question in the old NLM form, by RxCUI:

curl "http://localhost:8080/REST/interaction/list.json?rxcuis=207106+152923"

{ "nlmDisclaimer": "This response does not come from NLM. localddi is NOT a medical device ...", "fullInteractionTypeGroup": [ { "sourceDisclaimer": "DDInter data is licensed for non-commercial use only (CC BY-NC-SA 4.0). ...", "sourceName": "DDInter", "fullInteractionType": [ { "comment": "Drug1 (rxcui = 152923, name = simvastatin 40 MG Oral Tablet [Zocor], tty = SBD). Drug2 (rxcui = 207106, name = fluconazole 50 MG Oral Tablet [Diflucan], tty = SBD). Drug1 is resolved to simvastatin, Drug2 is resolved to fluconazole and interaction asserted in DDInter between Simvastatin and Fluconazole.", "minConcept": [ {"rxcui": "152923", "name": "simvastatin 40 MG Oral Tablet [Zocor]", "tty": "SBD"}, {"rxcui": "207106", "name": "fluconazole 50 MG Oral Tablet [Diflucan]", "tty": "SBD"} ], "interactionPair": [ { "interactionConcept": [ {"minConceptItem": {"rxcui": "36567", "name": "simvastatin", "tty": "IN"}, "sourceConceptItem": {"id": "DDInter1675", "name": "Simvastatin", "url": "https://ddinter2.scbdd.com/server/drug-detail/DDInter1675/"}}, {"minConceptItem": {"rxcui": "4450", "name": "fluconazole", "tty": "IN"}, "sourceConceptItem": {"id": "DDInter743", "name": "Fluconazole", "url": "https://ddinter2.scbdd.com/server/drug-detail/DDInter743/"}} ], "severity": "major", "description": "DDInter lists a major interaction between Simvastatin and Fluconazole." } ] } ] } ] }

Interactive API documentation is at http://localhost:8080/docs (OpenAPI at /openapi.json).

Just want to see the response shapes first? docker compose run --rm api localddi import --demo loads a tiny synthetic fixture instead: no download, no licensed data, and not real interaction data either.

pip install -e . localddi import localddi serve # http://127.0.0.1:8080 localddi check warfarin aspirin "Tylenol PM"

What it does, and what it deliberately does not

Deterministic. A lookup is a SQL query against a local SQLite file. The same request against the same import always gives the same response. There is no language model anywhere in it.

Offline after import. The server makes no outbound network calls and needs no API key or account. Only localddi import uses the network, and it can run from files you fetched yourself (--rxnorm-zip, --ddinter-dir).

RxNorm-aware. An input can be an ingredient, a US brand name, or a specific product (simvastatin 40 MG Oral Tablet [Zocor]); it is reduced to its ingredients using RxNorm's own relationships. A combination product is checked ingredient by ingredient.

Fixed name rules, no fuzzy matching. After an exact lookup fails, localddi tries removing a trailing qualifier, expanding abbreviations and dropping release words, stripping a trailing salt only if the remainder is an RxNorm ingredient, then resolving every part of a combination. The match field reports the rule used. A misspelt or unknown name stays "resolved": false with suggestions, and the summary says "complete": false; suggestions are never applied automatically.

It carries the licence with the data. Every response names its source, licence and attribution.

It does not write its own interaction data, explain mechanisms, give dosing or management advice, check food, disease or allergy interactions, or store anything about requests.

API

Native:

In native responses, each resolved drug's match field explains the lookup: exact, alias, source-name (an imported source name), rxcui, or a rewrite rule. Exact lookup uses a key with case, accents and punctuation normalised. Coumadin resolves through a built-in alias to warfarin.

In 0.1.1 the fallback order is qualifier-stripped, normalized, salt-stripped, then combination. These remove trailing qualifiers such as (topical), expand HCl/HBr/HCTZ/APAP/ASA and drop trailing release words such as ER/XR/XL/SR/CR/DR/ODT/HFA. A trailing salt is removed only if the remainder is an RxNorm ingredient. Combinations such as A/B, A-B or A with B resolve only if every part does. The rules do not measure similarity or correct misspellings. See the evaluation for details and the limits of ingredient-level matching.

Severity is one of contraindicated, major, moderate, minor, unknown. DDInter uses the middle three plus "Unknown"; about 23% of the stored DDInter rows are "Unknown", meaning DDInter lists the pair without a level. Set LOCALDDI_MIN_SEVERITY=minor to leave those out of every response, or pass min_severity per request on the native API.

The paths, parameters and JSON nesting match archived NLM responses, and a test compares the key structure against them. The content is different: sourceName is DDInter rather than DrugBank/ONCHigh, and descriptions are short generated sentences because DDInter's download files carry a severity level but no narrative. XML output is not implemented.

Read docs/nlm-compatibility.md before switching; it lists every known difference and includes the one-line change for OpenEMR. Nobody has reported running a production client against localddi yet, and it has not been tested inside OpenEMR. If you try it, an integration report would help a lot.

Measured on the import of 15 November 2026 (all 14 DDInter files, RxNorm release 2026-11-02):

The 373 unmatched drugs (19%) are mostly drugs no longer marketed in the United States (RxNorm's free subset covers currently prescribable US drugs), vaccines and herbal products named differently in the two vocabularies. Every unmatched name is written to import-report.json.

The 0.1.1 evaluation checks pair overlap and name resolution, not clinical correctness:

Read the methods, results and reproduction instructions, including the missing pairs and unknown severity levels. Clinical correctness, false positives and DDInter's own accuracy were not measured, and localddi has not been tested inside OpenEMR. Eleven well-known pairs were also spot-checked by hand and were listed; that was a smoke test, not a validation.

One judgement call you should know about: DDInter's download page links 8 of its 14 per-category files. The other 6 (cardiovascular, genito-urinary, anti-infective, musculoskeletal, nervous system, sensory organs) sit in the same download directory on DDInter's server but are not linked. localddi downloads all 14 by default, because with only the linked 8 a pair such as sildenafil + nitroglycerin is missing. Pass --ddinter-linked-only if you would rather use only what the page links.

All 14 ATC category files (A B C D G H J L M N P R S V) use the same five-column format. Per file, 81–85% of drugs match RxNorm and 66–84% of pairs are kept. Import now warns if any of the 14 files is missing.

All optional, set as environment variables (see .env.example):

There is no built-in TLS, rate limiting or audit log. Put it behind your own reverse proxy if it leaves localhost; see SECURITY.md.

To refresh the data, run the import again with --refresh. The database is rebuilt in a temporary file and swapped in atomically, so the server keeps answering.

localddi import --no-ddinter --csv my_interactions.csv
--source-name "MySource" --source-license "Licensed to Example Clinic"

Columns: drug_a, drug_b, and optionally severity, description, management, rxcui_a, rxcui_b. See docs/data-and-licensing.md.

What localddi adds is narrow: the NLM response shape, RxCUI in and out, fully offline operation, and no model in the loop.

pip install -e '.[dev]' make test # 158 tests, offline make lint

The tests cover the API, the NLM-compatible structure, the importer on a small synthetic fixture, name normalisation, the downloader (against a local server) and a check that the server never opens a network connection. See CONTRIBUTING.md.

localddi was extracted from an earlier research prototype of a pharmacist-facing interaction checker. The patient records, the web interface and the language-model explanation layer were left behind; the deterministic lookup was kept and rebuilt around RxNorm files instead of live RxNorm API calls.

Code: MIT. Data: not included, and under its publishers' terms, namely DDInter 2.0 (CC BY-NC-SA 4.0) and RxNorm Current Prescribable Content (public domain, U.S. National Library of Medicine). This project is not affiliated with or endorsed by NLM or DDInter.

If you use it in research, see CITATION.cff, and please cite DDInter.

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →