Most teams that come to Oushodh already have a medicine list: an item table in a POS, a product master in an ERP, a spreadsheet kept by the pharmacist, or a list copied from another site years ago. This post shows how to move that list onto Oushodh IDs from a CSV export, with a script you can run today, and without changing a record you hold.
What does moving to the API change in your data?
Less than you might expect. Your item codes, stock, selling prices, sales and invoices stay as they are. Each item gains the uuid of the Oushodh medicine it is, and the screens that show medicine details read them live with GET /v1/medicines/{uuid}.
The migration guide walks the five steps with screenshots of the member portal. This post covers the part most teams write themselves: the matching run.
What should the export look like?
One row per item, with your own code and the four things that tell medicines apart: brand, strength, dosage form and maker. Any other columns, such as your price, ride along untouched.
sku,brand,strength,form,maker,price
1001,Napa,500 mg,Tab,Beximco,1.20
1002,Napa,120mg/5ml,Susp,Beximco,35
1003,Seclo,20 mg,Cap,Square,7
1004,Shop bag,,,,5
Export the item table as it is today, and keep that file: it is your backup of the list before the move.
How does the script match each item?
It searches each item’s brand, and keeps only the answers whose strength, dosage form and maker fit your row. Search matches the start of words in the brand, an alternate name, the generic and the maker, but not the strength, so that check happens in your code. It saves the uuid only when exactly one medicine fits.
import csv
import os
import sys
import time
import requests
API = "https://api.oushodh.dev/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['OUSHODH_API_KEY']}"}
# Your own short forms, expanded before comparing.
SHORT = {"tab": "tablet", "cap": "capsule", "syp": "syrup", "inj": "injection", "susp": "suspension"}
def squash(s):
return "".join((s or "").lower().split())
def form(s):
s = squash(s).rstrip(".")
return SHORT.get(s, s)
def search(q):
while True:
r = requests.get(f"{API}/medicines/search", headers=HEADERS,
params={"q": q, "limit": 50}, timeout=10)
if r.status_code == 429:
time.sleep(int(r.headers.get("Retry-After", "60")))
continue
r.raise_for_status()
return r.json()["items"]
def fits(row):
return [m["uuid"] for m in search(row["brand"])
if squash(m["brand"]) == squash(row["brand"])
and squash(m["strength"]) == squash(row["strength"])
and squash(m["dosage_form"]) == form(row["form"])
and squash((m["manufacturer"] or {}).get("name")).startswith(squash(row["maker"]))]
src, out = sys.argv[1], sys.argv[2]
with open(src, newline="", encoding="utf-8") as f:
rows = list(csv.DictReader(f))
done = {}
if os.path.exists(out):
with open(out, newline="", encoding="utf-8") as f:
done = {r["sku"]: r for r in csv.DictReader(f)}
fields = list(rows[0]) + ["oushodh_uuid", "match_status", "candidates"]
with open(out, "w", newline="", encoding="utf-8") as f:
w = csv.DictWriter(f, fieldnames=fields)
w.writeheader()
for row in rows:
if row["sku"] in done: # matched on an earlier run
w.writerow(done[row["sku"]])
continue
found = fits(row)
status = "matched" if len(found) == 1 else "review" if found else "none"
w.writerow({**row, "oushodh_uuid": found[0] if status == "matched" else "",
"match_status": status, "candidates": " ".join(found) if status == "review" else ""})
f.flush()
Run it with your key in the environment, never in the file:
export OUSHODH_API_KEY=oush_...
python match.py items.csv items-matched.csv
On the four rows above, the output adds three columns:
sku,brand,strength,form,maker,price,oushodh_uuid,match_status,candidates
1001,Napa,500 mg,Tab,Beximco,1.20,01a1ba6f-f4d6-7143-ac84-9376f520eef8,matched,
1002,Napa,120mg/5ml,Susp,Beximco,35,01a1ba6f-fc33-7121-ac9c-a2b5ca7005e8,matched,
1003,Seclo,20 mg,Cap,Square,7,01a1ba6f-f71d-74e9-9b5d-7078fe508a55,matched,
1004,Shop bag,,,,5,,none,
squash drops spaces and case, so 120mg/5ml and 120 mg/5 ml compare equal. SHORT expands your own short forms: add the ones your records use. Napa comes as both a syrup and a suspension at 120 mg/5 ml, and the form keeps them apart.
What if the run stops halfway?
Run it again with the same two files. Rows already in the output are copied across without a new search, so the run picks up where it stopped and no request is spent twice. On a 429 answer the script waits the seconds in Retry-After, then goes on.
A Developer key makes up to 60 requests a minute, so 3,000 items take at least 50 minutes and use 3,000 of the month’s 50,000 requests. Try the first few hundred on a test app’s key, which runs at 10 a minute, before you run the whole list. The rate limits page has every plan’s numbers.
What happens to the rows that did not match?
review rows list the candidates’ uuids, and a person picks one, or none. none rows are often not medicines at all, like the shop bag, or are spelled so differently that a search by the generic finds them. A few are not in the data yet. All of them keep working in your system, unmapped.
Never take the first search result because it comes first. Rank says which name matched best, not which medicine is on your shelf. Connecting your inventory has the matching rules in more detail.
How do you load the result back?
Import oushodh_uuid and match_status into the two empty columns you added, by sku. Do not import anything else: the file holds IDs and your own data only, and the terms of use let you store medicine IDs with no time limit, but not the medicine records. Then switch the screens over behind a setting, as the migration guide shows, so turning it off puts everything back as it was.