This release is a pre-release and may not be stable for production use.
DMD database
A Python toolkit for building the NHS Dictionary of Medicines and Devices (DM+D) XML distribution files into a relational database. It provides an SQLAlchemy 2 ORM, CLI scripts for building single-version and multi-version warehouse databases, and a query API for looking up medicines by name, ID, or ingredient.
There is online documentation for dmd.
Please note, this is for research purposes only and was built to map prescriptions from sources such as CPRD and the UK BioBank. Please do not use for any healthcare related implementation.
Installation
Using pip
Install from a local clone for development:
git clone git@gitlab.com:cfinan/dmd.git
cd dmd
pip install -e ".[dev]"
Using conda
A conda package is available in the cfin channel for Python 3.11--3.13
(Linux-64):
conda install -c cfin -c conda-forge dmd
Usage
Command line
Build one weekly SQLite database from a TRUD zip pair:
dmd-build -v -B nhsbsa_dmdbonus_<version>.zip nhsbsa_dmd_<version>.zip ~/dmd.db
Walk a year-folder archive tree and write one weekly file per dump (existing destinations are skipped):
resources/bin/dmd-bulk-build.sh /data/Dmd/DmdArchive /data/Dmd/DmdDbs
Load those weeklies into the current warehouse file. Use --create
(not -c; -c is the config-file flag). The default destination is
/data/Dmd/Warehouse/dmd_warehouse_v2.db. The old file
dmd_warehouse.db is refused.
dmd-warehouse-build -v list --create \
/data/Dmd/Warehouse/weeklies.list \
/data/Dmd/Warehouse/dmd_warehouse_v2.db
dmd-warehouse-build corpus discovers remaining zips and records each
dump as loaded, set-aside, or skipped. Use it when weeklies are not
already built under year folders.
More information on DM+D can be found on the NHS digital TRUD site. You will need an account to subscribe and download.
For full CLI help:
dmd-build --help
dmd-warehouse-build --help
Python API
import sqlalchemy
from dmd.build import build_dmd
engine = sqlalchemy.create_engine("sqlite:///dmd.db")
sm = sqlalchemy.orm.sessionmaker(bind=engine)
build_dmd(
sm,
"nhsbsa_dmd_<version>.zip",
bonus_zip="nhsbsa_dmdbonus_<version>.zip",
)
Schema
The final database will have the following schema (including bonus file). Open in a separate browser tab to make it larger.
Release files for nhs-dmd 0.3.0b0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nhs_dmd-0.3.0b0.tar.gz | 96.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nhs_dmd-0.3.0b0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 194.1 kB
Release files / nhs_dmd-0.3.0b0.tar.gz
| Download URL | nhs_dmd-0.3.0b0.tar.gz |
|---|---|
| Size | 96.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77f4ffae7c1de8127e0a70448634ff6b47cf641d028278cbbd04e926323d43e5
|
|
BLAKE2b-256 checksum How to use checksums |
acf3a6054c598d746bc49ca5ee0f162a730a4e4f59e1f33de3368ac0202fa1a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Release files / nhs_dmd-0.3.0b0-py3-none-any.whl
| Download URL | nhs_dmd-0.3.0b0-py3-none-any.whl |
|---|---|
| Size | 97.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0307391828c5ad6ddfb289f2f2dcafbca72dece8c22fa8251989d0fb02aeb5a2
|
|
BLAKE2b-256 checksum How to use checksums |
776d7b0aceae1cd56f2f0355d5a6cc037a82dd11c5da8b8e6cea4abd42093764
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|