Spaces:
Paused
Paused
File size: 1,018 Bytes
12f2295 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#!/usr/bin/env python3
import sqlite3, csv, argparse
from metaphone import doublemetaphone
import sys, os
sys.path.append(os.getcwd())
from config import DB_PATH, RXNORM_CSV
def build_db(db_path: str, csv_path: str):
conn = sqlite3.connect(db_path)
c = conn.cursor()
c.execute("DROP TABLE IF EXISTS drugs")
c.execute("DROP TABLE IF EXISTS metaphone")
c.execute("CREATE TABLE drugs(name TEXT PRIMARY KEY, cui TEXT)")
c.execute("CREATE TABLE metaphone(meta TEXT, name TEXT, cui TEXT)")
with open(csv_path, newline='', encoding='utf-8') as f:
reader = csv.DictReader(f)
for row in reader:
nm, cui = row['name'], row['cui']
c.execute("INSERT OR IGNORE INTO drugs VALUES(?,?)", (nm, cui))
meta = doublemetaphone(nm)[0]
c.execute("INSERT INTO metaphone VALUES(?,?,?)", (meta, nm, cui))
conn.commit()
conn.close()
if __name__ == "__main__":
build_db(DB_PATH, RXNORM_CSV)
print(f"✅ RxNorm DB built at {DB_PATH}")
|